UNPKG

618 kBJavaScriptView Raw
1/** @license React v16.11.0
2 * react-art.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
13
14if (process.env.NODE_ENV !== "production") {
15 (function() {
16'use strict';
17
18var React = require('react');
19var _assign = require('object-assign');
20var Transform = require('art/core/transform');
21var Mode = require('art/modes/current');
22var checkPropTypes = require('prop-types/checkPropTypes');
23var Scheduler = require('scheduler');
24var tracing = require('scheduler/tracing');
25var FastNoSideEffects = require('art/modes/fast-noSideEffects');
26
27function _extends() {
28 _extends = Object.assign || function (target) {
29 for (var i = 1; i < arguments.length; i++) {
30 var source = arguments[i];
31
32 for (var key in source) {
33 if (Object.prototype.hasOwnProperty.call(source, key)) {
34 target[key] = source[key];
35 }
36 }
37 }
38
39 return target;
40 };
41
42 return _extends.apply(this, arguments);
43}
44
45function _inheritsLoose(subClass, superClass) {
46 subClass.prototype = Object.create(superClass.prototype);
47 subClass.prototype.constructor = subClass;
48 subClass.__proto__ = superClass;
49}
50
51function _assertThisInitialized(self) {
52 if (self === void 0) {
53 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
54 }
55
56 return self;
57}
58
59// TODO: this is special because it gets imported during build.
60
61var ReactVersion = '16.11.0';
62
63var LegacyRoot = 0;
64var BatchedRoot = 1;
65var ConcurrentRoot = 2;
66
67// Do not require this module directly! Use normal `invariant` calls with
68// template literal strings. The messages will be replaced with error codes
69// during build.
70
71var FunctionComponent = 0;
72var ClassComponent = 1;
73var IndeterminateComponent = 2; // Before we know whether it is function or class
74
75var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
76
77var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
78
79var HostComponent = 5;
80var HostText = 6;
81var Fragment = 7;
82var Mode$1 = 8;
83var ContextConsumer = 9;
84var ContextProvider = 10;
85var ForwardRef = 11;
86var Profiler = 12;
87var SuspenseComponent = 13;
88var MemoComponent = 14;
89var SimpleMemoComponent = 15;
90var LazyComponent = 16;
91var IncompleteClassComponent = 17;
92var DehydratedFragment = 18;
93var SuspenseListComponent = 19;
94var FundamentalComponent = 20;
95var ScopeComponent = 21;
96
97/**
98 * Use invariant() to assert state which your program assumes to be true.
99 *
100 * Provide sprintf-style format (only %s is supported) and arguments
101 * to provide information about what broke and what you were
102 * expecting.
103 *
104 * The invariant message will be stripped in production, but the invariant
105 * will remain to ensure logic does not differ in production.
106 */
107
108/**
109 * Similar to invariant but only logs a warning if the condition is not met.
110 * This can be used to log issues in development environments in critical
111 * paths. Removing the logging code for production environments will keep the
112 * same logic and follow the same code paths.
113 */
114var warningWithoutStack = function () {};
115
116{
117 warningWithoutStack = function (condition, format) {
118 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
119 args[_key - 2] = arguments[_key];
120 }
121
122 if (format === undefined) {
123 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
124 }
125
126 if (args.length > 8) {
127 // Check before the condition to catch violations early.
128 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
129 }
130
131 if (condition) {
132 return;
133 }
134
135 if (typeof console !== 'undefined') {
136 var argsWithFormat = args.map(function (item) {
137 return '' + item;
138 });
139 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
140 // breaks IE9: https://github.com/facebook/react/issues/13610
141
142 Function.prototype.apply.call(console.error, console, argsWithFormat);
143 }
144
145 try {
146 // --- Welcome to debugging React ---
147 // This error was thrown as a convenience so that you can use this stack
148 // to find the callsite that caused this warning to fire.
149 var argIndex = 0;
150 var message = 'Warning: ' + format.replace(/%s/g, function () {
151 return args[argIndex++];
152 });
153 throw new Error(message);
154 } catch (x) {}
155 };
156}
157
158var warningWithoutStack$1 = warningWithoutStack;
159
160/**
161 * `ReactInstanceMap` maintains a mapping from a public facing stateful
162 * instance (key) and the internal representation (value). This allows public
163 * methods to accept the user facing instance as an argument and map them back
164 * to internal methods.
165 *
166 * Note that this module is currently shared and assumed to be stateless.
167 * If this becomes an actual Map, that will break.
168 */
169
170/**
171 * This API should be called `delete` but we'd have to make sure to always
172 * transform these to strings for IE support. When this transform is fully
173 * supported we can rename it.
174 */
175
176function get(key) {
177 return key._reactInternalFiber;
178}
179
180function set$1(key, value) {
181 key._reactInternalFiber = value;
182}
183
184var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
185// Current owner and dispatcher used to share the same ref,
186// but PR #14548 split them out to better support the react-debug-tools package.
187
188if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
189 ReactSharedInternals.ReactCurrentDispatcher = {
190 current: null
191 };
192}
193
194if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
195 ReactSharedInternals.ReactCurrentBatchConfig = {
196 suspense: null
197 };
198}
199
200// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
201// nor polyfill, then a plain number is used for performance.
202var hasSymbol = typeof Symbol === 'function' && Symbol.for;
203var REACT_ELEMENT_TYPE$1 = hasSymbol ? Symbol.for('react.element') : 0xeac7;
204var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
205var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
206var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
207var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
208var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
209var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
210// (unstable) APIs that have been removed. Can we remove the symbols?
211
212
213var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
214var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
215var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
216var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
217var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
218var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
219var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
220var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
221var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
222var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
223var FAUX_ITERATOR_SYMBOL = '@@iterator';
224function getIteratorFn(maybeIterable) {
225 if (maybeIterable === null || typeof maybeIterable !== 'object') {
226 return null;
227 }
228
229 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
230
231 if (typeof maybeIterator === 'function') {
232 return maybeIterator;
233 }
234
235 return null;
236}
237
238/**
239 * Similar to invariant but only logs a warning if the condition is not met.
240 * This can be used to log issues in development environments in critical
241 * paths. Removing the logging code for production environments will keep the
242 * same logic and follow the same code paths.
243 */
244
245var warning = warningWithoutStack$1;
246
247{
248 warning = function (condition, format) {
249 if (condition) {
250 return;
251 }
252
253 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
254 var stack = ReactDebugCurrentFrame.getStackAddendum(); // eslint-disable-next-line react-internal/warning-and-invariant-args
255
256 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
257 args[_key - 2] = arguments[_key];
258 }
259
260 warningWithoutStack$1.apply(void 0, [false, format + '%s'].concat(args, [stack]));
261 };
262}
263
264var warning$1 = warning;
265
266var Uninitialized = -1;
267var Pending = 0;
268var Resolved = 1;
269var Rejected = 2;
270function refineResolvedLazyComponent(lazyComponent) {
271 return lazyComponent._status === Resolved ? lazyComponent._result : null;
272}
273function initializeLazyComponentType(lazyComponent) {
274 if (lazyComponent._status === Uninitialized) {
275 lazyComponent._status = Pending;
276 var ctor = lazyComponent._ctor;
277 var thenable = ctor();
278 lazyComponent._result = thenable;
279 thenable.then(function (moduleObject) {
280 if (lazyComponent._status === Pending) {
281 var defaultExport = moduleObject.default;
282
283 {
284 if (defaultExport === undefined) {
285 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);
286 }
287 }
288
289 lazyComponent._status = Resolved;
290 lazyComponent._result = defaultExport;
291 }
292 }, function (error) {
293 if (lazyComponent._status === Pending) {
294 lazyComponent._status = Rejected;
295 lazyComponent._result = error;
296 }
297 });
298 }
299}
300
301function getWrappedName(outerType, innerType, wrapperName) {
302 var functionName = innerType.displayName || innerType.name || '';
303 return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
304}
305
306function getComponentName(type) {
307 if (type == null) {
308 // Host root, text node or just invalid type.
309 return null;
310 }
311
312 {
313 if (typeof type.tag === 'number') {
314 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
315 }
316 }
317
318 if (typeof type === 'function') {
319 return type.displayName || type.name || null;
320 }
321
322 if (typeof type === 'string') {
323 return type;
324 }
325
326 switch (type) {
327 case REACT_FRAGMENT_TYPE:
328 return 'Fragment';
329
330 case REACT_PORTAL_TYPE:
331 return 'Portal';
332
333 case REACT_PROFILER_TYPE:
334 return "Profiler";
335
336 case REACT_STRICT_MODE_TYPE:
337 return 'StrictMode';
338
339 case REACT_SUSPENSE_TYPE:
340 return 'Suspense';
341
342 case REACT_SUSPENSE_LIST_TYPE:
343 return 'SuspenseList';
344 }
345
346 if (typeof type === 'object') {
347 switch (type.$$typeof) {
348 case REACT_CONTEXT_TYPE:
349 return 'Context.Consumer';
350
351 case REACT_PROVIDER_TYPE:
352 return 'Context.Provider';
353
354 case REACT_FORWARD_REF_TYPE:
355 return getWrappedName(type, type.render, 'ForwardRef');
356
357 case REACT_MEMO_TYPE:
358 return getComponentName(type.type);
359
360 case REACT_LAZY_TYPE:
361 {
362 var thenable = type;
363 var resolvedThenable = refineResolvedLazyComponent(thenable);
364
365 if (resolvedThenable) {
366 return getComponentName(resolvedThenable);
367 }
368
369 break;
370 }
371 }
372 }
373
374 return null;
375}
376
377// Don't change these two values. They're used by React Dev Tools.
378var NoEffect =
379/* */
3800;
381var PerformedWork =
382/* */
3831; // You can change the rest (and add more).
384
385var Placement =
386/* */
3872;
388var Update =
389/* */
3904;
391var PlacementAndUpdate =
392/* */
3936;
394var Deletion =
395/* */
3968;
397var ContentReset =
398/* */
39916;
400var Callback =
401/* */
40232;
403var DidCapture =
404/* */
40564;
406var Ref =
407/* */
408128;
409var Snapshot =
410/* */
411256;
412var Passive =
413/* */
414512;
415var Hydrating =
416/* */
4171024;
418var HydratingAndUpdate =
419/* */
4201028; // Passive & Update & Callback & Ref & Snapshot
421
422var LifecycleEffectMask =
423/* */
424932; // Union of all host effects
425
426var HostEffectMask =
427/* */
4282047;
429var Incomplete =
430/* */
4312048;
432var ShouldCapture =
433/* */
4344096;
435
436var enableUserTimingAPI = true; // Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
437
438var debugRenderPhaseSideEffects = false; // In some cases, StrictMode should also double-render lifecycles.
439// This can be confusing for tests though,
440// And it can be bad for performance in production.
441// This feature flag can be used to control the behavior:
442
443var debugRenderPhaseSideEffectsForStrictMode = true; // To preserve the "Pause on caught exceptions" behavior of the debugger, we
444// replay the begin phase of a failed component inside invokeGuardedCallback.
445
446var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; // Warn about deprecated, async-unsafe lifecycles; relates to RFC #6:
447
448var warnAboutDeprecatedLifecycles = true; // Gather advanced timing metrics for Profiler subtrees.
449
450var enableProfilerTimer = true; // Trace which interactions trigger each commit.
451
452var enableSchedulerTracing = true; // SSR experiments
453
454var enableSuspenseServerRenderer = false;
455 // Only used in www builds.
456
457 // Only used in www builds.
458
459 // Disable javascript: URL strings in href for XSS protection.
460
461 // React Fire: prevent the value and checked attributes from syncing
462// with their related DOM properties
463
464 // These APIs will no longer be "unstable" in the upcoming 16.7 release,
465// Control this behavior with a flag to support 16.6 minor releases in the meanwhile.
466
467
468 // Experimental React Flare event system and event components support.
469
470var enableFlareAPI = false; // Experimental Host Component support.
471
472var enableFundamentalAPI = false; // Experimental Scope support.
473
474var enableScopeAPI = false; // New API for JSX transforms to target - https://github.com/reactjs/rfcs/pull/107
475
476 // We will enforce mocking scheduler with scheduler/unstable_mock at some point. (v17?)
477// Till then, we warn about the missing mock, but still fallback to a sync mode compatible version
478
479var warnAboutUnmockedScheduler = false; // For tests, we flush suspense fallbacks in an act scope;
480// *except* in some of our own tests, where we test incremental loading states.
481
482var flushSuspenseFallbacksInTests = true; // Add a callback property to suspense to notify which promises are currently
483// in the update queue. This allows reporting and tracing of what is causing
484// the user to see a loading state.
485// Also allows hydration callbacks to fire when a dehydrated boundary gets
486// hydrated or deleted.
487
488var enableSuspenseCallback = false; // Part of the simplification of React.createElement so we can eventually move
489// from React.createElement to React.jsx
490// https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md
491
492var warnAboutDefaultPropsOnFunctionComponents = false;
493var warnAboutStringRefs = false;
494var disableLegacyContext = false;
495var disableSchedulerTimeoutBasedOnReactExpirationTime = false;
496
497var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
498function getNearestMountedFiber(fiber) {
499 var node = fiber;
500 var nearestMounted = fiber;
501
502 if (!fiber.alternate) {
503 // If there is no alternate, this might be a new tree that isn't inserted
504 // yet. If it is, then it will have a pending insertion effect on it.
505 var nextNode = node;
506
507 do {
508 node = nextNode;
509
510 if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
511 // This is an insertion or in-progress hydration. The nearest possible
512 // mounted fiber is the parent but we need to continue to figure out
513 // if that one is still mounted.
514 nearestMounted = node.return;
515 }
516
517 nextNode = node.return;
518 } while (nextNode);
519 } else {
520 while (node.return) {
521 node = node.return;
522 }
523 }
524
525 if (node.tag === HostRoot) {
526 // TODO: Check if this was a nested HostRoot when used with
527 // renderContainerIntoSubtree.
528 return nearestMounted;
529 } // If we didn't hit the root, that means that we're in an disconnected tree
530 // that has been unmounted.
531
532
533 return null;
534}
535
536
537function isFiberMounted(fiber) {
538 return getNearestMountedFiber(fiber) === fiber;
539}
540function isMounted(component) {
541 {
542 var owner = ReactCurrentOwner.current;
543
544 if (owner !== null && owner.tag === ClassComponent) {
545 var ownerFiber = owner;
546 var instance = ownerFiber.stateNode;
547 !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;
548 instance._warnedAboutRefsInRender = true;
549 }
550 }
551
552 var fiber = get(component);
553
554 if (!fiber) {
555 return false;
556 }
557
558 return getNearestMountedFiber(fiber) === fiber;
559}
560
561function assertIsMounted(fiber) {
562 if (!(getNearestMountedFiber(fiber) === fiber)) {
563 {
564 throw Error("Unable to find node on an unmounted component.");
565 }
566 }
567}
568
569function findCurrentFiberUsingSlowPath(fiber) {
570 var alternate = fiber.alternate;
571
572 if (!alternate) {
573 // If there is no alternate, then we only need to check if it is mounted.
574 var nearestMounted = getNearestMountedFiber(fiber);
575
576 if (!(nearestMounted !== null)) {
577 {
578 throw Error("Unable to find node on an unmounted component.");
579 }
580 }
581
582 if (nearestMounted !== fiber) {
583 return null;
584 }
585
586 return fiber;
587 } // If we have two possible branches, we'll walk backwards up to the root
588 // to see what path the root points to. On the way we may hit one of the
589 // special cases and we'll deal with them.
590
591
592 var a = fiber;
593 var b = alternate;
594
595 while (true) {
596 var parentA = a.return;
597
598 if (parentA === null) {
599 // We're at the root.
600 break;
601 }
602
603 var parentB = parentA.alternate;
604
605 if (parentB === null) {
606 // There is no alternate. This is an unusual case. Currently, it only
607 // happens when a Suspense component is hidden. An extra fragment fiber
608 // is inserted in between the Suspense fiber and its children. Skip
609 // over this extra fragment fiber and proceed to the next parent.
610 var nextParent = parentA.return;
611
612 if (nextParent !== null) {
613 a = b = nextParent;
614 continue;
615 } // If there's no parent, we're at the root.
616
617
618 break;
619 } // If both copies of the parent fiber point to the same child, we can
620 // assume that the child is current. This happens when we bailout on low
621 // priority: the bailed out fiber's child reuses the current child.
622
623
624 if (parentA.child === parentB.child) {
625 var child = parentA.child;
626
627 while (child) {
628 if (child === a) {
629 // We've determined that A is the current branch.
630 assertIsMounted(parentA);
631 return fiber;
632 }
633
634 if (child === b) {
635 // We've determined that B is the current branch.
636 assertIsMounted(parentA);
637 return alternate;
638 }
639
640 child = child.sibling;
641 } // We should never have an alternate for any mounting node. So the only
642 // way this could possibly happen is if this was unmounted, if at all.
643
644
645 {
646 {
647 throw Error("Unable to find node on an unmounted component.");
648 }
649 }
650 }
651
652 if (a.return !== b.return) {
653 // The return pointer of A and the return pointer of B point to different
654 // fibers. We assume that return pointers never criss-cross, so A must
655 // belong to the child set of A.return, and B must belong to the child
656 // set of B.return.
657 a = parentA;
658 b = parentB;
659 } else {
660 // The return pointers point to the same fiber. We'll have to use the
661 // default, slow path: scan the child sets of each parent alternate to see
662 // which child belongs to which set.
663 //
664 // Search parent A's child set
665 var didFindChild = false;
666 var _child = parentA.child;
667
668 while (_child) {
669 if (_child === a) {
670 didFindChild = true;
671 a = parentA;
672 b = parentB;
673 break;
674 }
675
676 if (_child === b) {
677 didFindChild = true;
678 b = parentA;
679 a = parentB;
680 break;
681 }
682
683 _child = _child.sibling;
684 }
685
686 if (!didFindChild) {
687 // Search parent B's child set
688 _child = parentB.child;
689
690 while (_child) {
691 if (_child === a) {
692 didFindChild = true;
693 a = parentB;
694 b = parentA;
695 break;
696 }
697
698 if (_child === b) {
699 didFindChild = true;
700 b = parentB;
701 a = parentA;
702 break;
703 }
704
705 _child = _child.sibling;
706 }
707
708 if (!didFindChild) {
709 {
710 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.");
711 }
712 }
713 }
714 }
715
716 if (!(a.alternate === b)) {
717 {
718 throw Error("Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue.");
719 }
720 }
721 } // If the root is not a host container, we're in a disconnected tree. I.e.
722 // unmounted.
723
724
725 if (!(a.tag === HostRoot)) {
726 {
727 throw Error("Unable to find node on an unmounted component.");
728 }
729 }
730
731 if (a.stateNode.current === a) {
732 // We've determined that A is the current branch.
733 return fiber;
734 } // Otherwise B has to be current branch.
735
736
737 return alternate;
738}
739function findCurrentHostFiber(parent) {
740 var currentParent = findCurrentFiberUsingSlowPath(parent);
741
742 if (!currentParent) {
743 return null;
744 } // Next we'll drill down this component to find the first HostComponent/Text.
745
746
747 var node = currentParent;
748
749 while (true) {
750 if (node.tag === HostComponent || node.tag === HostText) {
751 return node;
752 } else if (node.child) {
753 node.child.return = node;
754 node = node.child;
755 continue;
756 }
757
758 if (node === currentParent) {
759 return null;
760 }
761
762 while (!node.sibling) {
763 if (!node.return || node.return === currentParent) {
764 return null;
765 }
766
767 node = node.return;
768 }
769
770 node.sibling.return = node.return;
771 node = node.sibling;
772 } // Flow needs the return null here, but ESLint complains about it.
773 // eslint-disable-next-line no-unreachable
774
775
776 return null;
777}
778
779var TYPES = {
780 CLIPPING_RECTANGLE: 'ClippingRectangle',
781 GROUP: 'Group',
782 SHAPE: 'Shape',
783 TEXT: 'Text'
784};
785var EVENT_TYPES = {
786 onClick: 'click',
787 onMouseMove: 'mousemove',
788 onMouseOver: 'mouseover',
789 onMouseOut: 'mouseout',
790 onMouseUp: 'mouseup',
791 onMouseDown: 'mousedown'
792};
793function childrenAsString(children) {
794 if (!children) {
795 return '';
796 } else if (typeof children === 'string') {
797 return children;
798 } else if (children.length) {
799 return children.join('');
800 } else {
801 return '';
802 }
803}
804
805// can re-export everything from this module.
806
807function shim() {
808 {
809 {
810 throw Error("The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.");
811 }
812 }
813} // Persistence (when unsupported)
814
815
816var supportsPersistence = false;
817var cloneInstance = shim;
818var cloneFundamentalInstance = shim;
819var createContainerChildSet = shim;
820var appendChildToContainerChildSet = shim;
821var finalizeContainerChildren = shim;
822var replaceContainerChildren = shim;
823var cloneHiddenInstance = shim;
824var cloneHiddenTextInstance = shim;
825
826// can re-export everything from this module.
827
828function shim$1() {
829 {
830 {
831 throw Error("The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.");
832 }
833 }
834} // Hydration (when unsupported)
835
836
837var supportsHydration = false;
838var canHydrateInstance = shim$1;
839var canHydrateTextInstance = shim$1;
840var canHydrateSuspenseInstance = shim$1;
841var isSuspenseInstancePending = shim$1;
842var isSuspenseInstanceFallback = shim$1;
843var registerSuspenseInstanceRetry = shim$1;
844var getNextHydratableSibling = shim$1;
845var getFirstHydratableChild = shim$1;
846var hydrateInstance = shim$1;
847var hydrateTextInstance = shim$1;
848var hydrateSuspenseInstance = shim$1;
849var getNextHydratableInstanceAfterSuspenseInstance = shim$1;
850var commitHydratedContainer = shim$1;
851var commitHydratedSuspenseInstance = shim$1;
852var clearSuspenseBoundary = shim$1;
853var clearSuspenseBoundaryFromContainer = shim$1;
854var didNotMatchHydratedContainerTextInstance = shim$1;
855var didNotMatchHydratedTextInstance = shim$1;
856var didNotHydrateContainerInstance = shim$1;
857var didNotHydrateInstance = shim$1;
858var didNotFindHydratableContainerInstance = shim$1;
859var didNotFindHydratableContainerTextInstance = shim$1;
860var didNotFindHydratableContainerSuspenseInstance = shim$1;
861var didNotFindHydratableInstance = shim$1;
862var didNotFindHydratableTextInstance = shim$1;
863var didNotFindHydratableSuspenseInstance = shim$1;
864
865var pooledTransform = new Transform();
866var NO_CONTEXT = {};
867var UPDATE_SIGNAL = {};
868
869{
870 Object.freeze(NO_CONTEXT);
871 Object.freeze(UPDATE_SIGNAL);
872}
873/** Helper Methods */
874
875
876function addEventListeners(instance, type, listener) {
877 // We need to explicitly unregister before unmount.
878 // For this reason we need to track subscriptions.
879 if (!instance._listeners) {
880 instance._listeners = {};
881 instance._subscriptions = {};
882 }
883
884 instance._listeners[type] = listener;
885
886 if (listener) {
887 if (!instance._subscriptions[type]) {
888 instance._subscriptions[type] = instance.subscribe(type, createEventHandler(instance), instance);
889 }
890 } else {
891 if (instance._subscriptions[type]) {
892 instance._subscriptions[type]();
893
894 delete instance._subscriptions[type];
895 }
896 }
897}
898
899function createEventHandler(instance) {
900 return function handleEvent(event) {
901 var listener = instance._listeners[event.type];
902
903 if (!listener) {// Noop
904 } else if (typeof listener === 'function') {
905 listener.call(instance, event);
906 } else if (listener.handleEvent) {
907 listener.handleEvent(event);
908 }
909 };
910}
911
912function destroyEventListeners(instance) {
913 if (instance._subscriptions) {
914 for (var type in instance._subscriptions) {
915 instance._subscriptions[type]();
916 }
917 }
918
919 instance._subscriptions = null;
920 instance._listeners = null;
921}
922
923function getScaleX(props) {
924 if (props.scaleX != null) {
925 return props.scaleX;
926 } else if (props.scale != null) {
927 return props.scale;
928 } else {
929 return 1;
930 }
931}
932
933function getScaleY(props) {
934 if (props.scaleY != null) {
935 return props.scaleY;
936 } else if (props.scale != null) {
937 return props.scale;
938 } else {
939 return 1;
940 }
941}
942
943function isSameFont(oldFont, newFont) {
944 if (oldFont === newFont) {
945 return true;
946 } else if (typeof newFont === 'string' || typeof oldFont === 'string') {
947 return false;
948 } else {
949 return newFont.fontSize === oldFont.fontSize && newFont.fontStyle === oldFont.fontStyle && newFont.fontVariant === oldFont.fontVariant && newFont.fontWeight === oldFont.fontWeight && newFont.fontFamily === oldFont.fontFamily;
950 }
951}
952/** Render Methods */
953
954
955function applyClippingRectangleProps(instance, props) {
956 var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
957 applyNodeProps(instance, props, prevProps);
958 instance.width = props.width;
959 instance.height = props.height;
960}
961
962function applyGroupProps(instance, props) {
963 var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
964 applyNodeProps(instance, props, prevProps);
965 instance.width = props.width;
966 instance.height = props.height;
967}
968
969function applyNodeProps(instance, props) {
970 var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
971 var scaleX = getScaleX(props);
972 var scaleY = getScaleY(props);
973 pooledTransform.transformTo(1, 0, 0, 1, 0, 0).move(props.x || 0, props.y || 0).rotate(props.rotation || 0, props.originX, props.originY).scale(scaleX, scaleY, props.originX, props.originY);
974
975 if (props.transform != null) {
976 pooledTransform.transform(props.transform);
977 }
978
979 if (instance.xx !== pooledTransform.xx || instance.yx !== pooledTransform.yx || instance.xy !== pooledTransform.xy || instance.yy !== pooledTransform.yy || instance.x !== pooledTransform.x || instance.y !== pooledTransform.y) {
980 instance.transformTo(pooledTransform);
981 }
982
983 if (props.cursor !== prevProps.cursor || props.title !== prevProps.title) {
984 instance.indicate(props.cursor, props.title);
985 }
986
987 if (instance.blend && props.opacity !== prevProps.opacity) {
988 instance.blend(props.opacity == null ? 1 : props.opacity);
989 }
990
991 if (props.visible !== prevProps.visible) {
992 if (props.visible == null || props.visible) {
993 instance.show();
994 } else {
995 instance.hide();
996 }
997 }
998
999 for (var type in EVENT_TYPES) {
1000 addEventListeners(instance, EVENT_TYPES[type], props[type]);
1001 }
1002}
1003
1004function applyRenderableNodeProps(instance, props) {
1005 var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1006 applyNodeProps(instance, props, prevProps);
1007
1008 if (prevProps.fill !== props.fill) {
1009 if (props.fill && props.fill.applyFill) {
1010 props.fill.applyFill(instance);
1011 } else {
1012 instance.fill(props.fill);
1013 }
1014 }
1015
1016 if (prevProps.stroke !== props.stroke || prevProps.strokeWidth !== props.strokeWidth || prevProps.strokeCap !== props.strokeCap || prevProps.strokeJoin !== props.strokeJoin || // TODO: Consider deep check of stokeDash; may benefit VML in IE.
1017 prevProps.strokeDash !== props.strokeDash) {
1018 instance.stroke(props.stroke, props.strokeWidth, props.strokeCap, props.strokeJoin, props.strokeDash);
1019 }
1020}
1021
1022function applyShapeProps(instance, props) {
1023 var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1024 applyRenderableNodeProps(instance, props, prevProps);
1025 var path = props.d || childrenAsString(props.children);
1026 var prevDelta = instance._prevDelta;
1027 var prevPath = instance._prevPath;
1028
1029 if (path !== prevPath || path.delta !== prevDelta || prevProps.height !== props.height || prevProps.width !== props.width) {
1030 instance.draw(path, props.width, props.height);
1031 instance._prevDelta = path.delta;
1032 instance._prevPath = path;
1033 }
1034}
1035
1036function applyTextProps(instance, props) {
1037 var prevProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1038 applyRenderableNodeProps(instance, props, prevProps);
1039 var string = props.children;
1040
1041 if (instance._currentString !== string || !isSameFont(props.font, prevProps.font) || props.alignment !== prevProps.alignment || props.path !== prevProps.path) {
1042 instance.draw(string, props.font, props.alignment, props.path);
1043 instance._currentString = string;
1044 }
1045}
1046
1047function appendInitialChild(parentInstance, child) {
1048 if (typeof child === 'string') {
1049 // Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
1050 {
1051 {
1052 throw Error("Text children should already be flattened.");
1053 }
1054 }
1055
1056 return;
1057 }
1058
1059 child.inject(parentInstance);
1060}
1061function createInstance(type, props, internalInstanceHandle) {
1062 var instance;
1063
1064 switch (type) {
1065 case TYPES.CLIPPING_RECTANGLE:
1066 instance = Mode.ClippingRectangle();
1067 instance._applyProps = applyClippingRectangleProps;
1068 break;
1069
1070 case TYPES.GROUP:
1071 instance = Mode.Group();
1072 instance._applyProps = applyGroupProps;
1073 break;
1074
1075 case TYPES.SHAPE:
1076 instance = Mode.Shape();
1077 instance._applyProps = applyShapeProps;
1078 break;
1079
1080 case TYPES.TEXT:
1081 instance = Mode.Text(props.children, props.font, props.alignment, props.path);
1082 instance._applyProps = applyTextProps;
1083 break;
1084 }
1085
1086 if (!instance) {
1087 {
1088 throw Error("ReactART does not support the type \"" + type + "\"");
1089 }
1090 }
1091
1092 instance._applyProps(instance, props);
1093
1094 return instance;
1095}
1096function createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
1097 return text;
1098}
1099function finalizeInitialChildren(domElement, type, props) {
1100 return false;
1101}
1102function getPublicInstance(instance) {
1103 return instance;
1104}
1105function prepareForCommit() {// Noop
1106}
1107function prepareUpdate(domElement, type, oldProps, newProps) {
1108 return UPDATE_SIGNAL;
1109}
1110function resetAfterCommit() {// Noop
1111}
1112function resetTextContent(domElement) {// Noop
1113}
1114function shouldDeprioritizeSubtree(type, props) {
1115 return false;
1116}
1117function getRootHostContext() {
1118 return NO_CONTEXT;
1119}
1120function getChildHostContext() {
1121 return NO_CONTEXT;
1122}
1123var scheduleTimeout = setTimeout;
1124var cancelTimeout = clearTimeout;
1125var noTimeout = -1;
1126function shouldSetTextContent(type, props) {
1127 return typeof props.children === 'string' || typeof props.children === 'number';
1128} // The ART renderer is secondary to the React DOM renderer.
1129
1130var isPrimaryRenderer = false; // The ART renderer shouldn't trigger missing act() warnings
1131
1132var warnsIfNotActing = false;
1133var supportsMutation = true;
1134function appendChild(parentInstance, child) {
1135 if (child.parentNode === parentInstance) {
1136 child.eject();
1137 }
1138
1139 child.inject(parentInstance);
1140}
1141function appendChildToContainer(parentInstance, child) {
1142 if (child.parentNode === parentInstance) {
1143 child.eject();
1144 }
1145
1146 child.inject(parentInstance);
1147}
1148function insertBefore(parentInstance, child, beforeChild) {
1149 if (!(child !== beforeChild)) {
1150 {
1151 throw Error("ReactART: Can not insert node before itself");
1152 }
1153 }
1154
1155 child.injectBefore(beforeChild);
1156}
1157function insertInContainerBefore(parentInstance, child, beforeChild) {
1158 if (!(child !== beforeChild)) {
1159 {
1160 throw Error("ReactART: Can not insert node before itself");
1161 }
1162 }
1163
1164 child.injectBefore(beforeChild);
1165}
1166function removeChild(parentInstance, child) {
1167 destroyEventListeners(child);
1168 child.eject();
1169}
1170function removeChildFromContainer(parentInstance, child) {
1171 destroyEventListeners(child);
1172 child.eject();
1173}
1174
1175
1176function commitUpdate(instance, updatePayload, type, oldProps, newProps) {
1177 instance._applyProps(instance, newProps, oldProps);
1178}
1179function hideInstance(instance) {
1180 instance.hide();
1181}
1182
1183function unhideInstance(instance, props) {
1184 if (props.visible == null || props.visible) {
1185 instance.show();
1186 }
1187}
1188function unhideTextInstance(textInstance, text) {// Noop
1189}
1190function mountResponderInstance(responder, responderInstance, props, state, instance) {
1191 throw new Error('Not yet implemented.');
1192}
1193function unmountResponderInstance(responderInstance) {
1194 throw new Error('Not yet implemented.');
1195}
1196function getFundamentalComponentInstance(fundamentalInstance) {
1197 throw new Error('Not yet implemented.');
1198}
1199function mountFundamentalComponent(fundamentalInstance) {
1200 throw new Error('Not yet implemented.');
1201}
1202function shouldUpdateFundamentalComponent(fundamentalInstance) {
1203 throw new Error('Not yet implemented.');
1204}
1205function updateFundamentalComponent(fundamentalInstance) {
1206 throw new Error('Not yet implemented.');
1207}
1208function unmountFundamentalComponent(fundamentalInstance) {
1209 throw new Error('Not yet implemented.');
1210}
1211function getInstanceFromNode(node) {
1212 throw new Error('Not yet implemented.');
1213}
1214
1215var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
1216var describeComponentFrame = function (name, source, ownerName) {
1217 var sourceInfo = '';
1218
1219 if (source) {
1220 var path = source.fileName;
1221 var fileName = path.replace(BEFORE_SLASH_RE, '');
1222
1223 {
1224 // In DEV, include code for a common special case:
1225 // prefer "folder/index.js" instead of just "index.js".
1226 if (/^index\./.test(fileName)) {
1227 var match = path.match(BEFORE_SLASH_RE);
1228
1229 if (match) {
1230 var pathBeforeSlash = match[1];
1231
1232 if (pathBeforeSlash) {
1233 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
1234 fileName = folderName + '/' + fileName;
1235 }
1236 }
1237 }
1238 }
1239
1240 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
1241 } else if (ownerName) {
1242 sourceInfo = ' (created by ' + ownerName + ')';
1243 }
1244
1245 return '\n in ' + (name || 'Unknown') + sourceInfo;
1246};
1247
1248var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1249
1250function describeFiber(fiber) {
1251 switch (fiber.tag) {
1252 case HostRoot:
1253 case HostPortal:
1254 case HostText:
1255 case Fragment:
1256 case ContextProvider:
1257 case ContextConsumer:
1258 return '';
1259
1260 default:
1261 var owner = fiber._debugOwner;
1262 var source = fiber._debugSource;
1263 var name = getComponentName(fiber.type);
1264 var ownerName = null;
1265
1266 if (owner) {
1267 ownerName = getComponentName(owner.type);
1268 }
1269
1270 return describeComponentFrame(name, source, ownerName);
1271 }
1272}
1273
1274function getStackByFiberInDevAndProd(workInProgress) {
1275 var info = '';
1276 var node = workInProgress;
1277
1278 do {
1279 info += describeFiber(node);
1280 node = node.return;
1281 } while (node);
1282
1283 return info;
1284}
1285var current = null;
1286var phase = null;
1287function getCurrentFiberOwnerNameInDevOrNull() {
1288 {
1289 if (current === null) {
1290 return null;
1291 }
1292
1293 var owner = current._debugOwner;
1294
1295 if (owner !== null && typeof owner !== 'undefined') {
1296 return getComponentName(owner.type);
1297 }
1298 }
1299
1300 return null;
1301}
1302function getCurrentFiberStackInDev() {
1303 {
1304 if (current === null) {
1305 return '';
1306 } // Safe because if current fiber exists, we are reconciling,
1307 // and it is guaranteed to be the work-in-progress version.
1308
1309
1310 return getStackByFiberInDevAndProd(current);
1311 }
1312
1313 return '';
1314}
1315function resetCurrentFiber() {
1316 {
1317 ReactDebugCurrentFrame.getCurrentStack = null;
1318 current = null;
1319 phase = null;
1320 }
1321}
1322function setCurrentFiber(fiber) {
1323 {
1324 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1325 current = fiber;
1326 phase = null;
1327 }
1328}
1329function setCurrentPhase(lifeCyclePhase) {
1330 {
1331 phase = lifeCyclePhase;
1332 }
1333}
1334
1335// Prefix measurements so that it's possible to filter them.
1336// Longer prefixes are hard to read in DevTools.
1337var reactEmoji = "\u269B";
1338var warningEmoji = "\u26D4";
1339var 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.
1340// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1341
1342var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
1343// Reusing `currentFiber` would be confusing for this because user code fiber
1344// can change during commit phase too, but we don't need to unwind it (since
1345// lifecycles in the commit phase don't resemble a tree).
1346
1347var currentPhase = null;
1348var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
1349// so we will keep track of it, and include it in the report.
1350// Track commits caused by cascading updates.
1351
1352var isCommitting = false;
1353var hasScheduledUpdateInCurrentCommit = false;
1354var hasScheduledUpdateInCurrentPhase = false;
1355var commitCountInCurrentWorkLoop = 0;
1356var effectCountInCurrentCommit = 0;
1357// to avoid stretch the commit phase with measurement overhead.
1358
1359var labelsInCurrentCommit = new Set();
1360
1361var formatMarkName = function (markName) {
1362 return reactEmoji + " " + markName;
1363};
1364
1365var formatLabel = function (label, warning) {
1366 var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
1367 var suffix = warning ? " Warning: " + warning : '';
1368 return "" + prefix + label + suffix;
1369};
1370
1371var beginMark = function (markName) {
1372 performance.mark(formatMarkName(markName));
1373};
1374
1375var clearMark = function (markName) {
1376 performance.clearMarks(formatMarkName(markName));
1377};
1378
1379var endMark = function (label, markName, warning) {
1380 var formattedMarkName = formatMarkName(markName);
1381 var formattedLabel = formatLabel(label, warning);
1382
1383 try {
1384 performance.measure(formattedLabel, formattedMarkName);
1385 } catch (err) {} // If previous mark was missing for some reason, this will throw.
1386 // This could only happen if React crashed in an unexpected place earlier.
1387 // Don't pile on with more errors.
1388 // Clear marks immediately to avoid growing buffer.
1389
1390
1391 performance.clearMarks(formattedMarkName);
1392 performance.clearMeasures(formattedLabel);
1393};
1394
1395var getFiberMarkName = function (label, debugID) {
1396 return label + " (#" + debugID + ")";
1397};
1398
1399var getFiberLabel = function (componentName, isMounted, phase) {
1400 if (phase === null) {
1401 // These are composite component total time measurements.
1402 return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
1403 } else {
1404 // Composite component methods.
1405 return componentName + "." + phase;
1406 }
1407};
1408
1409var beginFiberMark = function (fiber, phase) {
1410 var componentName = getComponentName(fiber.type) || 'Unknown';
1411 var debugID = fiber._debugID;
1412 var isMounted = fiber.alternate !== null;
1413 var label = getFiberLabel(componentName, isMounted, phase);
1414
1415 if (isCommitting && labelsInCurrentCommit.has(label)) {
1416 // During the commit phase, we don't show duplicate labels because
1417 // there is a fixed overhead for every measurement, and we don't
1418 // want to stretch the commit phase beyond necessary.
1419 return false;
1420 }
1421
1422 labelsInCurrentCommit.add(label);
1423 var markName = getFiberMarkName(label, debugID);
1424 beginMark(markName);
1425 return true;
1426};
1427
1428var clearFiberMark = function (fiber, phase) {
1429 var componentName = getComponentName(fiber.type) || 'Unknown';
1430 var debugID = fiber._debugID;
1431 var isMounted = fiber.alternate !== null;
1432 var label = getFiberLabel(componentName, isMounted, phase);
1433 var markName = getFiberMarkName(label, debugID);
1434 clearMark(markName);
1435};
1436
1437var endFiberMark = function (fiber, phase, warning) {
1438 var componentName = getComponentName(fiber.type) || 'Unknown';
1439 var debugID = fiber._debugID;
1440 var isMounted = fiber.alternate !== null;
1441 var label = getFiberLabel(componentName, isMounted, phase);
1442 var markName = getFiberMarkName(label, debugID);
1443 endMark(label, markName, warning);
1444};
1445
1446var shouldIgnoreFiber = function (fiber) {
1447 // Host components should be skipped in the timeline.
1448 // We could check typeof fiber.type, but does this work with RN?
1449 switch (fiber.tag) {
1450 case HostRoot:
1451 case HostComponent:
1452 case HostText:
1453 case HostPortal:
1454 case Fragment:
1455 case ContextProvider:
1456 case ContextConsumer:
1457 case Mode$1:
1458 return true;
1459
1460 default:
1461 return false;
1462 }
1463};
1464
1465var clearPendingPhaseMeasurement = function () {
1466 if (currentPhase !== null && currentPhaseFiber !== null) {
1467 clearFiberMark(currentPhaseFiber, currentPhase);
1468 }
1469
1470 currentPhaseFiber = null;
1471 currentPhase = null;
1472 hasScheduledUpdateInCurrentPhase = false;
1473};
1474
1475var pauseTimers = function () {
1476 // Stops all currently active measurements so that they can be resumed
1477 // if we continue in a later deferred loop from the same unit of work.
1478 var fiber = currentFiber;
1479
1480 while (fiber) {
1481 if (fiber._debugIsCurrentlyTiming) {
1482 endFiberMark(fiber, null, null);
1483 }
1484
1485 fiber = fiber.return;
1486 }
1487};
1488
1489var resumeTimersRecursively = function (fiber) {
1490 if (fiber.return !== null) {
1491 resumeTimersRecursively(fiber.return);
1492 }
1493
1494 if (fiber._debugIsCurrentlyTiming) {
1495 beginFiberMark(fiber, null);
1496 }
1497};
1498
1499var resumeTimers = function () {
1500 // Resumes all measurements that were active during the last deferred loop.
1501 if (currentFiber !== null) {
1502 resumeTimersRecursively(currentFiber);
1503 }
1504};
1505
1506function recordEffect() {
1507 if (enableUserTimingAPI) {
1508 effectCountInCurrentCommit++;
1509 }
1510}
1511function recordScheduleUpdate() {
1512 if (enableUserTimingAPI) {
1513 if (isCommitting) {
1514 hasScheduledUpdateInCurrentCommit = true;
1515 }
1516
1517 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1518 hasScheduledUpdateInCurrentPhase = true;
1519 }
1520 }
1521}
1522
1523
1524function startWorkTimer(fiber) {
1525 if (enableUserTimingAPI) {
1526 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1527 return;
1528 } // If we pause, this is the fiber to unwind from.
1529
1530
1531 currentFiber = fiber;
1532
1533 if (!beginFiberMark(fiber, null)) {
1534 return;
1535 }
1536
1537 fiber._debugIsCurrentlyTiming = true;
1538 }
1539}
1540function cancelWorkTimer(fiber) {
1541 if (enableUserTimingAPI) {
1542 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1543 return;
1544 } // Remember we shouldn't complete measurement for this fiber.
1545 // Otherwise flamechart will be deep even for small updates.
1546
1547
1548 fiber._debugIsCurrentlyTiming = false;
1549 clearFiberMark(fiber, null);
1550 }
1551}
1552function stopWorkTimer(fiber) {
1553 if (enableUserTimingAPI) {
1554 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1555 return;
1556 } // If we pause, its parent is the fiber to unwind from.
1557
1558
1559 currentFiber = fiber.return;
1560
1561 if (!fiber._debugIsCurrentlyTiming) {
1562 return;
1563 }
1564
1565 fiber._debugIsCurrentlyTiming = false;
1566 endFiberMark(fiber, null, null);
1567 }
1568}
1569function stopFailedWorkTimer(fiber) {
1570 if (enableUserTimingAPI) {
1571 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1572 return;
1573 } // If we pause, its parent is the fiber to unwind from.
1574
1575
1576 currentFiber = fiber.return;
1577
1578 if (!fiber._debugIsCurrentlyTiming) {
1579 return;
1580 }
1581
1582 fiber._debugIsCurrentlyTiming = false;
1583 var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1584 endFiberMark(fiber, null, warning);
1585 }
1586}
1587function startPhaseTimer(fiber, phase) {
1588 if (enableUserTimingAPI) {
1589 if (!supportsUserTiming) {
1590 return;
1591 }
1592
1593 clearPendingPhaseMeasurement();
1594
1595 if (!beginFiberMark(fiber, phase)) {
1596 return;
1597 }
1598
1599 currentPhaseFiber = fiber;
1600 currentPhase = phase;
1601 }
1602}
1603function stopPhaseTimer() {
1604 if (enableUserTimingAPI) {
1605 if (!supportsUserTiming) {
1606 return;
1607 }
1608
1609 if (currentPhase !== null && currentPhaseFiber !== null) {
1610 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1611 endFiberMark(currentPhaseFiber, currentPhase, warning);
1612 }
1613
1614 currentPhase = null;
1615 currentPhaseFiber = null;
1616 }
1617}
1618function startWorkLoopTimer(nextUnitOfWork) {
1619 if (enableUserTimingAPI) {
1620 currentFiber = nextUnitOfWork;
1621
1622 if (!supportsUserTiming) {
1623 return;
1624 }
1625
1626 commitCountInCurrentWorkLoop = 0; // This is top level call.
1627 // Any other measurements are performed within.
1628
1629 beginMark('(React Tree Reconciliation)'); // Resume any measurements that were in progress during the last loop.
1630
1631 resumeTimers();
1632 }
1633}
1634function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1635 if (enableUserTimingAPI) {
1636 if (!supportsUserTiming) {
1637 return;
1638 }
1639
1640 var warning = null;
1641
1642 if (interruptedBy !== null) {
1643 if (interruptedBy.tag === HostRoot) {
1644 warning = 'A top-level update interrupted the previous render';
1645 } else {
1646 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1647 warning = "An update to " + componentName + " interrupted the previous render";
1648 }
1649 } else if (commitCountInCurrentWorkLoop > 1) {
1650 warning = 'There were cascading updates';
1651 }
1652
1653 commitCountInCurrentWorkLoop = 0;
1654 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)'; // Pause any measurements until the next loop.
1655
1656 pauseTimers();
1657 endMark(label, '(React Tree Reconciliation)', warning);
1658 }
1659}
1660function startCommitTimer() {
1661 if (enableUserTimingAPI) {
1662 if (!supportsUserTiming) {
1663 return;
1664 }
1665
1666 isCommitting = true;
1667 hasScheduledUpdateInCurrentCommit = false;
1668 labelsInCurrentCommit.clear();
1669 beginMark('(Committing Changes)');
1670 }
1671}
1672function stopCommitTimer() {
1673 if (enableUserTimingAPI) {
1674 if (!supportsUserTiming) {
1675 return;
1676 }
1677
1678 var warning = null;
1679
1680 if (hasScheduledUpdateInCurrentCommit) {
1681 warning = 'Lifecycle hook scheduled a cascading update';
1682 } else if (commitCountInCurrentWorkLoop > 0) {
1683 warning = 'Caused by a cascading update in earlier commit';
1684 }
1685
1686 hasScheduledUpdateInCurrentCommit = false;
1687 commitCountInCurrentWorkLoop++;
1688 isCommitting = false;
1689 labelsInCurrentCommit.clear();
1690 endMark('(Committing Changes)', '(Committing Changes)', warning);
1691 }
1692}
1693function startCommitSnapshotEffectsTimer() {
1694 if (enableUserTimingAPI) {
1695 if (!supportsUserTiming) {
1696 return;
1697 }
1698
1699 effectCountInCurrentCommit = 0;
1700 beginMark('(Committing Snapshot Effects)');
1701 }
1702}
1703function stopCommitSnapshotEffectsTimer() {
1704 if (enableUserTimingAPI) {
1705 if (!supportsUserTiming) {
1706 return;
1707 }
1708
1709 var count = effectCountInCurrentCommit;
1710 effectCountInCurrentCommit = 0;
1711 endMark("(Committing Snapshot Effects: " + count + " Total)", '(Committing Snapshot Effects)', null);
1712 }
1713}
1714function startCommitHostEffectsTimer() {
1715 if (enableUserTimingAPI) {
1716 if (!supportsUserTiming) {
1717 return;
1718 }
1719
1720 effectCountInCurrentCommit = 0;
1721 beginMark('(Committing Host Effects)');
1722 }
1723}
1724function stopCommitHostEffectsTimer() {
1725 if (enableUserTimingAPI) {
1726 if (!supportsUserTiming) {
1727 return;
1728 }
1729
1730 var count = effectCountInCurrentCommit;
1731 effectCountInCurrentCommit = 0;
1732 endMark("(Committing Host Effects: " + count + " Total)", '(Committing Host Effects)', null);
1733 }
1734}
1735function startCommitLifeCyclesTimer() {
1736 if (enableUserTimingAPI) {
1737 if (!supportsUserTiming) {
1738 return;
1739 }
1740
1741 effectCountInCurrentCommit = 0;
1742 beginMark('(Calling Lifecycle Methods)');
1743 }
1744}
1745function stopCommitLifeCyclesTimer() {
1746 if (enableUserTimingAPI) {
1747 if (!supportsUserTiming) {
1748 return;
1749 }
1750
1751 var count = effectCountInCurrentCommit;
1752 effectCountInCurrentCommit = 0;
1753 endMark("(Calling Lifecycle Methods: " + count + " Total)", '(Calling Lifecycle Methods)', null);
1754 }
1755}
1756
1757var valueStack = [];
1758var fiberStack;
1759
1760{
1761 fiberStack = [];
1762}
1763
1764var index = -1;
1765
1766function createCursor(defaultValue) {
1767 return {
1768 current: defaultValue
1769 };
1770}
1771
1772function pop(cursor, fiber) {
1773 if (index < 0) {
1774 {
1775 warningWithoutStack$1(false, 'Unexpected pop.');
1776 }
1777
1778 return;
1779 }
1780
1781 {
1782 if (fiber !== fiberStack[index]) {
1783 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1784 }
1785 }
1786
1787 cursor.current = valueStack[index];
1788 valueStack[index] = null;
1789
1790 {
1791 fiberStack[index] = null;
1792 }
1793
1794 index--;
1795}
1796
1797function push(cursor, value, fiber) {
1798 index++;
1799 valueStack[index] = cursor.current;
1800
1801 {
1802 fiberStack[index] = fiber;
1803 }
1804
1805 cursor.current = value;
1806}
1807
1808var warnedAboutMissingGetChildContext;
1809
1810{
1811 warnedAboutMissingGetChildContext = {};
1812}
1813
1814var emptyContextObject = {};
1815
1816{
1817 Object.freeze(emptyContextObject);
1818} // A cursor to the current merged context object on the stack.
1819
1820
1821var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
1822
1823var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
1824// We use this to get access to the parent context after we have already
1825// pushed the next context provider, and now need to merge their contexts.
1826
1827var previousContext = emptyContextObject;
1828
1829function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1830 if (disableLegacyContext) {
1831 return emptyContextObject;
1832 } else {
1833 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1834 // If the fiber is a context provider itself, when we read its context
1835 // we may have already pushed its own child context on the stack. A context
1836 // provider should not "see" its own child context. Therefore we read the
1837 // previous (parent) context instead for a context provider.
1838 return previousContext;
1839 }
1840
1841 return contextStackCursor.current;
1842 }
1843}
1844
1845function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1846 if (disableLegacyContext) {
1847 return;
1848 } else {
1849 var instance = workInProgress.stateNode;
1850 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1851 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1852 }
1853}
1854
1855function getMaskedContext(workInProgress, unmaskedContext) {
1856 if (disableLegacyContext) {
1857 return emptyContextObject;
1858 } else {
1859 var type = workInProgress.type;
1860 var contextTypes = type.contextTypes;
1861
1862 if (!contextTypes) {
1863 return emptyContextObject;
1864 } // Avoid recreating masked context unless unmasked context has changed.
1865 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1866 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1867
1868
1869 var instance = workInProgress.stateNode;
1870
1871 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1872 return instance.__reactInternalMemoizedMaskedChildContext;
1873 }
1874
1875 var context = {};
1876
1877 for (var key in contextTypes) {
1878 context[key] = unmaskedContext[key];
1879 }
1880
1881 {
1882 var name = getComponentName(type) || 'Unknown';
1883 checkPropTypes(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1884 } // Cache unmasked context so we can avoid recreating masked context unless necessary.
1885 // Context is created before the class component is instantiated so check for instance.
1886
1887
1888 if (instance) {
1889 cacheContext(workInProgress, unmaskedContext, context);
1890 }
1891
1892 return context;
1893 }
1894}
1895
1896function hasContextChanged() {
1897 if (disableLegacyContext) {
1898 return false;
1899 } else {
1900 return didPerformWorkStackCursor.current;
1901 }
1902}
1903
1904function isContextProvider(type) {
1905 if (disableLegacyContext) {
1906 return false;
1907 } else {
1908 var childContextTypes = type.childContextTypes;
1909 return childContextTypes !== null && childContextTypes !== undefined;
1910 }
1911}
1912
1913function popContext(fiber) {
1914 if (disableLegacyContext) {
1915 return;
1916 } else {
1917 pop(didPerformWorkStackCursor, fiber);
1918 pop(contextStackCursor, fiber);
1919 }
1920}
1921
1922function popTopLevelContextObject(fiber) {
1923 if (disableLegacyContext) {
1924 return;
1925 } else {
1926 pop(didPerformWorkStackCursor, fiber);
1927 pop(contextStackCursor, fiber);
1928 }
1929}
1930
1931function pushTopLevelContextObject(fiber, context, didChange) {
1932 if (disableLegacyContext) {
1933 return;
1934 } else {
1935 if (!(contextStackCursor.current === emptyContextObject)) {
1936 {
1937 throw Error("Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue.");
1938 }
1939 }
1940
1941 push(contextStackCursor, context, fiber);
1942 push(didPerformWorkStackCursor, didChange, fiber);
1943 }
1944}
1945
1946function processChildContext(fiber, type, parentContext) {
1947 if (disableLegacyContext) {
1948 return parentContext;
1949 } else {
1950 var instance = fiber.stateNode;
1951 var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1952 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1953
1954 if (typeof instance.getChildContext !== 'function') {
1955 {
1956 var componentName = getComponentName(type) || 'Unknown';
1957
1958 if (!warnedAboutMissingGetChildContext[componentName]) {
1959 warnedAboutMissingGetChildContext[componentName] = true;
1960 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);
1961 }
1962 }
1963
1964 return parentContext;
1965 }
1966
1967 var childContext;
1968
1969 {
1970 setCurrentPhase('getChildContext');
1971 }
1972
1973 startPhaseTimer(fiber, 'getChildContext');
1974 childContext = instance.getChildContext();
1975 stopPhaseTimer();
1976
1977 {
1978 setCurrentPhase(null);
1979 }
1980
1981 for (var contextKey in childContext) {
1982 if (!(contextKey in childContextTypes)) {
1983 {
1984 throw Error((getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes.");
1985 }
1986 }
1987 }
1988
1989 {
1990 var name = getComponentName(type) || 'Unknown';
1991 checkPropTypes(childContextTypes, childContext, 'child context', name, // In practice, there is one case in which we won't get a stack. It's when
1992 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1993 // context from the parent component instance. The stack will be missing
1994 // because it's outside of the reconciliation, and so the pointer has not
1995 // been set. This is rare and doesn't matter. We'll also remove that API.
1996 getCurrentFiberStackInDev);
1997 }
1998
1999 return _assign({}, parentContext, {}, childContext);
2000 }
2001}
2002
2003function pushContextProvider(workInProgress) {
2004 if (disableLegacyContext) {
2005 return false;
2006 } else {
2007 var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
2008 // If the instance does not exist yet, we will push null at first,
2009 // and replace it on the stack later when invalidating the context.
2010
2011 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
2012 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
2013
2014 previousContext = contextStackCursor.current;
2015 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
2016 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
2017 return true;
2018 }
2019}
2020
2021function invalidateContextProvider(workInProgress, type, didChange) {
2022 if (disableLegacyContext) {
2023 return;
2024 } else {
2025 var instance = workInProgress.stateNode;
2026
2027 if (!instance) {
2028 {
2029 throw Error("Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue.");
2030 }
2031 }
2032
2033 if (didChange) {
2034 // Merge parent and own context.
2035 // Skip this if we're not updating due to sCU.
2036 // This avoids unnecessarily recomputing memoized values.
2037 var mergedContext = processChildContext(workInProgress, type, previousContext);
2038 instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
2039 // It is important to unwind the context in the reverse order.
2040
2041 pop(didPerformWorkStackCursor, workInProgress);
2042 pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
2043
2044 push(contextStackCursor, mergedContext, workInProgress);
2045 push(didPerformWorkStackCursor, didChange, workInProgress);
2046 } else {
2047 pop(didPerformWorkStackCursor, workInProgress);
2048 push(didPerformWorkStackCursor, didChange, workInProgress);
2049 }
2050 }
2051}
2052
2053function findCurrentUnmaskedContext(fiber) {
2054 if (disableLegacyContext) {
2055 return emptyContextObject;
2056 } else {
2057 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
2058 // makes sense elsewhere
2059 if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
2060 {
2061 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.");
2062 }
2063 }
2064
2065 var node = fiber;
2066
2067 do {
2068 switch (node.tag) {
2069 case HostRoot:
2070 return node.stateNode.context;
2071
2072 case ClassComponent:
2073 {
2074 var Component = node.type;
2075
2076 if (isContextProvider(Component)) {
2077 return node.stateNode.__reactInternalMemoizedMergedChildContext;
2078 }
2079
2080 break;
2081 }
2082 }
2083
2084 node = node.return;
2085 } while (node !== null);
2086
2087 {
2088 {
2089 throw Error("Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.");
2090 }
2091 }
2092 }
2093}
2094
2095// Intentionally not named imports because Rollup would use dynamic dispatch for
2096// CommonJS interop named imports.
2097var Scheduler_runWithPriority = Scheduler.unstable_runWithPriority;
2098var Scheduler_scheduleCallback = Scheduler.unstable_scheduleCallback;
2099var Scheduler_cancelCallback = Scheduler.unstable_cancelCallback;
2100var Scheduler_shouldYield = Scheduler.unstable_shouldYield;
2101var Scheduler_requestPaint = Scheduler.unstable_requestPaint;
2102var Scheduler_now = Scheduler.unstable_now;
2103var Scheduler_getCurrentPriorityLevel = Scheduler.unstable_getCurrentPriorityLevel;
2104var Scheduler_ImmediatePriority = Scheduler.unstable_ImmediatePriority;
2105var Scheduler_UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
2106var Scheduler_NormalPriority = Scheduler.unstable_NormalPriority;
2107var Scheduler_LowPriority = Scheduler.unstable_LowPriority;
2108var Scheduler_IdlePriority = Scheduler.unstable_IdlePriority;
2109
2110if (enableSchedulerTracing) {
2111 // Provide explicit error message when production+profiling bundle of e.g.
2112 // react-dom is used with production (non-profiling) bundle of
2113 // scheduler/tracing
2114 if (!(tracing.__interactionsRef != null && tracing.__interactionsRef.current != null)) {
2115 {
2116 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");
2117 }
2118 }
2119}
2120
2121var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
2122// ascending numbers so we can compare them like numbers. They start at 90 to
2123// avoid clashing with Scheduler's priorities.
2124
2125var ImmediatePriority = 99;
2126var UserBlockingPriority = 98;
2127var NormalPriority = 97;
2128var LowPriority = 96;
2129var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
2130
2131var NoPriority = 90;
2132var shouldYield = Scheduler_shouldYield;
2133var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
2134Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
2135var syncQueue = null;
2136var immediateQueueCallbackNode = null;
2137var isFlushingSyncQueue = false;
2138var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
2139// This will be the case for modern browsers that support `performance.now`. In
2140// older browsers, Scheduler falls back to `Date.now`, which returns a Unix
2141// timestamp. In that case, subtract the module initialization time to simulate
2142// the behavior of performance.now and keep our times small enough to fit
2143// within 32 bits.
2144// TODO: Consider lifting this into Scheduler.
2145
2146var now = initialTimeMs < 10000 ? Scheduler_now : function () {
2147 return Scheduler_now() - initialTimeMs;
2148};
2149function getCurrentPriorityLevel() {
2150 switch (Scheduler_getCurrentPriorityLevel()) {
2151 case Scheduler_ImmediatePriority:
2152 return ImmediatePriority;
2153
2154 case Scheduler_UserBlockingPriority:
2155 return UserBlockingPriority;
2156
2157 case Scheduler_NormalPriority:
2158 return NormalPriority;
2159
2160 case Scheduler_LowPriority:
2161 return LowPriority;
2162
2163 case Scheduler_IdlePriority:
2164 return IdlePriority;
2165
2166 default:
2167 {
2168 {
2169 throw Error("Unknown priority level.");
2170 }
2171 }
2172
2173 }
2174}
2175
2176function reactPriorityToSchedulerPriority(reactPriorityLevel) {
2177 switch (reactPriorityLevel) {
2178 case ImmediatePriority:
2179 return Scheduler_ImmediatePriority;
2180
2181 case UserBlockingPriority:
2182 return Scheduler_UserBlockingPriority;
2183
2184 case NormalPriority:
2185 return Scheduler_NormalPriority;
2186
2187 case LowPriority:
2188 return Scheduler_LowPriority;
2189
2190 case IdlePriority:
2191 return Scheduler_IdlePriority;
2192
2193 default:
2194 {
2195 {
2196 throw Error("Unknown priority level.");
2197 }
2198 }
2199
2200 }
2201}
2202
2203function runWithPriority(reactPriorityLevel, fn) {
2204 var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
2205 return Scheduler_runWithPriority(priorityLevel, fn);
2206}
2207function scheduleCallback(reactPriorityLevel, callback, options) {
2208 var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
2209 return Scheduler_scheduleCallback(priorityLevel, callback, options);
2210}
2211function scheduleSyncCallback(callback) {
2212 // Push this callback into an internal queue. We'll flush these either in
2213 // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
2214 if (syncQueue === null) {
2215 syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
2216
2217 immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
2218 } else {
2219 // Push onto existing queue. Don't need to schedule a callback because
2220 // we already scheduled one when we created the queue.
2221 syncQueue.push(callback);
2222 }
2223
2224 return fakeCallbackNode;
2225}
2226function cancelCallback(callbackNode) {
2227 if (callbackNode !== fakeCallbackNode) {
2228 Scheduler_cancelCallback(callbackNode);
2229 }
2230}
2231function flushSyncCallbackQueue() {
2232 if (immediateQueueCallbackNode !== null) {
2233 var node = immediateQueueCallbackNode;
2234 immediateQueueCallbackNode = null;
2235 Scheduler_cancelCallback(node);
2236 }
2237
2238 flushSyncCallbackQueueImpl();
2239}
2240
2241function flushSyncCallbackQueueImpl() {
2242 if (!isFlushingSyncQueue && syncQueue !== null) {
2243 // Prevent re-entrancy.
2244 isFlushingSyncQueue = true;
2245 var i = 0;
2246
2247 try {
2248 var _isSync = true;
2249 var queue = syncQueue;
2250 runWithPriority(ImmediatePriority, function () {
2251 for (; i < queue.length; i++) {
2252 var callback = queue[i];
2253
2254 do {
2255 callback = callback(_isSync);
2256 } while (callback !== null);
2257 }
2258 });
2259 syncQueue = null;
2260 } catch (error) {
2261 // If something throws, leave the remaining callbacks on the queue.
2262 if (syncQueue !== null) {
2263 syncQueue = syncQueue.slice(i + 1);
2264 } // Resume flushing in the next tick
2265
2266
2267 Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
2268 throw error;
2269 } finally {
2270 isFlushingSyncQueue = false;
2271 }
2272 }
2273}
2274
2275var NoMode = 0;
2276var StrictMode = 1; // TODO: Remove BatchedMode and ConcurrentMode by reading from the root
2277// tag instead
2278
2279var BatchedMode = 2;
2280var ConcurrentMode = 4;
2281var ProfileMode = 8;
2282
2283// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
2284// Math.pow(2, 30) - 1
2285// 0b111111111111111111111111111111
2286var MAX_SIGNED_31_BIT_INT = 1073741823;
2287
2288var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
2289// Never work can be committed in an inconsistent state without tearing the UI.
2290// The main example is offscreen content, like a hidden subtree. So one possible
2291// name is Offscreen. However, it also includes dehydrated Suspense boundaries,
2292// which are inconsistent in the sense that they haven't finished yet, but
2293// aren't visibly inconsistent because the server rendered HTML matches what the
2294// hydrated tree would look like.
2295
2296var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
2297// order to be consistent.
2298
2299var Idle = 2; // Continuous Hydration is a moving priority. It is slightly higher than Idle
2300var Sync = MAX_SIGNED_31_BIT_INT;
2301var Batched = Sync - 1;
2302var UNIT_SIZE = 10;
2303var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
2304
2305function msToExpirationTime(ms) {
2306 // Always add an offset so that we don't clash with the magic number for NoWork.
2307 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
2308}
2309function expirationTimeToMs(expirationTime) {
2310 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
2311}
2312
2313function ceiling(num, precision) {
2314 return ((num / precision | 0) + 1) * precision;
2315}
2316
2317function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
2318 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
2319} // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
2320// the names to reflect.
2321
2322
2323var LOW_PRIORITY_EXPIRATION = 5000;
2324var LOW_PRIORITY_BATCH_SIZE = 250;
2325function computeAsyncExpiration(currentTime) {
2326 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
2327}
2328function computeSuspenseExpiration(currentTime, timeoutMs) {
2329 // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
2330 return computeExpirationBucket(currentTime, timeoutMs, LOW_PRIORITY_BATCH_SIZE);
2331} // We intentionally set a higher expiration time for interactive updates in
2332// dev than in production.
2333//
2334// If the main thread is being blocked so long that you hit the expiration,
2335// it's a problem that could be solved with better scheduling.
2336//
2337// People will be more likely to notice this and fix it with the long
2338// expiration time in development.
2339//
2340// In production we opt for better UX at the risk of masking scheduling
2341// problems, by expiring fast.
2342
2343var HIGH_PRIORITY_EXPIRATION = 500;
2344var HIGH_PRIORITY_BATCH_SIZE = 100;
2345function computeInteractiveExpiration(currentTime) {
2346 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
2347}
2348
2349function inferPriorityFromExpirationTime(currentTime, expirationTime) {
2350 if (expirationTime === Sync) {
2351 return ImmediatePriority;
2352 }
2353
2354 if (expirationTime === Never || expirationTime === Idle) {
2355 return IdlePriority;
2356 }
2357
2358 var msUntil = expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
2359
2360 if (msUntil <= 0) {
2361 return ImmediatePriority;
2362 }
2363
2364 if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
2365 return UserBlockingPriority;
2366 }
2367
2368 if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
2369 return NormalPriority;
2370 } // TODO: Handle LowPriority
2371 // Assume anything lower has idle priority
2372
2373
2374 return IdlePriority;
2375}
2376
2377/**
2378 * inlined Object.is polyfill to avoid requiring consumers ship their own
2379 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
2380 */
2381function is(x, y) {
2382 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
2383 ;
2384}
2385
2386var is$1 = typeof Object.is === 'function' ? Object.is : is;
2387
2388var hasOwnProperty = Object.prototype.hasOwnProperty;
2389/**
2390 * Performs equality by iterating through keys on an object and returning false
2391 * when any key has values which are not strictly equal between the arguments.
2392 * Returns true when the values of all keys are strictly equal.
2393 */
2394
2395function shallowEqual(objA, objB) {
2396 if (is$1(objA, objB)) {
2397 return true;
2398 }
2399
2400 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
2401 return false;
2402 }
2403
2404 var keysA = Object.keys(objA);
2405 var keysB = Object.keys(objB);
2406
2407 if (keysA.length !== keysB.length) {
2408 return false;
2409 } // Test for A's keys different from B.
2410
2411
2412 for (var i = 0; i < keysA.length; i++) {
2413 if (!hasOwnProperty.call(objB, keysA[i]) || !is$1(objA[keysA[i]], objB[keysA[i]])) {
2414 return false;
2415 }
2416 }
2417
2418 return true;
2419}
2420
2421/**
2422 * Forked from fbjs/warning:
2423 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2424 *
2425 * Only change is we use console.warn instead of console.error,
2426 * and do nothing when 'console' is not supported.
2427 * This really simplifies the code.
2428 * ---
2429 * Similar to invariant but only logs a warning if the condition is not met.
2430 * This can be used to log issues in development environments in critical
2431 * paths. Removing the logging code for production environments will keep the
2432 * same logic and follow the same code paths.
2433 */
2434var lowPriorityWarningWithoutStack = function () {};
2435
2436{
2437 var printWarning = function (format) {
2438 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2439 args[_key - 1] = arguments[_key];
2440 }
2441
2442 var argIndex = 0;
2443 var message = 'Warning: ' + format.replace(/%s/g, function () {
2444 return args[argIndex++];
2445 });
2446
2447 if (typeof console !== 'undefined') {
2448 console.warn(message);
2449 }
2450
2451 try {
2452 // --- Welcome to debugging React ---
2453 // This error was thrown as a convenience so that you can use this stack
2454 // to find the callsite that caused this warning to fire.
2455 throw new Error(message);
2456 } catch (x) {}
2457 };
2458
2459 lowPriorityWarningWithoutStack = function (condition, format) {
2460 if (format === undefined) {
2461 throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
2462 }
2463
2464 if (!condition) {
2465 for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2466 args[_key2 - 2] = arguments[_key2];
2467 }
2468
2469 printWarning.apply(void 0, [format].concat(args));
2470 }
2471 };
2472}
2473
2474var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack;
2475
2476var ReactStrictModeWarnings = {
2477 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2478 flushPendingUnsafeLifecycleWarnings: function () {},
2479 recordLegacyContextWarning: function (fiber, instance) {},
2480 flushLegacyContextWarning: function () {},
2481 discardPendingWarnings: function () {}
2482};
2483
2484{
2485 var findStrictRoot = function (fiber) {
2486 var maybeStrictRoot = null;
2487 var node = fiber;
2488
2489 while (node !== null) {
2490 if (node.mode & StrictMode) {
2491 maybeStrictRoot = node;
2492 }
2493
2494 node = node.return;
2495 }
2496
2497 return maybeStrictRoot;
2498 };
2499
2500 var setToSortedString = function (set) {
2501 var array = [];
2502 set.forEach(function (value) {
2503 array.push(value);
2504 });
2505 return array.sort().join(', ');
2506 };
2507
2508 var pendingComponentWillMountWarnings = [];
2509 var pendingUNSAFE_ComponentWillMountWarnings = [];
2510 var pendingComponentWillReceivePropsWarnings = [];
2511 var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2512 var pendingComponentWillUpdateWarnings = [];
2513 var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
2514
2515 var didWarnAboutUnsafeLifecycles = new Set();
2516
2517 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2518 // Dedup strategy: Warn once per component.
2519 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2520 return;
2521 }
2522
2523 if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
2524 instance.componentWillMount.__suppressDeprecationWarning !== true) {
2525 pendingComponentWillMountWarnings.push(fiber);
2526 }
2527
2528 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
2529 pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
2530 }
2531
2532 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2533 pendingComponentWillReceivePropsWarnings.push(fiber);
2534 }
2535
2536 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2537 pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
2538 }
2539
2540 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2541 pendingComponentWillUpdateWarnings.push(fiber);
2542 }
2543
2544 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
2545 pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
2546 }
2547 };
2548
2549 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2550 // We do an initial pass to gather component names
2551 var componentWillMountUniqueNames = new Set();
2552
2553 if (pendingComponentWillMountWarnings.length > 0) {
2554 pendingComponentWillMountWarnings.forEach(function (fiber) {
2555 componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
2556 didWarnAboutUnsafeLifecycles.add(fiber.type);
2557 });
2558 pendingComponentWillMountWarnings = [];
2559 }
2560
2561 var UNSAFE_componentWillMountUniqueNames = new Set();
2562
2563 if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
2564 pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
2565 UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
2566 didWarnAboutUnsafeLifecycles.add(fiber.type);
2567 });
2568 pendingUNSAFE_ComponentWillMountWarnings = [];
2569 }
2570
2571 var componentWillReceivePropsUniqueNames = new Set();
2572
2573 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2574 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2575 componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
2576 didWarnAboutUnsafeLifecycles.add(fiber.type);
2577 });
2578 pendingComponentWillReceivePropsWarnings = [];
2579 }
2580
2581 var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
2582
2583 if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
2584 pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
2585 UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
2586 didWarnAboutUnsafeLifecycles.add(fiber.type);
2587 });
2588 pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2589 }
2590
2591 var componentWillUpdateUniqueNames = new Set();
2592
2593 if (pendingComponentWillUpdateWarnings.length > 0) {
2594 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2595 componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
2596 didWarnAboutUnsafeLifecycles.add(fiber.type);
2597 });
2598 pendingComponentWillUpdateWarnings = [];
2599 }
2600
2601 var UNSAFE_componentWillUpdateUniqueNames = new Set();
2602
2603 if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
2604 pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
2605 UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
2606 didWarnAboutUnsafeLifecycles.add(fiber.type);
2607 });
2608 pendingUNSAFE_ComponentWillUpdateWarnings = [];
2609 } // Finally, we flush all the warnings
2610 // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
2611
2612
2613 if (UNSAFE_componentWillMountUniqueNames.size > 0) {
2614 var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
2615 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);
2616 }
2617
2618 if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
2619 var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
2620
2621 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);
2622 }
2623
2624 if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
2625 var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
2626
2627 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);
2628 }
2629
2630 if (componentWillMountUniqueNames.size > 0) {
2631 var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
2632
2633 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);
2634 }
2635
2636 if (componentWillReceivePropsUniqueNames.size > 0) {
2637 var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
2638
2639 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);
2640 }
2641
2642 if (componentWillUpdateUniqueNames.size > 0) {
2643 var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
2644
2645 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);
2646 }
2647 };
2648
2649 var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
2650
2651 var didWarnAboutLegacyContext = new Set();
2652
2653 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2654 var strictRoot = findStrictRoot(fiber);
2655
2656 if (strictRoot === null) {
2657 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.');
2658 return;
2659 } // Dedup strategy: Warn once per component.
2660
2661
2662 if (didWarnAboutLegacyContext.has(fiber.type)) {
2663 return;
2664 }
2665
2666 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2667
2668 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2669 if (warningsForRoot === undefined) {
2670 warningsForRoot = [];
2671 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2672 }
2673
2674 warningsForRoot.push(fiber);
2675 }
2676 };
2677
2678 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2679 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2680 var uniqueNames = new Set();
2681 fiberArray.forEach(function (fiber) {
2682 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2683 didWarnAboutLegacyContext.add(fiber.type);
2684 });
2685 var sortedNames = setToSortedString(uniqueNames);
2686 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2687 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);
2688 });
2689 };
2690
2691 ReactStrictModeWarnings.discardPendingWarnings = function () {
2692 pendingComponentWillMountWarnings = [];
2693 pendingUNSAFE_ComponentWillMountWarnings = [];
2694 pendingComponentWillReceivePropsWarnings = [];
2695 pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2696 pendingComponentWillUpdateWarnings = [];
2697 pendingUNSAFE_ComponentWillUpdateWarnings = [];
2698 pendingLegacyContextWarning = new Map();
2699 };
2700}
2701
2702var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
2703
2704var failedBoundaries = null;
2705var setRefreshHandler = function (handler) {
2706 {
2707 resolveFamily = handler;
2708 }
2709};
2710function resolveFunctionForHotReloading(type) {
2711 {
2712 if (resolveFamily === null) {
2713 // Hot reloading is disabled.
2714 return type;
2715 }
2716
2717 var family = resolveFamily(type);
2718
2719 if (family === undefined) {
2720 return type;
2721 } // Use the latest known implementation.
2722
2723
2724 return family.current;
2725 }
2726}
2727function resolveClassForHotReloading(type) {
2728 // No implementation differences.
2729 return resolveFunctionForHotReloading(type);
2730}
2731function resolveForwardRefForHotReloading(type) {
2732 {
2733 if (resolveFamily === null) {
2734 // Hot reloading is disabled.
2735 return type;
2736 }
2737
2738 var family = resolveFamily(type);
2739
2740 if (family === undefined) {
2741 // Check if we're dealing with a real forwardRef. Don't want to crash early.
2742 if (type !== null && type !== undefined && typeof type.render === 'function') {
2743 // ForwardRef is special because its resolved .type is an object,
2744 // but it's possible that we only have its inner render function in the map.
2745 // If that inner render function is different, we'll build a new forwardRef type.
2746 var currentRender = resolveFunctionForHotReloading(type.render);
2747
2748 if (type.render !== currentRender) {
2749 var syntheticType = {
2750 $$typeof: REACT_FORWARD_REF_TYPE,
2751 render: currentRender
2752 };
2753
2754 if (type.displayName !== undefined) {
2755 syntheticType.displayName = type.displayName;
2756 }
2757
2758 return syntheticType;
2759 }
2760 }
2761
2762 return type;
2763 } // Use the latest known implementation.
2764
2765
2766 return family.current;
2767 }
2768}
2769function isCompatibleFamilyForHotReloading(fiber, element) {
2770 {
2771 if (resolveFamily === null) {
2772 // Hot reloading is disabled.
2773 return false;
2774 }
2775
2776 var prevType = fiber.elementType;
2777 var nextType = element.type; // If we got here, we know types aren't === equal.
2778
2779 var needsCompareFamilies = false;
2780 var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
2781
2782 switch (fiber.tag) {
2783 case ClassComponent:
2784 {
2785 if (typeof nextType === 'function') {
2786 needsCompareFamilies = true;
2787 }
2788
2789 break;
2790 }
2791
2792 case FunctionComponent:
2793 {
2794 if (typeof nextType === 'function') {
2795 needsCompareFamilies = true;
2796 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2797 // We don't know the inner type yet.
2798 // We're going to assume that the lazy inner type is stable,
2799 // and so it is sufficient to avoid reconciling it away.
2800 // We're not going to unwrap or actually use the new lazy type.
2801 needsCompareFamilies = true;
2802 }
2803
2804 break;
2805 }
2806
2807 case ForwardRef:
2808 {
2809 if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
2810 needsCompareFamilies = true;
2811 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2812 needsCompareFamilies = true;
2813 }
2814
2815 break;
2816 }
2817
2818 case MemoComponent:
2819 case SimpleMemoComponent:
2820 {
2821 if ($$typeofNextType === REACT_MEMO_TYPE) {
2822 // TODO: if it was but can no longer be simple,
2823 // we shouldn't set this.
2824 needsCompareFamilies = true;
2825 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2826 needsCompareFamilies = true;
2827 }
2828
2829 break;
2830 }
2831
2832 default:
2833 return false;
2834 } // Check if both types have a family and it's the same one.
2835
2836
2837 if (needsCompareFamilies) {
2838 // Note: memo() and forwardRef() we'll compare outer rather than inner type.
2839 // This means both of them need to be registered to preserve state.
2840 // If we unwrapped and compared the inner types for wrappers instead,
2841 // then we would risk falsely saying two separate memo(Foo)
2842 // calls are equivalent because they wrap the same Foo function.
2843 var prevFamily = resolveFamily(prevType);
2844
2845 if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
2846 return true;
2847 }
2848 }
2849
2850 return false;
2851 }
2852}
2853function markFailedErrorBoundaryForHotReloading(fiber) {
2854 {
2855 if (resolveFamily === null) {
2856 // Hot reloading is disabled.
2857 return;
2858 }
2859
2860 if (typeof WeakSet !== 'function') {
2861 return;
2862 }
2863
2864 if (failedBoundaries === null) {
2865 failedBoundaries = new WeakSet();
2866 }
2867
2868 failedBoundaries.add(fiber);
2869 }
2870}
2871var scheduleRefresh = function (root, update) {
2872 {
2873 if (resolveFamily === null) {
2874 // Hot reloading is disabled.
2875 return;
2876 }
2877
2878 var staleFamilies = update.staleFamilies,
2879 updatedFamilies = update.updatedFamilies;
2880 flushPassiveEffects();
2881 flushSync(function () {
2882 scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
2883 });
2884 }
2885};
2886var scheduleRoot = function (root, element) {
2887 {
2888 if (root.context !== emptyContextObject) {
2889 // Super edge case: root has a legacy _renderSubtree context
2890 // but we don't know the parentComponent so we can't pass it.
2891 // Just ignore. We'll delete this with _renderSubtree code path later.
2892 return;
2893 }
2894
2895 flushPassiveEffects();
2896 syncUpdates(function () {
2897 updateContainer(element, root, null, null);
2898 });
2899 }
2900};
2901
2902function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
2903 {
2904 var alternate = fiber.alternate,
2905 child = fiber.child,
2906 sibling = fiber.sibling,
2907 tag = fiber.tag,
2908 type = fiber.type;
2909 var candidateType = null;
2910
2911 switch (tag) {
2912 case FunctionComponent:
2913 case SimpleMemoComponent:
2914 case ClassComponent:
2915 candidateType = type;
2916 break;
2917
2918 case ForwardRef:
2919 candidateType = type.render;
2920 break;
2921
2922 default:
2923 break;
2924 }
2925
2926 if (resolveFamily === null) {
2927 throw new Error('Expected resolveFamily to be set during hot reload.');
2928 }
2929
2930 var needsRender = false;
2931 var needsRemount = false;
2932
2933 if (candidateType !== null) {
2934 var family = resolveFamily(candidateType);
2935
2936 if (family !== undefined) {
2937 if (staleFamilies.has(family)) {
2938 needsRemount = true;
2939 } else if (updatedFamilies.has(family)) {
2940 if (tag === ClassComponent) {
2941 needsRemount = true;
2942 } else {
2943 needsRender = true;
2944 }
2945 }
2946 }
2947 }
2948
2949 if (failedBoundaries !== null) {
2950 if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
2951 needsRemount = true;
2952 }
2953 }
2954
2955 if (needsRemount) {
2956 fiber._debugNeedsRemount = true;
2957 }
2958
2959 if (needsRemount || needsRender) {
2960 scheduleWork(fiber, Sync);
2961 }
2962
2963 if (child !== null && !needsRemount) {
2964 scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
2965 }
2966
2967 if (sibling !== null) {
2968 scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
2969 }
2970 }
2971}
2972
2973var findHostInstancesForRefresh = function (root, families) {
2974 {
2975 var hostInstances = new Set();
2976 var types = new Set(families.map(function (family) {
2977 return family.current;
2978 }));
2979 findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
2980 return hostInstances;
2981 }
2982};
2983
2984function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
2985 {
2986 var child = fiber.child,
2987 sibling = fiber.sibling,
2988 tag = fiber.tag,
2989 type = fiber.type;
2990 var candidateType = null;
2991
2992 switch (tag) {
2993 case FunctionComponent:
2994 case SimpleMemoComponent:
2995 case ClassComponent:
2996 candidateType = type;
2997 break;
2998
2999 case ForwardRef:
3000 candidateType = type.render;
3001 break;
3002
3003 default:
3004 break;
3005 }
3006
3007 var didMatch = false;
3008
3009 if (candidateType !== null) {
3010 if (types.has(candidateType)) {
3011 didMatch = true;
3012 }
3013 }
3014
3015 if (didMatch) {
3016 // We have a match. This only drills down to the closest host components.
3017 // There's no need to search deeper because for the purpose of giving
3018 // visual feedback, "flashing" outermost parent rectangles is sufficient.
3019 findHostInstancesForFiberShallowly(fiber, hostInstances);
3020 } else {
3021 // If there's no match, maybe there will be one further down in the child tree.
3022 if (child !== null) {
3023 findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
3024 }
3025 }
3026
3027 if (sibling !== null) {
3028 findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
3029 }
3030 }
3031}
3032
3033function findHostInstancesForFiberShallowly(fiber, hostInstances) {
3034 {
3035 var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
3036
3037 if (foundHostInstances) {
3038 return;
3039 } // If we didn't find any host children, fallback to closest host parent.
3040
3041
3042 var node = fiber;
3043
3044 while (true) {
3045 switch (node.tag) {
3046 case HostComponent:
3047 hostInstances.add(node.stateNode);
3048 return;
3049
3050 case HostPortal:
3051 hostInstances.add(node.stateNode.containerInfo);
3052 return;
3053
3054 case HostRoot:
3055 hostInstances.add(node.stateNode.containerInfo);
3056 return;
3057 }
3058
3059 if (node.return === null) {
3060 throw new Error('Expected to reach root first.');
3061 }
3062
3063 node = node.return;
3064 }
3065 }
3066}
3067
3068function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
3069 {
3070 var node = fiber;
3071 var foundHostInstances = false;
3072
3073 while (true) {
3074 if (node.tag === HostComponent) {
3075 // We got a match.
3076 foundHostInstances = true;
3077 hostInstances.add(node.stateNode); // There may still be more, so keep searching.
3078 } else if (node.child !== null) {
3079 node.child.return = node;
3080 node = node.child;
3081 continue;
3082 }
3083
3084 if (node === fiber) {
3085 return foundHostInstances;
3086 }
3087
3088 while (node.sibling === null) {
3089 if (node.return === null || node.return === fiber) {
3090 return foundHostInstances;
3091 }
3092
3093 node = node.return;
3094 }
3095
3096 node.sibling.return = node.return;
3097 node = node.sibling;
3098 }
3099 }
3100
3101 return false;
3102}
3103
3104function resolveDefaultProps(Component, baseProps) {
3105 if (Component && Component.defaultProps) {
3106 // Resolve default props. Taken from ReactElement
3107 var props = _assign({}, baseProps);
3108
3109 var defaultProps = Component.defaultProps;
3110
3111 for (var propName in defaultProps) {
3112 if (props[propName] === undefined) {
3113 props[propName] = defaultProps[propName];
3114 }
3115 }
3116
3117 return props;
3118 }
3119
3120 return baseProps;
3121}
3122function readLazyComponentType(lazyComponent) {
3123 initializeLazyComponentType(lazyComponent);
3124
3125 if (lazyComponent._status !== Resolved) {
3126 throw lazyComponent._result;
3127 }
3128
3129 return lazyComponent._result;
3130}
3131
3132var valueCursor = createCursor(null);
3133var rendererSigil;
3134
3135{
3136 // Use this to detect multiple renderers using the same context
3137 rendererSigil = {};
3138}
3139
3140var currentlyRenderingFiber = null;
3141var lastContextDependency = null;
3142var lastContextWithAllBitsObserved = null;
3143var isDisallowedContextReadInDEV = false;
3144function resetContextDependencies() {
3145 // This is called right before React yields execution, to ensure `readContext`
3146 // cannot be called outside the render phase.
3147 currentlyRenderingFiber = null;
3148 lastContextDependency = null;
3149 lastContextWithAllBitsObserved = null;
3150
3151 {
3152 isDisallowedContextReadInDEV = false;
3153 }
3154}
3155function enterDisallowedContextReadInDEV() {
3156 {
3157 isDisallowedContextReadInDEV = true;
3158 }
3159}
3160function exitDisallowedContextReadInDEV() {
3161 {
3162 isDisallowedContextReadInDEV = false;
3163 }
3164}
3165function pushProvider(providerFiber, nextValue) {
3166 var context = providerFiber.type._context;
3167
3168 if (isPrimaryRenderer) {
3169 push(valueCursor, context._currentValue, providerFiber);
3170 context._currentValue = nextValue;
3171
3172 {
3173 !(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;
3174 context._currentRenderer = rendererSigil;
3175 }
3176 } else {
3177 push(valueCursor, context._currentValue2, providerFiber);
3178 context._currentValue2 = nextValue;
3179
3180 {
3181 !(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;
3182 context._currentRenderer2 = rendererSigil;
3183 }
3184 }
3185}
3186function popProvider(providerFiber) {
3187 var currentValue = valueCursor.current;
3188 pop(valueCursor, providerFiber);
3189 var context = providerFiber.type._context;
3190
3191 if (isPrimaryRenderer) {
3192 context._currentValue = currentValue;
3193 } else {
3194 context._currentValue2 = currentValue;
3195 }
3196}
3197function calculateChangedBits(context, newValue, oldValue) {
3198 if (is$1(oldValue, newValue)) {
3199 // No change
3200 return 0;
3201 } else {
3202 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
3203
3204 {
3205 !((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;
3206 }
3207
3208 return changedBits | 0;
3209 }
3210}
3211function scheduleWorkOnParentPath(parent, renderExpirationTime) {
3212 // Update the child expiration time of all the ancestors, including
3213 // the alternates.
3214 var node = parent;
3215
3216 while (node !== null) {
3217 var alternate = node.alternate;
3218
3219 if (node.childExpirationTime < renderExpirationTime) {
3220 node.childExpirationTime = renderExpirationTime;
3221
3222 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3223 alternate.childExpirationTime = renderExpirationTime;
3224 }
3225 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3226 alternate.childExpirationTime = renderExpirationTime;
3227 } else {
3228 // Neither alternate was updated, which means the rest of the
3229 // ancestor path already has sufficient priority.
3230 break;
3231 }
3232
3233 node = node.return;
3234 }
3235}
3236function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
3237 var fiber = workInProgress.child;
3238
3239 if (fiber !== null) {
3240 // Set the return pointer of the child to the work-in-progress fiber.
3241 fiber.return = workInProgress;
3242 }
3243
3244 while (fiber !== null) {
3245 var nextFiber = void 0; // Visit this fiber.
3246
3247 var list = fiber.dependencies;
3248
3249 if (list !== null) {
3250 nextFiber = fiber.child;
3251 var dependency = list.firstContext;
3252
3253 while (dependency !== null) {
3254 // Check if the context matches.
3255 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
3256 // Match! Schedule an update on this fiber.
3257 if (fiber.tag === ClassComponent) {
3258 // Schedule a force update on the work-in-progress.
3259 var update = createUpdate(renderExpirationTime, null);
3260 update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
3261 // update to the current fiber, too, which means it will persist even if
3262 // this render is thrown away. Since it's a race condition, not sure it's
3263 // worth fixing.
3264
3265 enqueueUpdate(fiber, update);
3266 }
3267
3268 if (fiber.expirationTime < renderExpirationTime) {
3269 fiber.expirationTime = renderExpirationTime;
3270 }
3271
3272 var alternate = fiber.alternate;
3273
3274 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
3275 alternate.expirationTime = renderExpirationTime;
3276 }
3277
3278 scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
3279
3280 if (list.expirationTime < renderExpirationTime) {
3281 list.expirationTime = renderExpirationTime;
3282 } // Since we already found a match, we can stop traversing the
3283 // dependency list.
3284
3285
3286 break;
3287 }
3288
3289 dependency = dependency.next;
3290 }
3291 } else if (fiber.tag === ContextProvider) {
3292 // Don't scan deeper if this is a matching provider
3293 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
3294 } else if (enableSuspenseServerRenderer && fiber.tag === DehydratedFragment) {
3295 // If a dehydrated suspense bounudary is in this subtree, we don't know
3296 // if it will have any context consumers in it. The best we can do is
3297 // mark it as having updates.
3298 var parentSuspense = fiber.return;
3299
3300 if (!(parentSuspense !== null)) {
3301 {
3302 throw Error("We just came from a parent so we must have had a parent. This is a bug in React.");
3303 }
3304 }
3305
3306 if (parentSuspense.expirationTime < renderExpirationTime) {
3307 parentSuspense.expirationTime = renderExpirationTime;
3308 }
3309
3310 var _alternate = parentSuspense.alternate;
3311
3312 if (_alternate !== null && _alternate.expirationTime < renderExpirationTime) {
3313 _alternate.expirationTime = renderExpirationTime;
3314 } // This is intentionally passing this fiber as the parent
3315 // because we want to schedule this fiber as having work
3316 // on its children. We'll use the childExpirationTime on
3317 // this fiber to indicate that a context has changed.
3318
3319
3320 scheduleWorkOnParentPath(parentSuspense, renderExpirationTime);
3321 nextFiber = fiber.sibling;
3322 } else {
3323 // Traverse down.
3324 nextFiber = fiber.child;
3325 }
3326
3327 if (nextFiber !== null) {
3328 // Set the return pointer of the child to the work-in-progress fiber.
3329 nextFiber.return = fiber;
3330 } else {
3331 // No child. Traverse to next sibling.
3332 nextFiber = fiber;
3333
3334 while (nextFiber !== null) {
3335 if (nextFiber === workInProgress) {
3336 // We're back to the root of this subtree. Exit.
3337 nextFiber = null;
3338 break;
3339 }
3340
3341 var sibling = nextFiber.sibling;
3342
3343 if (sibling !== null) {
3344 // Set the return pointer of the sibling to the work-in-progress fiber.
3345 sibling.return = nextFiber.return;
3346 nextFiber = sibling;
3347 break;
3348 } // No more siblings. Traverse up.
3349
3350
3351 nextFiber = nextFiber.return;
3352 }
3353 }
3354
3355 fiber = nextFiber;
3356 }
3357}
3358function prepareToReadContext(workInProgress, renderExpirationTime) {
3359 currentlyRenderingFiber = workInProgress;
3360 lastContextDependency = null;
3361 lastContextWithAllBitsObserved = null;
3362 var dependencies = workInProgress.dependencies;
3363
3364 if (dependencies !== null) {
3365 var firstContext = dependencies.firstContext;
3366
3367 if (firstContext !== null) {
3368 if (dependencies.expirationTime >= renderExpirationTime) {
3369 // Context list has a pending update. Mark that this fiber performed work.
3370 markWorkInProgressReceivedUpdate();
3371 } // Reset the work-in-progress list
3372
3373
3374 dependencies.firstContext = null;
3375 }
3376 }
3377}
3378function readContext(context, observedBits) {
3379 {
3380 // This warning would fire if you read context inside a Hook like useMemo.
3381 // Unlike the class check below, it's not enforced in production for perf.
3382 !!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;
3383 }
3384
3385 if (lastContextWithAllBitsObserved === context) {// Nothing to do. We already observe everything in this context.
3386 } else if (observedBits === false || observedBits === 0) {// Do not observe any updates.
3387 } else {
3388 var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
3389
3390 if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
3391 // Observe all updates.
3392 lastContextWithAllBitsObserved = context;
3393 resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
3394 } else {
3395 resolvedObservedBits = observedBits;
3396 }
3397
3398 var contextItem = {
3399 context: context,
3400 observedBits: resolvedObservedBits,
3401 next: null
3402 };
3403
3404 if (lastContextDependency === null) {
3405 if (!(currentlyRenderingFiber !== null)) {
3406 {
3407 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().");
3408 }
3409 } // This is the first dependency for this component. Create a new list.
3410
3411
3412 lastContextDependency = contextItem;
3413 currentlyRenderingFiber.dependencies = {
3414 expirationTime: NoWork,
3415 firstContext: contextItem,
3416 responders: null
3417 };
3418 } else {
3419 // Append a new context item.
3420 lastContextDependency = lastContextDependency.next = contextItem;
3421 }
3422 }
3423
3424 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
3425}
3426
3427// UpdateQueue is a linked list of prioritized updates.
3428//
3429// Like fibers, update queues come in pairs: a current queue, which represents
3430// the visible state of the screen, and a work-in-progress queue, which can be
3431// mutated and processed asynchronously before it is committed — a form of
3432// double buffering. If a work-in-progress render is discarded before finishing,
3433// we create a new work-in-progress by cloning the current queue.
3434//
3435// Both queues share a persistent, singly-linked list structure. To schedule an
3436// update, we append it to the end of both queues. Each queue maintains a
3437// pointer to first update in the persistent list that hasn't been processed.
3438// The work-in-progress pointer always has a position equal to or greater than
3439// the current queue, since we always work on that one. The current queue's
3440// pointer is only updated during the commit phase, when we swap in the
3441// work-in-progress.
3442//
3443// For example:
3444//
3445// Current pointer: A - B - C - D - E - F
3446// Work-in-progress pointer: D - E - F
3447// ^
3448// The work-in-progress queue has
3449// processed more updates than current.
3450//
3451// The reason we append to both queues is because otherwise we might drop
3452// updates without ever processing them. For example, if we only add updates to
3453// the work-in-progress queue, some updates could be lost whenever a work-in
3454// -progress render restarts by cloning from current. Similarly, if we only add
3455// updates to the current queue, the updates will be lost whenever an already
3456// in-progress queue commits and swaps with the current queue. However, by
3457// adding to both queues, we guarantee that the update will be part of the next
3458// work-in-progress. (And because the work-in-progress queue becomes the
3459// current queue once it commits, there's no danger of applying the same
3460// update twice.)
3461//
3462// Prioritization
3463// --------------
3464//
3465// Updates are not sorted by priority, but by insertion; new updates are always
3466// appended to the end of the list.
3467//
3468// The priority is still important, though. When processing the update queue
3469// during the render phase, only the updates with sufficient priority are
3470// included in the result. If we skip an update because it has insufficient
3471// priority, it remains in the queue to be processed later, during a lower
3472// priority render. Crucially, all updates subsequent to a skipped update also
3473// remain in the queue *regardless of their priority*. That means high priority
3474// updates are sometimes processed twice, at two separate priorities. We also
3475// keep track of a base state, that represents the state before the first
3476// update in the queue is applied.
3477//
3478// For example:
3479//
3480// Given a base state of '', and the following queue of updates
3481//
3482// A1 - B2 - C1 - D2
3483//
3484// where the number indicates the priority, and the update is applied to the
3485// previous state by appending a letter, React will process these updates as
3486// two separate renders, one per distinct priority level:
3487//
3488// First render, at priority 1:
3489// Base state: ''
3490// Updates: [A1, C1]
3491// Result state: 'AC'
3492//
3493// Second render, at priority 2:
3494// Base state: 'A' <- The base state does not include C1,
3495// because B2 was skipped.
3496// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
3497// Result state: 'ABCD'
3498//
3499// Because we process updates in insertion order, and rebase high priority
3500// updates when preceding updates are skipped, the final result is deterministic
3501// regardless of priority. Intermediate state may vary according to system
3502// resources, but the final state is always the same.
3503var UpdateState = 0;
3504var ReplaceState = 1;
3505var ForceUpdate = 2;
3506var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
3507// It should only be read right after calling `processUpdateQueue`, via
3508// `checkHasForceUpdateAfterProcessing`.
3509
3510var hasForceUpdate = false;
3511var didWarnUpdateInsideUpdate;
3512var currentlyProcessingQueue;
3513
3514
3515{
3516 didWarnUpdateInsideUpdate = false;
3517 currentlyProcessingQueue = null;
3518
3519
3520}
3521
3522function createUpdateQueue(baseState) {
3523 var queue = {
3524 baseState: baseState,
3525 firstUpdate: null,
3526 lastUpdate: null,
3527 firstCapturedUpdate: null,
3528 lastCapturedUpdate: null,
3529 firstEffect: null,
3530 lastEffect: null,
3531 firstCapturedEffect: null,
3532 lastCapturedEffect: null
3533 };
3534 return queue;
3535}
3536
3537function cloneUpdateQueue(currentQueue) {
3538 var queue = {
3539 baseState: currentQueue.baseState,
3540 firstUpdate: currentQueue.firstUpdate,
3541 lastUpdate: currentQueue.lastUpdate,
3542 // TODO: With resuming, if we bail out and resuse the child tree, we should
3543 // keep these effects.
3544 firstCapturedUpdate: null,
3545 lastCapturedUpdate: null,
3546 firstEffect: null,
3547 lastEffect: null,
3548 firstCapturedEffect: null,
3549 lastCapturedEffect: null
3550 };
3551 return queue;
3552}
3553
3554function createUpdate(expirationTime, suspenseConfig) {
3555 var update = {
3556 expirationTime: expirationTime,
3557 suspenseConfig: suspenseConfig,
3558 tag: UpdateState,
3559 payload: null,
3560 callback: null,
3561 next: null,
3562 nextEffect: null
3563 };
3564
3565 {
3566 update.priority = getCurrentPriorityLevel();
3567 }
3568
3569 return update;
3570}
3571
3572function appendUpdateToQueue(queue, update) {
3573 // Append the update to the end of the list.
3574 if (queue.lastUpdate === null) {
3575 // Queue is empty
3576 queue.firstUpdate = queue.lastUpdate = update;
3577 } else {
3578 queue.lastUpdate.next = update;
3579 queue.lastUpdate = update;
3580 }
3581}
3582
3583function enqueueUpdate(fiber, update) {
3584 // Update queues are created lazily.
3585 var alternate = fiber.alternate;
3586 var queue1;
3587 var queue2;
3588
3589 if (alternate === null) {
3590 // There's only one fiber.
3591 queue1 = fiber.updateQueue;
3592 queue2 = null;
3593
3594 if (queue1 === null) {
3595 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3596 }
3597 } else {
3598 // There are two owners.
3599 queue1 = fiber.updateQueue;
3600 queue2 = alternate.updateQueue;
3601
3602 if (queue1 === null) {
3603 if (queue2 === null) {
3604 // Neither fiber has an update queue. Create new ones.
3605 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3606 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
3607 } else {
3608 // Only one fiber has an update queue. Clone to create a new one.
3609 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
3610 }
3611 } else {
3612 if (queue2 === null) {
3613 // Only one fiber has an update queue. Clone to create a new one.
3614 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
3615 } else {// Both owners have an update queue.
3616 }
3617 }
3618 }
3619
3620 if (queue2 === null || queue1 === queue2) {
3621 // There's only a single queue.
3622 appendUpdateToQueue(queue1, update);
3623 } else {
3624 // There are two queues. We need to append the update to both queues,
3625 // while accounting for the persistent structure of the list — we don't
3626 // want the same update to be added multiple times.
3627 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
3628 // One of the queues is not empty. We must add the update to both queues.
3629 appendUpdateToQueue(queue1, update);
3630 appendUpdateToQueue(queue2, update);
3631 } else {
3632 // Both queues are non-empty. The last update is the same in both lists,
3633 // because of structural sharing. So, only append to one of the lists.
3634 appendUpdateToQueue(queue1, update); // But we still need to update the `lastUpdate` pointer of queue2.
3635
3636 queue2.lastUpdate = update;
3637 }
3638 }
3639
3640 {
3641 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
3642 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.');
3643 didWarnUpdateInsideUpdate = true;
3644 }
3645 }
3646}
3647function enqueueCapturedUpdate(workInProgress, update) {
3648 // Captured updates go into a separate list, and only on the work-in-
3649 // progress queue.
3650 var workInProgressQueue = workInProgress.updateQueue;
3651
3652 if (workInProgressQueue === null) {
3653 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
3654 } else {
3655 // TODO: I put this here rather than createWorkInProgress so that we don't
3656 // clone the queue unnecessarily. There's probably a better way to
3657 // structure this.
3658 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
3659 } // Append the update to the end of the list.
3660
3661
3662 if (workInProgressQueue.lastCapturedUpdate === null) {
3663 // This is the first render phase update
3664 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
3665 } else {
3666 workInProgressQueue.lastCapturedUpdate.next = update;
3667 workInProgressQueue.lastCapturedUpdate = update;
3668 }
3669}
3670
3671function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
3672 var current = workInProgress.alternate;
3673
3674 if (current !== null) {
3675 // If the work-in-progress queue is equal to the current queue,
3676 // we need to clone it first.
3677 if (queue === current.updateQueue) {
3678 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
3679 }
3680 }
3681
3682 return queue;
3683}
3684
3685function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
3686 switch (update.tag) {
3687 case ReplaceState:
3688 {
3689 var payload = update.payload;
3690
3691 if (typeof payload === 'function') {
3692 // Updater function
3693 {
3694 enterDisallowedContextReadInDEV();
3695
3696 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3697 payload.call(instance, prevState, nextProps);
3698 }
3699 }
3700
3701 var nextState = payload.call(instance, prevState, nextProps);
3702
3703 {
3704 exitDisallowedContextReadInDEV();
3705 }
3706
3707 return nextState;
3708 } // State object
3709
3710
3711 return payload;
3712 }
3713
3714 case CaptureUpdate:
3715 {
3716 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
3717 }
3718 // Intentional fallthrough
3719
3720 case UpdateState:
3721 {
3722 var _payload = update.payload;
3723 var partialState;
3724
3725 if (typeof _payload === 'function') {
3726 // Updater function
3727 {
3728 enterDisallowedContextReadInDEV();
3729
3730 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3731 _payload.call(instance, prevState, nextProps);
3732 }
3733 }
3734
3735 partialState = _payload.call(instance, prevState, nextProps);
3736
3737 {
3738 exitDisallowedContextReadInDEV();
3739 }
3740 } else {
3741 // Partial state object
3742 partialState = _payload;
3743 }
3744
3745 if (partialState === null || partialState === undefined) {
3746 // Null and undefined are treated as no-ops.
3747 return prevState;
3748 } // Merge the partial state and the previous state.
3749
3750
3751 return _assign({}, prevState, partialState);
3752 }
3753
3754 case ForceUpdate:
3755 {
3756 hasForceUpdate = true;
3757 return prevState;
3758 }
3759 }
3760
3761 return prevState;
3762}
3763
3764function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
3765 hasForceUpdate = false;
3766 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
3767
3768 {
3769 currentlyProcessingQueue = queue;
3770 } // These values may change as we process the queue.
3771
3772
3773 var newBaseState = queue.baseState;
3774 var newFirstUpdate = null;
3775 var newExpirationTime = NoWork; // Iterate through the list of updates to compute the result.
3776
3777 var update = queue.firstUpdate;
3778 var resultState = newBaseState;
3779
3780 while (update !== null) {
3781 var updateExpirationTime = update.expirationTime;
3782
3783 if (updateExpirationTime < renderExpirationTime) {
3784 // This update does not have sufficient priority. Skip it.
3785 if (newFirstUpdate === null) {
3786 // This is the first skipped update. It will be the first update in
3787 // the new list.
3788 newFirstUpdate = update; // Since this is the first update that was skipped, the current result
3789 // is the new base state.
3790
3791 newBaseState = resultState;
3792 } // Since this update will remain in the list, update the remaining
3793 // expiration time.
3794
3795
3796 if (newExpirationTime < updateExpirationTime) {
3797 newExpirationTime = updateExpirationTime;
3798 }
3799 } else {
3800 // This update does have sufficient priority.
3801 // Mark the event time of this update as relevant to this render pass.
3802 // TODO: This should ideally use the true event time of this update rather than
3803 // its priority which is a derived and not reverseable value.
3804 // TODO: We should skip this update if it was already committed but currently
3805 // we have no way of detecting the difference between a committed and suspended
3806 // update here.
3807 markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process it and compute a new result.
3808
3809 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3810 var callback = update.callback;
3811
3812 if (callback !== null) {
3813 workInProgress.effectTag |= Callback; // Set this to null, in case it was mutated during an aborted render.
3814
3815 update.nextEffect = null;
3816
3817 if (queue.lastEffect === null) {
3818 queue.firstEffect = queue.lastEffect = update;
3819 } else {
3820 queue.lastEffect.nextEffect = update;
3821 queue.lastEffect = update;
3822 }
3823 }
3824 } // Continue to the next update.
3825
3826
3827 update = update.next;
3828 } // Separately, iterate though the list of captured updates.
3829
3830
3831 var newFirstCapturedUpdate = null;
3832 update = queue.firstCapturedUpdate;
3833
3834 while (update !== null) {
3835 var _updateExpirationTime = update.expirationTime;
3836
3837 if (_updateExpirationTime < renderExpirationTime) {
3838 // This update does not have sufficient priority. Skip it.
3839 if (newFirstCapturedUpdate === null) {
3840 // This is the first skipped captured update. It will be the first
3841 // update in the new list.
3842 newFirstCapturedUpdate = update; // If this is the first update that was skipped, the current result is
3843 // the new base state.
3844
3845 if (newFirstUpdate === null) {
3846 newBaseState = resultState;
3847 }
3848 } // Since this update will remain in the list, update the remaining
3849 // expiration time.
3850
3851
3852 if (newExpirationTime < _updateExpirationTime) {
3853 newExpirationTime = _updateExpirationTime;
3854 }
3855 } else {
3856 // This update does have sufficient priority. Process it and compute
3857 // a new result.
3858 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3859 var _callback = update.callback;
3860
3861 if (_callback !== null) {
3862 workInProgress.effectTag |= Callback; // Set this to null, in case it was mutated during an aborted render.
3863
3864 update.nextEffect = null;
3865
3866 if (queue.lastCapturedEffect === null) {
3867 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
3868 } else {
3869 queue.lastCapturedEffect.nextEffect = update;
3870 queue.lastCapturedEffect = update;
3871 }
3872 }
3873 }
3874
3875 update = update.next;
3876 }
3877
3878 if (newFirstUpdate === null) {
3879 queue.lastUpdate = null;
3880 }
3881
3882 if (newFirstCapturedUpdate === null) {
3883 queue.lastCapturedUpdate = null;
3884 } else {
3885 workInProgress.effectTag |= Callback;
3886 }
3887
3888 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
3889 // We processed every update, without skipping. That means the new base
3890 // state is the same as the result state.
3891 newBaseState = resultState;
3892 }
3893
3894 queue.baseState = newBaseState;
3895 queue.firstUpdate = newFirstUpdate;
3896 queue.firstCapturedUpdate = newFirstCapturedUpdate; // Set the remaining expiration time to be whatever is remaining in the queue.
3897 // This should be fine because the only two other things that contribute to
3898 // expiration time are props and context. We're already in the middle of the
3899 // begin phase by the time we start processing the queue, so we've already
3900 // dealt with the props. Context in components that specify
3901 // shouldComponentUpdate is tricky; but we'll have to account for
3902 // that regardless.
3903
3904 markUnprocessedUpdateTime(newExpirationTime);
3905 workInProgress.expirationTime = newExpirationTime;
3906 workInProgress.memoizedState = resultState;
3907
3908 {
3909 currentlyProcessingQueue = null;
3910 }
3911}
3912
3913function callCallback(callback, context) {
3914 if (!(typeof callback === 'function')) {
3915 {
3916 throw Error("Invalid argument passed as callback. Expected a function. Instead received: " + callback);
3917 }
3918 }
3919
3920 callback.call(context);
3921}
3922
3923function resetHasForceUpdateBeforeProcessing() {
3924 hasForceUpdate = false;
3925}
3926function checkHasForceUpdateAfterProcessing() {
3927 return hasForceUpdate;
3928}
3929function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
3930 // If the finished render included captured updates, and there are still
3931 // lower priority updates left over, we need to keep the captured updates
3932 // in the queue so that they are rebased and not dropped once we process the
3933 // queue again at the lower priority.
3934 if (finishedQueue.firstCapturedUpdate !== null) {
3935 // Join the captured update list to the end of the normal list.
3936 if (finishedQueue.lastUpdate !== null) {
3937 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
3938 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
3939 } // Clear the list of captured updates.
3940
3941
3942 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
3943 } // Commit the effects
3944
3945
3946 commitUpdateEffects(finishedQueue.firstEffect, instance);
3947 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
3948 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
3949 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
3950}
3951
3952function commitUpdateEffects(effect, instance) {
3953 while (effect !== null) {
3954 var callback = effect.callback;
3955
3956 if (callback !== null) {
3957 effect.callback = null;
3958 callCallback(callback, instance);
3959 }
3960
3961 effect = effect.nextEffect;
3962 }
3963}
3964
3965var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
3966function requestCurrentSuspenseConfig() {
3967 return ReactCurrentBatchConfig.suspense;
3968}
3969
3970var fakeInternalInstance = {};
3971var isArray$1 = Array.isArray; // React.Component uses a shared frozen object by default.
3972// We'll use it to determine whether we need to initialize legacy refs.
3973
3974var emptyRefsObject = new React.Component().refs;
3975var didWarnAboutStateAssignmentForComponent;
3976var didWarnAboutUninitializedState;
3977var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
3978var didWarnAboutLegacyLifecyclesAndDerivedState;
3979var didWarnAboutUndefinedDerivedState;
3980var warnOnUndefinedDerivedState;
3981var warnOnInvalidCallback;
3982var didWarnAboutDirectlyAssigningPropsToState;
3983var didWarnAboutContextTypeAndContextTypes;
3984var didWarnAboutInvalidateContextType;
3985
3986{
3987 didWarnAboutStateAssignmentForComponent = new Set();
3988 didWarnAboutUninitializedState = new Set();
3989 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3990 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3991 didWarnAboutDirectlyAssigningPropsToState = new Set();
3992 didWarnAboutUndefinedDerivedState = new Set();
3993 didWarnAboutContextTypeAndContextTypes = new Set();
3994 didWarnAboutInvalidateContextType = new Set();
3995 var didWarnOnInvalidCallback = new Set();
3996
3997 warnOnInvalidCallback = function (callback, callerName) {
3998 if (callback === null || typeof callback === 'function') {
3999 return;
4000 }
4001
4002 var key = callerName + "_" + callback;
4003
4004 if (!didWarnOnInvalidCallback.has(key)) {
4005 didWarnOnInvalidCallback.add(key);
4006 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
4007 }
4008 };
4009
4010 warnOnUndefinedDerivedState = function (type, partialState) {
4011 if (partialState === undefined) {
4012 var componentName = getComponentName(type) || 'Component';
4013
4014 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
4015 didWarnAboutUndefinedDerivedState.add(componentName);
4016 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
4017 }
4018 }
4019 }; // This is so gross but it's at least non-critical and can be removed if
4020 // it causes problems. This is meant to give a nicer error message for
4021 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
4022 // ...)) which otherwise throws a "_processChildContext is not a function"
4023 // exception.
4024
4025
4026 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
4027 enumerable: false,
4028 value: function () {
4029 {
4030 {
4031 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).");
4032 }
4033 }
4034 }
4035 });
4036 Object.freeze(fakeInternalInstance);
4037}
4038
4039function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
4040 var prevState = workInProgress.memoizedState;
4041
4042 {
4043 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4044 // Invoke the function an extra time to help detect side-effects.
4045 getDerivedStateFromProps(nextProps, prevState);
4046 }
4047 }
4048
4049 var partialState = getDerivedStateFromProps(nextProps, prevState);
4050
4051 {
4052 warnOnUndefinedDerivedState(ctor, partialState);
4053 } // Merge the partial state and the previous state.
4054
4055
4056 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
4057 workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
4058 // base state.
4059
4060 var updateQueue = workInProgress.updateQueue;
4061
4062 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
4063 updateQueue.baseState = memoizedState;
4064 }
4065}
4066var classComponentUpdater = {
4067 isMounted: isMounted,
4068 enqueueSetState: function (inst, payload, callback) {
4069 var fiber = get(inst);
4070 var currentTime = requestCurrentTimeForUpdate();
4071 var suspenseConfig = requestCurrentSuspenseConfig();
4072 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4073 var update = createUpdate(expirationTime, suspenseConfig);
4074 update.payload = payload;
4075
4076 if (callback !== undefined && callback !== null) {
4077 {
4078 warnOnInvalidCallback(callback, 'setState');
4079 }
4080
4081 update.callback = callback;
4082 }
4083
4084 enqueueUpdate(fiber, update);
4085 scheduleWork(fiber, expirationTime);
4086 },
4087 enqueueReplaceState: function (inst, payload, callback) {
4088 var fiber = get(inst);
4089 var currentTime = requestCurrentTimeForUpdate();
4090 var suspenseConfig = requestCurrentSuspenseConfig();
4091 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4092 var update = createUpdate(expirationTime, suspenseConfig);
4093 update.tag = ReplaceState;
4094 update.payload = payload;
4095
4096 if (callback !== undefined && callback !== null) {
4097 {
4098 warnOnInvalidCallback(callback, 'replaceState');
4099 }
4100
4101 update.callback = callback;
4102 }
4103
4104 enqueueUpdate(fiber, update);
4105 scheduleWork(fiber, expirationTime);
4106 },
4107 enqueueForceUpdate: function (inst, callback) {
4108 var fiber = get(inst);
4109 var currentTime = requestCurrentTimeForUpdate();
4110 var suspenseConfig = requestCurrentSuspenseConfig();
4111 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4112 var update = createUpdate(expirationTime, suspenseConfig);
4113 update.tag = ForceUpdate;
4114
4115 if (callback !== undefined && callback !== null) {
4116 {
4117 warnOnInvalidCallback(callback, 'forceUpdate');
4118 }
4119
4120 update.callback = callback;
4121 }
4122
4123 enqueueUpdate(fiber, update);
4124 scheduleWork(fiber, expirationTime);
4125 }
4126};
4127
4128function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
4129 var instance = workInProgress.stateNode;
4130
4131 if (typeof instance.shouldComponentUpdate === 'function') {
4132 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
4133 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
4134 stopPhaseTimer();
4135
4136 {
4137 !(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;
4138 }
4139
4140 return shouldUpdate;
4141 }
4142
4143 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
4144 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
4145 }
4146
4147 return true;
4148}
4149
4150function checkClassInstance(workInProgress, ctor, newProps) {
4151 var instance = workInProgress.stateNode;
4152
4153 {
4154 var name = getComponentName(ctor) || 'Component';
4155 var renderPresent = instance.render;
4156
4157 if (!renderPresent) {
4158 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
4159 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
4160 } else {
4161 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
4162 }
4163 }
4164
4165 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
4166 !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;
4167 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
4168 !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;
4169 var noInstancePropTypes = !instance.propTypes;
4170 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
4171 var noInstanceContextType = !instance.contextType;
4172 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
4173
4174 if (disableLegacyContext) {
4175 if (ctor.childContextTypes) {
4176 warningWithoutStack$1(false, '%s uses the legacy childContextTypes API which is no longer supported. ' + 'Use React.createContext() instead.', name);
4177 }
4178
4179 if (ctor.contextTypes) {
4180 warningWithoutStack$1(false, '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with static contextType instead.', name);
4181 }
4182 } else {
4183 var noInstanceContextTypes = !instance.contextTypes;
4184 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
4185
4186 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
4187 didWarnAboutContextTypeAndContextTypes.add(ctor);
4188 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
4189 }
4190 }
4191
4192 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
4193 !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;
4194
4195 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
4196 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');
4197 }
4198
4199 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
4200 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
4201 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
4202 !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;
4203 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
4204 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
4205 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
4206 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
4207 var hasMutatedProps = instance.props !== newProps;
4208 !(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;
4209 var noInstanceDefaultProps = !instance.defaultProps;
4210 !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;
4211
4212 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
4213 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
4214 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
4215 }
4216
4217 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
4218 !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;
4219 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
4220 !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;
4221 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
4222 !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;
4223 var _state = instance.state;
4224
4225 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
4226 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
4227 }
4228
4229 if (typeof instance.getChildContext === 'function') {
4230 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
4231 }
4232 }
4233}
4234
4235function adoptClassInstance(workInProgress, instance) {
4236 instance.updater = classComponentUpdater;
4237 workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
4238
4239 set$1(instance, workInProgress);
4240
4241 {
4242 instance._reactInternalInstance = fakeInternalInstance;
4243 }
4244}
4245
4246function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
4247 var isLegacyContextConsumer = false;
4248 var unmaskedContext = emptyContextObject;
4249 var context = emptyContextObject;
4250 var contextType = ctor.contextType;
4251
4252 {
4253 if ('contextType' in ctor) {
4254 var isValid = // Allow null for conditional declaration
4255 contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
4256
4257 if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
4258 didWarnAboutInvalidateContextType.add(ctor);
4259 var addendum = '';
4260
4261 if (contextType === undefined) {
4262 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.';
4263 } else if (typeof contextType !== 'object') {
4264 addendum = ' However, it is set to a ' + typeof contextType + '.';
4265 } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
4266 addendum = ' Did you accidentally pass the Context.Provider instead?';
4267 } else if (contextType._context !== undefined) {
4268 // <Context.Consumer>
4269 addendum = ' Did you accidentally pass the Context.Consumer instead?';
4270 } else {
4271 addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
4272 }
4273
4274 warningWithoutStack$1(false, '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
4275 }
4276 }
4277 }
4278
4279 if (typeof contextType === 'object' && contextType !== null) {
4280 context = readContext(contextType);
4281 } else if (!disableLegacyContext) {
4282 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4283 var contextTypes = ctor.contextTypes;
4284 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
4285 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
4286 } // Instantiate twice to help detect side-effects.
4287
4288
4289 {
4290 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4291 new ctor(props, context); // eslint-disable-line no-new
4292 }
4293 }
4294
4295 var instance = new ctor(props, context);
4296 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
4297 adoptClassInstance(workInProgress, instance);
4298
4299 {
4300 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
4301 var componentName = getComponentName(ctor) || 'Component';
4302
4303 if (!didWarnAboutUninitializedState.has(componentName)) {
4304 didWarnAboutUninitializedState.add(componentName);
4305 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);
4306 }
4307 } // If new component APIs are defined, "unsafe" lifecycles won't be called.
4308 // Warn about these lifecycles if they are present.
4309 // Don't warn about react-lifecycles-compat polyfilled methods though.
4310
4311
4312 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
4313 var foundWillMountName = null;
4314 var foundWillReceivePropsName = null;
4315 var foundWillUpdateName = null;
4316
4317 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
4318 foundWillMountName = 'componentWillMount';
4319 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
4320 foundWillMountName = 'UNSAFE_componentWillMount';
4321 }
4322
4323 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
4324 foundWillReceivePropsName = 'componentWillReceiveProps';
4325 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4326 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
4327 }
4328
4329 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
4330 foundWillUpdateName = 'componentWillUpdate';
4331 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4332 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
4333 }
4334
4335 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
4336 var _componentName = getComponentName(ctor) || 'Component';
4337
4338 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
4339
4340 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
4341 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
4342 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 : '');
4343 }
4344 }
4345 }
4346 } // Cache unmasked context so we can avoid recreating masked context unless necessary.
4347 // ReactFiberContext usually updates this cache but can't for newly-created instances.
4348
4349
4350 if (isLegacyContextConsumer) {
4351 cacheContext(workInProgress, unmaskedContext, context);
4352 }
4353
4354 return instance;
4355}
4356
4357function callComponentWillMount(workInProgress, instance) {
4358 startPhaseTimer(workInProgress, 'componentWillMount');
4359 var oldState = instance.state;
4360
4361 if (typeof instance.componentWillMount === 'function') {
4362 instance.componentWillMount();
4363 }
4364
4365 if (typeof instance.UNSAFE_componentWillMount === 'function') {
4366 instance.UNSAFE_componentWillMount();
4367 }
4368
4369 stopPhaseTimer();
4370
4371 if (oldState !== instance.state) {
4372 {
4373 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');
4374 }
4375
4376 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
4377 }
4378}
4379
4380function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
4381 var oldState = instance.state;
4382 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
4383
4384 if (typeof instance.componentWillReceiveProps === 'function') {
4385 instance.componentWillReceiveProps(newProps, nextContext);
4386 }
4387
4388 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4389 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
4390 }
4391
4392 stopPhaseTimer();
4393
4394 if (instance.state !== oldState) {
4395 {
4396 var componentName = getComponentName(workInProgress.type) || 'Component';
4397
4398 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
4399 didWarnAboutStateAssignmentForComponent.add(componentName);
4400 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
4401 }
4402 }
4403
4404 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
4405 }
4406} // Invokes the mount life-cycles on a previously never rendered instance.
4407
4408
4409function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
4410 {
4411 checkClassInstance(workInProgress, ctor, newProps);
4412 }
4413
4414 var instance = workInProgress.stateNode;
4415 instance.props = newProps;
4416 instance.state = workInProgress.memoizedState;
4417 instance.refs = emptyRefsObject;
4418 var contextType = ctor.contextType;
4419
4420 if (typeof contextType === 'object' && contextType !== null) {
4421 instance.context = readContext(contextType);
4422 } else if (disableLegacyContext) {
4423 instance.context = emptyContextObject;
4424 } else {
4425 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4426 instance.context = getMaskedContext(workInProgress, unmaskedContext);
4427 }
4428
4429 {
4430 if (instance.state === newProps) {
4431 var componentName = getComponentName(ctor) || 'Component';
4432
4433 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
4434 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
4435 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);
4436 }
4437 }
4438
4439 if (workInProgress.mode & StrictMode) {
4440 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
4441 }
4442
4443 if (warnAboutDeprecatedLifecycles) {
4444 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
4445 }
4446 }
4447
4448 var updateQueue = workInProgress.updateQueue;
4449
4450 if (updateQueue !== null) {
4451 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4452 instance.state = workInProgress.memoizedState;
4453 }
4454
4455 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4456
4457 if (typeof getDerivedStateFromProps === 'function') {
4458 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4459 instance.state = workInProgress.memoizedState;
4460 } // In order to support react-lifecycles-compat polyfilled components,
4461 // Unsafe lifecycles should not be invoked for components using the new APIs.
4462
4463
4464 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
4465 callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
4466 // process them now.
4467
4468 updateQueue = workInProgress.updateQueue;
4469
4470 if (updateQueue !== null) {
4471 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4472 instance.state = workInProgress.memoizedState;
4473 }
4474 }
4475
4476 if (typeof instance.componentDidMount === 'function') {
4477 workInProgress.effectTag |= Update;
4478 }
4479}
4480
4481function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
4482 var instance = workInProgress.stateNode;
4483 var oldProps = workInProgress.memoizedProps;
4484 instance.props = oldProps;
4485 var oldContext = instance.context;
4486 var contextType = ctor.contextType;
4487 var nextContext = emptyContextObject;
4488
4489 if (typeof contextType === 'object' && contextType !== null) {
4490 nextContext = readContext(contextType);
4491 } else if (!disableLegacyContext) {
4492 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4493 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
4494 }
4495
4496 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4497 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
4498 // ever the previously attempted to render - not the "current". However,
4499 // during componentDidUpdate we pass the "current" props.
4500 // In order to support react-lifecycles-compat polyfilled components,
4501 // Unsafe lifecycles should not be invoked for components using the new APIs.
4502
4503 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
4504 if (oldProps !== newProps || oldContext !== nextContext) {
4505 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
4506 }
4507 }
4508
4509 resetHasForceUpdateBeforeProcessing();
4510 var oldState = workInProgress.memoizedState;
4511 var newState = instance.state = oldState;
4512 var updateQueue = workInProgress.updateQueue;
4513
4514 if (updateQueue !== null) {
4515 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4516 newState = workInProgress.memoizedState;
4517 }
4518
4519 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
4520 // If an update was already in progress, we should schedule an Update
4521 // effect even though we're bailing out, so that cWU/cDU are called.
4522 if (typeof instance.componentDidMount === 'function') {
4523 workInProgress.effectTag |= Update;
4524 }
4525
4526 return false;
4527 }
4528
4529 if (typeof getDerivedStateFromProps === 'function') {
4530 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4531 newState = workInProgress.memoizedState;
4532 }
4533
4534 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
4535
4536 if (shouldUpdate) {
4537 // In order to support react-lifecycles-compat polyfilled components,
4538 // Unsafe lifecycles should not be invoked for components using the new APIs.
4539 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
4540 startPhaseTimer(workInProgress, 'componentWillMount');
4541
4542 if (typeof instance.componentWillMount === 'function') {
4543 instance.componentWillMount();
4544 }
4545
4546 if (typeof instance.UNSAFE_componentWillMount === 'function') {
4547 instance.UNSAFE_componentWillMount();
4548 }
4549
4550 stopPhaseTimer();
4551 }
4552
4553 if (typeof instance.componentDidMount === 'function') {
4554 workInProgress.effectTag |= Update;
4555 }
4556 } else {
4557 // If an update was already in progress, we should schedule an Update
4558 // effect even though we're bailing out, so that cWU/cDU are called.
4559 if (typeof instance.componentDidMount === 'function') {
4560 workInProgress.effectTag |= Update;
4561 } // If shouldComponentUpdate returned false, we should still update the
4562 // memoized state to indicate that this work can be reused.
4563
4564
4565 workInProgress.memoizedProps = newProps;
4566 workInProgress.memoizedState = newState;
4567 } // Update the existing instance's state, props, and context pointers even
4568 // if shouldComponentUpdate returns false.
4569
4570
4571 instance.props = newProps;
4572 instance.state = newState;
4573 instance.context = nextContext;
4574 return shouldUpdate;
4575} // Invokes the update life-cycles and returns false if it shouldn't rerender.
4576
4577
4578function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
4579 var instance = workInProgress.stateNode;
4580 var oldProps = workInProgress.memoizedProps;
4581 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
4582 var oldContext = instance.context;
4583 var contextType = ctor.contextType;
4584 var nextContext = emptyContextObject;
4585
4586 if (typeof contextType === 'object' && contextType !== null) {
4587 nextContext = readContext(contextType);
4588 } else if (!disableLegacyContext) {
4589 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4590 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
4591 }
4592
4593 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4594 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
4595 // ever the previously attempted to render - not the "current". However,
4596 // during componentDidUpdate we pass the "current" props.
4597 // In order to support react-lifecycles-compat polyfilled components,
4598 // Unsafe lifecycles should not be invoked for components using the new APIs.
4599
4600 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
4601 if (oldProps !== newProps || oldContext !== nextContext) {
4602 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
4603 }
4604 }
4605
4606 resetHasForceUpdateBeforeProcessing();
4607 var oldState = workInProgress.memoizedState;
4608 var newState = instance.state = oldState;
4609 var updateQueue = workInProgress.updateQueue;
4610
4611 if (updateQueue !== null) {
4612 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4613 newState = workInProgress.memoizedState;
4614 }
4615
4616 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
4617 // If an update was already in progress, we should schedule an Update
4618 // effect even though we're bailing out, so that cWU/cDU are called.
4619 if (typeof instance.componentDidUpdate === 'function') {
4620 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4621 workInProgress.effectTag |= Update;
4622 }
4623 }
4624
4625 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4626 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4627 workInProgress.effectTag |= Snapshot;
4628 }
4629 }
4630
4631 return false;
4632 }
4633
4634 if (typeof getDerivedStateFromProps === 'function') {
4635 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4636 newState = workInProgress.memoizedState;
4637 }
4638
4639 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
4640
4641 if (shouldUpdate) {
4642 // In order to support react-lifecycles-compat polyfilled components,
4643 // Unsafe lifecycles should not be invoked for components using the new APIs.
4644 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
4645 startPhaseTimer(workInProgress, 'componentWillUpdate');
4646
4647 if (typeof instance.componentWillUpdate === 'function') {
4648 instance.componentWillUpdate(newProps, newState, nextContext);
4649 }
4650
4651 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4652 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
4653 }
4654
4655 stopPhaseTimer();
4656 }
4657
4658 if (typeof instance.componentDidUpdate === 'function') {
4659 workInProgress.effectTag |= Update;
4660 }
4661
4662 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4663 workInProgress.effectTag |= Snapshot;
4664 }
4665 } else {
4666 // If an update was already in progress, we should schedule an Update
4667 // effect even though we're bailing out, so that cWU/cDU are called.
4668 if (typeof instance.componentDidUpdate === 'function') {
4669 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4670 workInProgress.effectTag |= Update;
4671 }
4672 }
4673
4674 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4675 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4676 workInProgress.effectTag |= Snapshot;
4677 }
4678 } // If shouldComponentUpdate returned false, we should still update the
4679 // memoized props/state to indicate that this work can be reused.
4680
4681
4682 workInProgress.memoizedProps = newProps;
4683 workInProgress.memoizedState = newState;
4684 } // Update the existing instance's state, props, and context pointers even
4685 // if shouldComponentUpdate returns false.
4686
4687
4688 instance.props = newProps;
4689 instance.state = newState;
4690 instance.context = nextContext;
4691 return shouldUpdate;
4692}
4693
4694var didWarnAboutMaps;
4695var didWarnAboutGenerators;
4696var didWarnAboutStringRefs;
4697var ownerHasKeyUseWarning;
4698var ownerHasFunctionTypeWarning;
4699
4700var warnForMissingKey = function (child) {};
4701
4702{
4703 didWarnAboutMaps = false;
4704 didWarnAboutGenerators = false;
4705 didWarnAboutStringRefs = {};
4706 /**
4707 * Warn if there's no key explicitly set on dynamic arrays of children or
4708 * object keys are not valid. This allows us to keep track of children between
4709 * updates.
4710 */
4711
4712 ownerHasKeyUseWarning = {};
4713 ownerHasFunctionTypeWarning = {};
4714
4715 warnForMissingKey = function (child) {
4716 if (child === null || typeof child !== 'object') {
4717 return;
4718 }
4719
4720 if (!child._store || child._store.validated || child.key != null) {
4721 return;
4722 }
4723
4724 if (!(typeof child._store === 'object')) {
4725 {
4726 throw Error("React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue.");
4727 }
4728 }
4729
4730 child._store.validated = true;
4731 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
4732
4733 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
4734 return;
4735 }
4736
4737 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
4738 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
4739 };
4740}
4741
4742var isArray = Array.isArray;
4743
4744function coerceRef(returnFiber, current$$1, element) {
4745 var mixedRef = element.ref;
4746
4747 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
4748 {
4749 // TODO: Clean this up once we turn on the string ref warning for
4750 // everyone, because the strict mode case will no longer be relevant
4751 if (returnFiber.mode & StrictMode || warnAboutStringRefs) {
4752 var componentName = getComponentName(returnFiber.type) || 'Component';
4753
4754 if (!didWarnAboutStringRefs[componentName]) {
4755 if (warnAboutStringRefs) {
4756 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));
4757 } else {
4758 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));
4759 }
4760
4761 didWarnAboutStringRefs[componentName] = true;
4762 }
4763 }
4764 }
4765
4766 if (element._owner) {
4767 var owner = element._owner;
4768 var inst;
4769
4770 if (owner) {
4771 var ownerFiber = owner;
4772
4773 if (!(ownerFiber.tag === ClassComponent)) {
4774 {
4775 throw Error("Function components cannot have refs. Did you mean to use React.forwardRef()?");
4776 }
4777 }
4778
4779 inst = ownerFiber.stateNode;
4780 }
4781
4782 if (!inst) {
4783 {
4784 throw Error("Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue.");
4785 }
4786 }
4787
4788 var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
4789
4790 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
4791 return current$$1.ref;
4792 }
4793
4794 var ref = function (value) {
4795 var refs = inst.refs;
4796
4797 if (refs === emptyRefsObject) {
4798 // This is a lazy pooled frozen object, so we need to initialize.
4799 refs = inst.refs = {};
4800 }
4801
4802 if (value === null) {
4803 delete refs[stringRef];
4804 } else {
4805 refs[stringRef] = value;
4806 }
4807 };
4808
4809 ref._stringRef = stringRef;
4810 return ref;
4811 } else {
4812 if (!(typeof mixedRef === 'string')) {
4813 {
4814 throw Error("Expected ref to be a function, a string, an object returned by React.createRef(), or null.");
4815 }
4816 }
4817
4818 if (!element._owner) {
4819 {
4820 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.");
4821 }
4822 }
4823 }
4824 }
4825
4826 return mixedRef;
4827}
4828
4829function throwOnInvalidObjectType(returnFiber, newChild) {
4830 if (returnFiber.type !== 'textarea') {
4831 var addendum = '';
4832
4833 {
4834 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
4835 }
4836
4837 {
4838 {
4839 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);
4840 }
4841 }
4842 }
4843}
4844
4845function warnOnFunctionType() {
4846 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();
4847
4848 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
4849 return;
4850 }
4851
4852 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
4853 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.');
4854} // This wrapper function exists because I expect to clone the code in each path
4855// to be able to optimize each path individually by branching early. This needs
4856// a compiler or we can do it manually. Helpers that don't need this branching
4857// live outside of this function.
4858
4859
4860function ChildReconciler(shouldTrackSideEffects) {
4861 function deleteChild(returnFiber, childToDelete) {
4862 if (!shouldTrackSideEffects) {
4863 // Noop.
4864 return;
4865 } // Deletions are added in reversed order so we add it to the front.
4866 // At this point, the return fiber's effect list is empty except for
4867 // deletions, so we can just append the deletion to the list. The remaining
4868 // effects aren't added until the complete phase. Once we implement
4869 // resuming, this may not be true.
4870
4871
4872 var last = returnFiber.lastEffect;
4873
4874 if (last !== null) {
4875 last.nextEffect = childToDelete;
4876 returnFiber.lastEffect = childToDelete;
4877 } else {
4878 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
4879 }
4880
4881 childToDelete.nextEffect = null;
4882 childToDelete.effectTag = Deletion;
4883 }
4884
4885 function deleteRemainingChildren(returnFiber, currentFirstChild) {
4886 if (!shouldTrackSideEffects) {
4887 // Noop.
4888 return null;
4889 } // TODO: For the shouldClone case, this could be micro-optimized a bit by
4890 // assuming that after the first child we've already added everything.
4891
4892
4893 var childToDelete = currentFirstChild;
4894
4895 while (childToDelete !== null) {
4896 deleteChild(returnFiber, childToDelete);
4897 childToDelete = childToDelete.sibling;
4898 }
4899
4900 return null;
4901 }
4902
4903 function mapRemainingChildren(returnFiber, currentFirstChild) {
4904 // Add the remaining children to a temporary map so that we can find them by
4905 // keys quickly. Implicit (null) keys get added to this set with their index
4906 // instead.
4907 var existingChildren = new Map();
4908 var existingChild = currentFirstChild;
4909
4910 while (existingChild !== null) {
4911 if (existingChild.key !== null) {
4912 existingChildren.set(existingChild.key, existingChild);
4913 } else {
4914 existingChildren.set(existingChild.index, existingChild);
4915 }
4916
4917 existingChild = existingChild.sibling;
4918 }
4919
4920 return existingChildren;
4921 }
4922
4923 function useFiber(fiber, pendingProps, expirationTime) {
4924 // We currently set sibling to null and index to 0 here because it is easy
4925 // to forget to do before returning it. E.g. for the single child case.
4926 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4927 clone.index = 0;
4928 clone.sibling = null;
4929 return clone;
4930 }
4931
4932 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4933 newFiber.index = newIndex;
4934
4935 if (!shouldTrackSideEffects) {
4936 // Noop.
4937 return lastPlacedIndex;
4938 }
4939
4940 var current$$1 = newFiber.alternate;
4941
4942 if (current$$1 !== null) {
4943 var oldIndex = current$$1.index;
4944
4945 if (oldIndex < lastPlacedIndex) {
4946 // This is a move.
4947 newFiber.effectTag = Placement;
4948 return lastPlacedIndex;
4949 } else {
4950 // This item can stay in place.
4951 return oldIndex;
4952 }
4953 } else {
4954 // This is an insertion.
4955 newFiber.effectTag = Placement;
4956 return lastPlacedIndex;
4957 }
4958 }
4959
4960 function placeSingleChild(newFiber) {
4961 // This is simpler for the single child case. We only need to do a
4962 // placement for inserting new children.
4963 if (shouldTrackSideEffects && newFiber.alternate === null) {
4964 newFiber.effectTag = Placement;
4965 }
4966
4967 return newFiber;
4968 }
4969
4970 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4971 if (current$$1 === null || current$$1.tag !== HostText) {
4972 // Insert
4973 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4974 created.return = returnFiber;
4975 return created;
4976 } else {
4977 // Update
4978 var existing = useFiber(current$$1, textContent, expirationTime);
4979 existing.return = returnFiber;
4980 return existing;
4981 }
4982 }
4983
4984 function updateElement(returnFiber, current$$1, element, expirationTime) {
4985 if (current$$1 !== null && (current$$1.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
4986 isCompatibleFamilyForHotReloading(current$$1, element)))) {
4987 // Move based on index
4988 var existing = useFiber(current$$1, element.props, expirationTime);
4989 existing.ref = coerceRef(returnFiber, current$$1, element);
4990 existing.return = returnFiber;
4991
4992 {
4993 existing._debugSource = element._source;
4994 existing._debugOwner = element._owner;
4995 }
4996
4997 return existing;
4998 } else {
4999 // Insert
5000 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
5001 created.ref = coerceRef(returnFiber, current$$1, element);
5002 created.return = returnFiber;
5003 return created;
5004 }
5005 }
5006
5007 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
5008 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
5009 // Insert
5010 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
5011 created.return = returnFiber;
5012 return created;
5013 } else {
5014 // Update
5015 var existing = useFiber(current$$1, portal.children || [], expirationTime);
5016 existing.return = returnFiber;
5017 return existing;
5018 }
5019 }
5020
5021 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
5022 if (current$$1 === null || current$$1.tag !== Fragment) {
5023 // Insert
5024 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
5025 created.return = returnFiber;
5026 return created;
5027 } else {
5028 // Update
5029 var existing = useFiber(current$$1, fragment, expirationTime);
5030 existing.return = returnFiber;
5031 return existing;
5032 }
5033 }
5034
5035 function createChild(returnFiber, newChild, expirationTime) {
5036 if (typeof newChild === 'string' || typeof newChild === 'number') {
5037 // Text nodes don't have keys. If the previous node is implicitly keyed
5038 // we can continue to replace it without aborting even if it is not a text
5039 // node.
5040 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
5041 created.return = returnFiber;
5042 return created;
5043 }
5044
5045 if (typeof newChild === 'object' && newChild !== null) {
5046 switch (newChild.$$typeof) {
5047 case REACT_ELEMENT_TYPE$1:
5048 {
5049 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
5050
5051 _created.ref = coerceRef(returnFiber, null, newChild);
5052 _created.return = returnFiber;
5053 return _created;
5054 }
5055
5056 case REACT_PORTAL_TYPE:
5057 {
5058 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
5059
5060 _created2.return = returnFiber;
5061 return _created2;
5062 }
5063 }
5064
5065 if (isArray(newChild) || getIteratorFn(newChild)) {
5066 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
5067
5068 _created3.return = returnFiber;
5069 return _created3;
5070 }
5071
5072 throwOnInvalidObjectType(returnFiber, newChild);
5073 }
5074
5075 {
5076 if (typeof newChild === 'function') {
5077 warnOnFunctionType();
5078 }
5079 }
5080
5081 return null;
5082 }
5083
5084 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
5085 // Update the fiber if the keys match, otherwise return null.
5086 var key = oldFiber !== null ? oldFiber.key : null;
5087
5088 if (typeof newChild === 'string' || typeof newChild === 'number') {
5089 // Text nodes don't have keys. If the previous node is implicitly keyed
5090 // we can continue to replace it without aborting even if it is not a text
5091 // node.
5092 if (key !== null) {
5093 return null;
5094 }
5095
5096 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
5097 }
5098
5099 if (typeof newChild === 'object' && newChild !== null) {
5100 switch (newChild.$$typeof) {
5101 case REACT_ELEMENT_TYPE$1:
5102 {
5103 if (newChild.key === key) {
5104 if (newChild.type === REACT_FRAGMENT_TYPE) {
5105 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
5106 }
5107
5108 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
5109 } else {
5110 return null;
5111 }
5112 }
5113
5114 case REACT_PORTAL_TYPE:
5115 {
5116 if (newChild.key === key) {
5117 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
5118 } else {
5119 return null;
5120 }
5121 }
5122 }
5123
5124 if (isArray(newChild) || getIteratorFn(newChild)) {
5125 if (key !== null) {
5126 return null;
5127 }
5128
5129 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
5130 }
5131
5132 throwOnInvalidObjectType(returnFiber, newChild);
5133 }
5134
5135 {
5136 if (typeof newChild === 'function') {
5137 warnOnFunctionType();
5138 }
5139 }
5140
5141 return null;
5142 }
5143
5144 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
5145 if (typeof newChild === 'string' || typeof newChild === 'number') {
5146 // Text nodes don't have keys, so we neither have to check the old nor
5147 // new node for the key. If both are text nodes, they match.
5148 var matchedFiber = existingChildren.get(newIdx) || null;
5149 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
5150 }
5151
5152 if (typeof newChild === 'object' && newChild !== null) {
5153 switch (newChild.$$typeof) {
5154 case REACT_ELEMENT_TYPE$1:
5155 {
5156 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5157
5158 if (newChild.type === REACT_FRAGMENT_TYPE) {
5159 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
5160 }
5161
5162 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
5163 }
5164
5165 case REACT_PORTAL_TYPE:
5166 {
5167 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5168
5169 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
5170 }
5171 }
5172
5173 if (isArray(newChild) || getIteratorFn(newChild)) {
5174 var _matchedFiber3 = existingChildren.get(newIdx) || null;
5175
5176 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
5177 }
5178
5179 throwOnInvalidObjectType(returnFiber, newChild);
5180 }
5181
5182 {
5183 if (typeof newChild === 'function') {
5184 warnOnFunctionType();
5185 }
5186 }
5187
5188 return null;
5189 }
5190 /**
5191 * Warns if there is a duplicate or missing key
5192 */
5193
5194
5195 function warnOnInvalidKey(child, knownKeys) {
5196 {
5197 if (typeof child !== 'object' || child === null) {
5198 return knownKeys;
5199 }
5200
5201 switch (child.$$typeof) {
5202 case REACT_ELEMENT_TYPE$1:
5203 case REACT_PORTAL_TYPE:
5204 warnForMissingKey(child);
5205 var key = child.key;
5206
5207 if (typeof key !== 'string') {
5208 break;
5209 }
5210
5211 if (knownKeys === null) {
5212 knownKeys = new Set();
5213 knownKeys.add(key);
5214 break;
5215 }
5216
5217 if (!knownKeys.has(key)) {
5218 knownKeys.add(key);
5219 break;
5220 }
5221
5222 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);
5223 break;
5224
5225 default:
5226 break;
5227 }
5228 }
5229
5230 return knownKeys;
5231 }
5232
5233 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
5234 // This algorithm can't optimize by searching from both ends since we
5235 // don't have backpointers on fibers. I'm trying to see how far we can get
5236 // with that model. If it ends up not being worth the tradeoffs, we can
5237 // add it later.
5238 // Even with a two ended optimization, we'd want to optimize for the case
5239 // where there are few changes and brute force the comparison instead of
5240 // going for the Map. It'd like to explore hitting that path first in
5241 // forward-only mode and only go for the Map once we notice that we need
5242 // lots of look ahead. This doesn't handle reversal as well as two ended
5243 // search but that's unusual. Besides, for the two ended optimization to
5244 // work on Iterables, we'd need to copy the whole set.
5245 // In this first iteration, we'll just live with hitting the bad case
5246 // (adding everything to a Map) in for every insert/move.
5247 // If you change this code, also update reconcileChildrenIterator() which
5248 // uses the same algorithm.
5249 {
5250 // First, validate keys.
5251 var knownKeys = null;
5252
5253 for (var i = 0; i < newChildren.length; i++) {
5254 var child = newChildren[i];
5255 knownKeys = warnOnInvalidKey(child, knownKeys);
5256 }
5257 }
5258
5259 var resultingFirstChild = null;
5260 var previousNewFiber = null;
5261 var oldFiber = currentFirstChild;
5262 var lastPlacedIndex = 0;
5263 var newIdx = 0;
5264 var nextOldFiber = null;
5265
5266 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
5267 if (oldFiber.index > newIdx) {
5268 nextOldFiber = oldFiber;
5269 oldFiber = null;
5270 } else {
5271 nextOldFiber = oldFiber.sibling;
5272 }
5273
5274 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
5275
5276 if (newFiber === null) {
5277 // TODO: This breaks on empty slots like null children. That's
5278 // unfortunate because it triggers the slow path all the time. We need
5279 // a better way to communicate whether this was a miss or null,
5280 // boolean, undefined, etc.
5281 if (oldFiber === null) {
5282 oldFiber = nextOldFiber;
5283 }
5284
5285 break;
5286 }
5287
5288 if (shouldTrackSideEffects) {
5289 if (oldFiber && newFiber.alternate === null) {
5290 // We matched the slot, but we didn't reuse the existing fiber, so we
5291 // need to delete the existing child.
5292 deleteChild(returnFiber, oldFiber);
5293 }
5294 }
5295
5296 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5297
5298 if (previousNewFiber === null) {
5299 // TODO: Move out of the loop. This only happens for the first run.
5300 resultingFirstChild = newFiber;
5301 } else {
5302 // TODO: Defer siblings if we're not at the right index for this slot.
5303 // I.e. if we had null values before, then we want to defer this
5304 // for each null value. However, we also don't want to call updateSlot
5305 // with the previous one.
5306 previousNewFiber.sibling = newFiber;
5307 }
5308
5309 previousNewFiber = newFiber;
5310 oldFiber = nextOldFiber;
5311 }
5312
5313 if (newIdx === newChildren.length) {
5314 // We've reached the end of the new children. We can delete the rest.
5315 deleteRemainingChildren(returnFiber, oldFiber);
5316 return resultingFirstChild;
5317 }
5318
5319 if (oldFiber === null) {
5320 // If we don't have any more existing children we can choose a fast path
5321 // since the rest will all be insertions.
5322 for (; newIdx < newChildren.length; newIdx++) {
5323 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
5324
5325 if (_newFiber === null) {
5326 continue;
5327 }
5328
5329 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
5330
5331 if (previousNewFiber === null) {
5332 // TODO: Move out of the loop. This only happens for the first run.
5333 resultingFirstChild = _newFiber;
5334 } else {
5335 previousNewFiber.sibling = _newFiber;
5336 }
5337
5338 previousNewFiber = _newFiber;
5339 }
5340
5341 return resultingFirstChild;
5342 } // Add all children to a key map for quick lookups.
5343
5344
5345 var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
5346
5347 for (; newIdx < newChildren.length; newIdx++) {
5348 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
5349
5350 if (_newFiber2 !== null) {
5351 if (shouldTrackSideEffects) {
5352 if (_newFiber2.alternate !== null) {
5353 // The new fiber is a work in progress, but if there exists a
5354 // current, that means that we reused the fiber. We need to delete
5355 // it from the child list so that we don't add it to the deletion
5356 // list.
5357 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
5358 }
5359 }
5360
5361 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
5362
5363 if (previousNewFiber === null) {
5364 resultingFirstChild = _newFiber2;
5365 } else {
5366 previousNewFiber.sibling = _newFiber2;
5367 }
5368
5369 previousNewFiber = _newFiber2;
5370 }
5371 }
5372
5373 if (shouldTrackSideEffects) {
5374 // Any existing children that weren't consumed above were deleted. We need
5375 // to add them to the deletion list.
5376 existingChildren.forEach(function (child) {
5377 return deleteChild(returnFiber, child);
5378 });
5379 }
5380
5381 return resultingFirstChild;
5382 }
5383
5384 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
5385 // This is the same implementation as reconcileChildrenArray(),
5386 // but using the iterator instead.
5387 var iteratorFn = getIteratorFn(newChildrenIterable);
5388
5389 if (!(typeof iteratorFn === 'function')) {
5390 {
5391 throw Error("An object is not an iterable. This error is likely caused by a bug in React. Please file an issue.");
5392 }
5393 }
5394
5395 {
5396 // We don't support rendering Generators because it's a mutation.
5397 // See https://github.com/facebook/react/issues/12995
5398 if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
5399 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
5400 !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;
5401 didWarnAboutGenerators = true;
5402 } // Warn about using Maps as children
5403
5404
5405 if (newChildrenIterable.entries === iteratorFn) {
5406 !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;
5407 didWarnAboutMaps = true;
5408 } // First, validate keys.
5409 // We'll get a different iterator later for the main pass.
5410
5411
5412 var _newChildren = iteratorFn.call(newChildrenIterable);
5413
5414 if (_newChildren) {
5415 var knownKeys = null;
5416
5417 var _step = _newChildren.next();
5418
5419 for (; !_step.done; _step = _newChildren.next()) {
5420 var child = _step.value;
5421 knownKeys = warnOnInvalidKey(child, knownKeys);
5422 }
5423 }
5424 }
5425
5426 var newChildren = iteratorFn.call(newChildrenIterable);
5427
5428 if (!(newChildren != null)) {
5429 {
5430 throw Error("An iterable object provided no iterator.");
5431 }
5432 }
5433
5434 var resultingFirstChild = null;
5435 var previousNewFiber = null;
5436 var oldFiber = currentFirstChild;
5437 var lastPlacedIndex = 0;
5438 var newIdx = 0;
5439 var nextOldFiber = null;
5440 var step = newChildren.next();
5441
5442 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
5443 if (oldFiber.index > newIdx) {
5444 nextOldFiber = oldFiber;
5445 oldFiber = null;
5446 } else {
5447 nextOldFiber = oldFiber.sibling;
5448 }
5449
5450 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
5451
5452 if (newFiber === null) {
5453 // TODO: This breaks on empty slots like null children. That's
5454 // unfortunate because it triggers the slow path all the time. We need
5455 // a better way to communicate whether this was a miss or null,
5456 // boolean, undefined, etc.
5457 if (oldFiber === null) {
5458 oldFiber = nextOldFiber;
5459 }
5460
5461 break;
5462 }
5463
5464 if (shouldTrackSideEffects) {
5465 if (oldFiber && newFiber.alternate === null) {
5466 // We matched the slot, but we didn't reuse the existing fiber, so we
5467 // need to delete the existing child.
5468 deleteChild(returnFiber, oldFiber);
5469 }
5470 }
5471
5472 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5473
5474 if (previousNewFiber === null) {
5475 // TODO: Move out of the loop. This only happens for the first run.
5476 resultingFirstChild = newFiber;
5477 } else {
5478 // TODO: Defer siblings if we're not at the right index for this slot.
5479 // I.e. if we had null values before, then we want to defer this
5480 // for each null value. However, we also don't want to call updateSlot
5481 // with the previous one.
5482 previousNewFiber.sibling = newFiber;
5483 }
5484
5485 previousNewFiber = newFiber;
5486 oldFiber = nextOldFiber;
5487 }
5488
5489 if (step.done) {
5490 // We've reached the end of the new children. We can delete the rest.
5491 deleteRemainingChildren(returnFiber, oldFiber);
5492 return resultingFirstChild;
5493 }
5494
5495 if (oldFiber === null) {
5496 // If we don't have any more existing children we can choose a fast path
5497 // since the rest will all be insertions.
5498 for (; !step.done; newIdx++, step = newChildren.next()) {
5499 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
5500
5501 if (_newFiber3 === null) {
5502 continue;
5503 }
5504
5505 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
5506
5507 if (previousNewFiber === null) {
5508 // TODO: Move out of the loop. This only happens for the first run.
5509 resultingFirstChild = _newFiber3;
5510 } else {
5511 previousNewFiber.sibling = _newFiber3;
5512 }
5513
5514 previousNewFiber = _newFiber3;
5515 }
5516
5517 return resultingFirstChild;
5518 } // Add all children to a key map for quick lookups.
5519
5520
5521 var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
5522
5523 for (; !step.done; newIdx++, step = newChildren.next()) {
5524 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
5525
5526 if (_newFiber4 !== null) {
5527 if (shouldTrackSideEffects) {
5528 if (_newFiber4.alternate !== null) {
5529 // The new fiber is a work in progress, but if there exists a
5530 // current, that means that we reused the fiber. We need to delete
5531 // it from the child list so that we don't add it to the deletion
5532 // list.
5533 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
5534 }
5535 }
5536
5537 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
5538
5539 if (previousNewFiber === null) {
5540 resultingFirstChild = _newFiber4;
5541 } else {
5542 previousNewFiber.sibling = _newFiber4;
5543 }
5544
5545 previousNewFiber = _newFiber4;
5546 }
5547 }
5548
5549 if (shouldTrackSideEffects) {
5550 // Any existing children that weren't consumed above were deleted. We need
5551 // to add them to the deletion list.
5552 existingChildren.forEach(function (child) {
5553 return deleteChild(returnFiber, child);
5554 });
5555 }
5556
5557 return resultingFirstChild;
5558 }
5559
5560 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
5561 // There's no need to check for keys on text nodes since we don't have a
5562 // way to define them.
5563 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
5564 // We already have an existing node so let's just update it and delete
5565 // the rest.
5566 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
5567 var existing = useFiber(currentFirstChild, textContent, expirationTime);
5568 existing.return = returnFiber;
5569 return existing;
5570 } // The existing first child is not a text node so we need to create one
5571 // and delete the existing ones.
5572
5573
5574 deleteRemainingChildren(returnFiber, currentFirstChild);
5575 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
5576 created.return = returnFiber;
5577 return created;
5578 }
5579
5580 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
5581 var key = element.key;
5582 var child = currentFirstChild;
5583
5584 while (child !== null) {
5585 // TODO: If key === null and child.key === null, then this only applies to
5586 // the first item in the list.
5587 if (child.key === key) {
5588 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:
5589 isCompatibleFamilyForHotReloading(child, element))) {
5590 deleteRemainingChildren(returnFiber, child.sibling);
5591 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
5592 existing.ref = coerceRef(returnFiber, child, element);
5593 existing.return = returnFiber;
5594
5595 {
5596 existing._debugSource = element._source;
5597 existing._debugOwner = element._owner;
5598 }
5599
5600 return existing;
5601 } else {
5602 deleteRemainingChildren(returnFiber, child);
5603 break;
5604 }
5605 } else {
5606 deleteChild(returnFiber, child);
5607 }
5608
5609 child = child.sibling;
5610 }
5611
5612 if (element.type === REACT_FRAGMENT_TYPE) {
5613 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
5614 created.return = returnFiber;
5615 return created;
5616 } else {
5617 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
5618
5619 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
5620 _created4.return = returnFiber;
5621 return _created4;
5622 }
5623 }
5624
5625 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
5626 var key = portal.key;
5627 var child = currentFirstChild;
5628
5629 while (child !== null) {
5630 // TODO: If key === null and child.key === null, then this only applies to
5631 // the first item in the list.
5632 if (child.key === key) {
5633 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
5634 deleteRemainingChildren(returnFiber, child.sibling);
5635 var existing = useFiber(child, portal.children || [], expirationTime);
5636 existing.return = returnFiber;
5637 return existing;
5638 } else {
5639 deleteRemainingChildren(returnFiber, child);
5640 break;
5641 }
5642 } else {
5643 deleteChild(returnFiber, child);
5644 }
5645
5646 child = child.sibling;
5647 }
5648
5649 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
5650 created.return = returnFiber;
5651 return created;
5652 } // This API will tag the children with the side-effect of the reconciliation
5653 // itself. They will be added to the side-effect list as we pass through the
5654 // children and the parent.
5655
5656
5657 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
5658 // This function is not recursive.
5659 // If the top level item is an array, we treat it as a set of children,
5660 // not as a fragment. Nested arrays on the other hand will be treated as
5661 // fragment nodes. Recursion happens at the normal flow.
5662 // Handle top level unkeyed fragments as if they were arrays.
5663 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
5664 // We treat the ambiguous cases above the same.
5665 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
5666
5667 if (isUnkeyedTopLevelFragment) {
5668 newChild = newChild.props.children;
5669 } // Handle object types
5670
5671
5672 var isObject = typeof newChild === 'object' && newChild !== null;
5673
5674 if (isObject) {
5675 switch (newChild.$$typeof) {
5676 case REACT_ELEMENT_TYPE$1:
5677 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
5678
5679 case REACT_PORTAL_TYPE:
5680 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
5681 }
5682 }
5683
5684 if (typeof newChild === 'string' || typeof newChild === 'number') {
5685 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
5686 }
5687
5688 if (isArray(newChild)) {
5689 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
5690 }
5691
5692 if (getIteratorFn(newChild)) {
5693 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
5694 }
5695
5696 if (isObject) {
5697 throwOnInvalidObjectType(returnFiber, newChild);
5698 }
5699
5700 {
5701 if (typeof newChild === 'function') {
5702 warnOnFunctionType();
5703 }
5704 }
5705
5706 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
5707 // If the new child is undefined, and the return fiber is a composite
5708 // component, throw an error. If Fiber return types are disabled,
5709 // we already threw above.
5710 switch (returnFiber.tag) {
5711 case ClassComponent:
5712 {
5713 {
5714 var instance = returnFiber.stateNode;
5715
5716 if (instance.render._isMockFunction) {
5717 // We allow auto-mocks to proceed as if they're returning null.
5718 break;
5719 }
5720 }
5721 }
5722 // Intentionally fall through to the next case, which handles both
5723 // functions and classes
5724 // eslint-disable-next-lined no-fallthrough
5725
5726 case FunctionComponent:
5727 {
5728 var Component = returnFiber.type;
5729
5730 {
5731 {
5732 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.");
5733 }
5734 }
5735 }
5736 }
5737 } // Remaining cases are all treated as empty.
5738
5739
5740 return deleteRemainingChildren(returnFiber, currentFirstChild);
5741 }
5742
5743 return reconcileChildFibers;
5744}
5745
5746var reconcileChildFibers = ChildReconciler(true);
5747var mountChildFibers = ChildReconciler(false);
5748function cloneChildFibers(current$$1, workInProgress) {
5749 if (!(current$$1 === null || workInProgress.child === current$$1.child)) {
5750 {
5751 throw Error("Resuming work not yet implemented.");
5752 }
5753 }
5754
5755 if (workInProgress.child === null) {
5756 return;
5757 }
5758
5759 var currentChild = workInProgress.child;
5760 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
5761 workInProgress.child = newChild;
5762 newChild.return = workInProgress;
5763
5764 while (currentChild.sibling !== null) {
5765 currentChild = currentChild.sibling;
5766 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
5767 newChild.return = workInProgress;
5768 }
5769
5770 newChild.sibling = null;
5771} // Reset a workInProgress child set to prepare it for a second pass.
5772
5773function resetChildFibers(workInProgress, renderExpirationTime) {
5774 var child = workInProgress.child;
5775
5776 while (child !== null) {
5777 resetWorkInProgress(child, renderExpirationTime);
5778 child = child.sibling;
5779 }
5780}
5781
5782var NO_CONTEXT$1 = {};
5783var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
5784var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
5785var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
5786
5787function requiredContext(c) {
5788 if (!(c !== NO_CONTEXT$1)) {
5789 {
5790 throw Error("Expected host context to exist. This error is likely caused by a bug in React. Please file an issue.");
5791 }
5792 }
5793
5794 return c;
5795}
5796
5797function getRootHostContainer() {
5798 var rootInstance = requiredContext(rootInstanceStackCursor.current);
5799 return rootInstance;
5800}
5801
5802function pushHostContainer(fiber, nextRootInstance) {
5803 // Push current root instance onto the stack;
5804 // This allows us to reset root when portals are popped.
5805 push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
5806 // This enables us to pop only Fibers that provide unique contexts.
5807
5808 push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
5809 // However, we can't just call getRootHostContext() and push it because
5810 // we'd have a different number of entries on the stack depending on
5811 // whether getRootHostContext() throws somewhere in renderer code or not.
5812 // So we push an empty value first. This lets us safely unwind on errors.
5813
5814 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
5815 var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
5816
5817 pop(contextStackCursor$1, fiber);
5818 push(contextStackCursor$1, nextRootContext, fiber);
5819}
5820
5821function popHostContainer(fiber) {
5822 pop(contextStackCursor$1, fiber);
5823 pop(contextFiberStackCursor, fiber);
5824 pop(rootInstanceStackCursor, fiber);
5825}
5826
5827function getHostContext() {
5828 var context = requiredContext(contextStackCursor$1.current);
5829 return context;
5830}
5831
5832function pushHostContext(fiber) {
5833 var rootInstance = requiredContext(rootInstanceStackCursor.current);
5834 var context = requiredContext(contextStackCursor$1.current);
5835 var nextContext = getChildHostContext(context, fiber.type, rootInstance); // Don't push this Fiber's context unless it's unique.
5836
5837 if (context === nextContext) {
5838 return;
5839 } // Track the context and the Fiber that provided it.
5840 // This enables us to pop only Fibers that provide unique contexts.
5841
5842
5843 push(contextFiberStackCursor, fiber, fiber);
5844 push(contextStackCursor$1, nextContext, fiber);
5845}
5846
5847function popHostContext(fiber) {
5848 // Do not pop unless this Fiber provided the current context.
5849 // pushHostContext() only pushes Fibers that provide unique contexts.
5850 if (contextFiberStackCursor.current !== fiber) {
5851 return;
5852 }
5853
5854 pop(contextStackCursor$1, fiber);
5855 pop(contextFiberStackCursor, fiber);
5856}
5857
5858var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
5859// inherited deeply down the subtree. The upper bits only affect
5860// this immediate suspense boundary and gets reset each new
5861// boundary or suspense list.
5862
5863var SubtreeSuspenseContextMask = 1; // Subtree Flags:
5864// InvisibleParentSuspenseContext indicates that one of our parent Suspense
5865// boundaries is not currently showing visible main content.
5866// Either because it is already showing a fallback or is not mounted at all.
5867// We can use this to determine if it is desirable to trigger a fallback at
5868// the parent. If not, then we might need to trigger undesirable boundaries
5869// and/or suspend the commit to avoid hiding the parent content.
5870
5871var InvisibleParentSuspenseContext = 1; // Shallow Flags:
5872// ForceSuspenseFallback can be used by SuspenseList to force newly added
5873// items into their fallback state during one of the render passes.
5874
5875var ForceSuspenseFallback = 2;
5876var suspenseStackCursor = createCursor(DefaultSuspenseContext);
5877function hasSuspenseContext(parentContext, flag) {
5878 return (parentContext & flag) !== 0;
5879}
5880function setDefaultShallowSuspenseContext(parentContext) {
5881 return parentContext & SubtreeSuspenseContextMask;
5882}
5883function setShallowSuspenseContext(parentContext, shallowContext) {
5884 return parentContext & SubtreeSuspenseContextMask | shallowContext;
5885}
5886function addSubtreeSuspenseContext(parentContext, subtreeContext) {
5887 return parentContext | subtreeContext;
5888}
5889function pushSuspenseContext(fiber, newContext) {
5890 push(suspenseStackCursor, newContext, fiber);
5891}
5892function popSuspenseContext(fiber) {
5893 pop(suspenseStackCursor, fiber);
5894}
5895
5896function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
5897 // If it was the primary children that just suspended, capture and render the
5898 // fallback. Otherwise, don't capture and bubble to the next boundary.
5899 var nextState = workInProgress.memoizedState;
5900
5901 if (nextState !== null) {
5902 if (nextState.dehydrated !== null) {
5903 // A dehydrated boundary always captures.
5904 return true;
5905 }
5906
5907 return false;
5908 }
5909
5910 var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
5911
5912 if (props.fallback === undefined) {
5913 return false;
5914 } // Regular boundaries always capture.
5915
5916
5917 if (props.unstable_avoidThisFallback !== true) {
5918 return true;
5919 } // If it's a boundary we should avoid, then we prefer to bubble up to the
5920 // parent boundary if it is currently invisible.
5921
5922
5923 if (hasInvisibleParent) {
5924 return false;
5925 } // If the parent is not able to handle it, we must handle it.
5926
5927
5928 return true;
5929}
5930function findFirstSuspended(row) {
5931 var node = row;
5932
5933 while (node !== null) {
5934 if (node.tag === SuspenseComponent) {
5935 var state = node.memoizedState;
5936
5937 if (state !== null) {
5938 var dehydrated = state.dehydrated;
5939
5940 if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
5941 return node;
5942 }
5943 }
5944 } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
5945 // keep track of whether it suspended or not.
5946 node.memoizedProps.revealOrder !== undefined) {
5947 var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
5948
5949 if (didSuspend) {
5950 return node;
5951 }
5952 } else if (node.child !== null) {
5953 node.child.return = node;
5954 node = node.child;
5955 continue;
5956 }
5957
5958 if (node === row) {
5959 return null;
5960 }
5961
5962 while (node.sibling === null) {
5963 if (node.return === null || node.return === row) {
5964 return null;
5965 }
5966
5967 node = node.return;
5968 }
5969
5970 node.sibling.return = node.return;
5971 node = node.sibling;
5972 }
5973
5974 return null;
5975}
5976
5977var emptyObject = {};
5978var isArray$2 = Array.isArray;
5979function createResponderInstance(responder, responderProps, responderState, fiber) {
5980 return {
5981 fiber: fiber,
5982 props: responderProps,
5983 responder: responder,
5984 rootEventTypes: null,
5985 state: responderState
5986 };
5987}
5988
5989function mountEventResponder(responder, responderProps, fiber, respondersMap, rootContainerInstance) {
5990 var responderState = emptyObject;
5991 var getInitialState = responder.getInitialState;
5992
5993 if (getInitialState !== null) {
5994 responderState = getInitialState(responderProps);
5995 }
5996
5997 var responderInstance = createResponderInstance(responder, responderProps, responderState, fiber);
5998
5999 if (!rootContainerInstance) {
6000 var node = fiber;
6001
6002 while (node !== null) {
6003 var tag = node.tag;
6004
6005 if (tag === HostComponent) {
6006 rootContainerInstance = node.stateNode;
6007 break;
6008 } else if (tag === HostRoot) {
6009 rootContainerInstance = node.stateNode.containerInfo;
6010 break;
6011 }
6012
6013 node = node.return;
6014 }
6015 }
6016
6017 mountResponderInstance(responder, responderInstance, responderProps, responderState, rootContainerInstance);
6018 respondersMap.set(responder, responderInstance);
6019}
6020
6021function updateEventListener(listener, fiber, visistedResponders, respondersMap, rootContainerInstance) {
6022 var responder;
6023 var props;
6024
6025 if (listener) {
6026 responder = listener.responder;
6027 props = listener.props;
6028 }
6029
6030 if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) {
6031 {
6032 throw Error("An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponder().");
6033 }
6034 }
6035
6036 var listenerProps = props;
6037
6038 if (visistedResponders.has(responder)) {
6039 // show warning
6040 {
6041 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);
6042 }
6043
6044 return;
6045 }
6046
6047 visistedResponders.add(responder);
6048 var responderInstance = respondersMap.get(responder);
6049
6050 if (responderInstance === undefined) {
6051 // Mount (happens in either complete or commit phase)
6052 mountEventResponder(responder, listenerProps, fiber, respondersMap, rootContainerInstance);
6053 } else {
6054 // Update (happens during commit phase only)
6055 responderInstance.props = listenerProps;
6056 responderInstance.fiber = fiber;
6057 }
6058}
6059
6060function updateEventListeners(listeners, fiber, rootContainerInstance) {
6061 var visistedResponders = new Set();
6062 var dependencies = fiber.dependencies;
6063
6064 if (listeners != null) {
6065 if (dependencies === null) {
6066 dependencies = fiber.dependencies = {
6067 expirationTime: NoWork,
6068 firstContext: null,
6069 responders: new Map()
6070 };
6071 }
6072
6073 var respondersMap = dependencies.responders;
6074
6075 if (respondersMap === null) {
6076 respondersMap = new Map();
6077 }
6078
6079 if (isArray$2(listeners)) {
6080 for (var i = 0, length = listeners.length; i < length; i++) {
6081 var listener = listeners[i];
6082 updateEventListener(listener, fiber, visistedResponders, respondersMap, rootContainerInstance);
6083 }
6084 } else {
6085 updateEventListener(listeners, fiber, visistedResponders, respondersMap, rootContainerInstance);
6086 }
6087 }
6088
6089 if (dependencies !== null) {
6090 var _respondersMap = dependencies.responders;
6091
6092 if (_respondersMap !== null) {
6093 // Unmount
6094 var mountedResponders = Array.from(_respondersMap.keys());
6095
6096 for (var _i = 0, _length = mountedResponders.length; _i < _length; _i++) {
6097 var mountedResponder = mountedResponders[_i];
6098
6099 if (!visistedResponders.has(mountedResponder)) {
6100 var responderInstance = _respondersMap.get(mountedResponder);
6101
6102 unmountResponderInstance(responderInstance);
6103
6104 _respondersMap.delete(mountedResponder);
6105 }
6106 }
6107 }
6108 }
6109}
6110function createResponderListener(responder, props) {
6111 var eventResponderListener = {
6112 responder: responder,
6113 props: props
6114 };
6115
6116 {
6117 Object.freeze(eventResponderListener);
6118 }
6119
6120 return eventResponderListener;
6121}
6122
6123var NoEffect$1 =
6124/* */
61250;
6126var UnmountSnapshot =
6127/* */
61282;
6129var UnmountMutation =
6130/* */
61314;
6132var MountMutation =
6133/* */
61348;
6135var UnmountLayout =
6136/* */
613716;
6138var MountLayout =
6139/* */
614032;
6141var MountPassive =
6142/* */
614364;
6144var UnmountPassive =
6145/* */
6146128;
6147
6148var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
6149var ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
6150var didWarnAboutMismatchedHooksForComponent;
6151
6152{
6153 didWarnAboutMismatchedHooksForComponent = new Set();
6154}
6155
6156// These are set right before calling the component.
6157var renderExpirationTime$1 = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
6158// the work-in-progress hook.
6159
6160var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
6161// current hook list is the list that belongs to the current fiber. The
6162// work-in-progress hook list is a new list that will be added to the
6163// work-in-progress fiber.
6164
6165var currentHook = null;
6166var nextCurrentHook = null;
6167var firstWorkInProgressHook = null;
6168var workInProgressHook = null;
6169var nextWorkInProgressHook = null;
6170var remainingExpirationTime = NoWork;
6171var componentUpdateQueue = null;
6172var sideEffectTag = 0; // Updates scheduled during render will trigger an immediate re-render at the
6173// end of the current pass. We can't store these updates on the normal queue,
6174// because if the work is aborted, they should be discarded. Because this is
6175// a relatively rare case, we also don't want to add an additional field to
6176// either the hook or queue object types. So we store them in a lazily create
6177// map of queue -> render-phase updates, which are discarded once the component
6178// completes without re-rendering.
6179// Whether an update was scheduled during the currently executing render pass.
6180
6181var didScheduleRenderPhaseUpdate = false; // Lazily created map of render-phase updates
6182
6183var renderPhaseUpdates = null; // Counter to prevent infinite loops.
6184
6185var numberOfReRenders = 0;
6186var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
6187
6188var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
6189// The list stores the order of hooks used during the initial render (mount).
6190// Subsequent renders (updates) reference this list.
6191
6192var hookTypesDev = null;
6193var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
6194// the dependencies for Hooks that need them (e.g. useEffect or useMemo).
6195// When true, such Hooks will always be "remounted". Only used during hot reload.
6196
6197var ignorePreviousDependencies = false;
6198
6199function mountHookTypesDev() {
6200 {
6201 var hookName = currentHookNameInDev;
6202
6203 if (hookTypesDev === null) {
6204 hookTypesDev = [hookName];
6205 } else {
6206 hookTypesDev.push(hookName);
6207 }
6208 }
6209}
6210
6211function updateHookTypesDev() {
6212 {
6213 var hookName = currentHookNameInDev;
6214
6215 if (hookTypesDev !== null) {
6216 hookTypesUpdateIndexDev++;
6217
6218 if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
6219 warnOnHookMismatchInDev(hookName);
6220 }
6221 }
6222 }
6223}
6224
6225function checkDepsAreArrayDev(deps) {
6226 {
6227 if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
6228 // Verify deps, but only on mount to avoid extra checks.
6229 // It's unlikely their type would change as usually you define them inline.
6230 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);
6231 }
6232 }
6233}
6234
6235function warnOnHookMismatchInDev(currentHookName) {
6236 {
6237 var componentName = getComponentName(currentlyRenderingFiber$1.type);
6238
6239 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
6240 didWarnAboutMismatchedHooksForComponent.add(componentName);
6241
6242 if (hookTypesDev !== null) {
6243 var table = '';
6244 var secondColumnStart = 30;
6245
6246 for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
6247 var oldHookName = hookTypesDev[i];
6248 var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
6249 var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
6250 // lol @ IE not supporting String#repeat
6251
6252 while (row.length < secondColumnStart) {
6253 row += ' ';
6254 }
6255
6256 row += newHookName + '\n';
6257 table += row;
6258 }
6259
6260 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);
6261 }
6262 }
6263 }
6264}
6265
6266function throwInvalidHookError() {
6267 {
6268 {
6269 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.");
6270 }
6271 }
6272}
6273
6274function areHookInputsEqual(nextDeps, prevDeps) {
6275 {
6276 if (ignorePreviousDependencies) {
6277 // Only true when this component is being hot reloaded.
6278 return false;
6279 }
6280 }
6281
6282 if (prevDeps === null) {
6283 {
6284 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);
6285 }
6286
6287 return false;
6288 }
6289
6290 {
6291 // Don't bother comparing lengths in prod because these arrays should be
6292 // passed inline.
6293 if (nextDeps.length !== prevDeps.length) {
6294 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(', ') + "]");
6295 }
6296 }
6297
6298 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
6299 if (is$1(nextDeps[i], prevDeps[i])) {
6300 continue;
6301 }
6302
6303 return false;
6304 }
6305
6306 return true;
6307}
6308
6309function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
6310 renderExpirationTime$1 = nextRenderExpirationTime;
6311 currentlyRenderingFiber$1 = workInProgress;
6312 nextCurrentHook = current !== null ? current.memoizedState : null;
6313
6314 {
6315 hookTypesDev = current !== null ? current._debugHookTypes : null;
6316 hookTypesUpdateIndexDev = -1; // Used for hot reloading:
6317
6318 ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
6319 } // The following should have already been reset
6320 // currentHook = null;
6321 // workInProgressHook = null;
6322 // remainingExpirationTime = NoWork;
6323 // componentUpdateQueue = null;
6324 // didScheduleRenderPhaseUpdate = false;
6325 // renderPhaseUpdates = null;
6326 // numberOfReRenders = 0;
6327 // sideEffectTag = 0;
6328 // TODO Warn if no hooks are used at all during mount, then some are used during update.
6329 // Currently we will identify the update render as a mount because nextCurrentHook === null.
6330 // This is tricky because it's valid for certain types of components (e.g. React.lazy)
6331 // Using nextCurrentHook to differentiate between mount/update only works if at least one stateful hook is used.
6332 // Non-stateful hooks (e.g. context) don't get added to memoizedState,
6333 // so nextCurrentHook would be null during updates and mounts.
6334
6335
6336 {
6337 if (nextCurrentHook !== null) {
6338 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
6339 } else if (hookTypesDev !== null) {
6340 // This dispatcher handles an edge case where a component is updating,
6341 // but no stateful hooks have been used.
6342 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
6343 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
6344 // This dispatcher does that.
6345 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
6346 } else {
6347 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
6348 }
6349 }
6350
6351 var children = Component(props, refOrContext);
6352
6353 if (didScheduleRenderPhaseUpdate) {
6354 do {
6355 didScheduleRenderPhaseUpdate = false;
6356 numberOfReRenders += 1;
6357
6358 {
6359 // Even when hot reloading, allow dependencies to stabilize
6360 // after first render to prevent infinite render phase updates.
6361 ignorePreviousDependencies = false;
6362 } // Start over from the beginning of the list
6363
6364
6365 nextCurrentHook = current !== null ? current.memoizedState : null;
6366 nextWorkInProgressHook = firstWorkInProgressHook;
6367 currentHook = null;
6368 workInProgressHook = null;
6369 componentUpdateQueue = null;
6370
6371 {
6372 // Also validate hook order for cascading updates.
6373 hookTypesUpdateIndexDev = -1;
6374 }
6375
6376 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
6377 children = Component(props, refOrContext);
6378 } while (didScheduleRenderPhaseUpdate);
6379
6380 renderPhaseUpdates = null;
6381 numberOfReRenders = 0;
6382 } // We can assume the previous dispatcher is always this one, since we set it
6383 // at the beginning of the render phase and there's no re-entrancy.
6384
6385
6386 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
6387 var renderedWork = currentlyRenderingFiber$1;
6388 renderedWork.memoizedState = firstWorkInProgressHook;
6389 renderedWork.expirationTime = remainingExpirationTime;
6390 renderedWork.updateQueue = componentUpdateQueue;
6391 renderedWork.effectTag |= sideEffectTag;
6392
6393 {
6394 renderedWork._debugHookTypes = hookTypesDev;
6395 } // This check uses currentHook so that it works the same in DEV and prod bundles.
6396 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
6397
6398
6399 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
6400 renderExpirationTime$1 = NoWork;
6401 currentlyRenderingFiber$1 = null;
6402 currentHook = null;
6403 nextCurrentHook = null;
6404 firstWorkInProgressHook = null;
6405 workInProgressHook = null;
6406 nextWorkInProgressHook = null;
6407
6408 {
6409 currentHookNameInDev = null;
6410 hookTypesDev = null;
6411 hookTypesUpdateIndexDev = -1;
6412 }
6413
6414 remainingExpirationTime = NoWork;
6415 componentUpdateQueue = null;
6416 sideEffectTag = 0; // These were reset above
6417 // didScheduleRenderPhaseUpdate = false;
6418 // renderPhaseUpdates = null;
6419 // numberOfReRenders = 0;
6420
6421 if (!!didRenderTooFewHooks) {
6422 {
6423 throw Error("Rendered fewer hooks than expected. This may be caused by an accidental early return statement.");
6424 }
6425 }
6426
6427 return children;
6428}
6429function bailoutHooks(current, workInProgress, expirationTime) {
6430 workInProgress.updateQueue = current.updateQueue;
6431 workInProgress.effectTag &= ~(Passive | Update);
6432
6433 if (current.expirationTime <= expirationTime) {
6434 current.expirationTime = NoWork;
6435 }
6436}
6437function resetHooks() {
6438 // We can assume the previous dispatcher is always this one, since we set it
6439 // at the beginning of the render phase and there's no re-entrancy.
6440 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; // This is used to reset the state of this module when a component throws.
6441 // It's also called inside mountIndeterminateComponent if we determine the
6442 // component is a module-style component.
6443
6444 renderExpirationTime$1 = NoWork;
6445 currentlyRenderingFiber$1 = null;
6446 currentHook = null;
6447 nextCurrentHook = null;
6448 firstWorkInProgressHook = null;
6449 workInProgressHook = null;
6450 nextWorkInProgressHook = null;
6451
6452 {
6453 hookTypesDev = null;
6454 hookTypesUpdateIndexDev = -1;
6455 currentHookNameInDev = null;
6456 }
6457
6458 remainingExpirationTime = NoWork;
6459 componentUpdateQueue = null;
6460 sideEffectTag = 0;
6461 didScheduleRenderPhaseUpdate = false;
6462 renderPhaseUpdates = null;
6463 numberOfReRenders = 0;
6464}
6465
6466function mountWorkInProgressHook() {
6467 var hook = {
6468 memoizedState: null,
6469 baseState: null,
6470 queue: null,
6471 baseUpdate: null,
6472 next: null
6473 };
6474
6475 if (workInProgressHook === null) {
6476 // This is the first hook in the list
6477 firstWorkInProgressHook = workInProgressHook = hook;
6478 } else {
6479 // Append to the end of the list
6480 workInProgressHook = workInProgressHook.next = hook;
6481 }
6482
6483 return workInProgressHook;
6484}
6485
6486function updateWorkInProgressHook() {
6487 // This function is used both for updates and for re-renders triggered by a
6488 // render phase update. It assumes there is either a current hook we can
6489 // clone, or a work-in-progress hook from a previous render pass that we can
6490 // use as a base. When we reach the end of the base list, we must switch to
6491 // the dispatcher used for mounts.
6492 if (nextWorkInProgressHook !== null) {
6493 // There's already a work-in-progress. Reuse it.
6494 workInProgressHook = nextWorkInProgressHook;
6495 nextWorkInProgressHook = workInProgressHook.next;
6496 currentHook = nextCurrentHook;
6497 nextCurrentHook = currentHook !== null ? currentHook.next : null;
6498 } else {
6499 // Clone from the current hook.
6500 if (!(nextCurrentHook !== null)) {
6501 {
6502 throw Error("Rendered more hooks than during the previous render.");
6503 }
6504 }
6505
6506 currentHook = nextCurrentHook;
6507 var newHook = {
6508 memoizedState: currentHook.memoizedState,
6509 baseState: currentHook.baseState,
6510 queue: currentHook.queue,
6511 baseUpdate: currentHook.baseUpdate,
6512 next: null
6513 };
6514
6515 if (workInProgressHook === null) {
6516 // This is the first hook in the list.
6517 workInProgressHook = firstWorkInProgressHook = newHook;
6518 } else {
6519 // Append to the end of the list.
6520 workInProgressHook = workInProgressHook.next = newHook;
6521 }
6522
6523 nextCurrentHook = currentHook.next;
6524 }
6525
6526 return workInProgressHook;
6527}
6528
6529function createFunctionComponentUpdateQueue() {
6530 return {
6531 lastEffect: null
6532 };
6533}
6534
6535function basicStateReducer(state, action) {
6536 return typeof action === 'function' ? action(state) : action;
6537}
6538
6539function mountReducer(reducer, initialArg, init) {
6540 var hook = mountWorkInProgressHook();
6541 var initialState;
6542
6543 if (init !== undefined) {
6544 initialState = init(initialArg);
6545 } else {
6546 initialState = initialArg;
6547 }
6548
6549 hook.memoizedState = hook.baseState = initialState;
6550 var queue = hook.queue = {
6551 last: null,
6552 dispatch: null,
6553 lastRenderedReducer: reducer,
6554 lastRenderedState: initialState
6555 };
6556 var dispatch = queue.dispatch = dispatchAction.bind(null, // Flow doesn't know this is non-null, but we do.
6557 currentlyRenderingFiber$1, queue);
6558 return [hook.memoizedState, dispatch];
6559}
6560
6561function updateReducer(reducer, initialArg, init) {
6562 var hook = updateWorkInProgressHook();
6563 var queue = hook.queue;
6564
6565 if (!(queue !== null)) {
6566 {
6567 throw Error("Should have a queue. This is likely a bug in React. Please file an issue.");
6568 }
6569 }
6570
6571 queue.lastRenderedReducer = reducer;
6572
6573 if (numberOfReRenders > 0) {
6574 // This is a re-render. Apply the new render phase updates to the previous
6575 // work-in-progress hook.
6576 var _dispatch = queue.dispatch;
6577
6578 if (renderPhaseUpdates !== null) {
6579 // Render phase updates are stored in a map of queue -> linked list
6580 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
6581
6582 if (firstRenderPhaseUpdate !== undefined) {
6583 renderPhaseUpdates.delete(queue);
6584 var newState = hook.memoizedState;
6585 var update = firstRenderPhaseUpdate;
6586
6587 do {
6588 // Process this render phase update. We don't have to check the
6589 // priority because it will always be the same as the current
6590 // render's.
6591 var action = update.action;
6592 newState = reducer(newState, action);
6593 update = update.next;
6594 } while (update !== null); // Mark that the fiber performed work, but only if the new state is
6595 // different from the current state.
6596
6597
6598 if (!is$1(newState, hook.memoizedState)) {
6599 markWorkInProgressReceivedUpdate();
6600 }
6601
6602 hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
6603 // the base state unless the queue is empty.
6604 // TODO: Not sure if this is the desired semantics, but it's what we
6605 // do for gDSFP. I can't remember why.
6606
6607 if (hook.baseUpdate === queue.last) {
6608 hook.baseState = newState;
6609 }
6610
6611 queue.lastRenderedState = newState;
6612 return [newState, _dispatch];
6613 }
6614 }
6615
6616 return [hook.memoizedState, _dispatch];
6617 } // The last update in the entire queue
6618
6619
6620 var last = queue.last; // The last update that is part of the base state.
6621
6622 var baseUpdate = hook.baseUpdate;
6623 var baseState = hook.baseState; // Find the first unprocessed update.
6624
6625 var first;
6626
6627 if (baseUpdate !== null) {
6628 if (last !== null) {
6629 // For the first update, the queue is a circular linked list where
6630 // `queue.last.next = queue.first`. Once the first update commits, and
6631 // the `baseUpdate` is no longer empty, we can unravel the list.
6632 last.next = null;
6633 }
6634
6635 first = baseUpdate.next;
6636 } else {
6637 first = last !== null ? last.next : null;
6638 }
6639
6640 if (first !== null) {
6641 var _newState = baseState;
6642 var newBaseState = null;
6643 var newBaseUpdate = null;
6644 var prevUpdate = baseUpdate;
6645 var _update = first;
6646 var didSkip = false;
6647
6648 do {
6649 var updateExpirationTime = _update.expirationTime;
6650
6651 if (updateExpirationTime < renderExpirationTime$1) {
6652 // Priority is insufficient. Skip this update. If this is the first
6653 // skipped update, the previous update/state is the new base
6654 // update/state.
6655 if (!didSkip) {
6656 didSkip = true;
6657 newBaseUpdate = prevUpdate;
6658 newBaseState = _newState;
6659 } // Update the remaining priority in the queue.
6660
6661
6662 if (updateExpirationTime > remainingExpirationTime) {
6663 remainingExpirationTime = updateExpirationTime;
6664 markUnprocessedUpdateTime(remainingExpirationTime);
6665 }
6666 } else {
6667 // This update does have sufficient priority.
6668 // Mark the event time of this update as relevant to this render pass.
6669 // TODO: This should ideally use the true event time of this update rather than
6670 // its priority which is a derived and not reverseable value.
6671 // TODO: We should skip this update if it was already committed but currently
6672 // we have no way of detecting the difference between a committed and suspended
6673 // update here.
6674 markRenderEventTimeAndConfig(updateExpirationTime, _update.suspenseConfig); // Process this update.
6675
6676 if (_update.eagerReducer === reducer) {
6677 // If this update was processed eagerly, and its reducer matches the
6678 // current reducer, we can use the eagerly computed state.
6679 _newState = _update.eagerState;
6680 } else {
6681 var _action = _update.action;
6682 _newState = reducer(_newState, _action);
6683 }
6684 }
6685
6686 prevUpdate = _update;
6687 _update = _update.next;
6688 } while (_update !== null && _update !== first);
6689
6690 if (!didSkip) {
6691 newBaseUpdate = prevUpdate;
6692 newBaseState = _newState;
6693 } // Mark that the fiber performed work, but only if the new state is
6694 // different from the current state.
6695
6696
6697 if (!is$1(_newState, hook.memoizedState)) {
6698 markWorkInProgressReceivedUpdate();
6699 }
6700
6701 hook.memoizedState = _newState;
6702 hook.baseUpdate = newBaseUpdate;
6703 hook.baseState = newBaseState;
6704 queue.lastRenderedState = _newState;
6705 }
6706
6707 var dispatch = queue.dispatch;
6708 return [hook.memoizedState, dispatch];
6709}
6710
6711function mountState(initialState) {
6712 var hook = mountWorkInProgressHook();
6713
6714 if (typeof initialState === 'function') {
6715 initialState = initialState();
6716 }
6717
6718 hook.memoizedState = hook.baseState = initialState;
6719 var queue = hook.queue = {
6720 last: null,
6721 dispatch: null,
6722 lastRenderedReducer: basicStateReducer,
6723 lastRenderedState: initialState
6724 };
6725 var dispatch = queue.dispatch = dispatchAction.bind(null, // Flow doesn't know this is non-null, but we do.
6726 currentlyRenderingFiber$1, queue);
6727 return [hook.memoizedState, dispatch];
6728}
6729
6730function updateState(initialState) {
6731 return updateReducer(basicStateReducer, initialState);
6732}
6733
6734function pushEffect(tag, create, destroy, deps) {
6735 var effect = {
6736 tag: tag,
6737 create: create,
6738 destroy: destroy,
6739 deps: deps,
6740 // Circular
6741 next: null
6742 };
6743
6744 if (componentUpdateQueue === null) {
6745 componentUpdateQueue = createFunctionComponentUpdateQueue();
6746 componentUpdateQueue.lastEffect = effect.next = effect;
6747 } else {
6748 var lastEffect = componentUpdateQueue.lastEffect;
6749
6750 if (lastEffect === null) {
6751 componentUpdateQueue.lastEffect = effect.next = effect;
6752 } else {
6753 var firstEffect = lastEffect.next;
6754 lastEffect.next = effect;
6755 effect.next = firstEffect;
6756 componentUpdateQueue.lastEffect = effect;
6757 }
6758 }
6759
6760 return effect;
6761}
6762
6763function mountRef(initialValue) {
6764 var hook = mountWorkInProgressHook();
6765 var ref = {
6766 current: initialValue
6767 };
6768
6769 {
6770 Object.seal(ref);
6771 }
6772
6773 hook.memoizedState = ref;
6774 return ref;
6775}
6776
6777function updateRef(initialValue) {
6778 var hook = updateWorkInProgressHook();
6779 return hook.memoizedState;
6780}
6781
6782function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
6783 var hook = mountWorkInProgressHook();
6784 var nextDeps = deps === undefined ? null : deps;
6785 sideEffectTag |= fiberEffectTag;
6786 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
6787}
6788
6789function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
6790 var hook = updateWorkInProgressHook();
6791 var nextDeps = deps === undefined ? null : deps;
6792 var destroy = undefined;
6793
6794 if (currentHook !== null) {
6795 var prevEffect = currentHook.memoizedState;
6796 destroy = prevEffect.destroy;
6797
6798 if (nextDeps !== null) {
6799 var prevDeps = prevEffect.deps;
6800
6801 if (areHookInputsEqual(nextDeps, prevDeps)) {
6802 pushEffect(NoEffect$1, create, destroy, nextDeps);
6803 return;
6804 }
6805 }
6806 }
6807
6808 sideEffectTag |= fiberEffectTag;
6809 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
6810}
6811
6812function mountEffect(create, deps) {
6813 {
6814 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
6815 if ('undefined' !== typeof jest) {
6816 warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
6817 }
6818 }
6819
6820 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
6821}
6822
6823function updateEffect(create, deps) {
6824 {
6825 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
6826 if ('undefined' !== typeof jest) {
6827 warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
6828 }
6829 }
6830
6831 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
6832}
6833
6834function mountLayoutEffect(create, deps) {
6835 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
6836}
6837
6838function updateLayoutEffect(create, deps) {
6839 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
6840}
6841
6842function imperativeHandleEffect(create, ref) {
6843 if (typeof ref === 'function') {
6844 var refCallback = ref;
6845
6846 var _inst = create();
6847
6848 refCallback(_inst);
6849 return function () {
6850 refCallback(null);
6851 };
6852 } else if (ref !== null && ref !== undefined) {
6853 var refObject = ref;
6854
6855 {
6856 !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;
6857 }
6858
6859 var _inst2 = create();
6860
6861 refObject.current = _inst2;
6862 return function () {
6863 refObject.current = null;
6864 };
6865 }
6866}
6867
6868function mountImperativeHandle(ref, create, deps) {
6869 {
6870 !(typeof create === 'function') ? warning$1(false, 'Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null') : void 0;
6871 } // TODO: If deps are provided, should we skip comparing the ref itself?
6872
6873
6874 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
6875 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
6876}
6877
6878function updateImperativeHandle(ref, create, deps) {
6879 {
6880 !(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;
6881 } // TODO: If deps are provided, should we skip comparing the ref itself?
6882
6883
6884 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
6885 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
6886}
6887
6888function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
6889 // The react-debug-hooks package injects its own implementation
6890 // so that e.g. DevTools can display custom hook values.
6891}
6892
6893var updateDebugValue = mountDebugValue;
6894
6895function mountCallback(callback, deps) {
6896 var hook = mountWorkInProgressHook();
6897 var nextDeps = deps === undefined ? null : deps;
6898 hook.memoizedState = [callback, nextDeps];
6899 return callback;
6900}
6901
6902function updateCallback(callback, deps) {
6903 var hook = updateWorkInProgressHook();
6904 var nextDeps = deps === undefined ? null : deps;
6905 var prevState = hook.memoizedState;
6906
6907 if (prevState !== null) {
6908 if (nextDeps !== null) {
6909 var prevDeps = prevState[1];
6910
6911 if (areHookInputsEqual(nextDeps, prevDeps)) {
6912 return prevState[0];
6913 }
6914 }
6915 }
6916
6917 hook.memoizedState = [callback, nextDeps];
6918 return callback;
6919}
6920
6921function mountMemo(nextCreate, deps) {
6922 var hook = mountWorkInProgressHook();
6923 var nextDeps = deps === undefined ? null : deps;
6924 var nextValue = nextCreate();
6925 hook.memoizedState = [nextValue, nextDeps];
6926 return nextValue;
6927}
6928
6929function updateMemo(nextCreate, deps) {
6930 var hook = updateWorkInProgressHook();
6931 var nextDeps = deps === undefined ? null : deps;
6932 var prevState = hook.memoizedState;
6933
6934 if (prevState !== null) {
6935 // Assume these are defined. If they're not, areHookInputsEqual will warn.
6936 if (nextDeps !== null) {
6937 var prevDeps = prevState[1];
6938
6939 if (areHookInputsEqual(nextDeps, prevDeps)) {
6940 return prevState[0];
6941 }
6942 }
6943 }
6944
6945 var nextValue = nextCreate();
6946 hook.memoizedState = [nextValue, nextDeps];
6947 return nextValue;
6948}
6949
6950function mountDeferredValue(value, config) {
6951 var _mountState = mountState(value),
6952 prevValue = _mountState[0],
6953 setValue = _mountState[1];
6954
6955 mountEffect(function () {
6956 Scheduler.unstable_next(function () {
6957 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6958 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
6959
6960 try {
6961 setValue(value);
6962 } finally {
6963 ReactCurrentBatchConfig$1.suspense = previousConfig;
6964 }
6965 });
6966 }, [value, config]);
6967 return prevValue;
6968}
6969
6970function updateDeferredValue(value, config) {
6971 var _updateState = updateState(value),
6972 prevValue = _updateState[0],
6973 setValue = _updateState[1];
6974
6975 updateEffect(function () {
6976 Scheduler.unstable_next(function () {
6977 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6978 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
6979
6980 try {
6981 setValue(value);
6982 } finally {
6983 ReactCurrentBatchConfig$1.suspense = previousConfig;
6984 }
6985 });
6986 }, [value, config]);
6987 return prevValue;
6988}
6989
6990function mountTransition(config) {
6991 var _mountState2 = mountState(false),
6992 isPending = _mountState2[0],
6993 setPending = _mountState2[1];
6994
6995 var startTransition = mountCallback(function (callback) {
6996 setPending(true);
6997 Scheduler.unstable_next(function () {
6998 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6999 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
7000
7001 try {
7002 setPending(false);
7003 callback();
7004 } finally {
7005 ReactCurrentBatchConfig$1.suspense = previousConfig;
7006 }
7007 });
7008 }, [config, isPending]);
7009 return [startTransition, isPending];
7010}
7011
7012function updateTransition(config) {
7013 var _updateState2 = updateState(false),
7014 isPending = _updateState2[0],
7015 setPending = _updateState2[1];
7016
7017 var startTransition = updateCallback(function (callback) {
7018 setPending(true);
7019 Scheduler.unstable_next(function () {
7020 var previousConfig = ReactCurrentBatchConfig$1.suspense;
7021 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
7022
7023 try {
7024 setPending(false);
7025 callback();
7026 } finally {
7027 ReactCurrentBatchConfig$1.suspense = previousConfig;
7028 }
7029 });
7030 }, [config, isPending]);
7031 return [startTransition, isPending];
7032}
7033
7034function dispatchAction(fiber, queue, action) {
7035 if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
7036 {
7037 throw Error("Too many re-renders. React limits the number of renders to prevent an infinite loop.");
7038 }
7039 }
7040
7041 {
7042 !(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;
7043 }
7044
7045 var alternate = fiber.alternate;
7046
7047 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
7048 // This is a render phase update. Stash it in a lazily-created map of
7049 // queue -> linked list of updates. After this render pass, we'll restart
7050 // and apply the stashed updates on top of the work-in-progress hook.
7051 didScheduleRenderPhaseUpdate = true;
7052 var update = {
7053 expirationTime: renderExpirationTime$1,
7054 suspenseConfig: null,
7055 action: action,
7056 eagerReducer: null,
7057 eagerState: null,
7058 next: null
7059 };
7060
7061 {
7062 update.priority = getCurrentPriorityLevel();
7063 }
7064
7065 if (renderPhaseUpdates === null) {
7066 renderPhaseUpdates = new Map();
7067 }
7068
7069 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
7070
7071 if (firstRenderPhaseUpdate === undefined) {
7072 renderPhaseUpdates.set(queue, update);
7073 } else {
7074 // Append the update to the end of the list.
7075 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
7076
7077 while (lastRenderPhaseUpdate.next !== null) {
7078 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
7079 }
7080
7081 lastRenderPhaseUpdate.next = update;
7082 }
7083 } else {
7084 var currentTime = requestCurrentTimeForUpdate();
7085 var suspenseConfig = requestCurrentSuspenseConfig();
7086 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
7087 var _update2 = {
7088 expirationTime: expirationTime,
7089 suspenseConfig: suspenseConfig,
7090 action: action,
7091 eagerReducer: null,
7092 eagerState: null,
7093 next: null
7094 };
7095
7096 {
7097 _update2.priority = getCurrentPriorityLevel();
7098 } // Append the update to the end of the list.
7099
7100
7101 var last = queue.last;
7102
7103 if (last === null) {
7104 // This is the first update. Create a circular list.
7105 _update2.next = _update2;
7106 } else {
7107 var first = last.next;
7108
7109 if (first !== null) {
7110 // Still circular.
7111 _update2.next = first;
7112 }
7113
7114 last.next = _update2;
7115 }
7116
7117 queue.last = _update2;
7118
7119 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
7120 // The queue is currently empty, which means we can eagerly compute the
7121 // next state before entering the render phase. If the new state is the
7122 // same as the current state, we may be able to bail out entirely.
7123 var lastRenderedReducer = queue.lastRenderedReducer;
7124
7125 if (lastRenderedReducer !== null) {
7126 var prevDispatcher;
7127
7128 {
7129 prevDispatcher = ReactCurrentDispatcher$1.current;
7130 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7131 }
7132
7133 try {
7134 var currentState = queue.lastRenderedState;
7135 var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
7136 // it, on the update object. If the reducer hasn't changed by the
7137 // time we enter the render phase, then the eager state can be used
7138 // without calling the reducer again.
7139
7140 _update2.eagerReducer = lastRenderedReducer;
7141 _update2.eagerState = eagerState;
7142
7143 if (is$1(eagerState, currentState)) {
7144 // Fast path. We can bail out without scheduling React to re-render.
7145 // It's still possible that we'll need to rebase this update later,
7146 // if the component re-renders for a different reason and by that
7147 // time the reducer has changed.
7148 return;
7149 }
7150 } catch (error) {// Suppress the error. It will throw again in the render phase.
7151 } finally {
7152 {
7153 ReactCurrentDispatcher$1.current = prevDispatcher;
7154 }
7155 }
7156 }
7157 }
7158
7159 {
7160 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
7161 if ('undefined' !== typeof jest) {
7162 warnIfNotScopedWithMatchingAct(fiber);
7163 warnIfNotCurrentlyActingUpdatesInDev(fiber);
7164 }
7165 }
7166
7167 scheduleWork(fiber, expirationTime);
7168 }
7169}
7170
7171var ContextOnlyDispatcher = {
7172 readContext: readContext,
7173 useCallback: throwInvalidHookError,
7174 useContext: throwInvalidHookError,
7175 useEffect: throwInvalidHookError,
7176 useImperativeHandle: throwInvalidHookError,
7177 useLayoutEffect: throwInvalidHookError,
7178 useMemo: throwInvalidHookError,
7179 useReducer: throwInvalidHookError,
7180 useRef: throwInvalidHookError,
7181 useState: throwInvalidHookError,
7182 useDebugValue: throwInvalidHookError,
7183 useResponder: throwInvalidHookError,
7184 useDeferredValue: throwInvalidHookError,
7185 useTransition: throwInvalidHookError
7186};
7187var HooksDispatcherOnMountInDEV = null;
7188var HooksDispatcherOnMountWithHookTypesInDEV = null;
7189var HooksDispatcherOnUpdateInDEV = null;
7190var InvalidNestedHooksDispatcherOnMountInDEV = null;
7191var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
7192
7193{
7194 var warnInvalidContextAccess = function () {
7195 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().');
7196 };
7197
7198 var warnInvalidHookAccess = function () {
7199 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');
7200 };
7201
7202 HooksDispatcherOnMountInDEV = {
7203 readContext: function (context, observedBits) {
7204 return readContext(context, observedBits);
7205 },
7206 useCallback: function (callback, deps) {
7207 currentHookNameInDev = 'useCallback';
7208 mountHookTypesDev();
7209 checkDepsAreArrayDev(deps);
7210 return mountCallback(callback, deps);
7211 },
7212 useContext: function (context, observedBits) {
7213 currentHookNameInDev = 'useContext';
7214 mountHookTypesDev();
7215 return readContext(context, observedBits);
7216 },
7217 useEffect: function (create, deps) {
7218 currentHookNameInDev = 'useEffect';
7219 mountHookTypesDev();
7220 checkDepsAreArrayDev(deps);
7221 return mountEffect(create, deps);
7222 },
7223 useImperativeHandle: function (ref, create, deps) {
7224 currentHookNameInDev = 'useImperativeHandle';
7225 mountHookTypesDev();
7226 checkDepsAreArrayDev(deps);
7227 return mountImperativeHandle(ref, create, deps);
7228 },
7229 useLayoutEffect: function (create, deps) {
7230 currentHookNameInDev = 'useLayoutEffect';
7231 mountHookTypesDev();
7232 checkDepsAreArrayDev(deps);
7233 return mountLayoutEffect(create, deps);
7234 },
7235 useMemo: function (create, deps) {
7236 currentHookNameInDev = 'useMemo';
7237 mountHookTypesDev();
7238 checkDepsAreArrayDev(deps);
7239 var prevDispatcher = ReactCurrentDispatcher$1.current;
7240 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7241
7242 try {
7243 return mountMemo(create, deps);
7244 } finally {
7245 ReactCurrentDispatcher$1.current = prevDispatcher;
7246 }
7247 },
7248 useReducer: function (reducer, initialArg, init) {
7249 currentHookNameInDev = 'useReducer';
7250 mountHookTypesDev();
7251 var prevDispatcher = ReactCurrentDispatcher$1.current;
7252 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7253
7254 try {
7255 return mountReducer(reducer, initialArg, init);
7256 } finally {
7257 ReactCurrentDispatcher$1.current = prevDispatcher;
7258 }
7259 },
7260 useRef: function (initialValue) {
7261 currentHookNameInDev = 'useRef';
7262 mountHookTypesDev();
7263 return mountRef(initialValue);
7264 },
7265 useState: function (initialState) {
7266 currentHookNameInDev = 'useState';
7267 mountHookTypesDev();
7268 var prevDispatcher = ReactCurrentDispatcher$1.current;
7269 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7270
7271 try {
7272 return mountState(initialState);
7273 } finally {
7274 ReactCurrentDispatcher$1.current = prevDispatcher;
7275 }
7276 },
7277 useDebugValue: function (value, formatterFn) {
7278 currentHookNameInDev = 'useDebugValue';
7279 mountHookTypesDev();
7280 return mountDebugValue(value, formatterFn);
7281 },
7282 useResponder: function (responder, props) {
7283 currentHookNameInDev = 'useResponder';
7284 mountHookTypesDev();
7285 return createResponderListener(responder, props);
7286 },
7287 useDeferredValue: function (value, config) {
7288 currentHookNameInDev = 'useDeferredValue';
7289 mountHookTypesDev();
7290 return mountDeferredValue(value, config);
7291 },
7292 useTransition: function (config) {
7293 currentHookNameInDev = 'useTransition';
7294 mountHookTypesDev();
7295 return mountTransition(config);
7296 }
7297 };
7298 HooksDispatcherOnMountWithHookTypesInDEV = {
7299 readContext: function (context, observedBits) {
7300 return readContext(context, observedBits);
7301 },
7302 useCallback: function (callback, deps) {
7303 currentHookNameInDev = 'useCallback';
7304 updateHookTypesDev();
7305 return mountCallback(callback, deps);
7306 },
7307 useContext: function (context, observedBits) {
7308 currentHookNameInDev = 'useContext';
7309 updateHookTypesDev();
7310 return readContext(context, observedBits);
7311 },
7312 useEffect: function (create, deps) {
7313 currentHookNameInDev = 'useEffect';
7314 updateHookTypesDev();
7315 return mountEffect(create, deps);
7316 },
7317 useImperativeHandle: function (ref, create, deps) {
7318 currentHookNameInDev = 'useImperativeHandle';
7319 updateHookTypesDev();
7320 return mountImperativeHandle(ref, create, deps);
7321 },
7322 useLayoutEffect: function (create, deps) {
7323 currentHookNameInDev = 'useLayoutEffect';
7324 updateHookTypesDev();
7325 return mountLayoutEffect(create, deps);
7326 },
7327 useMemo: function (create, deps) {
7328 currentHookNameInDev = 'useMemo';
7329 updateHookTypesDev();
7330 var prevDispatcher = ReactCurrentDispatcher$1.current;
7331 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7332
7333 try {
7334 return mountMemo(create, deps);
7335 } finally {
7336 ReactCurrentDispatcher$1.current = prevDispatcher;
7337 }
7338 },
7339 useReducer: function (reducer, initialArg, init) {
7340 currentHookNameInDev = 'useReducer';
7341 updateHookTypesDev();
7342 var prevDispatcher = ReactCurrentDispatcher$1.current;
7343 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7344
7345 try {
7346 return mountReducer(reducer, initialArg, init);
7347 } finally {
7348 ReactCurrentDispatcher$1.current = prevDispatcher;
7349 }
7350 },
7351 useRef: function (initialValue) {
7352 currentHookNameInDev = 'useRef';
7353 updateHookTypesDev();
7354 return mountRef(initialValue);
7355 },
7356 useState: function (initialState) {
7357 currentHookNameInDev = 'useState';
7358 updateHookTypesDev();
7359 var prevDispatcher = ReactCurrentDispatcher$1.current;
7360 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7361
7362 try {
7363 return mountState(initialState);
7364 } finally {
7365 ReactCurrentDispatcher$1.current = prevDispatcher;
7366 }
7367 },
7368 useDebugValue: function (value, formatterFn) {
7369 currentHookNameInDev = 'useDebugValue';
7370 updateHookTypesDev();
7371 return mountDebugValue(value, formatterFn);
7372 },
7373 useResponder: function (responder, props) {
7374 currentHookNameInDev = 'useResponder';
7375 updateHookTypesDev();
7376 return createResponderListener(responder, props);
7377 },
7378 useDeferredValue: function (value, config) {
7379 currentHookNameInDev = 'useDeferredValue';
7380 updateHookTypesDev();
7381 return mountDeferredValue(value, config);
7382 },
7383 useTransition: function (config) {
7384 currentHookNameInDev = 'useTransition';
7385 updateHookTypesDev();
7386 return mountTransition(config);
7387 }
7388 };
7389 HooksDispatcherOnUpdateInDEV = {
7390 readContext: function (context, observedBits) {
7391 return readContext(context, observedBits);
7392 },
7393 useCallback: function (callback, deps) {
7394 currentHookNameInDev = 'useCallback';
7395 updateHookTypesDev();
7396 return updateCallback(callback, deps);
7397 },
7398 useContext: function (context, observedBits) {
7399 currentHookNameInDev = 'useContext';
7400 updateHookTypesDev();
7401 return readContext(context, observedBits);
7402 },
7403 useEffect: function (create, deps) {
7404 currentHookNameInDev = 'useEffect';
7405 updateHookTypesDev();
7406 return updateEffect(create, deps);
7407 },
7408 useImperativeHandle: function (ref, create, deps) {
7409 currentHookNameInDev = 'useImperativeHandle';
7410 updateHookTypesDev();
7411 return updateImperativeHandle(ref, create, deps);
7412 },
7413 useLayoutEffect: function (create, deps) {
7414 currentHookNameInDev = 'useLayoutEffect';
7415 updateHookTypesDev();
7416 return updateLayoutEffect(create, deps);
7417 },
7418 useMemo: function (create, deps) {
7419 currentHookNameInDev = 'useMemo';
7420 updateHookTypesDev();
7421 var prevDispatcher = ReactCurrentDispatcher$1.current;
7422 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7423
7424 try {
7425 return updateMemo(create, deps);
7426 } finally {
7427 ReactCurrentDispatcher$1.current = prevDispatcher;
7428 }
7429 },
7430 useReducer: function (reducer, initialArg, init) {
7431 currentHookNameInDev = 'useReducer';
7432 updateHookTypesDev();
7433 var prevDispatcher = ReactCurrentDispatcher$1.current;
7434 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7435
7436 try {
7437 return updateReducer(reducer, initialArg, init);
7438 } finally {
7439 ReactCurrentDispatcher$1.current = prevDispatcher;
7440 }
7441 },
7442 useRef: function (initialValue) {
7443 currentHookNameInDev = 'useRef';
7444 updateHookTypesDev();
7445 return updateRef(initialValue);
7446 },
7447 useState: function (initialState) {
7448 currentHookNameInDev = 'useState';
7449 updateHookTypesDev();
7450 var prevDispatcher = ReactCurrentDispatcher$1.current;
7451 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7452
7453 try {
7454 return updateState(initialState);
7455 } finally {
7456 ReactCurrentDispatcher$1.current = prevDispatcher;
7457 }
7458 },
7459 useDebugValue: function (value, formatterFn) {
7460 currentHookNameInDev = 'useDebugValue';
7461 updateHookTypesDev();
7462 return updateDebugValue(value, formatterFn);
7463 },
7464 useResponder: function (responder, props) {
7465 currentHookNameInDev = 'useResponder';
7466 updateHookTypesDev();
7467 return createResponderListener(responder, props);
7468 },
7469 useDeferredValue: function (value, config) {
7470 currentHookNameInDev = 'useDeferredValue';
7471 updateHookTypesDev();
7472 return updateDeferredValue(value, config);
7473 },
7474 useTransition: function (config) {
7475 currentHookNameInDev = 'useTransition';
7476 updateHookTypesDev();
7477 return updateTransition(config);
7478 }
7479 };
7480 InvalidNestedHooksDispatcherOnMountInDEV = {
7481 readContext: function (context, observedBits) {
7482 warnInvalidContextAccess();
7483 return readContext(context, observedBits);
7484 },
7485 useCallback: function (callback, deps) {
7486 currentHookNameInDev = 'useCallback';
7487 warnInvalidHookAccess();
7488 mountHookTypesDev();
7489 return mountCallback(callback, deps);
7490 },
7491 useContext: function (context, observedBits) {
7492 currentHookNameInDev = 'useContext';
7493 warnInvalidHookAccess();
7494 mountHookTypesDev();
7495 return readContext(context, observedBits);
7496 },
7497 useEffect: function (create, deps) {
7498 currentHookNameInDev = 'useEffect';
7499 warnInvalidHookAccess();
7500 mountHookTypesDev();
7501 return mountEffect(create, deps);
7502 },
7503 useImperativeHandle: function (ref, create, deps) {
7504 currentHookNameInDev = 'useImperativeHandle';
7505 warnInvalidHookAccess();
7506 mountHookTypesDev();
7507 return mountImperativeHandle(ref, create, deps);
7508 },
7509 useLayoutEffect: function (create, deps) {
7510 currentHookNameInDev = 'useLayoutEffect';
7511 warnInvalidHookAccess();
7512 mountHookTypesDev();
7513 return mountLayoutEffect(create, deps);
7514 },
7515 useMemo: function (create, deps) {
7516 currentHookNameInDev = 'useMemo';
7517 warnInvalidHookAccess();
7518 mountHookTypesDev();
7519 var prevDispatcher = ReactCurrentDispatcher$1.current;
7520 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7521
7522 try {
7523 return mountMemo(create, deps);
7524 } finally {
7525 ReactCurrentDispatcher$1.current = prevDispatcher;
7526 }
7527 },
7528 useReducer: function (reducer, initialArg, init) {
7529 currentHookNameInDev = 'useReducer';
7530 warnInvalidHookAccess();
7531 mountHookTypesDev();
7532 var prevDispatcher = ReactCurrentDispatcher$1.current;
7533 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7534
7535 try {
7536 return mountReducer(reducer, initialArg, init);
7537 } finally {
7538 ReactCurrentDispatcher$1.current = prevDispatcher;
7539 }
7540 },
7541 useRef: function (initialValue) {
7542 currentHookNameInDev = 'useRef';
7543 warnInvalidHookAccess();
7544 mountHookTypesDev();
7545 return mountRef(initialValue);
7546 },
7547 useState: function (initialState) {
7548 currentHookNameInDev = 'useState';
7549 warnInvalidHookAccess();
7550 mountHookTypesDev();
7551 var prevDispatcher = ReactCurrentDispatcher$1.current;
7552 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7553
7554 try {
7555 return mountState(initialState);
7556 } finally {
7557 ReactCurrentDispatcher$1.current = prevDispatcher;
7558 }
7559 },
7560 useDebugValue: function (value, formatterFn) {
7561 currentHookNameInDev = 'useDebugValue';
7562 warnInvalidHookAccess();
7563 mountHookTypesDev();
7564 return mountDebugValue(value, formatterFn);
7565 },
7566 useResponder: function (responder, props) {
7567 currentHookNameInDev = 'useResponder';
7568 warnInvalidHookAccess();
7569 mountHookTypesDev();
7570 return createResponderListener(responder, props);
7571 },
7572 useDeferredValue: function (value, config) {
7573 currentHookNameInDev = 'useDeferredValue';
7574 warnInvalidHookAccess();
7575 mountHookTypesDev();
7576 return mountDeferredValue(value, config);
7577 },
7578 useTransition: function (config) {
7579 currentHookNameInDev = 'useTransition';
7580 warnInvalidHookAccess();
7581 mountHookTypesDev();
7582 return mountTransition(config);
7583 }
7584 };
7585 InvalidNestedHooksDispatcherOnUpdateInDEV = {
7586 readContext: function (context, observedBits) {
7587 warnInvalidContextAccess();
7588 return readContext(context, observedBits);
7589 },
7590 useCallback: function (callback, deps) {
7591 currentHookNameInDev = 'useCallback';
7592 warnInvalidHookAccess();
7593 updateHookTypesDev();
7594 return updateCallback(callback, deps);
7595 },
7596 useContext: function (context, observedBits) {
7597 currentHookNameInDev = 'useContext';
7598 warnInvalidHookAccess();
7599 updateHookTypesDev();
7600 return readContext(context, observedBits);
7601 },
7602 useEffect: function (create, deps) {
7603 currentHookNameInDev = 'useEffect';
7604 warnInvalidHookAccess();
7605 updateHookTypesDev();
7606 return updateEffect(create, deps);
7607 },
7608 useImperativeHandle: function (ref, create, deps) {
7609 currentHookNameInDev = 'useImperativeHandle';
7610 warnInvalidHookAccess();
7611 updateHookTypesDev();
7612 return updateImperativeHandle(ref, create, deps);
7613 },
7614 useLayoutEffect: function (create, deps) {
7615 currentHookNameInDev = 'useLayoutEffect';
7616 warnInvalidHookAccess();
7617 updateHookTypesDev();
7618 return updateLayoutEffect(create, deps);
7619 },
7620 useMemo: function (create, deps) {
7621 currentHookNameInDev = 'useMemo';
7622 warnInvalidHookAccess();
7623 updateHookTypesDev();
7624 var prevDispatcher = ReactCurrentDispatcher$1.current;
7625 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7626
7627 try {
7628 return updateMemo(create, deps);
7629 } finally {
7630 ReactCurrentDispatcher$1.current = prevDispatcher;
7631 }
7632 },
7633 useReducer: function (reducer, initialArg, init) {
7634 currentHookNameInDev = 'useReducer';
7635 warnInvalidHookAccess();
7636 updateHookTypesDev();
7637 var prevDispatcher = ReactCurrentDispatcher$1.current;
7638 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7639
7640 try {
7641 return updateReducer(reducer, initialArg, init);
7642 } finally {
7643 ReactCurrentDispatcher$1.current = prevDispatcher;
7644 }
7645 },
7646 useRef: function (initialValue) {
7647 currentHookNameInDev = 'useRef';
7648 warnInvalidHookAccess();
7649 updateHookTypesDev();
7650 return updateRef(initialValue);
7651 },
7652 useState: function (initialState) {
7653 currentHookNameInDev = 'useState';
7654 warnInvalidHookAccess();
7655 updateHookTypesDev();
7656 var prevDispatcher = ReactCurrentDispatcher$1.current;
7657 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7658
7659 try {
7660 return updateState(initialState);
7661 } finally {
7662 ReactCurrentDispatcher$1.current = prevDispatcher;
7663 }
7664 },
7665 useDebugValue: function (value, formatterFn) {
7666 currentHookNameInDev = 'useDebugValue';
7667 warnInvalidHookAccess();
7668 updateHookTypesDev();
7669 return updateDebugValue(value, formatterFn);
7670 },
7671 useResponder: function (responder, props) {
7672 currentHookNameInDev = 'useResponder';
7673 warnInvalidHookAccess();
7674 updateHookTypesDev();
7675 return createResponderListener(responder, props);
7676 },
7677 useDeferredValue: function (value, config) {
7678 currentHookNameInDev = 'useDeferredValue';
7679 warnInvalidHookAccess();
7680 updateHookTypesDev();
7681 return updateDeferredValue(value, config);
7682 },
7683 useTransition: function (config) {
7684 currentHookNameInDev = 'useTransition';
7685 warnInvalidHookAccess();
7686 updateHookTypesDev();
7687 return updateTransition(config);
7688 }
7689 };
7690}
7691
7692// CommonJS interop named imports.
7693
7694var now$1 = Scheduler.unstable_now;
7695var commitTime = 0;
7696var profilerStartTime = -1;
7697
7698function getCommitTime() {
7699 return commitTime;
7700}
7701
7702function recordCommitTime() {
7703 if (!enableProfilerTimer) {
7704 return;
7705 }
7706
7707 commitTime = now$1();
7708}
7709
7710function startProfilerTimer(fiber) {
7711 if (!enableProfilerTimer) {
7712 return;
7713 }
7714
7715 profilerStartTime = now$1();
7716
7717 if (fiber.actualStartTime < 0) {
7718 fiber.actualStartTime = now$1();
7719 }
7720}
7721
7722function stopProfilerTimerIfRunning(fiber) {
7723 if (!enableProfilerTimer) {
7724 return;
7725 }
7726
7727 profilerStartTime = -1;
7728}
7729
7730function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
7731 if (!enableProfilerTimer) {
7732 return;
7733 }
7734
7735 if (profilerStartTime >= 0) {
7736 var elapsedTime = now$1() - profilerStartTime;
7737 fiber.actualDuration += elapsedTime;
7738
7739 if (overrideBaseTime) {
7740 fiber.selfBaseDuration = elapsedTime;
7741 }
7742
7743 profilerStartTime = -1;
7744 }
7745}
7746
7747// This may have been an insertion or a hydration.
7748
7749var hydrationParentFiber = null;
7750var nextHydratableInstance = null;
7751var isHydrating = false;
7752
7753function warnIfHydrating() {
7754 {
7755 !!isHydrating ? warning$1(false, 'We should not be hydrating here. This is a bug in React. Please file a bug.') : void 0;
7756 }
7757}
7758
7759function enterHydrationState(fiber) {
7760 if (!supportsHydration) {
7761 return false;
7762 }
7763
7764 var parentInstance = fiber.stateNode.containerInfo;
7765 nextHydratableInstance = getFirstHydratableChild(parentInstance);
7766 hydrationParentFiber = fiber;
7767 isHydrating = true;
7768 return true;
7769}
7770
7771function reenterHydrationStateFromDehydratedSuspenseInstance(fiber, suspenseInstance) {
7772 if (!supportsHydration) {
7773 return false;
7774 }
7775
7776 nextHydratableInstance = getNextHydratableSibling(suspenseInstance);
7777 popToNextHostParent(fiber);
7778 isHydrating = true;
7779 return true;
7780}
7781
7782function deleteHydratableInstance(returnFiber, instance) {
7783 {
7784 switch (returnFiber.tag) {
7785 case HostRoot:
7786 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
7787 break;
7788
7789 case HostComponent:
7790 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
7791 break;
7792 }
7793 }
7794
7795 var childToDelete = createFiberFromHostInstanceForDeletion();
7796 childToDelete.stateNode = instance;
7797 childToDelete.return = returnFiber;
7798 childToDelete.effectTag = Deletion; // This might seem like it belongs on progressedFirstDeletion. However,
7799 // these children are not part of the reconciliation list of children.
7800 // Even if we abort and rereconcile the children, that will try to hydrate
7801 // again and the nodes are still in the host tree so these will be
7802 // recreated.
7803
7804 if (returnFiber.lastEffect !== null) {
7805 returnFiber.lastEffect.nextEffect = childToDelete;
7806 returnFiber.lastEffect = childToDelete;
7807 } else {
7808 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
7809 }
7810}
7811
7812function insertNonHydratedInstance(returnFiber, fiber) {
7813 fiber.effectTag = fiber.effectTag & ~Hydrating | Placement;
7814
7815 {
7816 switch (returnFiber.tag) {
7817 case HostRoot:
7818 {
7819 var parentContainer = returnFiber.stateNode.containerInfo;
7820
7821 switch (fiber.tag) {
7822 case HostComponent:
7823 var type = fiber.type;
7824 var props = fiber.pendingProps;
7825 didNotFindHydratableContainerInstance(parentContainer, type, props);
7826 break;
7827
7828 case HostText:
7829 var text = fiber.pendingProps;
7830 didNotFindHydratableContainerTextInstance(parentContainer, text);
7831 break;
7832
7833 case SuspenseComponent:
7834 didNotFindHydratableContainerSuspenseInstance(parentContainer);
7835 break;
7836 }
7837
7838 break;
7839 }
7840
7841 case HostComponent:
7842 {
7843 var parentType = returnFiber.type;
7844 var parentProps = returnFiber.memoizedProps;
7845 var parentInstance = returnFiber.stateNode;
7846
7847 switch (fiber.tag) {
7848 case HostComponent:
7849 var _type = fiber.type;
7850 var _props = fiber.pendingProps;
7851 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
7852 break;
7853
7854 case HostText:
7855 var _text = fiber.pendingProps;
7856 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
7857 break;
7858
7859 case SuspenseComponent:
7860 didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance);
7861 break;
7862 }
7863
7864 break;
7865 }
7866
7867 default:
7868 return;
7869 }
7870 }
7871}
7872
7873function tryHydrate(fiber, nextInstance) {
7874 switch (fiber.tag) {
7875 case HostComponent:
7876 {
7877 var type = fiber.type;
7878 var props = fiber.pendingProps;
7879 var instance = canHydrateInstance(nextInstance, type, props);
7880
7881 if (instance !== null) {
7882 fiber.stateNode = instance;
7883 return true;
7884 }
7885
7886 return false;
7887 }
7888
7889 case HostText:
7890 {
7891 var text = fiber.pendingProps;
7892 var textInstance = canHydrateTextInstance(nextInstance, text);
7893
7894 if (textInstance !== null) {
7895 fiber.stateNode = textInstance;
7896 return true;
7897 }
7898
7899 return false;
7900 }
7901
7902 case SuspenseComponent:
7903 {
7904 if (enableSuspenseServerRenderer) {
7905 var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
7906
7907 if (suspenseInstance !== null) {
7908 var suspenseState = {
7909 dehydrated: suspenseInstance,
7910 retryTime: Never
7911 };
7912 fiber.memoizedState = suspenseState; // Store the dehydrated fragment as a child fiber.
7913 // This simplifies the code for getHostSibling and deleting nodes,
7914 // since it doesn't have to consider all Suspense boundaries and
7915 // check if they're dehydrated ones or not.
7916
7917 var dehydratedFragment = createFiberFromDehydratedFragment(suspenseInstance);
7918 dehydratedFragment.return = fiber;
7919 fiber.child = dehydratedFragment;
7920 return true;
7921 }
7922 }
7923
7924 return false;
7925 }
7926
7927 default:
7928 return false;
7929 }
7930}
7931
7932function tryToClaimNextHydratableInstance(fiber) {
7933 if (!isHydrating) {
7934 return;
7935 }
7936
7937 var nextInstance = nextHydratableInstance;
7938
7939 if (!nextInstance) {
7940 // Nothing to hydrate. Make it an insertion.
7941 insertNonHydratedInstance(hydrationParentFiber, fiber);
7942 isHydrating = false;
7943 hydrationParentFiber = fiber;
7944 return;
7945 }
7946
7947 var firstAttemptedInstance = nextInstance;
7948
7949 if (!tryHydrate(fiber, nextInstance)) {
7950 // If we can't hydrate this instance let's try the next one.
7951 // We use this as a heuristic. It's based on intuition and not data so it
7952 // might be flawed or unnecessary.
7953 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
7954
7955 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
7956 // Nothing to hydrate. Make it an insertion.
7957 insertNonHydratedInstance(hydrationParentFiber, fiber);
7958 isHydrating = false;
7959 hydrationParentFiber = fiber;
7960 return;
7961 } // We matched the next one, we'll now assume that the first one was
7962 // superfluous and we'll delete it. Since we can't eagerly delete it
7963 // we'll have to schedule a deletion. To do that, this node needs a dummy
7964 // fiber associated with it.
7965
7966
7967 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
7968 }
7969
7970 hydrationParentFiber = fiber;
7971 nextHydratableInstance = getFirstHydratableChild(nextInstance);
7972}
7973
7974function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
7975 if (!supportsHydration) {
7976 {
7977 {
7978 throw Error("Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
7979 }
7980 }
7981 }
7982
7983 var instance = fiber.stateNode;
7984 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber); // TODO: Type this specific to this type of component.
7985
7986 fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
7987 // is a new ref we mark this as an update.
7988
7989 if (updatePayload !== null) {
7990 return true;
7991 }
7992
7993 return false;
7994}
7995
7996function prepareToHydrateHostTextInstance(fiber) {
7997 if (!supportsHydration) {
7998 {
7999 {
8000 throw Error("Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
8001 }
8002 }
8003 }
8004
8005 var textInstance = fiber.stateNode;
8006 var textContent = fiber.memoizedProps;
8007 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
8008
8009 {
8010 if (shouldUpdate) {
8011 // We assume that prepareToHydrateHostTextInstance is called in a context where the
8012 // hydration parent is the parent host component of this host text.
8013 var returnFiber = hydrationParentFiber;
8014
8015 if (returnFiber !== null) {
8016 switch (returnFiber.tag) {
8017 case HostRoot:
8018 {
8019 var parentContainer = returnFiber.stateNode.containerInfo;
8020 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
8021 break;
8022 }
8023
8024 case HostComponent:
8025 {
8026 var parentType = returnFiber.type;
8027 var parentProps = returnFiber.memoizedProps;
8028 var parentInstance = returnFiber.stateNode;
8029 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
8030 break;
8031 }
8032 }
8033 }
8034 }
8035 }
8036
8037 return shouldUpdate;
8038}
8039
8040function prepareToHydrateHostSuspenseInstance(fiber) {
8041 if (!supportsHydration) {
8042 {
8043 {
8044 throw Error("Expected prepareToHydrateHostSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
8045 }
8046 }
8047 }
8048
8049 var suspenseState = fiber.memoizedState;
8050 var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
8051
8052 if (!suspenseInstance) {
8053 {
8054 throw Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.");
8055 }
8056 }
8057
8058 hydrateSuspenseInstance(suspenseInstance, fiber);
8059}
8060
8061function skipPastDehydratedSuspenseInstance(fiber) {
8062 if (!supportsHydration) {
8063 {
8064 {
8065 throw Error("Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
8066 }
8067 }
8068 }
8069
8070 var suspenseState = fiber.memoizedState;
8071 var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
8072
8073 if (!suspenseInstance) {
8074 {
8075 throw Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.");
8076 }
8077 }
8078
8079 return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
8080}
8081
8082function popToNextHostParent(fiber) {
8083 var parent = fiber.return;
8084
8085 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
8086 parent = parent.return;
8087 }
8088
8089 hydrationParentFiber = parent;
8090}
8091
8092function popHydrationState(fiber) {
8093 if (!supportsHydration) {
8094 return false;
8095 }
8096
8097 if (fiber !== hydrationParentFiber) {
8098 // We're deeper than the current hydration context, inside an inserted
8099 // tree.
8100 return false;
8101 }
8102
8103 if (!isHydrating) {
8104 // If we're not currently hydrating but we're in a hydration context, then
8105 // we were an insertion and now need to pop up reenter hydration of our
8106 // siblings.
8107 popToNextHostParent(fiber);
8108 isHydrating = true;
8109 return false;
8110 }
8111
8112 var type = fiber.type; // If we have any remaining hydratable nodes, we need to delete them now.
8113 // We only do this deeper than head and body since they tend to have random
8114 // other nodes in them. We also ignore components with pure text content in
8115 // side of them.
8116 // TODO: Better heuristic.
8117
8118 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
8119 var nextInstance = nextHydratableInstance;
8120
8121 while (nextInstance) {
8122 deleteHydratableInstance(fiber, nextInstance);
8123 nextInstance = getNextHydratableSibling(nextInstance);
8124 }
8125 }
8126
8127 popToNextHostParent(fiber);
8128
8129 if (fiber.tag === SuspenseComponent) {
8130 nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
8131 } else {
8132 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
8133 }
8134
8135 return true;
8136}
8137
8138function resetHydrationState() {
8139 if (!supportsHydration) {
8140 return;
8141 }
8142
8143 hydrationParentFiber = null;
8144 nextHydratableInstance = null;
8145 isHydrating = false;
8146}
8147
8148var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
8149var didReceiveUpdate = false;
8150var didWarnAboutBadClass;
8151var didWarnAboutModulePatternComponent;
8152var didWarnAboutContextTypeOnFunctionComponent;
8153var didWarnAboutGetDerivedStateOnFunctionComponent;
8154var didWarnAboutFunctionRefs;
8155var didWarnAboutReassigningProps;
8156var didWarnAboutMaxDuration;
8157var didWarnAboutRevealOrder;
8158var didWarnAboutTailOptions;
8159var didWarnAboutDefaultPropsOnFunctionComponent;
8160
8161{
8162 didWarnAboutBadClass = {};
8163 didWarnAboutModulePatternComponent = {};
8164 didWarnAboutContextTypeOnFunctionComponent = {};
8165 didWarnAboutGetDerivedStateOnFunctionComponent = {};
8166 didWarnAboutFunctionRefs = {};
8167 didWarnAboutReassigningProps = false;
8168 didWarnAboutMaxDuration = false;
8169 didWarnAboutRevealOrder = {};
8170 didWarnAboutTailOptions = {};
8171 didWarnAboutDefaultPropsOnFunctionComponent = {};
8172}
8173
8174function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
8175 if (current$$1 === null) {
8176 // If this is a fresh new component that hasn't been rendered yet, we
8177 // won't update its child set by applying minimal side-effects. Instead,
8178 // we will add them all to the child before it gets rendered. That means
8179 // we can optimize this reconciliation pass by not tracking side-effects.
8180 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8181 } else {
8182 // If the current child is the same as the work in progress, it means that
8183 // we haven't yet started any work on these children. Therefore, we use
8184 // the clone algorithm to create a copy of all the current children.
8185 // If we had any progressed work already, that is invalid at this point so
8186 // let's throw it out.
8187 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
8188 }
8189}
8190
8191function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
8192 // This function is fork of reconcileChildren. It's used in cases where we
8193 // want to reconcile without matching against the existing set. This has the
8194 // effect of all current children being unmounted; even if the type and key
8195 // are the same, the old child is unmounted and a new child is created.
8196 //
8197 // To do this, we're going to go through the reconcile algorithm twice. In
8198 // the first pass, we schedule a deletion for all the current children by
8199 // passing null.
8200 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime); // In the second pass, we mount the new children. The trick here is that we
8201 // pass null in place of where we usually pass the current child set. This has
8202 // the effect of remounting all children regardless of whether their their
8203 // identity matches.
8204
8205 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8206}
8207
8208function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8209 // TODO: current can be non-null here even if the component
8210 // hasn't yet mounted. This happens after the first render suspends.
8211 // We'll need to figure out if this is fine or can cause issues.
8212 {
8213 if (workInProgress.type !== workInProgress.elementType) {
8214 // Lazy component props can't be validated in createElement
8215 // because they're only guaranteed to be resolved here.
8216 var innerPropTypes = Component.propTypes;
8217
8218 if (innerPropTypes) {
8219 checkPropTypes(innerPropTypes, nextProps, // Resolved props
8220 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8221 }
8222 }
8223 }
8224
8225 var render = Component.render;
8226 var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
8227
8228 var nextChildren;
8229 prepareToReadContext(workInProgress, renderExpirationTime);
8230
8231 {
8232 ReactCurrentOwner$2.current = workInProgress;
8233 setCurrentPhase('render');
8234 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
8235
8236 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8237 // Only double-render components with Hooks
8238 if (workInProgress.memoizedState !== null) {
8239 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
8240 }
8241 }
8242
8243 setCurrentPhase(null);
8244 }
8245
8246 if (current$$1 !== null && !didReceiveUpdate) {
8247 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
8248 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8249 } // React DevTools reads this flag.
8250
8251
8252 workInProgress.effectTag |= PerformedWork;
8253 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8254 return workInProgress.child;
8255}
8256
8257function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
8258 if (current$$1 === null) {
8259 var type = Component.type;
8260
8261 if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
8262 Component.defaultProps === undefined) {
8263 var resolvedType = type;
8264
8265 {
8266 resolvedType = resolveFunctionForHotReloading(type);
8267 } // If this is a plain function component without default props,
8268 // and with only the default shallow comparison, we upgrade it
8269 // to a SimpleMemoComponent to allow fast path updates.
8270
8271
8272 workInProgress.tag = SimpleMemoComponent;
8273 workInProgress.type = resolvedType;
8274
8275 {
8276 validateFunctionComponentInDev(workInProgress, type);
8277 }
8278
8279 return updateSimpleMemoComponent(current$$1, workInProgress, resolvedType, nextProps, updateExpirationTime, renderExpirationTime);
8280 }
8281
8282 {
8283 var innerPropTypes = type.propTypes;
8284
8285 if (innerPropTypes) {
8286 // Inner memo component props aren't currently validated in createElement.
8287 // We could move it there, but we'd still need this for lazy code path.
8288 checkPropTypes(innerPropTypes, nextProps, // Resolved props
8289 'prop', getComponentName(type), getCurrentFiberStackInDev);
8290 }
8291 }
8292
8293 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
8294 child.ref = workInProgress.ref;
8295 child.return = workInProgress;
8296 workInProgress.child = child;
8297 return child;
8298 }
8299
8300 {
8301 var _type = Component.type;
8302 var _innerPropTypes = _type.propTypes;
8303
8304 if (_innerPropTypes) {
8305 // Inner memo component props aren't currently validated in createElement.
8306 // We could move it there, but we'd still need this for lazy code path.
8307 checkPropTypes(_innerPropTypes, nextProps, // Resolved props
8308 'prop', getComponentName(_type), getCurrentFiberStackInDev);
8309 }
8310 }
8311
8312 var currentChild = current$$1.child; // This is always exactly one child
8313
8314 if (updateExpirationTime < renderExpirationTime) {
8315 // This will be the props with resolved defaultProps,
8316 // unlike current.memoizedProps which will be the unresolved ones.
8317 var prevProps = currentChild.memoizedProps; // Default to shallow comparison
8318
8319 var compare = Component.compare;
8320 compare = compare !== null ? compare : shallowEqual;
8321
8322 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
8323 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8324 }
8325 } // React DevTools reads this flag.
8326
8327
8328 workInProgress.effectTag |= PerformedWork;
8329 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
8330 newChild.ref = workInProgress.ref;
8331 newChild.return = workInProgress;
8332 workInProgress.child = newChild;
8333 return newChild;
8334}
8335
8336function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
8337 // TODO: current can be non-null here even if the component
8338 // hasn't yet mounted. This happens when the inner render suspends.
8339 // We'll need to figure out if this is fine or can cause issues.
8340 {
8341 if (workInProgress.type !== workInProgress.elementType) {
8342 // Lazy component props can't be validated in createElement
8343 // because they're only guaranteed to be resolved here.
8344 var outerMemoType = workInProgress.elementType;
8345
8346 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
8347 // We warn when you define propTypes on lazy()
8348 // so let's just skip over it to find memo() outer wrapper.
8349 // Inner props for memo are validated later.
8350 outerMemoType = refineResolvedLazyComponent(outerMemoType);
8351 }
8352
8353 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
8354
8355 if (outerPropTypes) {
8356 checkPropTypes(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
8357 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
8358 } // Inner propTypes will be validated in the function component path.
8359
8360 }
8361 }
8362
8363 if (current$$1 !== null) {
8364 var prevProps = current$$1.memoizedProps;
8365
8366 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload:
8367 workInProgress.type === current$$1.type)) {
8368 didReceiveUpdate = false;
8369
8370 if (updateExpirationTime < renderExpirationTime) {
8371 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8372 }
8373 }
8374 }
8375
8376 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
8377}
8378
8379function updateFragment(current$$1, workInProgress, renderExpirationTime) {
8380 var nextChildren = workInProgress.pendingProps;
8381 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8382 return workInProgress.child;
8383}
8384
8385function updateMode(current$$1, workInProgress, renderExpirationTime) {
8386 var nextChildren = workInProgress.pendingProps.children;
8387 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8388 return workInProgress.child;
8389}
8390
8391function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
8392 if (enableProfilerTimer) {
8393 workInProgress.effectTag |= Update;
8394 }
8395
8396 var nextProps = workInProgress.pendingProps;
8397 var nextChildren = nextProps.children;
8398 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8399 return workInProgress.child;
8400}
8401
8402function markRef(current$$1, workInProgress) {
8403 var ref = workInProgress.ref;
8404
8405 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
8406 // Schedule a Ref effect
8407 workInProgress.effectTag |= Ref;
8408 }
8409}
8410
8411function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8412 {
8413 if (workInProgress.type !== workInProgress.elementType) {
8414 // Lazy component props can't be validated in createElement
8415 // because they're only guaranteed to be resolved here.
8416 var innerPropTypes = Component.propTypes;
8417
8418 if (innerPropTypes) {
8419 checkPropTypes(innerPropTypes, nextProps, // Resolved props
8420 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8421 }
8422 }
8423 }
8424
8425 var context;
8426
8427 if (!disableLegacyContext) {
8428 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
8429 context = getMaskedContext(workInProgress, unmaskedContext);
8430 }
8431
8432 var nextChildren;
8433 prepareToReadContext(workInProgress, renderExpirationTime);
8434
8435 {
8436 ReactCurrentOwner$2.current = workInProgress;
8437 setCurrentPhase('render');
8438 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
8439
8440 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8441 // Only double-render components with Hooks
8442 if (workInProgress.memoizedState !== null) {
8443 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
8444 }
8445 }
8446
8447 setCurrentPhase(null);
8448 }
8449
8450 if (current$$1 !== null && !didReceiveUpdate) {
8451 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
8452 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8453 } // React DevTools reads this flag.
8454
8455
8456 workInProgress.effectTag |= PerformedWork;
8457 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8458 return workInProgress.child;
8459}
8460
8461function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8462 {
8463 if (workInProgress.type !== workInProgress.elementType) {
8464 // Lazy component props can't be validated in createElement
8465 // because they're only guaranteed to be resolved here.
8466 var innerPropTypes = Component.propTypes;
8467
8468 if (innerPropTypes) {
8469 checkPropTypes(innerPropTypes, nextProps, // Resolved props
8470 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8471 }
8472 }
8473 } // Push context providers early to prevent context stack mismatches.
8474 // During mounting we don't know the child context yet as the instance doesn't exist.
8475 // We will invalidate the child context in finishClassComponent() right after rendering.
8476
8477
8478 var hasContext;
8479
8480 if (isContextProvider(Component)) {
8481 hasContext = true;
8482 pushContextProvider(workInProgress);
8483 } else {
8484 hasContext = false;
8485 }
8486
8487 prepareToReadContext(workInProgress, renderExpirationTime);
8488 var instance = workInProgress.stateNode;
8489 var shouldUpdate;
8490
8491 if (instance === null) {
8492 if (current$$1 !== null) {
8493 // An class component without an instance only mounts if it suspended
8494 // inside a non- concurrent tree, in an inconsistent state. We want to
8495 // tree it like a new mount, even though an empty version of it already
8496 // committed. Disconnect the alternate pointers.
8497 current$$1.alternate = null;
8498 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8499
8500 workInProgress.effectTag |= Placement;
8501 } // In the initial pass we might need to construct the instance.
8502
8503
8504 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8505 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8506 shouldUpdate = true;
8507 } else if (current$$1 === null) {
8508 // In a resume, we'll already have an instance we can reuse.
8509 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8510 } else {
8511 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
8512 }
8513
8514 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
8515
8516 {
8517 var inst = workInProgress.stateNode;
8518
8519 if (inst.props !== nextProps) {
8520 !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;
8521 didWarnAboutReassigningProps = true;
8522 }
8523 }
8524
8525 return nextUnitOfWork;
8526}
8527
8528function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
8529 // Refs should update even if shouldComponentUpdate returns false
8530 markRef(current$$1, workInProgress);
8531 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
8532
8533 if (!shouldUpdate && !didCaptureError) {
8534 // Context providers should defer to sCU for rendering
8535 if (hasContext) {
8536 invalidateContextProvider(workInProgress, Component, false);
8537 }
8538
8539 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8540 }
8541
8542 var instance = workInProgress.stateNode; // Rerender
8543
8544 ReactCurrentOwner$2.current = workInProgress;
8545 var nextChildren;
8546
8547 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
8548 // If we captured an error, but getDerivedStateFrom catch is not defined,
8549 // unmount all the children. componentDidCatch will schedule an update to
8550 // re-render a fallback. This is temporary until we migrate everyone to
8551 // the new API.
8552 // TODO: Warn in a future release.
8553 nextChildren = null;
8554
8555 if (enableProfilerTimer) {
8556 stopProfilerTimerIfRunning(workInProgress);
8557 }
8558 } else {
8559 {
8560 setCurrentPhase('render');
8561 nextChildren = instance.render();
8562
8563 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8564 instance.render();
8565 }
8566
8567 setCurrentPhase(null);
8568 }
8569 } // React DevTools reads this flag.
8570
8571
8572 workInProgress.effectTag |= PerformedWork;
8573
8574 if (current$$1 !== null && didCaptureError) {
8575 // If we're recovering from an error, reconcile without reusing any of
8576 // the existing children. Conceptually, the normal children and the children
8577 // that are shown on error are two different sets, so we shouldn't reuse
8578 // normal children even if their identities match.
8579 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
8580 } else {
8581 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8582 } // Memoize state using the values we just used to render.
8583 // TODO: Restructure so we never read values from the instance.
8584
8585
8586 workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
8587
8588 if (hasContext) {
8589 invalidateContextProvider(workInProgress, Component, true);
8590 }
8591
8592 return workInProgress.child;
8593}
8594
8595function pushHostRootContext(workInProgress) {
8596 var root = workInProgress.stateNode;
8597
8598 if (root.pendingContext) {
8599 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
8600 } else if (root.context) {
8601 // Should always be set
8602 pushTopLevelContextObject(workInProgress, root.context, false);
8603 }
8604
8605 pushHostContainer(workInProgress, root.containerInfo);
8606}
8607
8608function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
8609 pushHostRootContext(workInProgress);
8610 var updateQueue = workInProgress.updateQueue;
8611
8612 if (!(updateQueue !== null)) {
8613 {
8614 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.");
8615 }
8616 }
8617
8618 var nextProps = workInProgress.pendingProps;
8619 var prevState = workInProgress.memoizedState;
8620 var prevChildren = prevState !== null ? prevState.element : null;
8621 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
8622 var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
8623 // being called "element".
8624
8625 var nextChildren = nextState.element;
8626
8627 if (nextChildren === prevChildren) {
8628 // If the state is the same as before, that's a bailout because we had
8629 // no work that expires at this time.
8630 resetHydrationState();
8631 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8632 }
8633
8634 var root = workInProgress.stateNode;
8635
8636 if (root.hydrate && enterHydrationState(workInProgress)) {
8637 // If we don't have any current children this might be the first pass.
8638 // We always try to hydrate. If this isn't a hydration pass there won't
8639 // be any children to hydrate which is effectively the same thing as
8640 // not hydrating.
8641 var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8642 workInProgress.child = child;
8643 var node = child;
8644
8645 while (node) {
8646 // Mark each child as hydrating. This is a fast path to know whether this
8647 // tree is part of a hydrating tree. This is used to determine if a child
8648 // node has fully mounted yet, and for scheduling event replaying.
8649 // Conceptually this is similar to Placement in that a new subtree is
8650 // inserted into the React tree here. It just happens to not need DOM
8651 // mutations because it already exists.
8652 node.effectTag = node.effectTag & ~Placement | Hydrating;
8653 node = node.sibling;
8654 }
8655 } else {
8656 // Otherwise reset hydration state in case we aborted and resumed another
8657 // root.
8658 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8659 resetHydrationState();
8660 }
8661
8662 return workInProgress.child;
8663}
8664
8665function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
8666 pushHostContext(workInProgress);
8667
8668 if (current$$1 === null) {
8669 tryToClaimNextHydratableInstance(workInProgress);
8670 }
8671
8672 var type = workInProgress.type;
8673 var nextProps = workInProgress.pendingProps;
8674 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
8675 var nextChildren = nextProps.children;
8676 var isDirectTextChild = shouldSetTextContent(type, nextProps);
8677
8678 if (isDirectTextChild) {
8679 // We special case a direct text child of a host node. This is a common
8680 // case. We won't handle it as a reified child. We will instead handle
8681 // this in the host environment that also have access to this prop. That
8682 // avoids allocating another HostText fiber and traversing it.
8683 nextChildren = null;
8684 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
8685 // If we're switching from a direct text child to a normal child, or to
8686 // empty, we need to schedule the text content to be reset.
8687 workInProgress.effectTag |= ContentReset;
8688 }
8689
8690 markRef(current$$1, workInProgress); // Check the host config to see if the children are offscreen/hidden.
8691
8692 if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(type, nextProps)) {
8693 if (enableSchedulerTracing) {
8694 markSpawnedWork(Never);
8695 } // Schedule this fiber to re-render at offscreen priority. Then bailout.
8696
8697
8698 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
8699 return null;
8700 }
8701
8702 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8703 return workInProgress.child;
8704}
8705
8706function updateHostText(current$$1, workInProgress) {
8707 if (current$$1 === null) {
8708 tryToClaimNextHydratableInstance(workInProgress);
8709 } // Nothing to do here. This is terminal. We'll do the completion step
8710 // immediately after.
8711
8712
8713 return null;
8714}
8715
8716function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
8717 if (_current !== null) {
8718 // An lazy component only mounts if it suspended inside a non-
8719 // concurrent tree, in an inconsistent state. We want to treat it like
8720 // a new mount, even though an empty version of it already committed.
8721 // Disconnect the alternate pointers.
8722 _current.alternate = null;
8723 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8724
8725 workInProgress.effectTag |= Placement;
8726 }
8727
8728 var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
8729 // Cancel and resume right after we know the tag.
8730
8731 cancelWorkTimer(workInProgress);
8732 var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
8733
8734 workInProgress.type = Component;
8735 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
8736 startWorkTimer(workInProgress);
8737 var resolvedProps = resolveDefaultProps(Component, props);
8738 var child;
8739
8740 switch (resolvedTag) {
8741 case FunctionComponent:
8742 {
8743 {
8744 validateFunctionComponentInDev(workInProgress, Component);
8745 workInProgress.type = Component = resolveFunctionForHotReloading(Component);
8746 }
8747
8748 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8749 break;
8750 }
8751
8752 case ClassComponent:
8753 {
8754 {
8755 workInProgress.type = Component = resolveClassForHotReloading(Component);
8756 }
8757
8758 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8759 break;
8760 }
8761
8762 case ForwardRef:
8763 {
8764 {
8765 workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
8766 }
8767
8768 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8769 break;
8770 }
8771
8772 case MemoComponent:
8773 {
8774 {
8775 if (workInProgress.type !== workInProgress.elementType) {
8776 var outerPropTypes = Component.propTypes;
8777
8778 if (outerPropTypes) {
8779 checkPropTypes(outerPropTypes, resolvedProps, // Resolved for outer only
8780 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8781 }
8782 }
8783 }
8784
8785 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
8786 updateExpirationTime, renderExpirationTime);
8787 break;
8788 }
8789
8790 default:
8791 {
8792 var hint = '';
8793
8794 {
8795 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
8796 hint = ' Did you wrap a component in React.lazy() more than once?';
8797 }
8798 } // This message intentionally doesn't mention ForwardRef or MemoComponent
8799 // because the fact that it's a separate type of work is an
8800 // implementation detail.
8801
8802
8803 {
8804 {
8805 throw Error("Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint);
8806 }
8807 }
8808 }
8809 }
8810
8811 return child;
8812}
8813
8814function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
8815 if (_current !== null) {
8816 // An incomplete component only mounts if it suspended inside a non-
8817 // concurrent tree, in an inconsistent state. We want to treat it like
8818 // a new mount, even though an empty version of it already committed.
8819 // Disconnect the alternate pointers.
8820 _current.alternate = null;
8821 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8822
8823 workInProgress.effectTag |= Placement;
8824 } // Promote the fiber to a class and try rendering again.
8825
8826
8827 workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
8828 // Push context providers early to prevent context stack mismatches.
8829 // During mounting we don't know the child context yet as the instance doesn't exist.
8830 // We will invalidate the child context in finishClassComponent() right after rendering.
8831
8832 var hasContext;
8833
8834 if (isContextProvider(Component)) {
8835 hasContext = true;
8836 pushContextProvider(workInProgress);
8837 } else {
8838 hasContext = false;
8839 }
8840
8841 prepareToReadContext(workInProgress, renderExpirationTime);
8842 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8843 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8844 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
8845}
8846
8847function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
8848 if (_current !== null) {
8849 // An indeterminate component only mounts if it suspended inside a non-
8850 // concurrent tree, in an inconsistent state. We want to treat it like
8851 // a new mount, even though an empty version of it already committed.
8852 // Disconnect the alternate pointers.
8853 _current.alternate = null;
8854 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8855
8856 workInProgress.effectTag |= Placement;
8857 }
8858
8859 var props = workInProgress.pendingProps;
8860 var context;
8861
8862 if (!disableLegacyContext) {
8863 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
8864 context = getMaskedContext(workInProgress, unmaskedContext);
8865 }
8866
8867 prepareToReadContext(workInProgress, renderExpirationTime);
8868 var value;
8869
8870 {
8871 if (Component.prototype && typeof Component.prototype.render === 'function') {
8872 var componentName = getComponentName(Component) || 'Unknown';
8873
8874 if (!didWarnAboutBadClass[componentName]) {
8875 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);
8876 didWarnAboutBadClass[componentName] = true;
8877 }
8878 }
8879
8880 if (workInProgress.mode & StrictMode) {
8881 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
8882 }
8883
8884 ReactCurrentOwner$2.current = workInProgress;
8885 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
8886 } // React DevTools reads this flag.
8887
8888
8889 workInProgress.effectTag |= PerformedWork;
8890
8891 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
8892 {
8893 var _componentName = getComponentName(Component) || 'Unknown';
8894
8895 if (!didWarnAboutModulePatternComponent[_componentName]) {
8896 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);
8897 didWarnAboutModulePatternComponent[_componentName] = true;
8898 }
8899 } // Proceed under the assumption that this is a class instance
8900
8901
8902 workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
8903
8904 resetHooks(); // Push context providers early to prevent context stack mismatches.
8905 // During mounting we don't know the child context yet as the instance doesn't exist.
8906 // We will invalidate the child context in finishClassComponent() right after rendering.
8907
8908 var hasContext = false;
8909
8910 if (isContextProvider(Component)) {
8911 hasContext = true;
8912 pushContextProvider(workInProgress);
8913 } else {
8914 hasContext = false;
8915 }
8916
8917 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
8918 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
8919
8920 if (typeof getDerivedStateFromProps === 'function') {
8921 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
8922 }
8923
8924 adoptClassInstance(workInProgress, value);
8925 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
8926 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
8927 } else {
8928 // Proceed under the assumption that this is a function component
8929 workInProgress.tag = FunctionComponent;
8930
8931 {
8932 if (disableLegacyContext && Component.contextTypes) {
8933 warningWithoutStack$1(false, '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with React.useContext() instead.', getComponentName(Component) || 'Unknown');
8934 }
8935
8936 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8937 // Only double-render components with Hooks
8938 if (workInProgress.memoizedState !== null) {
8939 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
8940 }
8941 }
8942 }
8943
8944 reconcileChildren(null, workInProgress, value, renderExpirationTime);
8945
8946 {
8947 validateFunctionComponentInDev(workInProgress, Component);
8948 }
8949
8950 return workInProgress.child;
8951 }
8952}
8953
8954function validateFunctionComponentInDev(workInProgress, Component) {
8955 if (Component) {
8956 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
8957 }
8958
8959 if (workInProgress.ref !== null) {
8960 var info = '';
8961 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
8962
8963 if (ownerName) {
8964 info += '\n\nCheck the render method of `' + ownerName + '`.';
8965 }
8966
8967 var warningKey = ownerName || workInProgress._debugID || '';
8968 var debugSource = workInProgress._debugSource;
8969
8970 if (debugSource) {
8971 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
8972 }
8973
8974 if (!didWarnAboutFunctionRefs[warningKey]) {
8975 didWarnAboutFunctionRefs[warningKey] = true;
8976 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);
8977 }
8978 }
8979
8980 if (warnAboutDefaultPropsOnFunctionComponents && Component.defaultProps !== undefined) {
8981 var componentName = getComponentName(Component) || 'Unknown';
8982
8983 if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
8984 warningWithoutStack$1(false, '%s: Support for defaultProps will be removed from function components ' + 'in a future major release. Use JavaScript default parameters instead.', componentName);
8985 didWarnAboutDefaultPropsOnFunctionComponent[componentName] = true;
8986 }
8987 }
8988
8989 if (typeof Component.getDerivedStateFromProps === 'function') {
8990 var _componentName2 = getComponentName(Component) || 'Unknown';
8991
8992 if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
8993 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', _componentName2);
8994 didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
8995 }
8996 }
8997
8998 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
8999 var _componentName3 = getComponentName(Component) || 'Unknown';
9000
9001 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
9002 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName3);
9003 didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
9004 }
9005 }
9006}
9007
9008var SUSPENDED_MARKER = {
9009 dehydrated: null,
9010 retryTime: NoWork
9011};
9012
9013function shouldRemainOnFallback(suspenseContext, current$$1, workInProgress) {
9014 // If the context is telling us that we should show a fallback, and we're not
9015 // already showing content, then we should show the fallback instead.
9016 return hasSuspenseContext(suspenseContext, ForceSuspenseFallback) && (current$$1 === null || current$$1.memoizedState !== null);
9017}
9018
9019function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
9020 var mode = workInProgress.mode;
9021 var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
9022
9023 {
9024 if (shouldSuspend(workInProgress)) {
9025 workInProgress.effectTag |= DidCapture;
9026 }
9027 }
9028
9029 var suspenseContext = suspenseStackCursor.current;
9030 var nextDidTimeout = false;
9031 var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
9032
9033 if (didSuspend || shouldRemainOnFallback(suspenseContext, current$$1, workInProgress)) {
9034 // Something in this boundary's subtree already suspended. Switch to
9035 // rendering the fallback children.
9036 nextDidTimeout = true;
9037 workInProgress.effectTag &= ~DidCapture;
9038 } else {
9039 // Attempting the main content
9040 if (current$$1 === null || current$$1.memoizedState !== null) {
9041 // This is a new mount or this boundary is already showing a fallback state.
9042 // Mark this subtree context as having at least one invisible parent that could
9043 // handle the fallback state.
9044 // Boundaries without fallbacks or should be avoided are not considered since
9045 // they cannot handle preferred fallback states.
9046 if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
9047 suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
9048 }
9049 }
9050 }
9051
9052 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
9053 pushSuspenseContext(workInProgress, suspenseContext);
9054
9055 {
9056 if ('maxDuration' in nextProps) {
9057 if (!didWarnAboutMaxDuration) {
9058 didWarnAboutMaxDuration = true;
9059 warning$1(false, 'maxDuration has been removed from React. ' + 'Remove the maxDuration prop.');
9060 }
9061 }
9062 } // This next part is a bit confusing. If the children timeout, we switch to
9063 // showing the fallback children in place of the "primary" children.
9064 // However, we don't want to delete the primary children because then their
9065 // state will be lost (both the React state and the host state, e.g.
9066 // uncontrolled form inputs). Instead we keep them mounted and hide them.
9067 // Both the fallback children AND the primary children are rendered at the
9068 // same time. Once the primary children are un-suspended, we can delete
9069 // the fallback children — don't need to preserve their state.
9070 //
9071 // The two sets of children are siblings in the host environment, but
9072 // semantically, for purposes of reconciliation, they are two separate sets.
9073 // So we store them using two fragment fibers.
9074 //
9075 // However, we want to avoid allocating extra fibers for every placeholder.
9076 // They're only necessary when the children time out, because that's the
9077 // only time when both sets are mounted.
9078 //
9079 // So, the extra fragment fibers are only used if the children time out.
9080 // Otherwise, we render the primary children directly. This requires some
9081 // custom reconciliation logic to preserve the state of the primary
9082 // children. It's essentially a very basic form of re-parenting.
9083
9084
9085 if (current$$1 === null) {
9086 // If we're currently hydrating, try to hydrate this boundary.
9087 // But only if this has a fallback.
9088 if (nextProps.fallback !== undefined) {
9089 tryToClaimNextHydratableInstance(workInProgress); // This could've been a dehydrated suspense component.
9090
9091 if (enableSuspenseServerRenderer) {
9092 var suspenseState = workInProgress.memoizedState;
9093
9094 if (suspenseState !== null) {
9095 var dehydrated = suspenseState.dehydrated;
9096
9097 if (dehydrated !== null) {
9098 return mountDehydratedSuspenseComponent(workInProgress, dehydrated, renderExpirationTime);
9099 }
9100 }
9101 }
9102 } // This is the initial mount. This branch is pretty simple because there's
9103 // no previous state that needs to be preserved.
9104
9105
9106 if (nextDidTimeout) {
9107 // Mount separate fragments for primary and fallback children.
9108 var nextFallbackChildren = nextProps.fallback;
9109 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
9110 primaryChildFragment.return = workInProgress;
9111
9112 if ((workInProgress.mode & BatchedMode) === NoMode) {
9113 // Outside of batched mode, we commit the effects from the
9114 // partially completed, timed-out tree, too.
9115 var progressedState = workInProgress.memoizedState;
9116 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
9117 primaryChildFragment.child = progressedPrimaryChild;
9118 var progressedChild = progressedPrimaryChild;
9119
9120 while (progressedChild !== null) {
9121 progressedChild.return = primaryChildFragment;
9122 progressedChild = progressedChild.sibling;
9123 }
9124 }
9125
9126 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
9127 fallbackChildFragment.return = workInProgress;
9128 primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
9129 // fallback children.
9130
9131 workInProgress.memoizedState = SUSPENDED_MARKER;
9132 workInProgress.child = primaryChildFragment;
9133 return fallbackChildFragment;
9134 } else {
9135 // Mount the primary children without an intermediate fragment fiber.
9136 var nextPrimaryChildren = nextProps.children;
9137 workInProgress.memoizedState = null;
9138 return workInProgress.child = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
9139 }
9140 } else {
9141 // This is an update. This branch is more complicated because we need to
9142 // ensure the state of the primary children is preserved.
9143 var prevState = current$$1.memoizedState;
9144
9145 if (prevState !== null) {
9146 if (enableSuspenseServerRenderer) {
9147 var _dehydrated = prevState.dehydrated;
9148
9149 if (_dehydrated !== null) {
9150 if (!didSuspend) {
9151 return updateDehydratedSuspenseComponent(current$$1, workInProgress, _dehydrated, prevState, renderExpirationTime);
9152 } else if (workInProgress.memoizedState !== null) {
9153 // Something suspended and we should still be in dehydrated mode.
9154 // Leave the existing child in place.
9155 workInProgress.child = current$$1.child; // The dehydrated completion pass expects this flag to be there
9156 // but the normal suspense pass doesn't.
9157
9158 workInProgress.effectTag |= DidCapture;
9159 return null;
9160 } else {
9161 // Suspended but we should no longer be in dehydrated mode.
9162 // Therefore we now have to render the fallback. Wrap the children
9163 // in a fragment fiber to keep them separate from the fallback
9164 // children.
9165 var _nextFallbackChildren = nextProps.fallback;
9166
9167 var _primaryChildFragment = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
9168 // going to render this fragment.
9169 null, mode, NoWork, null);
9170
9171 _primaryChildFragment.return = workInProgress; // This is always null since we never want the previous child
9172 // that we're not going to hydrate.
9173
9174 _primaryChildFragment.child = null;
9175
9176 if ((workInProgress.mode & BatchedMode) === NoMode) {
9177 // Outside of batched mode, we commit the effects from the
9178 // partially completed, timed-out tree, too.
9179 var _progressedChild = _primaryChildFragment.child = workInProgress.child;
9180
9181 while (_progressedChild !== null) {
9182 _progressedChild.return = _primaryChildFragment;
9183 _progressedChild = _progressedChild.sibling;
9184 }
9185 } else {
9186 // We will have dropped the effect list which contains the deletion.
9187 // We need to reconcile to delete the current child.
9188 reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
9189 } // Because primaryChildFragment is a new fiber that we're inserting as the
9190 // parent of a new tree, we need to set its treeBaseDuration.
9191
9192
9193 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9194 // treeBaseDuration is the sum of all the child tree base durations.
9195 var treeBaseDuration = 0;
9196 var hiddenChild = _primaryChildFragment.child;
9197
9198 while (hiddenChild !== null) {
9199 treeBaseDuration += hiddenChild.treeBaseDuration;
9200 hiddenChild = hiddenChild.sibling;
9201 }
9202
9203 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
9204 } // Create a fragment from the fallback children, too.
9205
9206
9207 var _fallbackChildFragment = createFiberFromFragment(_nextFallbackChildren, mode, renderExpirationTime, null);
9208
9209 _fallbackChildFragment.return = workInProgress;
9210 _primaryChildFragment.sibling = _fallbackChildFragment;
9211 _fallbackChildFragment.effectTag |= Placement;
9212 _primaryChildFragment.childExpirationTime = NoWork;
9213 workInProgress.memoizedState = SUSPENDED_MARKER;
9214 workInProgress.child = _primaryChildFragment; // Skip the primary children, and continue working on the
9215 // fallback children.
9216
9217 return _fallbackChildFragment;
9218 }
9219 }
9220 } // The current tree already timed out. That means each child set is
9221 // wrapped in a fragment fiber.
9222
9223
9224 var currentPrimaryChildFragment = current$$1.child;
9225 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
9226
9227 if (nextDidTimeout) {
9228 // Still timed out. Reuse the current primary children by cloning
9229 // its fragment. We're going to skip over these entirely.
9230 var _nextFallbackChildren2 = nextProps.fallback;
9231
9232 var _primaryChildFragment2 = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
9233
9234 _primaryChildFragment2.return = workInProgress;
9235
9236 if ((workInProgress.mode & BatchedMode) === NoMode) {
9237 // Outside of batched mode, we commit the effects from the
9238 // partially completed, timed-out tree, too.
9239 var _progressedState = workInProgress.memoizedState;
9240
9241 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
9242
9243 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
9244 _primaryChildFragment2.child = _progressedPrimaryChild;
9245 var _progressedChild2 = _progressedPrimaryChild;
9246
9247 while (_progressedChild2 !== null) {
9248 _progressedChild2.return = _primaryChildFragment2;
9249 _progressedChild2 = _progressedChild2.sibling;
9250 }
9251 }
9252 } // Because primaryChildFragment is a new fiber that we're inserting as the
9253 // parent of a new tree, we need to set its treeBaseDuration.
9254
9255
9256 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9257 // treeBaseDuration is the sum of all the child tree base durations.
9258 var _treeBaseDuration = 0;
9259 var _hiddenChild = _primaryChildFragment2.child;
9260
9261 while (_hiddenChild !== null) {
9262 _treeBaseDuration += _hiddenChild.treeBaseDuration;
9263 _hiddenChild = _hiddenChild.sibling;
9264 }
9265
9266 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
9267 } // Clone the fallback child fragment, too. These we'll continue
9268 // working on.
9269
9270
9271 var _fallbackChildFragment2 = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren2, currentFallbackChildFragment.expirationTime);
9272
9273 _fallbackChildFragment2.return = workInProgress;
9274 _primaryChildFragment2.sibling = _fallbackChildFragment2;
9275 _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
9276 // fallback children.
9277
9278 workInProgress.memoizedState = SUSPENDED_MARKER;
9279 workInProgress.child = _primaryChildFragment2;
9280 return _fallbackChildFragment2;
9281 } else {
9282 // No longer suspended. Switch back to showing the primary children,
9283 // and remove the intermediate fragment fiber.
9284 var _nextPrimaryChildren = nextProps.children;
9285 var currentPrimaryChild = currentPrimaryChildFragment.child;
9286 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime); // If this render doesn't suspend, we need to delete the fallback
9287 // children. Wait until the complete phase, after we've confirmed the
9288 // fallback is no longer needed.
9289 // TODO: Would it be better to store the fallback fragment on
9290 // the stateNode?
9291 // Continue rendering the children, like we normally do.
9292
9293 workInProgress.memoizedState = null;
9294 return workInProgress.child = primaryChild;
9295 }
9296 } else {
9297 // The current tree has not already timed out. That means the primary
9298 // children are not wrapped in a fragment fiber.
9299 var _currentPrimaryChild = current$$1.child;
9300
9301 if (nextDidTimeout) {
9302 // Timed out. Wrap the children in a fragment fiber to keep them
9303 // separate from the fallback children.
9304 var _nextFallbackChildren3 = nextProps.fallback;
9305
9306 var _primaryChildFragment3 = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
9307 // going to render this fragment.
9308 null, mode, NoWork, null);
9309
9310 _primaryChildFragment3.return = workInProgress;
9311 _primaryChildFragment3.child = _currentPrimaryChild;
9312
9313 if (_currentPrimaryChild !== null) {
9314 _currentPrimaryChild.return = _primaryChildFragment3;
9315 } // Even though we're creating a new fiber, there are no new children,
9316 // because we're reusing an already mounted tree. So we don't need to
9317 // schedule a placement.
9318 // primaryChildFragment.effectTag |= Placement;
9319
9320
9321 if ((workInProgress.mode & BatchedMode) === NoMode) {
9322 // Outside of batched mode, we commit the effects from the
9323 // partially completed, timed-out tree, too.
9324 var _progressedState2 = workInProgress.memoizedState;
9325
9326 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
9327
9328 _primaryChildFragment3.child = _progressedPrimaryChild2;
9329 var _progressedChild3 = _progressedPrimaryChild2;
9330
9331 while (_progressedChild3 !== null) {
9332 _progressedChild3.return = _primaryChildFragment3;
9333 _progressedChild3 = _progressedChild3.sibling;
9334 }
9335 } // Because primaryChildFragment is a new fiber that we're inserting as the
9336 // parent of a new tree, we need to set its treeBaseDuration.
9337
9338
9339 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9340 // treeBaseDuration is the sum of all the child tree base durations.
9341 var _treeBaseDuration2 = 0;
9342 var _hiddenChild2 = _primaryChildFragment3.child;
9343
9344 while (_hiddenChild2 !== null) {
9345 _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
9346 _hiddenChild2 = _hiddenChild2.sibling;
9347 }
9348
9349 _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
9350 } // Create a fragment from the fallback children, too.
9351
9352
9353 var _fallbackChildFragment3 = createFiberFromFragment(_nextFallbackChildren3, mode, renderExpirationTime, null);
9354
9355 _fallbackChildFragment3.return = workInProgress;
9356 _primaryChildFragment3.sibling = _fallbackChildFragment3;
9357 _fallbackChildFragment3.effectTag |= Placement;
9358 _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
9359 // fallback children.
9360
9361 workInProgress.memoizedState = SUSPENDED_MARKER;
9362 workInProgress.child = _primaryChildFragment3;
9363 return _fallbackChildFragment3;
9364 } else {
9365 // Still haven't timed out. Continue rendering the children, like we
9366 // normally do.
9367 workInProgress.memoizedState = null;
9368 var _nextPrimaryChildren2 = nextProps.children;
9369 return workInProgress.child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
9370 }
9371 }
9372 }
9373}
9374
9375function retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime) {
9376 // We're now not suspended nor dehydrated.
9377 workInProgress.memoizedState = null; // Retry with the full children.
9378
9379 var nextProps = workInProgress.pendingProps;
9380 var nextChildren = nextProps.children; // This will ensure that the children get Placement effects and
9381 // that the old child gets a Deletion effect.
9382 // We could also call forceUnmountCurrentAndReconcile.
9383
9384 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9385 return workInProgress.child;
9386}
9387
9388function mountDehydratedSuspenseComponent(workInProgress, suspenseInstance, renderExpirationTime) {
9389 // During the first pass, we'll bail out and not drill into the children.
9390 // Instead, we'll leave the content in place and try to hydrate it later.
9391 if ((workInProgress.mode & BatchedMode) === NoMode) {
9392 {
9393 warning$1(false, 'Cannot hydrate Suspense in legacy mode. Switch from ' + 'ReactDOM.hydrate(element, container) to ' + 'ReactDOM.createSyncRoot(container, { hydrate: true })' + '.render(element) or remove the Suspense components from ' + 'the server rendered components.');
9394 }
9395
9396 workInProgress.expirationTime = Sync;
9397 } else if (isSuspenseInstanceFallback(suspenseInstance)) {
9398 // This is a client-only boundary. Since we won't get any content from the server
9399 // for this, we need to schedule that at a higher priority based on when it would
9400 // have timed out. In theory we could render it in this pass but it would have the
9401 // wrong priority associated with it and will prevent hydration of parent path.
9402 // Instead, we'll leave work left on it to render it in a separate commit.
9403 // TODO This time should be the time at which the server rendered response that is
9404 // a parent to this boundary was displayed. However, since we currently don't have
9405 // a protocol to transfer that time, we'll just estimate it by using the current
9406 // time. This will mean that Suspense timeouts are slightly shifted to later than
9407 // they should be.
9408 var serverDisplayTime = requestCurrentTimeForUpdate(); // Schedule a normal pri update to render this content.
9409
9410 var newExpirationTime = computeAsyncExpiration(serverDisplayTime);
9411
9412 if (enableSchedulerTracing) {
9413 markSpawnedWork(newExpirationTime);
9414 }
9415
9416 workInProgress.expirationTime = newExpirationTime;
9417 } else {
9418 // We'll continue hydrating the rest at offscreen priority since we'll already
9419 // be showing the right content coming from the server, it is no rush.
9420 workInProgress.expirationTime = Never;
9421
9422 if (enableSchedulerTracing) {
9423 markSpawnedWork(Never);
9424 }
9425 }
9426
9427 return null;
9428}
9429
9430function updateDehydratedSuspenseComponent(current$$1, workInProgress, suspenseInstance, suspenseState, renderExpirationTime) {
9431 // We should never be hydrating at this point because it is the first pass,
9432 // but after we've already committed once.
9433 warnIfHydrating();
9434
9435 if ((workInProgress.mode & BatchedMode) === NoMode) {
9436 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9437 }
9438
9439 if (isSuspenseInstanceFallback(suspenseInstance)) {
9440 // This boundary is in a permanent fallback state. In this case, we'll never
9441 // get an update and we'll never be able to hydrate the final content. Let's just try the
9442 // client side render instead.
9443 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9444 } // We use childExpirationTime to indicate that a child might depend on context, so if
9445 // any context has changed, we need to treat is as if the input might have changed.
9446
9447
9448 var hasContextChanged$$1 = current$$1.childExpirationTime >= renderExpirationTime;
9449
9450 if (didReceiveUpdate || hasContextChanged$$1) {
9451 // This boundary has changed since the first render. This means that we are now unable to
9452 // hydrate it. We might still be able to hydrate it using an earlier expiration time, if
9453 // we are rendering at lower expiration than sync.
9454 if (renderExpirationTime < Sync) {
9455 if (suspenseState.retryTime <= renderExpirationTime) {
9456 // This render is even higher pri than we've seen before, let's try again
9457 // at even higher pri.
9458 var attemptHydrationAtExpirationTime = renderExpirationTime + 1;
9459 suspenseState.retryTime = attemptHydrationAtExpirationTime;
9460 scheduleWork(current$$1, attemptHydrationAtExpirationTime); // TODO: Early abort this render.
9461 } else {// We have already tried to ping at a higher priority than we're rendering with
9462 // so if we got here, we must have failed to hydrate at those levels. We must
9463 // now give up. Instead, we're going to delete the whole subtree and instead inject
9464 // a new real Suspense boundary to take its place, which may render content
9465 // or fallback. This might suspend for a while and if it does we might still have
9466 // an opportunity to hydrate before this pass commits.
9467 }
9468 } // If we have scheduled higher pri work above, this will probably just abort the render
9469 // since we now have higher priority work, but in case it doesn't, we need to prepare to
9470 // render something, if we time out. Even if that requires us to delete everything and
9471 // skip hydration.
9472 // Delay having to do this as long as the suspense timeout allows us.
9473
9474
9475 renderDidSuspendDelayIfPossible();
9476 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9477 } else if (isSuspenseInstancePending(suspenseInstance)) {
9478 // This component is still pending more data from the server, so we can't hydrate its
9479 // content. We treat it as if this component suspended itself. It might seem as if
9480 // we could just try to render it client-side instead. However, this will perform a
9481 // lot of unnecessary work and is unlikely to complete since it often will suspend
9482 // on missing data anyway. Additionally, the server might be able to render more
9483 // than we can on the client yet. In that case we'd end up with more fallback states
9484 // on the client than if we just leave it alone. If the server times out or errors
9485 // these should update this boundary to the permanent Fallback state instead.
9486 // Mark it as having captured (i.e. suspended).
9487 workInProgress.effectTag |= DidCapture; // Leave the child in place. I.e. the dehydrated fragment.
9488
9489 workInProgress.child = current$$1.child; // Register a callback to retry this boundary once the server has sent the result.
9490
9491 registerSuspenseInstanceRetry(suspenseInstance, retryDehydratedSuspenseBoundary.bind(null, current$$1));
9492 return null;
9493 } else {
9494 // This is the first attempt.
9495 reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress, suspenseInstance);
9496 var nextProps = workInProgress.pendingProps;
9497 var nextChildren = nextProps.children;
9498 var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
9499 var node = child;
9500
9501 while (node) {
9502 // Mark each child as hydrating. This is a fast path to know whether this
9503 // tree is part of a hydrating tree. This is used to determine if a child
9504 // node has fully mounted yet, and for scheduling event replaying.
9505 // Conceptually this is similar to Placement in that a new subtree is
9506 // inserted into the React tree here. It just happens to not need DOM
9507 // mutations because it already exists.
9508 node.effectTag |= Hydrating;
9509 node = node.sibling;
9510 }
9511
9512 workInProgress.child = child;
9513 return workInProgress.child;
9514 }
9515}
9516
9517function scheduleWorkOnFiber(fiber, renderExpirationTime) {
9518 if (fiber.expirationTime < renderExpirationTime) {
9519 fiber.expirationTime = renderExpirationTime;
9520 }
9521
9522 var alternate = fiber.alternate;
9523
9524 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
9525 alternate.expirationTime = renderExpirationTime;
9526 }
9527
9528 scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
9529}
9530
9531function propagateSuspenseContextChange(workInProgress, firstChild, renderExpirationTime) {
9532 // Mark any Suspense boundaries with fallbacks as having work to do.
9533 // If they were previously forced into fallbacks, they may now be able
9534 // to unblock.
9535 var node = firstChild;
9536
9537 while (node !== null) {
9538 if (node.tag === SuspenseComponent) {
9539 var state = node.memoizedState;
9540
9541 if (state !== null) {
9542 scheduleWorkOnFiber(node, renderExpirationTime);
9543 }
9544 } else if (node.tag === SuspenseListComponent) {
9545 // If the tail is hidden there might not be an Suspense boundaries
9546 // to schedule work on. In this case we have to schedule it on the
9547 // list itself.
9548 // We don't have to traverse to the children of the list since
9549 // the list will propagate the change when it rerenders.
9550 scheduleWorkOnFiber(node, renderExpirationTime);
9551 } else if (node.child !== null) {
9552 node.child.return = node;
9553 node = node.child;
9554 continue;
9555 }
9556
9557 if (node === workInProgress) {
9558 return;
9559 }
9560
9561 while (node.sibling === null) {
9562 if (node.return === null || node.return === workInProgress) {
9563 return;
9564 }
9565
9566 node = node.return;
9567 }
9568
9569 node.sibling.return = node.return;
9570 node = node.sibling;
9571 }
9572}
9573
9574function findLastContentRow(firstChild) {
9575 // This is going to find the last row among these children that is already
9576 // showing content on the screen, as opposed to being in fallback state or
9577 // new. If a row has multiple Suspense boundaries, any of them being in the
9578 // fallback state, counts as the whole row being in a fallback state.
9579 // Note that the "rows" will be workInProgress, but any nested children
9580 // will still be current since we haven't rendered them yet. The mounted
9581 // order may not be the same as the new order. We use the new order.
9582 var row = firstChild;
9583 var lastContentRow = null;
9584
9585 while (row !== null) {
9586 var currentRow = row.alternate; // New rows can't be content rows.
9587
9588 if (currentRow !== null && findFirstSuspended(currentRow) === null) {
9589 lastContentRow = row;
9590 }
9591
9592 row = row.sibling;
9593 }
9594
9595 return lastContentRow;
9596}
9597
9598function validateRevealOrder(revealOrder) {
9599 {
9600 if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
9601 didWarnAboutRevealOrder[revealOrder] = true;
9602
9603 if (typeof revealOrder === 'string') {
9604 switch (revealOrder.toLowerCase()) {
9605 case 'together':
9606 case 'forwards':
9607 case 'backwards':
9608 {
9609 warning$1(false, '"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
9610 break;
9611 }
9612
9613 case 'forward':
9614 case 'backward':
9615 {
9616 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());
9617 break;
9618 }
9619
9620 default:
9621 warning$1(false, '"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
9622 break;
9623 }
9624 } else {
9625 warning$1(false, '%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
9626 }
9627 }
9628 }
9629}
9630
9631function validateTailOptions(tailMode, revealOrder) {
9632 {
9633 if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
9634 if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
9635 didWarnAboutTailOptions[tailMode] = true;
9636 warning$1(false, '"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
9637 } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
9638 didWarnAboutTailOptions[tailMode] = true;
9639 warning$1(false, '<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
9640 }
9641 }
9642 }
9643}
9644
9645function validateSuspenseListNestedChild(childSlot, index) {
9646 {
9647 var isArray = Array.isArray(childSlot);
9648 var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
9649
9650 if (isArray || isIterable) {
9651 var type = isArray ? 'array' : 'iterable';
9652 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);
9653 return false;
9654 }
9655 }
9656
9657 return true;
9658}
9659
9660function validateSuspenseListChildren(children, revealOrder) {
9661 {
9662 if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
9663 if (Array.isArray(children)) {
9664 for (var i = 0; i < children.length; i++) {
9665 if (!validateSuspenseListNestedChild(children[i], i)) {
9666 return;
9667 }
9668 }
9669 } else {
9670 var iteratorFn = getIteratorFn(children);
9671
9672 if (typeof iteratorFn === 'function') {
9673 var childrenIterator = iteratorFn.call(children);
9674
9675 if (childrenIterator) {
9676 var step = childrenIterator.next();
9677 var _i = 0;
9678
9679 for (; !step.done; step = childrenIterator.next()) {
9680 if (!validateSuspenseListNestedChild(step.value, _i)) {
9681 return;
9682 }
9683
9684 _i++;
9685 }
9686 }
9687 } else {
9688 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);
9689 }
9690 }
9691 }
9692 }
9693}
9694
9695function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode, lastEffectBeforeRendering) {
9696 var renderState = workInProgress.memoizedState;
9697
9698 if (renderState === null) {
9699 workInProgress.memoizedState = {
9700 isBackwards: isBackwards,
9701 rendering: null,
9702 last: lastContentRow,
9703 tail: tail,
9704 tailExpiration: 0,
9705 tailMode: tailMode,
9706 lastEffect: lastEffectBeforeRendering
9707 };
9708 } else {
9709 // We can reuse the existing object from previous renders.
9710 renderState.isBackwards = isBackwards;
9711 renderState.rendering = null;
9712 renderState.last = lastContentRow;
9713 renderState.tail = tail;
9714 renderState.tailExpiration = 0;
9715 renderState.tailMode = tailMode;
9716 renderState.lastEffect = lastEffectBeforeRendering;
9717 }
9718} // This can end up rendering this component multiple passes.
9719// The first pass splits the children fibers into two sets. A head and tail.
9720// We first render the head. If anything is in fallback state, we do another
9721// pass through beginWork to rerender all children (including the tail) with
9722// the force suspend context. If the first render didn't have anything in
9723// in fallback state. Then we render each row in the tail one-by-one.
9724// That happens in the completeWork phase without going back to beginWork.
9725
9726
9727function updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime) {
9728 var nextProps = workInProgress.pendingProps;
9729 var revealOrder = nextProps.revealOrder;
9730 var tailMode = nextProps.tail;
9731 var newChildren = nextProps.children;
9732 validateRevealOrder(revealOrder);
9733 validateTailOptions(tailMode, revealOrder);
9734 validateSuspenseListChildren(newChildren, revealOrder);
9735 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9736 var suspenseContext = suspenseStackCursor.current;
9737 var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
9738
9739 if (shouldForceFallback) {
9740 suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
9741 workInProgress.effectTag |= DidCapture;
9742 } else {
9743 var didSuspendBefore = current$$1 !== null && (current$$1.effectTag & DidCapture) !== NoEffect;
9744
9745 if (didSuspendBefore) {
9746 // If we previously forced a fallback, we need to schedule work
9747 // on any nested boundaries to let them know to try to render
9748 // again. This is the same as context updating.
9749 propagateSuspenseContextChange(workInProgress, workInProgress.child, renderExpirationTime);
9750 }
9751
9752 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
9753 }
9754
9755 pushSuspenseContext(workInProgress, suspenseContext);
9756
9757 if ((workInProgress.mode & BatchedMode) === NoMode) {
9758 // Outside of batched mode, SuspenseList doesn't work so we just
9759 // use make it a noop by treating it as the default revealOrder.
9760 workInProgress.memoizedState = null;
9761 } else {
9762 switch (revealOrder) {
9763 case 'forwards':
9764 {
9765 var lastContentRow = findLastContentRow(workInProgress.child);
9766 var tail;
9767
9768 if (lastContentRow === null) {
9769 // The whole list is part of the tail.
9770 // TODO: We could fast path by just rendering the tail now.
9771 tail = workInProgress.child;
9772 workInProgress.child = null;
9773 } else {
9774 // Disconnect the tail rows after the content row.
9775 // We're going to render them separately later.
9776 tail = lastContentRow.sibling;
9777 lastContentRow.sibling = null;
9778 }
9779
9780 initSuspenseListRenderState(workInProgress, false, // isBackwards
9781 tail, lastContentRow, tailMode, workInProgress.lastEffect);
9782 break;
9783 }
9784
9785 case 'backwards':
9786 {
9787 // We're going to find the first row that has existing content.
9788 // At the same time we're going to reverse the list of everything
9789 // we pass in the meantime. That's going to be our tail in reverse
9790 // order.
9791 var _tail = null;
9792 var row = workInProgress.child;
9793 workInProgress.child = null;
9794
9795 while (row !== null) {
9796 var currentRow = row.alternate; // New rows can't be content rows.
9797
9798 if (currentRow !== null && findFirstSuspended(currentRow) === null) {
9799 // This is the beginning of the main content.
9800 workInProgress.child = row;
9801 break;
9802 }
9803
9804 var nextRow = row.sibling;
9805 row.sibling = _tail;
9806 _tail = row;
9807 row = nextRow;
9808 } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
9809
9810
9811 initSuspenseListRenderState(workInProgress, true, // isBackwards
9812 _tail, null, // last
9813 tailMode, workInProgress.lastEffect);
9814 break;
9815 }
9816
9817 case 'together':
9818 {
9819 initSuspenseListRenderState(workInProgress, false, // isBackwards
9820 null, // tail
9821 null, // last
9822 undefined, workInProgress.lastEffect);
9823 break;
9824 }
9825
9826 default:
9827 {
9828 // The default reveal order is the same as not having
9829 // a boundary.
9830 workInProgress.memoizedState = null;
9831 }
9832 }
9833 }
9834
9835 return workInProgress.child;
9836}
9837
9838function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
9839 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
9840 var nextChildren = workInProgress.pendingProps;
9841
9842 if (current$$1 === null) {
9843 // Portals are special because we don't append the children during mount
9844 // but at commit. Therefore we need to track insertions which the normal
9845 // flow doesn't do during mount. This doesn't happen at the root because
9846 // the root always starts with a "current" with a null child.
9847 // TODO: Consider unifying this with how the root works.
9848 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
9849 } else {
9850 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9851 }
9852
9853 return workInProgress.child;
9854}
9855
9856function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
9857 var providerType = workInProgress.type;
9858 var context = providerType._context;
9859 var newProps = workInProgress.pendingProps;
9860 var oldProps = workInProgress.memoizedProps;
9861 var newValue = newProps.value;
9862
9863 {
9864 var providerPropTypes = workInProgress.type.propTypes;
9865
9866 if (providerPropTypes) {
9867 checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
9868 }
9869 }
9870
9871 pushProvider(workInProgress, newValue);
9872
9873 if (oldProps !== null) {
9874 var oldValue = oldProps.value;
9875 var changedBits = calculateChangedBits(context, newValue, oldValue);
9876
9877 if (changedBits === 0) {
9878 // No change. Bailout early if children are the same.
9879 if (oldProps.children === newProps.children && !hasContextChanged()) {
9880 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
9881 }
9882 } else {
9883 // The context value changed. Search for matching consumers and schedule
9884 // them to update.
9885 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
9886 }
9887 }
9888
9889 var newChildren = newProps.children;
9890 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9891 return workInProgress.child;
9892}
9893
9894var hasWarnedAboutUsingContextAsConsumer = false;
9895
9896function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
9897 var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
9898 // DEV mode, we create a separate object for Context.Consumer that acts
9899 // like a proxy to Context. This proxy object adds unnecessary code in PROD
9900 // so we use the old behaviour (Context.Consumer references Context) to
9901 // reduce size and overhead. The separate object references context via
9902 // a property called "_context", which also gives us the ability to check
9903 // in DEV mode if this property exists or not and warn if it does not.
9904
9905 {
9906 if (context._context === undefined) {
9907 // This may be because it's a Context (rather than a Consumer).
9908 // Or it may be because it's older React where they're the same thing.
9909 // We only want to warn if we're sure it's a new React.
9910 if (context !== context.Consumer) {
9911 if (!hasWarnedAboutUsingContextAsConsumer) {
9912 hasWarnedAboutUsingContextAsConsumer = true;
9913 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?');
9914 }
9915 }
9916 } else {
9917 context = context._context;
9918 }
9919 }
9920
9921 var newProps = workInProgress.pendingProps;
9922 var render = newProps.children;
9923
9924 {
9925 !(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;
9926 }
9927
9928 prepareToReadContext(workInProgress, renderExpirationTime);
9929 var newValue = readContext(context, newProps.unstable_observedBits);
9930 var newChildren;
9931
9932 {
9933 ReactCurrentOwner$2.current = workInProgress;
9934 setCurrentPhase('render');
9935 newChildren = render(newValue);
9936 setCurrentPhase(null);
9937 } // React DevTools reads this flag.
9938
9939
9940 workInProgress.effectTag |= PerformedWork;
9941 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9942 return workInProgress.child;
9943}
9944
9945function updateFundamentalComponent$1(current$$1, workInProgress, renderExpirationTime) {
9946 var fundamentalImpl = workInProgress.type.impl;
9947
9948 if (fundamentalImpl.reconcileChildren === false) {
9949 return null;
9950 }
9951
9952 var nextProps = workInProgress.pendingProps;
9953 var nextChildren = nextProps.children;
9954 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9955 return workInProgress.child;
9956}
9957
9958function updateScopeComponent(current$$1, workInProgress, renderExpirationTime) {
9959 var nextProps = workInProgress.pendingProps;
9960 var nextChildren = nextProps.children;
9961 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9962 return workInProgress.child;
9963}
9964
9965function markWorkInProgressReceivedUpdate() {
9966 didReceiveUpdate = true;
9967}
9968
9969function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
9970 cancelWorkTimer(workInProgress);
9971
9972 if (current$$1 !== null) {
9973 // Reuse previous dependencies
9974 workInProgress.dependencies = current$$1.dependencies;
9975 }
9976
9977 if (enableProfilerTimer) {
9978 // Don't update "base" render times for bailouts.
9979 stopProfilerTimerIfRunning(workInProgress);
9980 }
9981
9982 var updateExpirationTime = workInProgress.expirationTime;
9983
9984 if (updateExpirationTime !== NoWork) {
9985 markUnprocessedUpdateTime(updateExpirationTime);
9986 } // Check if the children have any pending work.
9987
9988
9989 var childExpirationTime = workInProgress.childExpirationTime;
9990
9991 if (childExpirationTime < renderExpirationTime) {
9992 // The children don't have any work either. We can skip them.
9993 // TODO: Once we add back resuming, we should check if the children are
9994 // a work-in-progress set. If so, we need to transfer their effects.
9995 return null;
9996 } else {
9997 // This fiber doesn't have work, but its subtree does. Clone the child
9998 // fibers and continue.
9999 cloneChildFibers(current$$1, workInProgress);
10000 return workInProgress.child;
10001 }
10002}
10003
10004function remountFiber(current$$1, oldWorkInProgress, newWorkInProgress) {
10005 {
10006 var returnFiber = oldWorkInProgress.return;
10007
10008 if (returnFiber === null) {
10009 throw new Error('Cannot swap the root fiber.');
10010 } // Disconnect from the old current.
10011 // It will get deleted.
10012
10013
10014 current$$1.alternate = null;
10015 oldWorkInProgress.alternate = null; // Connect to the new tree.
10016
10017 newWorkInProgress.index = oldWorkInProgress.index;
10018 newWorkInProgress.sibling = oldWorkInProgress.sibling;
10019 newWorkInProgress.return = oldWorkInProgress.return;
10020 newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
10021
10022 if (oldWorkInProgress === returnFiber.child) {
10023 returnFiber.child = newWorkInProgress;
10024 } else {
10025 var prevSibling = returnFiber.child;
10026
10027 if (prevSibling === null) {
10028 throw new Error('Expected parent to have a child.');
10029 }
10030
10031 while (prevSibling.sibling !== oldWorkInProgress) {
10032 prevSibling = prevSibling.sibling;
10033
10034 if (prevSibling === null) {
10035 throw new Error('Expected to find the previous sibling.');
10036 }
10037 }
10038
10039 prevSibling.sibling = newWorkInProgress;
10040 } // Delete the old fiber and place the new one.
10041 // Since the old fiber is disconnected, we have to schedule it manually.
10042
10043
10044 var last = returnFiber.lastEffect;
10045
10046 if (last !== null) {
10047 last.nextEffect = current$$1;
10048 returnFiber.lastEffect = current$$1;
10049 } else {
10050 returnFiber.firstEffect = returnFiber.lastEffect = current$$1;
10051 }
10052
10053 current$$1.nextEffect = null;
10054 current$$1.effectTag = Deletion;
10055 newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
10056
10057 return newWorkInProgress;
10058 }
10059}
10060
10061function beginWork$1(current$$1, workInProgress, renderExpirationTime) {
10062 var updateExpirationTime = workInProgress.expirationTime;
10063
10064 {
10065 if (workInProgress._debugNeedsRemount && current$$1 !== null) {
10066 // This will restart the begin phase with a new fiber.
10067 return remountFiber(current$$1, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.expirationTime));
10068 }
10069 }
10070
10071 if (current$$1 !== null) {
10072 var oldProps = current$$1.memoizedProps;
10073 var newProps = workInProgress.pendingProps;
10074
10075 if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
10076 workInProgress.type !== current$$1.type)) {
10077 // If props or context changed, mark the fiber as having performed work.
10078 // This may be unset if the props are determined to be equal later (memo).
10079 didReceiveUpdate = true;
10080 } else if (updateExpirationTime < renderExpirationTime) {
10081 didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
10082 // the begin phase. There's still some bookkeeping we that needs to be done
10083 // in this optimized path, mostly pushing stuff onto the stack.
10084
10085 switch (workInProgress.tag) {
10086 case HostRoot:
10087 pushHostRootContext(workInProgress);
10088 resetHydrationState();
10089 break;
10090
10091 case HostComponent:
10092 pushHostContext(workInProgress);
10093
10094 if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(workInProgress.type, newProps)) {
10095 if (enableSchedulerTracing) {
10096 markSpawnedWork(Never);
10097 } // Schedule this fiber to re-render at offscreen priority. Then bailout.
10098
10099
10100 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
10101 return null;
10102 }
10103
10104 break;
10105
10106 case ClassComponent:
10107 {
10108 var Component = workInProgress.type;
10109
10110 if (isContextProvider(Component)) {
10111 pushContextProvider(workInProgress);
10112 }
10113
10114 break;
10115 }
10116
10117 case HostPortal:
10118 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
10119 break;
10120
10121 case ContextProvider:
10122 {
10123 var newValue = workInProgress.memoizedProps.value;
10124 pushProvider(workInProgress, newValue);
10125 break;
10126 }
10127
10128 case Profiler:
10129 if (enableProfilerTimer) {
10130 workInProgress.effectTag |= Update;
10131 }
10132
10133 break;
10134
10135 case SuspenseComponent:
10136 {
10137 var state = workInProgress.memoizedState;
10138
10139 if (state !== null) {
10140 if (enableSuspenseServerRenderer) {
10141 if (state.dehydrated !== null) {
10142 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // We know that this component will suspend again because if it has
10143 // been unsuspended it has committed as a resolved Suspense component.
10144 // If it needs to be retried, it should have work scheduled on it.
10145
10146 workInProgress.effectTag |= DidCapture;
10147 break;
10148 }
10149 } // If this boundary is currently timed out, we need to decide
10150 // whether to retry the primary children, or to skip over it and
10151 // go straight to the fallback. Check the priority of the primary
10152 // child fragment.
10153
10154
10155 var primaryChildFragment = workInProgress.child;
10156 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
10157
10158 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
10159 // The primary children have pending work. Use the normal path
10160 // to attempt to render the primary children again.
10161 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
10162 } else {
10163 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
10164 // priority. Bailout.
10165
10166 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
10167
10168 if (child !== null) {
10169 // The fallback children have pending work. Skip over the
10170 // primary children and work on the fallback.
10171 return child.sibling;
10172 } else {
10173 return null;
10174 }
10175 }
10176 } else {
10177 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
10178 }
10179
10180 break;
10181 }
10182
10183 case SuspenseListComponent:
10184 {
10185 var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect;
10186 var hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
10187
10188 if (didSuspendBefore) {
10189 if (hasChildWork) {
10190 // If something was in fallback state last time, and we have all the
10191 // same children then we're still in progressive loading state.
10192 // Something might get unblocked by state updates or retries in the
10193 // tree which will affect the tail. So we need to use the normal
10194 // path to compute the correct tail.
10195 return updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime);
10196 } // If none of the children had any work, that means that none of
10197 // them got retried so they'll still be blocked in the same way
10198 // as before. We can fast bail out.
10199
10200
10201 workInProgress.effectTag |= DidCapture;
10202 } // If nothing suspended before and we're rendering the same children,
10203 // then the tail doesn't matter. Anything new that suspends will work
10204 // in the "together" mode, so we can continue from the state we had.
10205
10206
10207 var renderState = workInProgress.memoizedState;
10208
10209 if (renderState !== null) {
10210 // Reset to the "together" mode in case we've started a different
10211 // update in the past but didn't complete it.
10212 renderState.rendering = null;
10213 renderState.tail = null;
10214 }
10215
10216 pushSuspenseContext(workInProgress, suspenseStackCursor.current);
10217
10218 if (hasChildWork) {
10219 break;
10220 } else {
10221 // If none of the children had any work, that means that none of
10222 // them got retried so they'll still be blocked in the same way
10223 // as before. We can fast bail out.
10224 return null;
10225 }
10226 }
10227 }
10228
10229 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
10230 } else {
10231 // An update was scheduled on this fiber, but there are no new props
10232 // nor legacy context. Set this to false. If an update queue or context
10233 // consumer produces a changed value, it will set this to true. Otherwise,
10234 // the component will assume the children have not changed and bail out.
10235 didReceiveUpdate = false;
10236 }
10237 } else {
10238 didReceiveUpdate = false;
10239 } // Before entering the begin phase, clear the expiration time.
10240
10241
10242 workInProgress.expirationTime = NoWork;
10243
10244 switch (workInProgress.tag) {
10245 case IndeterminateComponent:
10246 {
10247 return mountIndeterminateComponent(current$$1, workInProgress, workInProgress.type, renderExpirationTime);
10248 }
10249
10250 case LazyComponent:
10251 {
10252 var elementType = workInProgress.elementType;
10253 return mountLazyComponent(current$$1, workInProgress, elementType, updateExpirationTime, renderExpirationTime);
10254 }
10255
10256 case FunctionComponent:
10257 {
10258 var _Component = workInProgress.type;
10259 var unresolvedProps = workInProgress.pendingProps;
10260 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
10261 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
10262 }
10263
10264 case ClassComponent:
10265 {
10266 var _Component2 = workInProgress.type;
10267 var _unresolvedProps = workInProgress.pendingProps;
10268
10269 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
10270
10271 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
10272 }
10273
10274 case HostRoot:
10275 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
10276
10277 case HostComponent:
10278 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
10279
10280 case HostText:
10281 return updateHostText(current$$1, workInProgress);
10282
10283 case SuspenseComponent:
10284 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
10285
10286 case HostPortal:
10287 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
10288
10289 case ForwardRef:
10290 {
10291 var type = workInProgress.type;
10292 var _unresolvedProps2 = workInProgress.pendingProps;
10293
10294 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
10295
10296 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
10297 }
10298
10299 case Fragment:
10300 return updateFragment(current$$1, workInProgress, renderExpirationTime);
10301
10302 case Mode$1:
10303 return updateMode(current$$1, workInProgress, renderExpirationTime);
10304
10305 case Profiler:
10306 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
10307
10308 case ContextProvider:
10309 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
10310
10311 case ContextConsumer:
10312 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
10313
10314 case MemoComponent:
10315 {
10316 var _type2 = workInProgress.type;
10317 var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
10318
10319 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
10320
10321 {
10322 if (workInProgress.type !== workInProgress.elementType) {
10323 var outerPropTypes = _type2.propTypes;
10324
10325 if (outerPropTypes) {
10326 checkPropTypes(outerPropTypes, _resolvedProps3, // Resolved for outer only
10327 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
10328 }
10329 }
10330 }
10331
10332 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
10333 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
10334 }
10335
10336 case SimpleMemoComponent:
10337 {
10338 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
10339 }
10340
10341 case IncompleteClassComponent:
10342 {
10343 var _Component3 = workInProgress.type;
10344 var _unresolvedProps4 = workInProgress.pendingProps;
10345
10346 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
10347
10348 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
10349 }
10350
10351 case SuspenseListComponent:
10352 {
10353 return updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime);
10354 }
10355
10356 case FundamentalComponent:
10357 {
10358 if (enableFundamentalAPI) {
10359 return updateFundamentalComponent$1(current$$1, workInProgress, renderExpirationTime);
10360 }
10361
10362 break;
10363 }
10364
10365 case ScopeComponent:
10366 {
10367 if (enableScopeAPI) {
10368 return updateScopeComponent(current$$1, workInProgress, renderExpirationTime);
10369 }
10370
10371 break;
10372 }
10373 }
10374
10375 {
10376 {
10377 throw Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue.");
10378 }
10379 }
10380}
10381
10382function createFundamentalStateInstance(currentFiber, props, impl, state) {
10383 return {
10384 currentFiber: currentFiber,
10385 impl: impl,
10386 instance: null,
10387 prevProps: null,
10388 props: props,
10389 state: state
10390 };
10391}
10392
10393function isFiberSuspenseAndTimedOut(fiber) {
10394 return fiber.tag === SuspenseComponent && fiber.memoizedState !== null;
10395}
10396
10397function getSuspenseFallbackChild(fiber) {
10398 return fiber.child.sibling.child;
10399}
10400
10401function collectScopedNodes(node, fn, scopedNodes) {
10402 if (enableScopeAPI) {
10403 if (node.tag === HostComponent) {
10404 var _type = node.type,
10405 memoizedProps = node.memoizedProps;
10406
10407 if (fn(_type, memoizedProps) === true) {
10408 scopedNodes.push(getPublicInstance(node.stateNode));
10409 }
10410 }
10411
10412 var child = node.child;
10413
10414 if (isFiberSuspenseAndTimedOut(node)) {
10415 child = getSuspenseFallbackChild(node);
10416 }
10417
10418 if (child !== null) {
10419 collectScopedNodesFromChildren(child, fn, scopedNodes);
10420 }
10421 }
10422}
10423
10424function collectFirstScopedNode(node, fn) {
10425 if (enableScopeAPI) {
10426 if (node.tag === HostComponent) {
10427 var _type2 = node.type,
10428 memoizedProps = node.memoizedProps;
10429
10430 if (fn(_type2, memoizedProps) === true) {
10431 return getPublicInstance(node.stateNode);
10432 }
10433 }
10434
10435 var child = node.child;
10436
10437 if (isFiberSuspenseAndTimedOut(node)) {
10438 child = getSuspenseFallbackChild(node);
10439 }
10440
10441 if (child !== null) {
10442 return collectFirstScopedNodeFromChildren(child, fn);
10443 }
10444 }
10445
10446 return null;
10447}
10448
10449function collectScopedNodesFromChildren(startingChild, fn, scopedNodes) {
10450 var child = startingChild;
10451
10452 while (child !== null) {
10453 collectScopedNodes(child, fn, scopedNodes);
10454 child = child.sibling;
10455 }
10456}
10457
10458function collectFirstScopedNodeFromChildren(startingChild, fn) {
10459 var child = startingChild;
10460
10461 while (child !== null) {
10462 var scopedNode = collectFirstScopedNode(child, fn);
10463
10464 if (scopedNode !== null) {
10465 return scopedNode;
10466 }
10467
10468 child = child.sibling;
10469 }
10470
10471 return null;
10472}
10473
10474function collectNearestScopeMethods(node, scope, childrenScopes) {
10475 if (isValidScopeNode(node, scope)) {
10476 childrenScopes.push(node.stateNode.methods);
10477 } else {
10478 var child = node.child;
10479
10480 if (isFiberSuspenseAndTimedOut(node)) {
10481 child = getSuspenseFallbackChild(node);
10482 }
10483
10484 if (child !== null) {
10485 collectNearestChildScopeMethods(child, scope, childrenScopes);
10486 }
10487 }
10488}
10489
10490function collectNearestChildScopeMethods(startingChild, scope, childrenScopes) {
10491 var child = startingChild;
10492
10493 while (child !== null) {
10494 collectNearestScopeMethods(child, scope, childrenScopes);
10495 child = child.sibling;
10496 }
10497}
10498
10499function isValidScopeNode(node, scope) {
10500 return node.tag === ScopeComponent && node.type === scope && node.stateNode !== null;
10501}
10502
10503function createScopeMethods(scope, instance) {
10504 return {
10505 getChildren: function () {
10506 var currentFiber = instance.fiber;
10507 var child = currentFiber.child;
10508 var childrenScopes = [];
10509
10510 if (child !== null) {
10511 collectNearestChildScopeMethods(child, scope, childrenScopes);
10512 }
10513
10514 return childrenScopes.length === 0 ? null : childrenScopes;
10515 },
10516 getChildrenFromRoot: function () {
10517 var currentFiber = instance.fiber;
10518 var node = currentFiber;
10519
10520 while (node !== null) {
10521 var parent = node.return;
10522
10523 if (parent === null) {
10524 break;
10525 }
10526
10527 node = parent;
10528
10529 if (node.tag === ScopeComponent && node.type === scope) {
10530 break;
10531 }
10532 }
10533
10534 var childrenScopes = [];
10535 collectNearestChildScopeMethods(node.child, scope, childrenScopes);
10536 return childrenScopes.length === 0 ? null : childrenScopes;
10537 },
10538 getParent: function () {
10539 var node = instance.fiber.return;
10540
10541 while (node !== null) {
10542 if (node.tag === ScopeComponent && node.type === scope) {
10543 return node.stateNode.methods;
10544 }
10545
10546 node = node.return;
10547 }
10548
10549 return null;
10550 },
10551 getProps: function () {
10552 var currentFiber = instance.fiber;
10553 return currentFiber.memoizedProps;
10554 },
10555 queryAllNodes: function (fn) {
10556 var currentFiber = instance.fiber;
10557 var child = currentFiber.child;
10558 var scopedNodes = [];
10559
10560 if (child !== null) {
10561 collectScopedNodesFromChildren(child, fn, scopedNodes);
10562 }
10563
10564 return scopedNodes.length === 0 ? null : scopedNodes;
10565 },
10566 queryFirstNode: function (fn) {
10567 var currentFiber = instance.fiber;
10568 var child = currentFiber.child;
10569
10570 if (child !== null) {
10571 return collectFirstScopedNodeFromChildren(child, fn);
10572 }
10573
10574 return null;
10575 },
10576 containsNode: function (node) {
10577 var fiber = getInstanceFromNode(node);
10578
10579 while (fiber !== null) {
10580 if (fiber.tag === ScopeComponent && fiber.type === scope && fiber.stateNode === instance) {
10581 return true;
10582 }
10583
10584 fiber = fiber.return;
10585 }
10586
10587 return false;
10588 }
10589 };
10590}
10591
10592function markUpdate(workInProgress) {
10593 // Tag the fiber with an update effect. This turns a Placement into
10594 // a PlacementAndUpdate.
10595 workInProgress.effectTag |= Update;
10596}
10597
10598function markRef$1(workInProgress) {
10599 workInProgress.effectTag |= Ref;
10600}
10601
10602var appendAllChildren;
10603var updateHostContainer;
10604var updateHostComponent$1;
10605var updateHostText$1;
10606
10607if (supportsMutation) {
10608 // Mutation mode
10609 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
10610 // We only have the top Fiber that was created but we need recurse down its
10611 // children to find all the terminal nodes.
10612 var node = workInProgress.child;
10613
10614 while (node !== null) {
10615 if (node.tag === HostComponent || node.tag === HostText) {
10616 appendInitialChild(parent, node.stateNode);
10617 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10618 appendInitialChild(parent, node.stateNode.instance);
10619 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10620 // down its children. Instead, we'll get insertions from each child in
10621 // the portal directly.
10622 } else if (node.child !== null) {
10623 node.child.return = node;
10624 node = node.child;
10625 continue;
10626 }
10627
10628 if (node === workInProgress) {
10629 return;
10630 }
10631
10632 while (node.sibling === null) {
10633 if (node.return === null || node.return === workInProgress) {
10634 return;
10635 }
10636
10637 node = node.return;
10638 }
10639
10640 node.sibling.return = node.return;
10641 node = node.sibling;
10642 }
10643 };
10644
10645 updateHostContainer = function (workInProgress) {// Noop
10646 };
10647
10648 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
10649 // If we have an alternate, that means this is an update and we need to
10650 // schedule a side-effect to do the updates.
10651 var oldProps = current.memoizedProps;
10652
10653 if (oldProps === newProps) {
10654 // In mutation mode, this is sufficient for a bailout because
10655 // we won't touch this node even if children changed.
10656 return;
10657 } // If we get updated because one of our children updated, we don't
10658 // have newProps so we'll have to reuse them.
10659 // TODO: Split the update API as separate for the props vs. children.
10660 // Even better would be if children weren't special cased at all tho.
10661
10662
10663 var instance = workInProgress.stateNode;
10664 var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
10665 // component is hitting the resume path. Figure out why. Possibly
10666 // related to `hidden`.
10667
10668 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext); // TODO: Type this specific to this type of component.
10669
10670 workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
10671 // is a new ref we mark this as an update. All the work is done in commitWork.
10672
10673 if (updatePayload) {
10674 markUpdate(workInProgress);
10675 }
10676 };
10677
10678 updateHostText$1 = function (current, workInProgress, oldText, newText) {
10679 // If the text differs, mark it as an update. All the work in done in commitWork.
10680 if (oldText !== newText) {
10681 markUpdate(workInProgress);
10682 }
10683 };
10684} else if (supportsPersistence) {
10685 // Persistent host tree mode
10686 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
10687 // We only have the top Fiber that was created but we need recurse down its
10688 // children to find all the terminal nodes.
10689 var node = workInProgress.child;
10690
10691 while (node !== null) {
10692 // eslint-disable-next-line no-labels
10693 branches: if (node.tag === HostComponent) {
10694 var instance = node.stateNode;
10695
10696 if (needsVisibilityToggle && isHidden) {
10697 // This child is inside a timed out tree. Hide it.
10698 var props = node.memoizedProps;
10699 var type = node.type;
10700 instance = cloneHiddenInstance(instance, type, props, node);
10701 }
10702
10703 appendInitialChild(parent, instance);
10704 } else if (node.tag === HostText) {
10705 var _instance = node.stateNode;
10706
10707 if (needsVisibilityToggle && isHidden) {
10708 // This child is inside a timed out tree. Hide it.
10709 var text = node.memoizedProps;
10710 _instance = cloneHiddenTextInstance(_instance, text, node);
10711 }
10712
10713 appendInitialChild(parent, _instance);
10714 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10715 var _instance2 = node.stateNode.instance;
10716
10717 if (needsVisibilityToggle && isHidden) {
10718 // This child is inside a timed out tree. Hide it.
10719 var _props = node.memoizedProps;
10720 var _type = node.type;
10721 _instance2 = cloneHiddenInstance(_instance2, _type, _props, node);
10722 }
10723
10724 appendInitialChild(parent, _instance2);
10725 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10726 // down its children. Instead, we'll get insertions from each child in
10727 // the portal directly.
10728 } else if (node.tag === SuspenseComponent) {
10729 if ((node.effectTag & Update) !== NoEffect) {
10730 // Need to toggle the visibility of the primary children.
10731 var newIsHidden = node.memoizedState !== null;
10732
10733 if (newIsHidden) {
10734 var primaryChildParent = node.child;
10735
10736 if (primaryChildParent !== null) {
10737 if (primaryChildParent.child !== null) {
10738 primaryChildParent.child.return = primaryChildParent;
10739 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
10740 }
10741
10742 var fallbackChildParent = primaryChildParent.sibling;
10743
10744 if (fallbackChildParent !== null) {
10745 fallbackChildParent.return = node;
10746 node = fallbackChildParent;
10747 continue;
10748 }
10749 }
10750 }
10751 }
10752
10753 if (node.child !== null) {
10754 // Continue traversing like normal
10755 node.child.return = node;
10756 node = node.child;
10757 continue;
10758 }
10759 } else if (node.child !== null) {
10760 node.child.return = node;
10761 node = node.child;
10762 continue;
10763 } // $FlowFixMe This is correct but Flow is confused by the labeled break.
10764
10765
10766 node = node;
10767
10768 if (node === workInProgress) {
10769 return;
10770 }
10771
10772 while (node.sibling === null) {
10773 if (node.return === null || node.return === workInProgress) {
10774 return;
10775 }
10776
10777 node = node.return;
10778 }
10779
10780 node.sibling.return = node.return;
10781 node = node.sibling;
10782 }
10783 }; // An unfortunate fork of appendAllChildren because we have two different parent types.
10784
10785
10786 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
10787 // We only have the top Fiber that was created but we need recurse down its
10788 // children to find all the terminal nodes.
10789 var node = workInProgress.child;
10790
10791 while (node !== null) {
10792 // eslint-disable-next-line no-labels
10793 branches: if (node.tag === HostComponent) {
10794 var instance = node.stateNode;
10795
10796 if (needsVisibilityToggle && isHidden) {
10797 // This child is inside a timed out tree. Hide it.
10798 var props = node.memoizedProps;
10799 var type = node.type;
10800 instance = cloneHiddenInstance(instance, type, props, node);
10801 }
10802
10803 appendChildToContainerChildSet(containerChildSet, instance);
10804 } else if (node.tag === HostText) {
10805 var _instance3 = node.stateNode;
10806
10807 if (needsVisibilityToggle && isHidden) {
10808 // This child is inside a timed out tree. Hide it.
10809 var text = node.memoizedProps;
10810 _instance3 = cloneHiddenTextInstance(_instance3, text, node);
10811 }
10812
10813 appendChildToContainerChildSet(containerChildSet, _instance3);
10814 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10815 var _instance4 = node.stateNode.instance;
10816
10817 if (needsVisibilityToggle && isHidden) {
10818 // This child is inside a timed out tree. Hide it.
10819 var _props2 = node.memoizedProps;
10820 var _type2 = node.type;
10821 _instance4 = cloneHiddenInstance(_instance4, _type2, _props2, node);
10822 }
10823
10824 appendChildToContainerChildSet(containerChildSet, _instance4);
10825 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10826 // down its children. Instead, we'll get insertions from each child in
10827 // the portal directly.
10828 } else if (node.tag === SuspenseComponent) {
10829 if ((node.effectTag & Update) !== NoEffect) {
10830 // Need to toggle the visibility of the primary children.
10831 var newIsHidden = node.memoizedState !== null;
10832
10833 if (newIsHidden) {
10834 var primaryChildParent = node.child;
10835
10836 if (primaryChildParent !== null) {
10837 if (primaryChildParent.child !== null) {
10838 primaryChildParent.child.return = primaryChildParent;
10839 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
10840 }
10841
10842 var fallbackChildParent = primaryChildParent.sibling;
10843
10844 if (fallbackChildParent !== null) {
10845 fallbackChildParent.return = node;
10846 node = fallbackChildParent;
10847 continue;
10848 }
10849 }
10850 }
10851 }
10852
10853 if (node.child !== null) {
10854 // Continue traversing like normal
10855 node.child.return = node;
10856 node = node.child;
10857 continue;
10858 }
10859 } else if (node.child !== null) {
10860 node.child.return = node;
10861 node = node.child;
10862 continue;
10863 } // $FlowFixMe This is correct but Flow is confused by the labeled break.
10864
10865
10866 node = node;
10867
10868 if (node === workInProgress) {
10869 return;
10870 }
10871
10872 while (node.sibling === null) {
10873 if (node.return === null || node.return === workInProgress) {
10874 return;
10875 }
10876
10877 node = node.return;
10878 }
10879
10880 node.sibling.return = node.return;
10881 node = node.sibling;
10882 }
10883 };
10884
10885 updateHostContainer = function (workInProgress) {
10886 var portalOrRoot = workInProgress.stateNode;
10887 var childrenUnchanged = workInProgress.firstEffect === null;
10888
10889 if (childrenUnchanged) {// No changes, just reuse the existing instance.
10890 } else {
10891 var container = portalOrRoot.containerInfo;
10892 var newChildSet = createContainerChildSet(container); // If children might have changed, we have to add them all to the set.
10893
10894 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
10895 portalOrRoot.pendingChildren = newChildSet; // Schedule an update on the container to swap out the container.
10896
10897 markUpdate(workInProgress);
10898 finalizeContainerChildren(container, newChildSet);
10899 }
10900 };
10901
10902 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
10903 var currentInstance = current.stateNode;
10904 var oldProps = current.memoizedProps; // If there are no effects associated with this node, then none of our children had any updates.
10905 // This guarantees that we can reuse all of them.
10906
10907 var childrenUnchanged = workInProgress.firstEffect === null;
10908
10909 if (childrenUnchanged && oldProps === newProps) {
10910 // No changes, just reuse the existing instance.
10911 // Note that this might release a previous clone.
10912 workInProgress.stateNode = currentInstance;
10913 return;
10914 }
10915
10916 var recyclableInstance = workInProgress.stateNode;
10917 var currentHostContext = getHostContext();
10918 var updatePayload = null;
10919
10920 if (oldProps !== newProps) {
10921 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
10922 }
10923
10924 if (childrenUnchanged && updatePayload === null) {
10925 // No changes, just reuse the existing instance.
10926 // Note that this might release a previous clone.
10927 workInProgress.stateNode = currentInstance;
10928 return;
10929 }
10930
10931 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
10932
10933 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
10934 markUpdate(workInProgress);
10935 }
10936
10937 workInProgress.stateNode = newInstance;
10938
10939 if (childrenUnchanged) {
10940 // If there are no other effects in this tree, we need to flag this node as having one.
10941 // Even though we're not going to use it for anything.
10942 // Otherwise parents won't know that there are new children to propagate upwards.
10943 markUpdate(workInProgress);
10944 } else {
10945 // If children might have changed, we have to add them all to the set.
10946 appendAllChildren(newInstance, workInProgress, false, false);
10947 }
10948 };
10949
10950 updateHostText$1 = function (current, workInProgress, oldText, newText) {
10951 if (oldText !== newText) {
10952 // If the text content differs, we'll create a new text instance for it.
10953 var rootContainerInstance = getRootHostContainer();
10954 var currentHostContext = getHostContext();
10955 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.
10956 // This lets the parents know that at least one of their children has changed.
10957
10958 markUpdate(workInProgress);
10959 }
10960 };
10961} else {
10962 // No host operations
10963 updateHostContainer = function (workInProgress) {// Noop
10964 };
10965
10966 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {// Noop
10967 };
10968
10969 updateHostText$1 = function (current, workInProgress, oldText, newText) {// Noop
10970 };
10971}
10972
10973function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
10974 switch (renderState.tailMode) {
10975 case 'hidden':
10976 {
10977 // Any insertions at the end of the tail list after this point
10978 // should be invisible. If there are already mounted boundaries
10979 // anything before them are not considered for collapsing.
10980 // Therefore we need to go through the whole tail to find if
10981 // there are any.
10982 var tailNode = renderState.tail;
10983 var lastTailNode = null;
10984
10985 while (tailNode !== null) {
10986 if (tailNode.alternate !== null) {
10987 lastTailNode = tailNode;
10988 }
10989
10990 tailNode = tailNode.sibling;
10991 } // Next we're simply going to delete all insertions after the
10992 // last rendered item.
10993
10994
10995 if (lastTailNode === null) {
10996 // All remaining items in the tail are insertions.
10997 renderState.tail = null;
10998 } else {
10999 // Detach the insertion after the last node that was already
11000 // inserted.
11001 lastTailNode.sibling = null;
11002 }
11003
11004 break;
11005 }
11006
11007 case 'collapsed':
11008 {
11009 // Any insertions at the end of the tail list after this point
11010 // should be invisible. If there are already mounted boundaries
11011 // anything before them are not considered for collapsing.
11012 // Therefore we need to go through the whole tail to find if
11013 // there are any.
11014 var _tailNode = renderState.tail;
11015 var _lastTailNode = null;
11016
11017 while (_tailNode !== null) {
11018 if (_tailNode.alternate !== null) {
11019 _lastTailNode = _tailNode;
11020 }
11021
11022 _tailNode = _tailNode.sibling;
11023 } // Next we're simply going to delete all insertions after the
11024 // last rendered item.
11025
11026
11027 if (_lastTailNode === null) {
11028 // All remaining items in the tail are insertions.
11029 if (!hasRenderedATailFallback && renderState.tail !== null) {
11030 // We suspended during the head. We want to show at least one
11031 // row at the tail. So we'll keep on and cut off the rest.
11032 renderState.tail.sibling = null;
11033 } else {
11034 renderState.tail = null;
11035 }
11036 } else {
11037 // Detach the insertion after the last node that was already
11038 // inserted.
11039 _lastTailNode.sibling = null;
11040 }
11041
11042 break;
11043 }
11044 }
11045}
11046
11047function completeWork(current, workInProgress, renderExpirationTime) {
11048 var newProps = workInProgress.pendingProps;
11049
11050 switch (workInProgress.tag) {
11051 case IndeterminateComponent:
11052 break;
11053
11054 case LazyComponent:
11055 break;
11056
11057 case SimpleMemoComponent:
11058 case FunctionComponent:
11059 break;
11060
11061 case ClassComponent:
11062 {
11063 var Component = workInProgress.type;
11064
11065 if (isContextProvider(Component)) {
11066 popContext(workInProgress);
11067 }
11068
11069 break;
11070 }
11071
11072 case HostRoot:
11073 {
11074 popHostContainer(workInProgress);
11075 popTopLevelContextObject(workInProgress);
11076 var fiberRoot = workInProgress.stateNode;
11077
11078 if (fiberRoot.pendingContext) {
11079 fiberRoot.context = fiberRoot.pendingContext;
11080 fiberRoot.pendingContext = null;
11081 }
11082
11083 if (current === null || current.child === null) {
11084 // If we hydrated, pop so that we can delete any remaining children
11085 // that weren't hydrated.
11086 var wasHydrated = popHydrationState(workInProgress);
11087
11088 if (wasHydrated) {
11089 // If we hydrated, then we'll need to schedule an update for
11090 // the commit side-effects on the root.
11091 markUpdate(workInProgress);
11092 }
11093 }
11094
11095 updateHostContainer(workInProgress);
11096 break;
11097 }
11098
11099 case HostComponent:
11100 {
11101 popHostContext(workInProgress);
11102 var rootContainerInstance = getRootHostContainer();
11103 var type = workInProgress.type;
11104
11105 if (current !== null && workInProgress.stateNode != null) {
11106 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
11107
11108 if (enableFlareAPI) {
11109 var prevListeners = current.memoizedProps.listeners;
11110 var nextListeners = newProps.listeners;
11111
11112 if (prevListeners !== nextListeners) {
11113 markUpdate(workInProgress);
11114 }
11115 }
11116
11117 if (current.ref !== workInProgress.ref) {
11118 markRef$1(workInProgress);
11119 }
11120 } else {
11121 if (!newProps) {
11122 if (!(workInProgress.stateNode !== null)) {
11123 {
11124 throw Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.");
11125 }
11126 } // This can happen when we abort work.
11127
11128
11129 break;
11130 }
11131
11132 var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
11133 // "stack" as the parent. Then append children as we go in beginWork
11134 // or completeWork depending on we want to add then top->down or
11135 // bottom->up. Top->down is faster in IE11.
11136
11137 var _wasHydrated = popHydrationState(workInProgress);
11138
11139 if (_wasHydrated) {
11140 // TODO: Move this and createInstance step into the beginPhase
11141 // to consolidate.
11142 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
11143 // If changes to the hydrated node needs to be applied at the
11144 // commit-phase we mark this as such.
11145 markUpdate(workInProgress);
11146 }
11147
11148 if (enableFlareAPI) {
11149 var listeners = newProps.listeners;
11150
11151 if (listeners != null) {
11152 updateEventListeners(listeners, workInProgress, rootContainerInstance);
11153 }
11154 }
11155 } else {
11156 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
11157 appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
11158
11159 workInProgress.stateNode = instance;
11160
11161 if (enableFlareAPI) {
11162 var _listeners = newProps.listeners;
11163
11164 if (_listeners != null) {
11165 updateEventListeners(_listeners, workInProgress, rootContainerInstance);
11166 }
11167 } // Certain renderers require commit-time effects for initial mount.
11168 // (eg DOM renderer supports auto-focus for certain elements).
11169 // Make sure such renderers get scheduled for later work.
11170
11171
11172 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
11173 markUpdate(workInProgress);
11174 }
11175 }
11176
11177 if (workInProgress.ref !== null) {
11178 // If there is a ref on a host node we need to schedule a callback
11179 markRef$1(workInProgress);
11180 }
11181 }
11182
11183 break;
11184 }
11185
11186 case HostText:
11187 {
11188 var newText = newProps;
11189
11190 if (current && workInProgress.stateNode != null) {
11191 var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
11192 // to schedule a side-effect to do the updates.
11193
11194 updateHostText$1(current, workInProgress, oldText, newText);
11195 } else {
11196 if (typeof newText !== 'string') {
11197 if (!(workInProgress.stateNode !== null)) {
11198 {
11199 throw Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.");
11200 }
11201 } // This can happen when we abort work.
11202
11203 }
11204
11205 var _rootContainerInstance = getRootHostContainer();
11206
11207 var _currentHostContext = getHostContext();
11208
11209 var _wasHydrated2 = popHydrationState(workInProgress);
11210
11211 if (_wasHydrated2) {
11212 if (prepareToHydrateHostTextInstance(workInProgress)) {
11213 markUpdate(workInProgress);
11214 }
11215 } else {
11216 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
11217 }
11218 }
11219
11220 break;
11221 }
11222
11223 case ForwardRef:
11224 break;
11225
11226 case SuspenseComponent:
11227 {
11228 popSuspenseContext(workInProgress);
11229 var nextState = workInProgress.memoizedState;
11230
11231 if (enableSuspenseServerRenderer) {
11232 if (nextState !== null && nextState.dehydrated !== null) {
11233 if (current === null) {
11234 var _wasHydrated3 = popHydrationState(workInProgress);
11235
11236 if (!_wasHydrated3) {
11237 {
11238 throw Error("A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React.");
11239 }
11240 }
11241
11242 prepareToHydrateHostSuspenseInstance(workInProgress);
11243
11244 if (enableSchedulerTracing) {
11245 markSpawnedWork(Never);
11246 }
11247
11248 return null;
11249 } else {
11250 // We should never have been in a hydration state if we didn't have a current.
11251 // However, in some of those paths, we might have reentered a hydration state
11252 // and then we might be inside a hydration state. In that case, we'll need to
11253 // exit out of it.
11254 resetHydrationState();
11255
11256 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
11257 // This boundary did not suspend so it's now hydrated and unsuspended.
11258 workInProgress.memoizedState = null;
11259 } // If nothing suspended, we need to schedule an effect to mark this boundary
11260 // as having hydrated so events know that they're free be invoked.
11261 // It's also a signal to replay events and the suspense callback.
11262 // If something suspended, schedule an effect to attach retry listeners.
11263 // So we might as well always mark this.
11264
11265
11266 workInProgress.effectTag |= Update;
11267 return null;
11268 }
11269 }
11270 }
11271
11272 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
11273 // Something suspended. Re-render with the fallback children.
11274 workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
11275
11276 return workInProgress;
11277 }
11278
11279 var nextDidTimeout = nextState !== null;
11280 var prevDidTimeout = false;
11281
11282 if (current === null) {
11283 if (workInProgress.memoizedProps.fallback !== undefined) {
11284 popHydrationState(workInProgress);
11285 }
11286 } else {
11287 var prevState = current.memoizedState;
11288 prevDidTimeout = prevState !== null;
11289
11290 if (!nextDidTimeout && prevState !== null) {
11291 // We just switched from the fallback to the normal children.
11292 // Delete the fallback.
11293 // TODO: Would it be better to store the fallback fragment on
11294 // the stateNode during the begin phase?
11295 var currentFallbackChild = current.child.sibling;
11296
11297 if (currentFallbackChild !== null) {
11298 // Deletions go at the beginning of the return fiber's effect list
11299 var first = workInProgress.firstEffect;
11300
11301 if (first !== null) {
11302 workInProgress.firstEffect = currentFallbackChild;
11303 currentFallbackChild.nextEffect = first;
11304 } else {
11305 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
11306 currentFallbackChild.nextEffect = null;
11307 }
11308
11309 currentFallbackChild.effectTag = Deletion;
11310 }
11311 }
11312 }
11313
11314 if (nextDidTimeout && !prevDidTimeout) {
11315 // If this subtreee is running in batched mode we can suspend,
11316 // otherwise we won't suspend.
11317 // TODO: This will still suspend a synchronous tree if anything
11318 // in the concurrent tree already suspended during this render.
11319 // This is a known bug.
11320 if ((workInProgress.mode & BatchedMode) !== NoMode) {
11321 // TODO: Move this back to throwException because this is too late
11322 // if this is a large tree which is common for initial loads. We
11323 // don't know if we should restart a render or not until we get
11324 // this marker, and this is too late.
11325 // If this render already had a ping or lower pri updates,
11326 // and this is the first time we know we're going to suspend we
11327 // should be able to immediately restart from within throwException.
11328 var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
11329
11330 if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
11331 // If this was in an invisible tree or a new render, then showing
11332 // this boundary is ok.
11333 renderDidSuspend();
11334 } else {
11335 // Otherwise, we're going to have to hide content so we should
11336 // suspend for longer if possible.
11337 renderDidSuspendDelayIfPossible();
11338 }
11339 }
11340 }
11341
11342 if (supportsPersistence) {
11343 // TODO: Only schedule updates if not prevDidTimeout.
11344 if (nextDidTimeout) {
11345 // If this boundary just timed out, schedule an effect to attach a
11346 // retry listener to the proimse. This flag is also used to hide the
11347 // primary children.
11348 workInProgress.effectTag |= Update;
11349 }
11350 }
11351
11352 if (supportsMutation) {
11353 // TODO: Only schedule updates if these values are non equal, i.e. it changed.
11354 if (nextDidTimeout || prevDidTimeout) {
11355 // If this boundary just timed out, schedule an effect to attach a
11356 // retry listener to the proimse. This flag is also used to hide the
11357 // primary children. In mutation mode, we also need the flag to
11358 // *unhide* children that were previously hidden, so check if the
11359 // is currently timed out, too.
11360 workInProgress.effectTag |= Update;
11361 }
11362 }
11363
11364 if (enableSuspenseCallback && workInProgress.updateQueue !== null && workInProgress.memoizedProps.suspenseCallback != null) {
11365 // Always notify the callback
11366 workInProgress.effectTag |= Update;
11367 }
11368
11369 break;
11370 }
11371
11372 case Fragment:
11373 break;
11374
11375 case Mode$1:
11376 break;
11377
11378 case Profiler:
11379 break;
11380
11381 case HostPortal:
11382 popHostContainer(workInProgress);
11383 updateHostContainer(workInProgress);
11384 break;
11385
11386 case ContextProvider:
11387 // Pop provider fiber
11388 popProvider(workInProgress);
11389 break;
11390
11391 case ContextConsumer:
11392 break;
11393
11394 case MemoComponent:
11395 break;
11396
11397 case IncompleteClassComponent:
11398 {
11399 // Same as class component case. I put it down here so that the tags are
11400 // sequential to ensure this switch is compiled to a jump table.
11401 var _Component = workInProgress.type;
11402
11403 if (isContextProvider(_Component)) {
11404 popContext(workInProgress);
11405 }
11406
11407 break;
11408 }
11409
11410 case SuspenseListComponent:
11411 {
11412 popSuspenseContext(workInProgress);
11413 var renderState = workInProgress.memoizedState;
11414
11415 if (renderState === null) {
11416 // We're running in the default, "independent" mode. We don't do anything
11417 // in this mode.
11418 break;
11419 }
11420
11421 var didSuspendAlready = (workInProgress.effectTag & DidCapture) !== NoEffect;
11422 var renderedTail = renderState.rendering;
11423
11424 if (renderedTail === null) {
11425 // We just rendered the head.
11426 if (!didSuspendAlready) {
11427 // This is the first pass. We need to figure out if anything is still
11428 // suspended in the rendered set.
11429 // If new content unsuspended, but there's still some content that
11430 // didn't. Then we need to do a second pass that forces everything
11431 // to keep showing their fallbacks.
11432 // We might be suspended if something in this render pass suspended, or
11433 // something in the previous committed pass suspended. Otherwise,
11434 // there's no chance so we can skip the expensive call to
11435 // findFirstSuspended.
11436 var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.effectTag & DidCapture) === NoEffect);
11437
11438 if (!cannotBeSuspended) {
11439 var row = workInProgress.child;
11440
11441 while (row !== null) {
11442 var suspended = findFirstSuspended(row);
11443
11444 if (suspended !== null) {
11445 didSuspendAlready = true;
11446 workInProgress.effectTag |= DidCapture;
11447 cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
11448 // part of the second pass. In that case nothing will subscribe to
11449 // its thennables. Instead, we'll transfer its thennables to the
11450 // SuspenseList so that it can retry if they resolve.
11451 // There might be multiple of these in the list but since we're
11452 // going to wait for all of them anyway, it doesn't really matter
11453 // which ones gets to ping. In theory we could get clever and keep
11454 // track of how many dependencies remain but it gets tricky because
11455 // in the meantime, we can add/remove/change items and dependencies.
11456 // We might bail out of the loop before finding any but that
11457 // doesn't matter since that means that the other boundaries that
11458 // we did find already has their listeners attached.
11459
11460 var newThennables = suspended.updateQueue;
11461
11462 if (newThennables !== null) {
11463 workInProgress.updateQueue = newThennables;
11464 workInProgress.effectTag |= Update;
11465 } // Rerender the whole list, but this time, we'll force fallbacks
11466 // to stay in place.
11467 // Reset the effect list before doing the second pass since that's now invalid.
11468
11469
11470 if (renderState.lastEffect === null) {
11471 workInProgress.firstEffect = null;
11472 }
11473
11474 workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
11475
11476 resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
11477 // rerender the children.
11478
11479 pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
11480 return workInProgress.child;
11481 }
11482
11483 row = row.sibling;
11484 }
11485 }
11486 } else {
11487 cutOffTailIfNeeded(renderState, false);
11488 } // Next we're going to render the tail.
11489
11490 } else {
11491 // Append the rendered row to the child list.
11492 if (!didSuspendAlready) {
11493 var _suspended = findFirstSuspended(renderedTail);
11494
11495 if (_suspended !== null) {
11496 workInProgress.effectTag |= DidCapture;
11497 didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
11498 // get lost if this row ends up dropped during a second pass.
11499
11500 var _newThennables = _suspended.updateQueue;
11501
11502 if (_newThennables !== null) {
11503 workInProgress.updateQueue = _newThennables;
11504 workInProgress.effectTag |= Update;
11505 }
11506
11507 cutOffTailIfNeeded(renderState, true); // This might have been modified.
11508
11509 if (renderState.tail === null && renderState.tailMode === 'hidden') {
11510 // We need to delete the row we just rendered.
11511 // Reset the effect list to what it w as before we rendered this
11512 // child. The nested children have already appended themselves.
11513 var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
11514
11515 if (lastEffect !== null) {
11516 lastEffect.nextEffect = null;
11517 } // We're done.
11518
11519
11520 return null;
11521 }
11522 } else if (now() > renderState.tailExpiration && renderExpirationTime > Never) {
11523 // We have now passed our CPU deadline and we'll just give up further
11524 // attempts to render the main content and only render fallbacks.
11525 // The assumption is that this is usually faster.
11526 workInProgress.effectTag |= DidCapture;
11527 didSuspendAlready = true;
11528 cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
11529 // to get it started back up to attempt the next item. If we can show
11530 // them, then they really have the same priority as this render.
11531 // So we'll pick it back up the very next render pass once we've had
11532 // an opportunity to yield for paint.
11533
11534 var nextPriority = renderExpirationTime - 1;
11535 workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
11536
11537 if (enableSchedulerTracing) {
11538 markSpawnedWork(nextPriority);
11539 }
11540 }
11541 }
11542
11543 if (renderState.isBackwards) {
11544 // The effect list of the backwards tail will have been added
11545 // to the end. This breaks the guarantee that life-cycles fire in
11546 // sibling order but that isn't a strong guarantee promised by React.
11547 // Especially since these might also just pop in during future commits.
11548 // Append to the beginning of the list.
11549 renderedTail.sibling = workInProgress.child;
11550 workInProgress.child = renderedTail;
11551 } else {
11552 var previousSibling = renderState.last;
11553
11554 if (previousSibling !== null) {
11555 previousSibling.sibling = renderedTail;
11556 } else {
11557 workInProgress.child = renderedTail;
11558 }
11559
11560 renderState.last = renderedTail;
11561 }
11562 }
11563
11564 if (renderState.tail !== null) {
11565 // We still have tail rows to render.
11566 if (renderState.tailExpiration === 0) {
11567 // Heuristic for how long we're willing to spend rendering rows
11568 // until we just give up and show what we have so far.
11569 var TAIL_EXPIRATION_TIMEOUT_MS = 500;
11570 renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS;
11571 } // Pop a row.
11572
11573
11574 var next = renderState.tail;
11575 renderState.rendering = next;
11576 renderState.tail = next.sibling;
11577 renderState.lastEffect = workInProgress.lastEffect;
11578 next.sibling = null; // Restore the context.
11579 // TODO: We can probably just avoid popping it instead and only
11580 // setting it the first time we go from not suspended to suspended.
11581
11582 var suspenseContext = suspenseStackCursor.current;
11583
11584 if (didSuspendAlready) {
11585 suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
11586 } else {
11587 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
11588 }
11589
11590 pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
11591
11592 return next;
11593 }
11594
11595 break;
11596 }
11597
11598 case FundamentalComponent:
11599 {
11600 if (enableFundamentalAPI) {
11601 var fundamentalImpl = workInProgress.type.impl;
11602 var fundamentalInstance = workInProgress.stateNode;
11603
11604 if (fundamentalInstance === null) {
11605 var getInitialState = fundamentalImpl.getInitialState;
11606 var fundamentalState;
11607
11608 if (getInitialState !== undefined) {
11609 fundamentalState = getInitialState(newProps);
11610 }
11611
11612 fundamentalInstance = workInProgress.stateNode = createFundamentalStateInstance(workInProgress, newProps, fundamentalImpl, fundamentalState || {});
11613
11614 var _instance5 = getFundamentalComponentInstance(fundamentalInstance);
11615
11616 fundamentalInstance.instance = _instance5;
11617
11618 if (fundamentalImpl.reconcileChildren === false) {
11619 return null;
11620 }
11621
11622 appendAllChildren(_instance5, workInProgress, false, false);
11623 mountFundamentalComponent(fundamentalInstance);
11624 } else {
11625 // We fire update in commit phase
11626 var prevProps = fundamentalInstance.props;
11627 fundamentalInstance.prevProps = prevProps;
11628 fundamentalInstance.props = newProps;
11629 fundamentalInstance.currentFiber = workInProgress;
11630
11631 if (supportsPersistence) {
11632 var _instance6 = cloneFundamentalInstance(fundamentalInstance);
11633
11634 fundamentalInstance.instance = _instance6;
11635 appendAllChildren(_instance6, workInProgress, false, false);
11636 }
11637
11638 var shouldUpdate = shouldUpdateFundamentalComponent(fundamentalInstance);
11639
11640 if (shouldUpdate) {
11641 markUpdate(workInProgress);
11642 }
11643 }
11644 }
11645
11646 break;
11647 }
11648
11649 case ScopeComponent:
11650 {
11651 if (enableScopeAPI) {
11652 if (current === null) {
11653 var _type3 = workInProgress.type;
11654 var scopeInstance = {
11655 fiber: workInProgress,
11656 methods: null
11657 };
11658 workInProgress.stateNode = scopeInstance;
11659 scopeInstance.methods = createScopeMethods(_type3, scopeInstance);
11660
11661 if (enableFlareAPI) {
11662 var _listeners2 = newProps.listeners;
11663
11664 if (_listeners2 != null) {
11665 var _rootContainerInstance2 = getRootHostContainer();
11666
11667 updateEventListeners(_listeners2, workInProgress, _rootContainerInstance2);
11668 }
11669 }
11670
11671 if (workInProgress.ref !== null) {
11672 markRef$1(workInProgress);
11673 markUpdate(workInProgress);
11674 }
11675 } else {
11676 if (enableFlareAPI) {
11677 var _prevListeners = current.memoizedProps.listeners;
11678 var _nextListeners = newProps.listeners;
11679
11680 if (_prevListeners !== _nextListeners || workInProgress.ref !== null) {
11681 markUpdate(workInProgress);
11682 }
11683 } else {
11684 if (workInProgress.ref !== null) {
11685 markUpdate(workInProgress);
11686 }
11687 }
11688
11689 if (current.ref !== workInProgress.ref) {
11690 markRef$1(workInProgress);
11691 }
11692 }
11693 }
11694
11695 break;
11696 }
11697
11698 default:
11699 {
11700 {
11701 throw Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue.");
11702 }
11703 }
11704
11705 }
11706
11707 return null;
11708}
11709
11710function unwindWork(workInProgress, renderExpirationTime) {
11711 switch (workInProgress.tag) {
11712 case ClassComponent:
11713 {
11714 var Component = workInProgress.type;
11715
11716 if (isContextProvider(Component)) {
11717 popContext(workInProgress);
11718 }
11719
11720 var effectTag = workInProgress.effectTag;
11721
11722 if (effectTag & ShouldCapture) {
11723 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
11724 return workInProgress;
11725 }
11726
11727 return null;
11728 }
11729
11730 case HostRoot:
11731 {
11732 popHostContainer(workInProgress);
11733 popTopLevelContextObject(workInProgress);
11734 var _effectTag = workInProgress.effectTag;
11735
11736 if (!((_effectTag & DidCapture) === NoEffect)) {
11737 {
11738 throw Error("The root failed to unmount after an error. This is likely a bug in React. Please file an issue.");
11739 }
11740 }
11741
11742 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
11743 return workInProgress;
11744 }
11745
11746 case HostComponent:
11747 {
11748 // TODO: popHydrationState
11749 popHostContext(workInProgress);
11750 return null;
11751 }
11752
11753 case SuspenseComponent:
11754 {
11755 popSuspenseContext(workInProgress);
11756
11757 if (enableSuspenseServerRenderer) {
11758 var suspenseState = workInProgress.memoizedState;
11759
11760 if (suspenseState !== null && suspenseState.dehydrated !== null) {
11761 if (!(workInProgress.alternate !== null)) {
11762 {
11763 throw Error("Threw in newly mounted dehydrated component. This is likely a bug in React. Please file an issue.");
11764 }
11765 }
11766
11767 resetHydrationState();
11768 }
11769 }
11770
11771 var _effectTag2 = workInProgress.effectTag;
11772
11773 if (_effectTag2 & ShouldCapture) {
11774 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
11775
11776 return workInProgress;
11777 }
11778
11779 return null;
11780 }
11781
11782 case SuspenseListComponent:
11783 {
11784 popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
11785 // caught by a nested boundary. If not, it should bubble through.
11786
11787 return null;
11788 }
11789
11790 case HostPortal:
11791 popHostContainer(workInProgress);
11792 return null;
11793
11794 case ContextProvider:
11795 popProvider(workInProgress);
11796 return null;
11797
11798 default:
11799 return null;
11800 }
11801}
11802
11803function unwindInterruptedWork(interruptedWork) {
11804 switch (interruptedWork.tag) {
11805 case ClassComponent:
11806 {
11807 var childContextTypes = interruptedWork.type.childContextTypes;
11808
11809 if (childContextTypes !== null && childContextTypes !== undefined) {
11810 popContext(interruptedWork);
11811 }
11812
11813 break;
11814 }
11815
11816 case HostRoot:
11817 {
11818 popHostContainer(interruptedWork);
11819 popTopLevelContextObject(interruptedWork);
11820 break;
11821 }
11822
11823 case HostComponent:
11824 {
11825 popHostContext(interruptedWork);
11826 break;
11827 }
11828
11829 case HostPortal:
11830 popHostContainer(interruptedWork);
11831 break;
11832
11833 case SuspenseComponent:
11834 popSuspenseContext(interruptedWork);
11835 break;
11836
11837 case SuspenseListComponent:
11838 popSuspenseContext(interruptedWork);
11839 break;
11840
11841 case ContextProvider:
11842 popProvider(interruptedWork);
11843 break;
11844
11845 default:
11846 break;
11847 }
11848}
11849
11850function createCapturedValue(value, source) {
11851 // If the value is an error, call this function immediately after it is thrown
11852 // so the stack is accurate.
11853 return {
11854 value: value,
11855 source: source,
11856 stack: getStackByFiberInDevAndProd(source)
11857 };
11858}
11859
11860var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
11861 var funcArgs = Array.prototype.slice.call(arguments, 3);
11862
11863 try {
11864 func.apply(context, funcArgs);
11865 } catch (error) {
11866 this.onError(error);
11867 }
11868};
11869
11870{
11871 // In DEV mode, we swap out invokeGuardedCallback for a special version
11872 // that plays more nicely with the browser's DevTools. The idea is to preserve
11873 // "Pause on exceptions" behavior. Because React wraps all user-provided
11874 // functions in invokeGuardedCallback, and the production version of
11875 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
11876 // like caught exceptions, and the DevTools won't pause unless the developer
11877 // takes the extra step of enabling pause on caught exceptions. This is
11878 // unintuitive, though, because even though React has caught the error, from
11879 // the developer's perspective, the error is uncaught.
11880 //
11881 // To preserve the expected "Pause on exceptions" behavior, we don't use a
11882 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
11883 // DOM node, and call the user-provided callback from inside an event handler
11884 // for that fake event. If the callback throws, the error is "captured" using
11885 // a global event handler. But because the error happens in a different
11886 // event loop context, it does not interrupt the normal program flow.
11887 // Effectively, this gives us try-catch behavior without actually using
11888 // try-catch. Neat!
11889 // Check that the browser supports the APIs we need to implement our special
11890 // DEV version of invokeGuardedCallback
11891 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
11892 var fakeNode = document.createElement('react');
11893
11894 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
11895 // If document doesn't exist we know for sure we will crash in this method
11896 // when we call document.createEvent(). However this can cause confusing
11897 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
11898 // So we preemptively throw with a better message instead.
11899 if (!(typeof document !== 'undefined')) {
11900 {
11901 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.");
11902 }
11903 }
11904
11905 var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
11906 // set this to true at the beginning, then set it to false right after
11907 // calling the function. If the function errors, `didError` will never be
11908 // set to false. This strategy works even if the browser is flaky and
11909 // fails to call our global error handler, because it doesn't rely on
11910 // the error event at all.
11911
11912 var didError = true; // Keeps track of the value of window.event so that we can reset it
11913 // during the callback to let user code access window.event in the
11914 // browsers that support it.
11915
11916 var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
11917 // dispatching: https://github.com/facebook/react/issues/13688
11918
11919 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event'); // Create an event handler for our fake event. We will synchronously
11920 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
11921 // call the user-provided callback.
11922
11923 var funcArgs = Array.prototype.slice.call(arguments, 3);
11924
11925 function callCallback() {
11926 // We immediately remove the callback from event listeners so that
11927 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
11928 // nested call would trigger the fake event handlers of any call higher
11929 // in the stack.
11930 fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
11931 // window.event assignment in both IE <= 10 as they throw an error
11932 // "Member not found" in strict mode, and in Firefox which does not
11933 // support window.event.
11934
11935 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
11936 window.event = windowEvent;
11937 }
11938
11939 func.apply(context, funcArgs);
11940 didError = false;
11941 } // Create a global error event handler. We use this to capture the value
11942 // that was thrown. It's possible that this error handler will fire more
11943 // than once; for example, if non-React code also calls `dispatchEvent`
11944 // and a handler for that event throws. We should be resilient to most of
11945 // those cases. Even if our error event handler fires more than once, the
11946 // last error event is always used. If the callback actually does error,
11947 // we know that the last error event is the correct one, because it's not
11948 // possible for anything else to have happened in between our callback
11949 // erroring and the code that follows the `dispatchEvent` call below. If
11950 // the callback doesn't error, but the error event was fired, we know to
11951 // ignore it because `didError` will be false, as described above.
11952
11953
11954 var error; // Use this to track whether the error event is ever called.
11955
11956 var didSetError = false;
11957 var isCrossOriginError = false;
11958
11959 function handleWindowError(event) {
11960 error = event.error;
11961 didSetError = true;
11962
11963 if (error === null && event.colno === 0 && event.lineno === 0) {
11964 isCrossOriginError = true;
11965 }
11966
11967 if (event.defaultPrevented) {
11968 // Some other error handler has prevented default.
11969 // Browsers silence the error report if this happens.
11970 // We'll remember this to later decide whether to log it or not.
11971 if (error != null && typeof error === 'object') {
11972 try {
11973 error._suppressLogging = true;
11974 } catch (inner) {// Ignore.
11975 }
11976 }
11977 }
11978 } // Create a fake event type.
11979
11980
11981 var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
11982
11983 window.addEventListener('error', handleWindowError);
11984 fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
11985 // errors, it will trigger our global error handler.
11986
11987 evt.initEvent(evtType, false, false);
11988 fakeNode.dispatchEvent(evt);
11989
11990 if (windowEventDescriptor) {
11991 Object.defineProperty(window, 'event', windowEventDescriptor);
11992 }
11993
11994 if (didError) {
11995 if (!didSetError) {
11996 // The callback errored, but the error event never fired.
11997 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.');
11998 } else if (isCrossOriginError) {
11999 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.');
12000 }
12001
12002 this.onError(error);
12003 } // Remove our event listeners
12004
12005
12006 window.removeEventListener('error', handleWindowError);
12007 };
12008
12009 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
12010 }
12011}
12012
12013var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
12014
12015var hasError = false;
12016var caughtError = null; // Used by event system to capture/rethrow the first error.
12017
12018var reporter = {
12019 onError: function (error) {
12020 hasError = true;
12021 caughtError = error;
12022 }
12023};
12024/**
12025 * Call a function while guarding against errors that happens within it.
12026 * Returns an error if it throws, otherwise null.
12027 *
12028 * In production, this is implemented using a try-catch. The reason we don't
12029 * use a try-catch directly is so that we can swap out a different
12030 * implementation in DEV mode.
12031 *
12032 * @param {String} name of the guard to use for logging or debugging
12033 * @param {Function} func The function to invoke
12034 * @param {*} context The context to use when calling the function
12035 * @param {...*} args Arguments for function
12036 */
12037
12038function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
12039 hasError = false;
12040 caughtError = null;
12041 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
12042}
12043/**
12044 * Same as invokeGuardedCallback, but instead of returning an error, it stores
12045 * it in a global so it can be rethrown by `rethrowCaughtError` later.
12046 * TODO: See if caughtError and rethrowError can be unified.
12047 *
12048 * @param {String} name of the guard to use for logging or debugging
12049 * @param {Function} func The function to invoke
12050 * @param {*} context The context to use when calling the function
12051 * @param {...*} args Arguments for function
12052 */
12053
12054
12055/**
12056 * During execution of guarded functions we will capture the first error which
12057 * we will rethrow to be handled by the top level error handler.
12058 */
12059
12060
12061function hasCaughtError() {
12062 return hasError;
12063}
12064function clearCaughtError() {
12065 if (hasError) {
12066 var error = caughtError;
12067 hasError = false;
12068 caughtError = null;
12069 return error;
12070 } else {
12071 {
12072 {
12073 throw Error("clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.");
12074 }
12075 }
12076 }
12077}
12078
12079// This module is forked in different environments.
12080// By default, return `true` to log errors to the console.
12081// Forks can return `false` if this isn't desirable.
12082function showErrorDialog(capturedError) {
12083 return true;
12084}
12085
12086function logCapturedError(capturedError) {
12087 var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
12088 // This enables renderers like ReactNative to better manage redbox behavior.
12089
12090 if (logError === false) {
12091 return;
12092 }
12093
12094 var error = capturedError.error;
12095
12096 {
12097 var componentName = capturedError.componentName,
12098 componentStack = capturedError.componentStack,
12099 errorBoundaryName = capturedError.errorBoundaryName,
12100 errorBoundaryFound = capturedError.errorBoundaryFound,
12101 willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
12102 // `preventDefault()` in window `error` handler.
12103 // We record this information as an expando on the error.
12104
12105 if (error != null && error._suppressLogging) {
12106 if (errorBoundaryFound && willRetry) {
12107 // The error is recoverable and was silenced.
12108 // Ignore it and don't print the stack addendum.
12109 // This is handy for testing error boundaries without noise.
12110 return;
12111 } // The error is fatal. Since the silencing might have
12112 // been accidental, we'll surface it anyway.
12113 // However, the browser would have silenced the original error
12114 // so we'll print it first, and then print the stack addendum.
12115
12116
12117 console.error(error); // For a more detailed description of this block, see:
12118 // https://github.com/facebook/react/pull/13384
12119 }
12120
12121 var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
12122 var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
12123
12124 if (errorBoundaryFound && errorBoundaryName) {
12125 if (willRetry) {
12126 errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
12127 } else {
12128 errorBoundaryMessage = "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree.";
12129 }
12130 } else {
12131 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.';
12132 }
12133
12134 var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
12135 // We don't include the original error message and JS stack because the browser
12136 // has already printed it. Even if the application swallows the error, it is still
12137 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
12138
12139 console.error(combinedMessage);
12140 }
12141}
12142
12143var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
12144
12145{
12146 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
12147}
12148
12149var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
12150function logError(boundary, errorInfo) {
12151 var source = errorInfo.source;
12152 var stack = errorInfo.stack;
12153
12154 if (stack === null && source !== null) {
12155 stack = getStackByFiberInDevAndProd(source);
12156 }
12157
12158 var capturedError = {
12159 componentName: source !== null ? getComponentName(source.type) : null,
12160 componentStack: stack !== null ? stack : '',
12161 error: errorInfo.value,
12162 errorBoundary: null,
12163 errorBoundaryName: null,
12164 errorBoundaryFound: false,
12165 willRetry: false
12166 };
12167
12168 if (boundary !== null && boundary.tag === ClassComponent) {
12169 capturedError.errorBoundary = boundary.stateNode;
12170 capturedError.errorBoundaryName = getComponentName(boundary.type);
12171 capturedError.errorBoundaryFound = true;
12172 capturedError.willRetry = true;
12173 }
12174
12175 try {
12176 logCapturedError(capturedError);
12177 } catch (e) {
12178 // This method must not throw, or React internal state will get messed up.
12179 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
12180 // we want to report this error outside of the normal stack as a last resort.
12181 // https://github.com/facebook/react/issues/13188
12182 setTimeout(function () {
12183 throw e;
12184 });
12185 }
12186}
12187
12188var callComponentWillUnmountWithTimer = function (current$$1, instance) {
12189 startPhaseTimer(current$$1, 'componentWillUnmount');
12190 instance.props = current$$1.memoizedProps;
12191 instance.state = current$$1.memoizedState;
12192 instance.componentWillUnmount();
12193 stopPhaseTimer();
12194}; // Capture errors so they don't interrupt unmounting.
12195
12196
12197function safelyCallComponentWillUnmount(current$$1, instance) {
12198 {
12199 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
12200
12201 if (hasCaughtError()) {
12202 var unmountError = clearCaughtError();
12203 captureCommitPhaseError(current$$1, unmountError);
12204 }
12205 }
12206}
12207
12208function safelyDetachRef(current$$1) {
12209 var ref = current$$1.ref;
12210
12211 if (ref !== null) {
12212 if (typeof ref === 'function') {
12213 {
12214 invokeGuardedCallback(null, ref, null, null);
12215
12216 if (hasCaughtError()) {
12217 var refError = clearCaughtError();
12218 captureCommitPhaseError(current$$1, refError);
12219 }
12220 }
12221 } else {
12222 ref.current = null;
12223 }
12224 }
12225}
12226
12227function safelyCallDestroy(current$$1, destroy) {
12228 {
12229 invokeGuardedCallback(null, destroy, null);
12230
12231 if (hasCaughtError()) {
12232 var error = clearCaughtError();
12233 captureCommitPhaseError(current$$1, error);
12234 }
12235 }
12236}
12237
12238function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
12239 switch (finishedWork.tag) {
12240 case FunctionComponent:
12241 case ForwardRef:
12242 case SimpleMemoComponent:
12243 {
12244 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
12245 return;
12246 }
12247
12248 case ClassComponent:
12249 {
12250 if (finishedWork.effectTag & Snapshot) {
12251 if (current$$1 !== null) {
12252 var prevProps = current$$1.memoizedProps;
12253 var prevState = current$$1.memoizedState;
12254 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
12255 var instance = finishedWork.stateNode; // We could update instance props and state here,
12256 // but instead we rely on them being set during last render.
12257 // TODO: revisit this when we implement resuming.
12258
12259 {
12260 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12261 !(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;
12262 !(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;
12263 }
12264 }
12265
12266 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
12267
12268 {
12269 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
12270
12271 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
12272 didWarnSet.add(finishedWork.type);
12273 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
12274 }
12275 }
12276
12277 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
12278 stopPhaseTimer();
12279 }
12280 }
12281
12282 return;
12283 }
12284
12285 case HostRoot:
12286 case HostComponent:
12287 case HostText:
12288 case HostPortal:
12289 case IncompleteClassComponent:
12290 // Nothing to do for these component types
12291 return;
12292
12293 default:
12294 {
12295 {
12296 {
12297 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.");
12298 }
12299 }
12300 }
12301 }
12302}
12303
12304function commitHookEffectList(unmountTag, mountTag, finishedWork) {
12305 var updateQueue = finishedWork.updateQueue;
12306 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
12307
12308 if (lastEffect !== null) {
12309 var firstEffect = lastEffect.next;
12310 var effect = firstEffect;
12311
12312 do {
12313 if ((effect.tag & unmountTag) !== NoEffect$1) {
12314 // Unmount
12315 var destroy = effect.destroy;
12316 effect.destroy = undefined;
12317
12318 if (destroy !== undefined) {
12319 destroy();
12320 }
12321 }
12322
12323 if ((effect.tag & mountTag) !== NoEffect$1) {
12324 // Mount
12325 var create = effect.create;
12326 effect.destroy = create();
12327
12328 {
12329 var _destroy = effect.destroy;
12330
12331 if (_destroy !== undefined && typeof _destroy !== 'function') {
12332 var addendum = void 0;
12333
12334 if (_destroy === null) {
12335 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
12336 } else if (typeof _destroy.then === 'function') {
12337 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';
12338 } else {
12339 addendum = ' You returned: ' + _destroy;
12340 }
12341
12342 warningWithoutStack$1(false, 'An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
12343 }
12344 }
12345 }
12346
12347 effect = effect.next;
12348 } while (effect !== firstEffect);
12349 }
12350}
12351
12352function commitPassiveHookEffects(finishedWork) {
12353 if ((finishedWork.effectTag & Passive) !== NoEffect) {
12354 switch (finishedWork.tag) {
12355 case FunctionComponent:
12356 case ForwardRef:
12357 case SimpleMemoComponent:
12358 {
12359 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
12360 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
12361 break;
12362 }
12363
12364 default:
12365 break;
12366 }
12367 }
12368}
12369
12370function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
12371 switch (finishedWork.tag) {
12372 case FunctionComponent:
12373 case ForwardRef:
12374 case SimpleMemoComponent:
12375 {
12376 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
12377 break;
12378 }
12379
12380 case ClassComponent:
12381 {
12382 var instance = finishedWork.stateNode;
12383
12384 if (finishedWork.effectTag & Update) {
12385 if (current$$1 === null) {
12386 startPhaseTimer(finishedWork, 'componentDidMount'); // We could update instance props and state here,
12387 // but instead we rely on them being set during last render.
12388 // TODO: revisit this when we implement resuming.
12389
12390 {
12391 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12392 !(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;
12393 !(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;
12394 }
12395 }
12396
12397 instance.componentDidMount();
12398 stopPhaseTimer();
12399 } else {
12400 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
12401 var prevState = current$$1.memoizedState;
12402 startPhaseTimer(finishedWork, 'componentDidUpdate'); // We could update instance props and state here,
12403 // but instead we rely on them being set during last render.
12404 // TODO: revisit this when we implement resuming.
12405
12406 {
12407 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12408 !(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;
12409 !(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;
12410 }
12411 }
12412
12413 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
12414 stopPhaseTimer();
12415 }
12416 }
12417
12418 var updateQueue = finishedWork.updateQueue;
12419
12420 if (updateQueue !== null) {
12421 {
12422 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12423 !(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;
12424 !(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;
12425 }
12426 } // We could update instance props and state here,
12427 // but instead we rely on them being set during last render.
12428 // TODO: revisit this when we implement resuming.
12429
12430
12431 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
12432 }
12433
12434 return;
12435 }
12436
12437 case HostRoot:
12438 {
12439 var _updateQueue = finishedWork.updateQueue;
12440
12441 if (_updateQueue !== null) {
12442 var _instance = null;
12443
12444 if (finishedWork.child !== null) {
12445 switch (finishedWork.child.tag) {
12446 case HostComponent:
12447 _instance = getPublicInstance(finishedWork.child.stateNode);
12448 break;
12449
12450 case ClassComponent:
12451 _instance = finishedWork.child.stateNode;
12452 break;
12453 }
12454 }
12455
12456 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
12457 }
12458
12459 return;
12460 }
12461
12462 case HostComponent:
12463 {
12464 var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
12465 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
12466 // These effects should only be committed when components are first mounted,
12467 // aka when there is no current/alternate.
12468
12469 if (current$$1 === null && finishedWork.effectTag & Update) {
12470 var type = finishedWork.type;
12471 var props = finishedWork.memoizedProps;
12472
12473 }
12474
12475 return;
12476 }
12477
12478 case HostText:
12479 {
12480 // We have no life-cycles associated with text.
12481 return;
12482 }
12483
12484 case HostPortal:
12485 {
12486 // We have no life-cycles associated with portals.
12487 return;
12488 }
12489
12490 case Profiler:
12491 {
12492 if (enableProfilerTimer) {
12493 var onRender = finishedWork.memoizedProps.onRender;
12494
12495 if (typeof onRender === 'function') {
12496 if (enableSchedulerTracing) {
12497 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
12498 } else {
12499 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
12500 }
12501 }
12502 }
12503
12504 return;
12505 }
12506
12507 case SuspenseComponent:
12508 {
12509 commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);
12510 return;
12511 }
12512
12513 case SuspenseListComponent:
12514 case IncompleteClassComponent:
12515 case FundamentalComponent:
12516 case ScopeComponent:
12517 return;
12518
12519 default:
12520 {
12521 {
12522 {
12523 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.");
12524 }
12525 }
12526 }
12527 }
12528}
12529
12530function hideOrUnhideAllChildren(finishedWork, isHidden) {
12531 if (supportsMutation) {
12532 // We only have the top Fiber that was inserted but we need to recurse down its
12533 // children to find all the terminal nodes.
12534 var node = finishedWork;
12535
12536 while (true) {
12537 if (node.tag === HostComponent) {
12538 var instance = node.stateNode;
12539
12540 if (isHidden) {
12541 hideInstance(instance);
12542 } else {
12543 unhideInstance(node.stateNode, node.memoizedProps);
12544 }
12545 } else if (node.tag === HostText) {
12546 var _instance3 = node.stateNode;
12547
12548 if (isHidden) {
12549
12550 } else {
12551 unhideTextInstance(_instance3, node.memoizedProps);
12552 }
12553 } else if (node.tag === SuspenseComponent && node.memoizedState !== null && node.memoizedState.dehydrated === null) {
12554 // Found a nested Suspense component that timed out. Skip over the
12555 // primary child fragment, which should remain hidden.
12556 var fallbackChildFragment = node.child.sibling;
12557 fallbackChildFragment.return = node;
12558 node = fallbackChildFragment;
12559 continue;
12560 } else if (node.child !== null) {
12561 node.child.return = node;
12562 node = node.child;
12563 continue;
12564 }
12565
12566 if (node === finishedWork) {
12567 return;
12568 }
12569
12570 while (node.sibling === null) {
12571 if (node.return === null || node.return === finishedWork) {
12572 return;
12573 }
12574
12575 node = node.return;
12576 }
12577
12578 node.sibling.return = node.return;
12579 node = node.sibling;
12580 }
12581 }
12582}
12583
12584function commitAttachRef(finishedWork) {
12585 var ref = finishedWork.ref;
12586
12587 if (ref !== null) {
12588 var instance = finishedWork.stateNode;
12589 var instanceToUse;
12590
12591 switch (finishedWork.tag) {
12592 case HostComponent:
12593 instanceToUse = getPublicInstance(instance);
12594 break;
12595
12596 default:
12597 instanceToUse = instance;
12598 } // Moved outside to ensure DCE works with this flag
12599
12600
12601 if (enableScopeAPI && finishedWork.tag === ScopeComponent) {
12602 instanceToUse = instance.methods;
12603 }
12604
12605 if (typeof ref === 'function') {
12606 ref(instanceToUse);
12607 } else {
12608 {
12609 if (!ref.hasOwnProperty('current')) {
12610 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
12611 }
12612 }
12613
12614 ref.current = instanceToUse;
12615 }
12616 }
12617}
12618
12619function commitDetachRef(current$$1) {
12620 var currentRef = current$$1.ref;
12621
12622 if (currentRef !== null) {
12623 if (typeof currentRef === 'function') {
12624 currentRef(null);
12625 } else {
12626 currentRef.current = null;
12627 }
12628 }
12629} // User-originating errors (lifecycles and refs) should not interrupt
12630// deletion, so don't let them throw. Host-originating errors should
12631// interrupt deletion, so it's okay
12632
12633
12634function commitUnmount(finishedRoot, current$$1, renderPriorityLevel) {
12635 onCommitUnmount(current$$1);
12636
12637 switch (current$$1.tag) {
12638 case FunctionComponent:
12639 case ForwardRef:
12640 case MemoComponent:
12641 case SimpleMemoComponent:
12642 {
12643 var updateQueue = current$$1.updateQueue;
12644
12645 if (updateQueue !== null) {
12646 var lastEffect = updateQueue.lastEffect;
12647
12648 if (lastEffect !== null) {
12649 var firstEffect = lastEffect.next; // When the owner fiber is deleted, the destroy function of a passive
12650 // effect hook is called during the synchronous commit phase. This is
12651 // a concession to implementation complexity. Calling it in the
12652 // passive effect phase (like they usually are, when dependencies
12653 // change during an update) would require either traversing the
12654 // children of the deleted fiber again, or including unmount effects
12655 // as part of the fiber effect list.
12656 //
12657 // Because this is during the sync commit phase, we need to change
12658 // the priority.
12659 //
12660 // TODO: Reconsider this implementation trade off.
12661
12662 var priorityLevel = renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel;
12663 runWithPriority(priorityLevel, function () {
12664 var effect = firstEffect;
12665
12666 do {
12667 var destroy = effect.destroy;
12668
12669 if (destroy !== undefined) {
12670 safelyCallDestroy(current$$1, destroy);
12671 }
12672
12673 effect = effect.next;
12674 } while (effect !== firstEffect);
12675 });
12676 }
12677 }
12678
12679 break;
12680 }
12681
12682 case ClassComponent:
12683 {
12684 safelyDetachRef(current$$1);
12685 var instance = current$$1.stateNode;
12686
12687 if (typeof instance.componentWillUnmount === 'function') {
12688 safelyCallComponentWillUnmount(current$$1, instance);
12689 }
12690
12691 return;
12692 }
12693
12694 case HostComponent:
12695 {
12696 if (enableFlareAPI) {
12697 var dependencies = current$$1.dependencies;
12698
12699 if (dependencies !== null) {
12700 var respondersMap = dependencies.responders;
12701
12702 if (respondersMap !== null) {
12703 var responderInstances = Array.from(respondersMap.values());
12704
12705 for (var i = 0, length = responderInstances.length; i < length; i++) {
12706 var responderInstance = responderInstances[i];
12707 unmountResponderInstance(responderInstance);
12708 }
12709
12710 dependencies.responders = null;
12711 }
12712 }
12713 }
12714
12715 safelyDetachRef(current$$1);
12716 return;
12717 }
12718
12719 case HostPortal:
12720 {
12721 // TODO: this is recursive.
12722 // We are also not using this parent because
12723 // the portal will get pushed immediately.
12724 if (supportsMutation) {
12725 unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel);
12726 } else if (supportsPersistence) {
12727 emptyPortalContainer(current$$1);
12728 }
12729
12730 return;
12731 }
12732
12733 case FundamentalComponent:
12734 {
12735 if (enableFundamentalAPI) {
12736 var fundamentalInstance = current$$1.stateNode;
12737
12738 if (fundamentalInstance !== null) {
12739 unmountFundamentalComponent(fundamentalInstance);
12740 current$$1.stateNode = null;
12741 }
12742 }
12743
12744 return;
12745 }
12746
12747 case DehydratedFragment:
12748 {
12749 if (enableSuspenseCallback) {
12750 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
12751
12752 if (hydrationCallbacks !== null) {
12753 var onDeleted = hydrationCallbacks.onDeleted;
12754
12755 if (onDeleted) {
12756 onDeleted(current$$1.stateNode);
12757 }
12758 }
12759 }
12760
12761 return;
12762 }
12763
12764 case ScopeComponent:
12765 {
12766 if (enableScopeAPI) {
12767 safelyDetachRef(current$$1);
12768 }
12769 }
12770 }
12771}
12772
12773function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
12774 // While we're inside a removed host node we don't want to call
12775 // removeChild on the inner nodes because they're removed by the top
12776 // call anyway. We also want to call componentWillUnmount on all
12777 // composites before this host node is removed from the tree. Therefore
12778 // we do an inner loop while we're still inside the host node.
12779 var node = root;
12780
12781 while (true) {
12782 commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
12783 // Skip portals because commitUnmount() currently visits them recursively.
12784
12785 if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
12786 // If we don't use mutation we drill down into portals here instead.
12787 !supportsMutation || node.tag !== HostPortal)) {
12788 node.child.return = node;
12789 node = node.child;
12790 continue;
12791 }
12792
12793 if (node === root) {
12794 return;
12795 }
12796
12797 while (node.sibling === null) {
12798 if (node.return === null || node.return === root) {
12799 return;
12800 }
12801
12802 node = node.return;
12803 }
12804
12805 node.sibling.return = node.return;
12806 node = node.sibling;
12807 }
12808}
12809
12810function detachFiber(current$$1) {
12811 var alternate = current$$1.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
12812 // should clear the child pointer of the parent alternate to let this
12813 // get GC:ed but we don't know which for sure which parent is the current
12814 // one so we'll settle for GC:ing the subtree of this child. This child
12815 // itself will be GC:ed when the parent updates the next time.
12816
12817 current$$1.return = null;
12818 current$$1.child = null;
12819 current$$1.memoizedState = null;
12820 current$$1.updateQueue = null;
12821 current$$1.dependencies = null;
12822 current$$1.alternate = null;
12823 current$$1.firstEffect = null;
12824 current$$1.lastEffect = null;
12825 current$$1.pendingProps = null;
12826 current$$1.memoizedProps = null;
12827
12828 if (alternate !== null) {
12829 detachFiber(alternate);
12830 }
12831}
12832
12833function emptyPortalContainer(current$$1) {
12834 if (!supportsPersistence) {
12835 return;
12836 }
12837
12838 var portal = current$$1.stateNode;
12839 var containerInfo = portal.containerInfo;
12840 var emptyChildSet = createContainerChildSet(containerInfo);
12841 replaceContainerChildren(containerInfo, emptyChildSet);
12842}
12843
12844function commitContainer(finishedWork) {
12845 if (!supportsPersistence) {
12846 return;
12847 }
12848
12849 switch (finishedWork.tag) {
12850 case ClassComponent:
12851 case HostComponent:
12852 case HostText:
12853 case FundamentalComponent:
12854 {
12855 return;
12856 }
12857
12858 case HostRoot:
12859 case HostPortal:
12860 {
12861 var portalOrRoot = finishedWork.stateNode;
12862 var containerInfo = portalOrRoot.containerInfo,
12863 pendingChildren = portalOrRoot.pendingChildren;
12864 replaceContainerChildren(containerInfo, pendingChildren);
12865 return;
12866 }
12867
12868 default:
12869 {
12870 {
12871 {
12872 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.");
12873 }
12874 }
12875 }
12876 }
12877}
12878
12879function getHostParentFiber(fiber) {
12880 var parent = fiber.return;
12881
12882 while (parent !== null) {
12883 if (isHostParent(parent)) {
12884 return parent;
12885 }
12886
12887 parent = parent.return;
12888 }
12889
12890 {
12891 {
12892 throw Error("Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.");
12893 }
12894 }
12895}
12896
12897function isHostParent(fiber) {
12898 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
12899}
12900
12901function getHostSibling(fiber) {
12902 // We're going to search forward into the tree until we find a sibling host
12903 // node. Unfortunately, if multiple insertions are done in a row we have to
12904 // search past them. This leads to exponential search for the next sibling.
12905 // TODO: Find a more efficient way to do this.
12906 var node = fiber;
12907
12908 siblings: while (true) {
12909 // If we didn't find anything, let's try the next sibling.
12910 while (node.sibling === null) {
12911 if (node.return === null || isHostParent(node.return)) {
12912 // If we pop out of the root or hit the parent the fiber we are the
12913 // last sibling.
12914 return null;
12915 }
12916
12917 node = node.return;
12918 }
12919
12920 node.sibling.return = node.return;
12921 node = node.sibling;
12922
12923 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
12924 // If it is not host node and, we might have a host node inside it.
12925 // Try to search down until we find one.
12926 if (node.effectTag & Placement) {
12927 // If we don't have a child, try the siblings instead.
12928 continue siblings;
12929 } // If we don't have a child, try the siblings instead.
12930 // We also skip portals because they are not part of this host tree.
12931
12932
12933 if (node.child === null || node.tag === HostPortal) {
12934 continue siblings;
12935 } else {
12936 node.child.return = node;
12937 node = node.child;
12938 }
12939 } // Check if this host node is stable or about to be placed.
12940
12941
12942 if (!(node.effectTag & Placement)) {
12943 // Found it!
12944 return node.stateNode;
12945 }
12946 }
12947}
12948
12949function commitPlacement(finishedWork) {
12950 if (!supportsMutation) {
12951 return;
12952 } // Recursively insert all host nodes into the parent.
12953
12954
12955 var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
12956
12957 var parent;
12958 var isContainer;
12959 var parentStateNode = parentFiber.stateNode;
12960
12961 switch (parentFiber.tag) {
12962 case HostComponent:
12963 parent = parentStateNode;
12964 isContainer = false;
12965 break;
12966
12967 case HostRoot:
12968 parent = parentStateNode.containerInfo;
12969 isContainer = true;
12970 break;
12971
12972 case HostPortal:
12973 parent = parentStateNode.containerInfo;
12974 isContainer = true;
12975 break;
12976
12977 case FundamentalComponent:
12978 if (enableFundamentalAPI) {
12979 parent = parentStateNode.instance;
12980 isContainer = false;
12981 }
12982
12983 // eslint-disable-next-line-no-fallthrough
12984
12985 default:
12986 {
12987 {
12988 throw Error("Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.");
12989 }
12990 }
12991
12992 }
12993
12994 if (parentFiber.effectTag & ContentReset) {
12995 // Reset the text content of the parent before doing any insertions
12996 parentFiber.effectTag &= ~ContentReset;
12997 }
12998
12999 var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
13000 // children to find all the terminal nodes.
13001
13002 var node = finishedWork;
13003
13004 while (true) {
13005 var isHost = node.tag === HostComponent || node.tag === HostText;
13006
13007 if (isHost || enableFundamentalAPI && node.tag === FundamentalComponent) {
13008 var stateNode = isHost ? node.stateNode : node.stateNode.instance;
13009
13010 if (before) {
13011 if (isContainer) {
13012 insertInContainerBefore(parent, stateNode, before);
13013 } else {
13014 insertBefore(parent, stateNode, before);
13015 }
13016 } else {
13017 if (isContainer) {
13018 appendChildToContainer(parent, stateNode);
13019 } else {
13020 appendChild(parent, stateNode);
13021 }
13022 }
13023 } else if (node.tag === HostPortal) {// If the insertion itself is a portal, then we don't want to traverse
13024 // down its children. Instead, we'll get insertions from each child in
13025 // the portal directly.
13026 } else if (node.child !== null) {
13027 node.child.return = node;
13028 node = node.child;
13029 continue;
13030 }
13031
13032 if (node === finishedWork) {
13033 return;
13034 }
13035
13036 while (node.sibling === null) {
13037 if (node.return === null || node.return === finishedWork) {
13038 return;
13039 }
13040
13041 node = node.return;
13042 }
13043
13044 node.sibling.return = node.return;
13045 node = node.sibling;
13046 }
13047}
13048
13049function unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel) {
13050 // We only have the top Fiber that was deleted but we need to recurse down its
13051 // children to find all the terminal nodes.
13052 var node = current$$1; // Each iteration, currentParent is populated with node's host parent if not
13053 // currentParentIsValid.
13054
13055 var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
13056
13057 var currentParent;
13058 var currentParentIsContainer;
13059
13060 while (true) {
13061 if (!currentParentIsValid) {
13062 var parent = node.return;
13063
13064 findParent: while (true) {
13065 if (!(parent !== null)) {
13066 {
13067 throw Error("Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.");
13068 }
13069 }
13070
13071 var parentStateNode = parent.stateNode;
13072
13073 switch (parent.tag) {
13074 case HostComponent:
13075 currentParent = parentStateNode;
13076 currentParentIsContainer = false;
13077 break findParent;
13078
13079 case HostRoot:
13080 currentParent = parentStateNode.containerInfo;
13081 currentParentIsContainer = true;
13082 break findParent;
13083
13084 case HostPortal:
13085 currentParent = parentStateNode.containerInfo;
13086 currentParentIsContainer = true;
13087 break findParent;
13088
13089 case FundamentalComponent:
13090 if (enableFundamentalAPI) {
13091 currentParent = parentStateNode.instance;
13092 currentParentIsContainer = false;
13093 }
13094
13095 }
13096
13097 parent = parent.return;
13098 }
13099
13100 currentParentIsValid = true;
13101 }
13102
13103 if (node.tag === HostComponent || node.tag === HostText) {
13104 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
13105 // node from the tree.
13106
13107 if (currentParentIsContainer) {
13108 removeChildFromContainer(currentParent, node.stateNode);
13109 } else {
13110 removeChild(currentParent, node.stateNode);
13111 } // Don't visit children because we already visited them.
13112
13113 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
13114 var fundamentalNode = node.stateNode.instance;
13115 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
13116 // node from the tree.
13117
13118 if (currentParentIsContainer) {
13119 removeChildFromContainer(currentParent, fundamentalNode);
13120 } else {
13121 removeChild(currentParent, fundamentalNode);
13122 }
13123 } else if (enableSuspenseServerRenderer && node.tag === DehydratedFragment) {
13124 if (enableSuspenseCallback) {
13125 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
13126
13127 if (hydrationCallbacks !== null) {
13128 var onDeleted = hydrationCallbacks.onDeleted;
13129
13130 if (onDeleted) {
13131 onDeleted(node.stateNode);
13132 }
13133 }
13134 } // Delete the dehydrated suspense boundary and all of its content.
13135
13136
13137 if (currentParentIsContainer) {
13138 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);
13139 } else {
13140 clearSuspenseBoundary(currentParent, node.stateNode);
13141 }
13142 } else if (node.tag === HostPortal) {
13143 if (node.child !== null) {
13144 // When we go into a portal, it becomes the parent to remove from.
13145 // We will reassign it back when we pop the portal on the way up.
13146 currentParent = node.stateNode.containerInfo;
13147 currentParentIsContainer = true; // Visit children because portals might contain host components.
13148
13149 node.child.return = node;
13150 node = node.child;
13151 continue;
13152 }
13153 } else {
13154 commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
13155
13156 if (node.child !== null) {
13157 node.child.return = node;
13158 node = node.child;
13159 continue;
13160 }
13161 }
13162
13163 if (node === current$$1) {
13164 return;
13165 }
13166
13167 while (node.sibling === null) {
13168 if (node.return === null || node.return === current$$1) {
13169 return;
13170 }
13171
13172 node = node.return;
13173
13174 if (node.tag === HostPortal) {
13175 // When we go out of the portal, we need to restore the parent.
13176 // Since we don't keep a stack of them, we will search for it.
13177 currentParentIsValid = false;
13178 }
13179 }
13180
13181 node.sibling.return = node.return;
13182 node = node.sibling;
13183 }
13184}
13185
13186function commitDeletion(finishedRoot, current$$1, renderPriorityLevel) {
13187 if (supportsMutation) {
13188 // Recursively delete all host nodes from the parent.
13189 // Detach refs and call componentWillUnmount() on the whole subtree.
13190 unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel);
13191 } else {
13192 // Detach refs and call componentWillUnmount() on the whole subtree.
13193 commitNestedUnmounts(finishedRoot, current$$1, renderPriorityLevel);
13194 }
13195
13196 detachFiber(current$$1);
13197}
13198
13199function commitWork(current$$1, finishedWork) {
13200 if (!supportsMutation) {
13201 switch (finishedWork.tag) {
13202 case FunctionComponent:
13203 case ForwardRef:
13204 case MemoComponent:
13205 case SimpleMemoComponent:
13206 {
13207 // Note: We currently never use MountMutation, but useLayout uses
13208 // UnmountMutation.
13209 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
13210 return;
13211 }
13212
13213 case Profiler:
13214 {
13215 return;
13216 }
13217
13218 case SuspenseComponent:
13219 {
13220 commitSuspenseComponent(finishedWork);
13221 attachSuspenseRetryListeners(finishedWork);
13222 return;
13223 }
13224
13225 case SuspenseListComponent:
13226 {
13227 attachSuspenseRetryListeners(finishedWork);
13228 return;
13229 }
13230
13231 case HostRoot:
13232 {
13233 if (supportsHydration) {
13234 var root = finishedWork.stateNode;
13235
13236 if (root.hydrate) {
13237 // We've just hydrated. No need to hydrate again.
13238 root.hydrate = false;
13239 commitHydratedContainer(root.containerInfo);
13240 }
13241 }
13242
13243 break;
13244 }
13245 }
13246
13247 commitContainer(finishedWork);
13248 return;
13249 }
13250
13251 switch (finishedWork.tag) {
13252 case FunctionComponent:
13253 case ForwardRef:
13254 case MemoComponent:
13255 case SimpleMemoComponent:
13256 {
13257 // Note: We currently never use MountMutation, but useLayout uses
13258 // UnmountMutation.
13259 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
13260 return;
13261 }
13262
13263 case ClassComponent:
13264 {
13265 return;
13266 }
13267
13268 case HostComponent:
13269 {
13270 var instance = finishedWork.stateNode;
13271
13272 if (instance != null) {
13273 // Commit the work prepared earlier.
13274 var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
13275 // as the newProps. The updatePayload will contain the real change in
13276 // this case.
13277
13278 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
13279 var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
13280
13281 var updatePayload = finishedWork.updateQueue;
13282 finishedWork.updateQueue = null;
13283
13284 if (updatePayload !== null) {
13285 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
13286 }
13287
13288 if (enableFlareAPI) {
13289 var prevListeners = oldProps.listeners;
13290 var nextListeners = newProps.listeners;
13291
13292 if (prevListeners !== nextListeners) {
13293 updateEventListeners(nextListeners, finishedWork, null);
13294 }
13295 }
13296 }
13297
13298 return;
13299 }
13300
13301 case HostText:
13302 {
13303 if (!(finishedWork.stateNode !== null)) {
13304 {
13305 throw Error("This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue.");
13306 }
13307 }
13308
13309 var textInstance = finishedWork.stateNode;
13310 var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
13311 // as the newProps. The updatePayload will contain the real change in
13312 // this case.
13313
13314 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
13315 return;
13316 }
13317
13318 case HostRoot:
13319 {
13320 if (supportsHydration) {
13321 var _root = finishedWork.stateNode;
13322
13323 if (_root.hydrate) {
13324 // We've just hydrated. No need to hydrate again.
13325 _root.hydrate = false;
13326 commitHydratedContainer(_root.containerInfo);
13327 }
13328 }
13329
13330 return;
13331 }
13332
13333 case Profiler:
13334 {
13335 return;
13336 }
13337
13338 case SuspenseComponent:
13339 {
13340 commitSuspenseComponent(finishedWork);
13341 attachSuspenseRetryListeners(finishedWork);
13342 return;
13343 }
13344
13345 case SuspenseListComponent:
13346 {
13347 attachSuspenseRetryListeners(finishedWork);
13348 return;
13349 }
13350
13351 case IncompleteClassComponent:
13352 {
13353 return;
13354 }
13355
13356 case FundamentalComponent:
13357 {
13358 if (enableFundamentalAPI) {
13359 var fundamentalInstance = finishedWork.stateNode;
13360 updateFundamentalComponent(fundamentalInstance);
13361 }
13362
13363 return;
13364 }
13365
13366 case ScopeComponent:
13367 {
13368 if (enableScopeAPI) {
13369 var scopeInstance = finishedWork.stateNode;
13370 scopeInstance.fiber = finishedWork;
13371
13372 if (enableFlareAPI) {
13373 var _newProps = finishedWork.memoizedProps;
13374
13375 var _oldProps = current$$1 !== null ? current$$1.memoizedProps : _newProps;
13376
13377 var _prevListeners = _oldProps.listeners;
13378 var _nextListeners = _newProps.listeners;
13379
13380 if (_prevListeners !== _nextListeners) {
13381 updateEventListeners(_nextListeners, finishedWork, null);
13382 }
13383 }
13384 }
13385
13386 return;
13387 }
13388
13389 default:
13390 {
13391 {
13392 {
13393 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.");
13394 }
13395 }
13396 }
13397 }
13398}
13399
13400function commitSuspenseComponent(finishedWork) {
13401 var newState = finishedWork.memoizedState;
13402 var newDidTimeout;
13403 var primaryChildParent = finishedWork;
13404
13405 if (newState === null) {
13406 newDidTimeout = false;
13407 } else {
13408 newDidTimeout = true;
13409 primaryChildParent = finishedWork.child;
13410 markCommitTimeOfFallback();
13411 }
13412
13413 if (supportsMutation && primaryChildParent !== null) {
13414 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
13415 }
13416
13417 if (enableSuspenseCallback && newState !== null) {
13418 var suspenseCallback = finishedWork.memoizedProps.suspenseCallback;
13419
13420 if (typeof suspenseCallback === 'function') {
13421 var thenables = finishedWork.updateQueue;
13422
13423 if (thenables !== null) {
13424 suspenseCallback(new Set(thenables));
13425 }
13426 } else {
13427 if (suspenseCallback !== undefined) {
13428 warning$1(false, 'Unexpected type for suspenseCallback.');
13429 }
13430 }
13431 }
13432}
13433
13434function commitSuspenseHydrationCallbacks(finishedRoot, finishedWork) {
13435 if (!supportsHydration) {
13436 return;
13437 }
13438
13439 var newState = finishedWork.memoizedState;
13440
13441 if (newState === null) {
13442 var current$$1 = finishedWork.alternate;
13443
13444 if (current$$1 !== null) {
13445 var prevState = current$$1.memoizedState;
13446
13447 if (prevState !== null) {
13448 var suspenseInstance = prevState.dehydrated;
13449
13450 if (suspenseInstance !== null) {
13451 commitHydratedSuspenseInstance(suspenseInstance);
13452
13453 if (enableSuspenseCallback) {
13454 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
13455
13456 if (hydrationCallbacks !== null) {
13457 var onHydrated = hydrationCallbacks.onHydrated;
13458
13459 if (onHydrated) {
13460 onHydrated(suspenseInstance);
13461 }
13462 }
13463 }
13464 }
13465 }
13466 }
13467 }
13468}
13469
13470function attachSuspenseRetryListeners(finishedWork) {
13471 // If this boundary just timed out, then it will have a set of thenables.
13472 // For each thenable, attach a listener so that when it resolves, React
13473 // attempts to re-render the boundary in the primary (pre-timeout) state.
13474 var thenables = finishedWork.updateQueue;
13475
13476 if (thenables !== null) {
13477 finishedWork.updateQueue = null;
13478 var retryCache = finishedWork.stateNode;
13479
13480 if (retryCache === null) {
13481 retryCache = finishedWork.stateNode = new PossiblyWeakSet();
13482 }
13483
13484 thenables.forEach(function (thenable) {
13485 // Memoize using the boundary fiber to prevent redundant listeners.
13486 var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
13487
13488 if (!retryCache.has(thenable)) {
13489 if (enableSchedulerTracing) {
13490 if (thenable.__reactDoNotTraceInteractions !== true) {
13491 retry = tracing.unstable_wrap(retry);
13492 }
13493 }
13494
13495 retryCache.add(thenable);
13496 thenable.then(retry, retry);
13497 }
13498 });
13499 }
13500}
13501
13502function commitResetTextContent(current$$1) {
13503 if (!supportsMutation) {
13504 return;
13505 }
13506
13507 resetTextContent(current$$1.stateNode);
13508}
13509
13510var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
13511
13512function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
13513 var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
13514
13515 update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
13516 // being called "element".
13517
13518 update.payload = {
13519 element: null
13520 };
13521 var error = errorInfo.value;
13522
13523 update.callback = function () {
13524 onUncaughtError(error);
13525 logError(fiber, errorInfo);
13526 };
13527
13528 return update;
13529}
13530
13531function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
13532 var update = createUpdate(expirationTime, null);
13533 update.tag = CaptureUpdate;
13534 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
13535
13536 if (typeof getDerivedStateFromError === 'function') {
13537 var error = errorInfo.value;
13538
13539 update.payload = function () {
13540 logError(fiber, errorInfo);
13541 return getDerivedStateFromError(error);
13542 };
13543 }
13544
13545 var inst = fiber.stateNode;
13546
13547 if (inst !== null && typeof inst.componentDidCatch === 'function') {
13548 update.callback = function callback() {
13549 {
13550 markFailedErrorBoundaryForHotReloading(fiber);
13551 }
13552
13553 if (typeof getDerivedStateFromError !== 'function') {
13554 // To preserve the preexisting retry behavior of error boundaries,
13555 // we keep track of which ones already failed during this batch.
13556 // This gets reset before we yield back to the browser.
13557 // TODO: Warn in strict mode if getDerivedStateFromError is
13558 // not defined.
13559 markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
13560
13561 logError(fiber, errorInfo);
13562 }
13563
13564 var error = errorInfo.value;
13565 var stack = errorInfo.stack;
13566 this.componentDidCatch(error, {
13567 componentStack: stack !== null ? stack : ''
13568 });
13569
13570 {
13571 if (typeof getDerivedStateFromError !== 'function') {
13572 // If componentDidCatch is the only error boundary method defined,
13573 // then it needs to call setState to recover from errors.
13574 // If no state update is scheduled then the boundary will swallow the error.
13575 !(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;
13576 }
13577 }
13578 };
13579 } else {
13580 update.callback = function () {
13581 markFailedErrorBoundaryForHotReloading(fiber);
13582 };
13583 }
13584
13585 return update;
13586}
13587
13588function attachPingListener(root, renderExpirationTime, thenable) {
13589 // Attach a listener to the promise to "ping" the root and retry. But
13590 // only if one does not already exist for the current render expiration
13591 // time (which acts like a "thread ID" here).
13592 var pingCache = root.pingCache;
13593 var threadIDs;
13594
13595 if (pingCache === null) {
13596 pingCache = root.pingCache = new PossiblyWeakMap();
13597 threadIDs = new Set();
13598 pingCache.set(thenable, threadIDs);
13599 } else {
13600 threadIDs = pingCache.get(thenable);
13601
13602 if (threadIDs === undefined) {
13603 threadIDs = new Set();
13604 pingCache.set(thenable, threadIDs);
13605 }
13606 }
13607
13608 if (!threadIDs.has(renderExpirationTime)) {
13609 // Memoize using the thread ID to prevent redundant listeners.
13610 threadIDs.add(renderExpirationTime);
13611 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
13612 thenable.then(ping, ping);
13613 }
13614}
13615
13616function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
13617 // The source fiber did not complete.
13618 sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
13619
13620 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
13621
13622 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
13623 // This is a thenable.
13624 var thenable = value;
13625 checkForWrongSuspensePriorityInDEV(sourceFiber);
13626 var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
13627
13628 var _workInProgress = returnFiber;
13629
13630 do {
13631 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
13632 // Found the nearest boundary.
13633 // Stash the promise on the boundary fiber. If the boundary times out, we'll
13634 // attach another listener to flip the boundary back to its normal state.
13635 var thenables = _workInProgress.updateQueue;
13636
13637 if (thenables === null) {
13638 var updateQueue = new Set();
13639 updateQueue.add(thenable);
13640 _workInProgress.updateQueue = updateQueue;
13641 } else {
13642 thenables.add(thenable);
13643 } // If the boundary is outside of batched mode, we should *not*
13644 // suspend the commit. Pretend as if the suspended component rendered
13645 // null and keep rendering. In the commit phase, we'll schedule a
13646 // subsequent synchronous update to re-render the Suspense.
13647 //
13648 // Note: It doesn't matter whether the component that suspended was
13649 // inside a batched mode tree. If the Suspense is outside of it, we
13650 // should *not* suspend the commit.
13651
13652
13653 if ((_workInProgress.mode & BatchedMode) === NoMode) {
13654 _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
13655 // But we shouldn't call any lifecycle methods or callbacks. Remove
13656 // all lifecycle effect tags.
13657
13658 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
13659
13660 if (sourceFiber.tag === ClassComponent) {
13661 var currentSourceFiber = sourceFiber.alternate;
13662
13663 if (currentSourceFiber === null) {
13664 // This is a new mount. Change the tag so it's not mistaken for a
13665 // completed class component. For example, we should not call
13666 // componentWillUnmount if it is deleted.
13667 sourceFiber.tag = IncompleteClassComponent;
13668 } else {
13669 // When we try rendering again, we should not reuse the current fiber,
13670 // since it's known to be in an inconsistent state. Use a force update to
13671 // prevent a bail out.
13672 var update = createUpdate(Sync, null);
13673 update.tag = ForceUpdate;
13674 enqueueUpdate(sourceFiber, update);
13675 }
13676 } // The source fiber did not complete. Mark it with Sync priority to
13677 // indicate that it still has pending work.
13678
13679
13680 sourceFiber.expirationTime = Sync; // Exit without suspending.
13681
13682 return;
13683 } // Confirmed that the boundary is in a concurrent mode tree. Continue
13684 // with the normal suspend path.
13685 //
13686 // After this we'll use a set of heuristics to determine whether this
13687 // render pass will run to completion or restart or "suspend" the commit.
13688 // The actual logic for this is spread out in different places.
13689 //
13690 // This first principle is that if we're going to suspend when we complete
13691 // a root, then we should also restart if we get an update or ping that
13692 // might unsuspend it, and vice versa. The only reason to suspend is
13693 // because you think you might want to restart before committing. However,
13694 // it doesn't make sense to restart only while in the period we're suspended.
13695 //
13696 // Restarting too aggressively is also not good because it starves out any
13697 // intermediate loading state. So we use heuristics to determine when.
13698 // Suspense Heuristics
13699 //
13700 // If nothing threw a Promise or all the same fallbacks are already showing,
13701 // then don't suspend/restart.
13702 //
13703 // If this is an initial render of a new tree of Suspense boundaries and
13704 // those trigger a fallback, then don't suspend/restart. We want to ensure
13705 // that we can show the initial loading state as quickly as possible.
13706 //
13707 // If we hit a "Delayed" case, such as when we'd switch from content back into
13708 // a fallback, then we should always suspend/restart. SuspenseConfig applies to
13709 // this case. If none is defined, JND is used instead.
13710 //
13711 // If we're already showing a fallback and it gets "retried", allowing us to show
13712 // another level, but there's still an inner boundary that would show a fallback,
13713 // then we suspend/restart for 500ms since the last time we showed a fallback
13714 // anywhere in the tree. This effectively throttles progressive loading into a
13715 // consistent train of commits. This also gives us an opportunity to restart to
13716 // get to the completed state slightly earlier.
13717 //
13718 // If there's ambiguity due to batching it's resolved in preference of:
13719 // 1) "delayed", 2) "initial render", 3) "retry".
13720 //
13721 // We want to ensure that a "busy" state doesn't get force committed. We want to
13722 // ensure that new initial loading states can commit as soon as possible.
13723
13724
13725 attachPingListener(root, renderExpirationTime, thenable);
13726 _workInProgress.effectTag |= ShouldCapture;
13727 _workInProgress.expirationTime = renderExpirationTime;
13728 return;
13729 } // This boundary already captured during this render. Continue to the next
13730 // boundary.
13731
13732
13733 _workInProgress = _workInProgress.return;
13734 } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
13735 // TODO: Use invariant so the message is stripped in prod?
13736
13737
13738 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));
13739 } // We didn't find a boundary that could handle this type of exception. Start
13740 // over and traverse parent path again, this time treating the exception
13741 // as an error.
13742
13743
13744 renderDidError();
13745 value = createCapturedValue(value, sourceFiber);
13746 var workInProgress = returnFiber;
13747
13748 do {
13749 switch (workInProgress.tag) {
13750 case HostRoot:
13751 {
13752 var _errorInfo = value;
13753 workInProgress.effectTag |= ShouldCapture;
13754 workInProgress.expirationTime = renderExpirationTime;
13755
13756 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
13757
13758 enqueueCapturedUpdate(workInProgress, _update);
13759 return;
13760 }
13761
13762 case ClassComponent:
13763 // Capture and retry
13764 var errorInfo = value;
13765 var ctor = workInProgress.type;
13766 var instance = workInProgress.stateNode;
13767
13768 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
13769 workInProgress.effectTag |= ShouldCapture;
13770 workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
13771
13772 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
13773
13774 enqueueCapturedUpdate(workInProgress, _update2);
13775 return;
13776 }
13777
13778 break;
13779
13780 default:
13781 break;
13782 }
13783
13784 workInProgress = workInProgress.return;
13785 } while (workInProgress !== null);
13786}
13787
13788var ceil = Math.ceil;
13789var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
13790var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
13791var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
13792var NoContext =
13793/* */
137940;
13795var BatchedContext =
13796/* */
137971;
13798var DiscreteEventContext =
13799/* */
138004;
13801var LegacyUnbatchedContext =
13802/* */
138038;
13804var RenderContext =
13805/* */
1380616;
13807var CommitContext =
13808/* */
1380932;
13810var RootIncomplete = 0;
13811var RootFatalErrored = 1;
13812var RootErrored = 2;
13813var RootSuspended = 3;
13814var RootSuspendedWithDelay = 4;
13815var RootCompleted = 5;
13816// Describes where we are in the React execution stack
13817var executionContext = NoContext; // The root we're working on
13818
13819var workInProgressRoot = null; // The fiber we're working on
13820
13821var workInProgress = null; // The expiration time we're rendering
13822
13823var renderExpirationTime = NoWork; // Whether to root completed, errored, suspended, etc.
13824
13825var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
13826
13827var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
13828// This is conceptually a time stamp but expressed in terms of an ExpirationTime
13829// because we deal mostly with expiration times in the hot path, so this avoids
13830// the conversion happening in the hot path.
13831
13832var workInProgressRootLatestProcessedExpirationTime = Sync;
13833var workInProgressRootLatestSuspenseTimeout = Sync;
13834var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
13835// includes unprocessed updates, not work in bailed out children.
13836
13837var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
13838// This flag determines if it might be worthwhile to restart if an opportunity
13839// happens latere.
13840
13841var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
13842// model where we don't commit new loading states in too quick succession.
13843
13844var globalMostRecentFallbackTime = 0;
13845var FALLBACK_THROTTLE_MS = 500;
13846var nextEffect = null;
13847var hasUncaughtError = false;
13848var firstUncaughtError = null;
13849var legacyErrorBoundariesThatAlreadyFailed = null;
13850var rootDoesHavePassiveEffects = false;
13851var rootWithPendingPassiveEffects = null;
13852var pendingPassiveEffectsRenderPriority = NoPriority;
13853var pendingPassiveEffectsExpirationTime = NoWork;
13854var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
13855
13856var NESTED_UPDATE_LIMIT = 50;
13857var nestedUpdateCount = 0;
13858var rootWithNestedUpdates = null;
13859var NESTED_PASSIVE_UPDATE_LIMIT = 50;
13860var nestedPassiveUpdateCount = 0;
13861var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
13862// during the commit phase. This enables them to be traced across components
13863// that spawn new work during render. E.g. hidden boundaries, suspended SSR
13864// hydration or SuspenseList.
13865
13866var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
13867// time). However, if two updates are scheduled within the same event, we
13868// should treat their start times as simultaneous, even if the actual clock
13869// time has advanced between the first and second call.
13870// In other words, because expiration times determine how updates are batched,
13871// we want all updates of like priority that occur within the same event to
13872// receive the same expiration time. Otherwise we get tearing.
13873
13874var currentEventTime = NoWork;
13875function requestCurrentTimeForUpdate() {
13876 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
13877 // We're inside React, so it's fine to read the actual time.
13878 return msToExpirationTime(now());
13879 } // We're not inside React, so we may be in the middle of a browser event.
13880
13881
13882 if (currentEventTime !== NoWork) {
13883 // Use the same start time for all updates until we enter React again.
13884 return currentEventTime;
13885 } // This is the first update since React yielded. Compute a new start time.
13886
13887
13888 currentEventTime = msToExpirationTime(now());
13889 return currentEventTime;
13890}
13891function getCurrentTime() {
13892 return msToExpirationTime(now());
13893}
13894function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
13895 var mode = fiber.mode;
13896
13897 if ((mode & BatchedMode) === NoMode) {
13898 return Sync;
13899 }
13900
13901 var priorityLevel = getCurrentPriorityLevel();
13902
13903 if ((mode & ConcurrentMode) === NoMode) {
13904 return priorityLevel === ImmediatePriority ? Sync : Batched;
13905 }
13906
13907 if ((executionContext & RenderContext) !== NoContext) {
13908 // Use whatever time we're already rendering
13909 // TODO: Should there be a way to opt out, like with `runWithPriority`?
13910 return renderExpirationTime;
13911 }
13912
13913 var expirationTime;
13914
13915 if (suspenseConfig !== null) {
13916 // Compute an expiration time based on the Suspense timeout.
13917 expirationTime = computeSuspenseExpiration(currentTime, suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
13918 } else {
13919 // Compute an expiration time based on the Scheduler priority.
13920 switch (priorityLevel) {
13921 case ImmediatePriority:
13922 expirationTime = Sync;
13923 break;
13924
13925 case UserBlockingPriority:
13926 // TODO: Rename this to computeUserBlockingExpiration
13927 expirationTime = computeInteractiveExpiration(currentTime);
13928 break;
13929
13930 case NormalPriority:
13931 case LowPriority:
13932 // TODO: Handle LowPriority
13933 // TODO: Rename this to... something better.
13934 expirationTime = computeAsyncExpiration(currentTime);
13935 break;
13936
13937 case IdlePriority:
13938 expirationTime = Idle;
13939 break;
13940
13941 default:
13942 {
13943 {
13944 throw Error("Expected a valid priority level");
13945 }
13946 }
13947
13948 }
13949 } // If we're in the middle of rendering a tree, do not update at the same
13950 // expiration time that is already rendering.
13951 // TODO: We shouldn't have to do this if the update is on a different root.
13952 // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
13953 // the root when we check for this condition.
13954
13955
13956 if (workInProgressRoot !== null && expirationTime === renderExpirationTime) {
13957 // This is a trick to move this update into a separate batch
13958 expirationTime -= 1;
13959 }
13960
13961 return expirationTime;
13962}
13963function scheduleUpdateOnFiber(fiber, expirationTime) {
13964 checkForNestedUpdates();
13965 warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber);
13966 var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
13967
13968 if (root === null) {
13969 warnAboutUpdateOnUnmountedFiberInDEV(fiber);
13970 return;
13971 }
13972
13973 checkForInterruption(fiber, expirationTime);
13974 recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
13975 // priority as an argument to that function and this one.
13976
13977 var priorityLevel = getCurrentPriorityLevel();
13978
13979 if (expirationTime === Sync) {
13980 if ( // Check if we're inside unbatchedUpdates
13981 (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
13982 (executionContext & (RenderContext | CommitContext)) === NoContext) {
13983 // Register pending interactions on the root to avoid losing traced interaction data.
13984 schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
13985 // root inside of batchedUpdates should be synchronous, but layout updates
13986 // should be deferred until the end of the batch.
13987
13988 performSyncWorkOnRoot(root);
13989 } else {
13990 ensureRootIsScheduled(root);
13991 schedulePendingInteractions(root, expirationTime);
13992
13993 if (executionContext === NoContext) {
13994 // Flush the synchronous work now, unless we're already working or inside
13995 // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
13996 // scheduleCallbackForFiber to preserve the ability to schedule a callback
13997 // without immediately flushing it. We only do this for user-initiated
13998 // updates, to preserve historical behavior of sync mode.
13999 flushSyncCallbackQueue();
14000 }
14001 }
14002 } else {
14003 ensureRootIsScheduled(root);
14004 schedulePendingInteractions(root, expirationTime);
14005 }
14006
14007 if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
14008 // discrete, even inside a discrete event.
14009 priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority)) {
14010 // This is the result of a discrete event. Track the lowest priority
14011 // discrete update per root so we can flush them early, if needed.
14012 if (rootsWithPendingDiscreteUpdates === null) {
14013 rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
14014 } else {
14015 var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
14016
14017 if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
14018 rootsWithPendingDiscreteUpdates.set(root, expirationTime);
14019 }
14020 }
14021 }
14022}
14023var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
14024// work without treating it as a typical update that originates from an event;
14025// e.g. retrying a Suspense boundary isn't an update, but it does schedule work
14026// on a fiber.
14027
14028function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
14029 // Update the source fiber's expiration time
14030 if (fiber.expirationTime < expirationTime) {
14031 fiber.expirationTime = expirationTime;
14032 }
14033
14034 var alternate = fiber.alternate;
14035
14036 if (alternate !== null && alternate.expirationTime < expirationTime) {
14037 alternate.expirationTime = expirationTime;
14038 } // Walk the parent path to the root and update the child expiration time.
14039
14040
14041 var node = fiber.return;
14042 var root = null;
14043
14044 if (node === null && fiber.tag === HostRoot) {
14045 root = fiber.stateNode;
14046 } else {
14047 while (node !== null) {
14048 alternate = node.alternate;
14049
14050 if (node.childExpirationTime < expirationTime) {
14051 node.childExpirationTime = expirationTime;
14052
14053 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
14054 alternate.childExpirationTime = expirationTime;
14055 }
14056 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
14057 alternate.childExpirationTime = expirationTime;
14058 }
14059
14060 if (node.return === null && node.tag === HostRoot) {
14061 root = node.stateNode;
14062 break;
14063 }
14064
14065 node = node.return;
14066 }
14067 }
14068
14069 if (root !== null) {
14070 if (workInProgressRoot === root) {
14071 // Received an update to a tree that's in the middle of rendering. Mark
14072 // that's unprocessed work on this root.
14073 markUnprocessedUpdateTime(expirationTime);
14074
14075 if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
14076 // The root already suspended with a delay, which means this render
14077 // definitely won't finish. Since we have a new update, let's mark it as
14078 // suspended now, right before marking the incoming update. This has the
14079 // effect of interrupting the current render and switching to the update.
14080 // TODO: This happens to work when receiving an update during the render
14081 // phase, because of the trick inside computeExpirationForFiber to
14082 // subtract 1 from `renderExpirationTime` to move it into a
14083 // separate bucket. But we should probably model it with an exception,
14084 // using the same mechanism we use to force hydration of a subtree.
14085 // TODO: This does not account for low pri updates that were already
14086 // scheduled before the root started rendering. Need to track the next
14087 // pending expiration time (perhaps by backtracking the return path) and
14088 // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
14089 markRootSuspendedAtTime(root, renderExpirationTime);
14090 }
14091 } // Mark that the root has a pending update.
14092
14093
14094 markRootUpdatedAtTime(root, expirationTime);
14095 }
14096
14097 return root;
14098}
14099
14100function getNextRootExpirationTimeToWorkOn(root) {
14101 // Determines the next expiration time that the root should render, taking
14102 // into account levels that may be suspended, or levels that may have
14103 // received a ping.
14104 var lastExpiredTime = root.lastExpiredTime;
14105
14106 if (lastExpiredTime !== NoWork) {
14107 return lastExpiredTime;
14108 } // "Pending" refers to any update that hasn't committed yet, including if it
14109 // suspended. The "suspended" range is therefore a subset.
14110
14111
14112 var firstPendingTime = root.firstPendingTime;
14113
14114 if (!isRootSuspendedAtTime(root, firstPendingTime)) {
14115 // The highest priority pending time is not suspended. Let's work on that.
14116 return firstPendingTime;
14117 } // If the first pending time is suspended, check if there's a lower priority
14118 // pending level that we know about. Or check if we received a ping. Work
14119 // on whichever is higher priority.
14120
14121
14122 var lastPingedTime = root.lastPingedTime;
14123 var nextKnownPendingLevel = root.nextKnownPendingLevel;
14124 return lastPingedTime > nextKnownPendingLevel ? lastPingedTime : nextKnownPendingLevel;
14125} // Use this function to schedule a task for a root. There's only one task per
14126// root; if a task was already scheduled, we'll check to make sure the
14127// expiration time of the existing task is the same as the expiration time of
14128// the next level that the root has work on. This function is called on every
14129// update, and right before exiting a task.
14130
14131
14132function ensureRootIsScheduled(root) {
14133 var lastExpiredTime = root.lastExpiredTime;
14134
14135 if (lastExpiredTime !== NoWork) {
14136 // Special case: Expired work should flush synchronously.
14137 root.callbackExpirationTime = Sync;
14138 root.callbackPriority = ImmediatePriority;
14139 root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
14140 return;
14141 }
14142
14143 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
14144 var existingCallbackNode = root.callbackNode;
14145
14146 if (expirationTime === NoWork) {
14147 // There's nothing to work on.
14148 if (existingCallbackNode !== null) {
14149 root.callbackNode = null;
14150 root.callbackExpirationTime = NoWork;
14151 root.callbackPriority = NoPriority;
14152 }
14153
14154 return;
14155 } // TODO: If this is an update, we already read the current time. Pass the
14156 // time as an argument.
14157
14158
14159 var currentTime = requestCurrentTimeForUpdate();
14160 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
14161 // expiration time. Otherwise, we'll cancel it and schedule a new one.
14162
14163 if (existingCallbackNode !== null) {
14164 var existingCallbackPriority = root.callbackPriority;
14165 var existingCallbackExpirationTime = root.callbackExpirationTime;
14166
14167 if ( // Callback must have the exact same expiration time.
14168 existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
14169 existingCallbackPriority >= priorityLevel) {
14170 // Existing callback is sufficient.
14171 return;
14172 } // Need to schedule a new task.
14173 // TODO: Instead of scheduling a new task, we should be able to change the
14174 // priority of the existing one.
14175
14176
14177 cancelCallback(existingCallbackNode);
14178 }
14179
14180 root.callbackExpirationTime = expirationTime;
14181 root.callbackPriority = priorityLevel;
14182 var callbackNode;
14183
14184 if (expirationTime === Sync) {
14185 // Sync React callbacks are scheduled on a special internal queue
14186 callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
14187 } else if (disableSchedulerTimeoutBasedOnReactExpirationTime) {
14188 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root));
14189 } else {
14190 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
14191 // ordering because tasks are processed in timeout order.
14192 {
14193 timeout: expirationTimeToMs(expirationTime) - now()
14194 });
14195 }
14196
14197 root.callbackNode = callbackNode;
14198} // This is the entry point for every concurrent task, i.e. anything that
14199// goes through Scheduler.
14200
14201
14202function performConcurrentWorkOnRoot(root, didTimeout) {
14203 // Since we know we're in a React event, we can clear the current
14204 // event time. The next update will compute a new event time.
14205 currentEventTime = NoWork;
14206
14207 if (didTimeout) {
14208 // The render task took too long to complete. Mark the current time as
14209 // expired to synchronously render all expired work in a single batch.
14210 var currentTime = requestCurrentTimeForUpdate();
14211 markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
14212
14213 ensureRootIsScheduled(root);
14214 return null;
14215 } // Determine the next expiration time to work on, using the fields stored
14216 // on the root.
14217
14218
14219 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
14220
14221 if (expirationTime !== NoWork) {
14222 var originalCallbackNode = root.callbackNode;
14223
14224 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14225 {
14226 throw Error("Should not already be working.");
14227 }
14228 }
14229
14230 flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
14231 // and prepare a fresh one. Otherwise we'll continue where we left off.
14232
14233 if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
14234 prepareFreshStack(root, expirationTime);
14235 startWorkOnPendingInteractions(root, expirationTime);
14236 } // If we have a work-in-progress fiber, it means there's still work to do
14237 // in this root.
14238
14239
14240 if (workInProgress !== null) {
14241 var prevExecutionContext = executionContext;
14242 executionContext |= RenderContext;
14243 var prevDispatcher = pushDispatcher(root);
14244 var prevInteractions = pushInteractions(root);
14245 startWorkLoopTimer(workInProgress);
14246
14247 do {
14248 try {
14249 workLoopConcurrent();
14250 break;
14251 } catch (thrownValue) {
14252 handleError(root, thrownValue);
14253 }
14254 } while (true);
14255
14256 resetContextDependencies();
14257 executionContext = prevExecutionContext;
14258 popDispatcher(prevDispatcher);
14259
14260 if (enableSchedulerTracing) {
14261 popInteractions(prevInteractions);
14262 }
14263
14264 if (workInProgressRootExitStatus === RootFatalErrored) {
14265 var fatalError = workInProgressRootFatalError;
14266 stopInterruptedWorkLoopTimer();
14267 prepareFreshStack(root, expirationTime);
14268 markRootSuspendedAtTime(root, expirationTime);
14269 ensureRootIsScheduled(root);
14270 throw fatalError;
14271 }
14272
14273 if (workInProgress !== null) {
14274 // There's still work left over. Exit without committing.
14275 stopInterruptedWorkLoopTimer();
14276 } else {
14277 // We now have a consistent tree. The next step is either to commit it,
14278 // or, if something suspended, wait to commit it after a timeout.
14279 stopFinishedWorkLoopTimer();
14280 var finishedWork = root.finishedWork = root.current.alternate;
14281 root.finishedExpirationTime = expirationTime;
14282 finishConcurrentRender(root, finishedWork, workInProgressRootExitStatus, expirationTime);
14283 }
14284
14285 ensureRootIsScheduled(root);
14286
14287 if (root.callbackNode === originalCallbackNode) {
14288 // The task node scheduled for this root is the same one that's
14289 // currently executed. Need to return a continuation.
14290 return performConcurrentWorkOnRoot.bind(null, root);
14291 }
14292 }
14293 }
14294
14295 return null;
14296}
14297
14298function finishConcurrentRender(root, finishedWork, exitStatus, expirationTime) {
14299 // Set this to null to indicate there's no in-progress render.
14300 workInProgressRoot = null;
14301
14302 switch (exitStatus) {
14303 case RootIncomplete:
14304 case RootFatalErrored:
14305 {
14306 {
14307 {
14308 throw Error("Root did not complete. This is a bug in React.");
14309 }
14310 }
14311 }
14312 // Flow knows about invariant, so it complains if I add a break
14313 // statement, but eslint doesn't know about invariant, so it complains
14314 // if I do. eslint-disable-next-line no-fallthrough
14315
14316 case RootErrored:
14317 {
14318 // If this was an async render, the error may have happened due to
14319 // a mutation in a concurrent event. Try rendering one more time,
14320 // synchronously, to see if the error goes away. If there are
14321 // lower priority updates, let's include those, too, in case they
14322 // fix the inconsistency. Render at Idle to include all updates.
14323 // If it was Idle or Never or some not-yet-invented time, render
14324 // at that time.
14325 markRootExpiredAtTime(root, expirationTime > Idle ? Idle : expirationTime); // We assume that this second render pass will be synchronous
14326 // and therefore not hit this path again.
14327
14328 break;
14329 }
14330
14331 case RootSuspended:
14332 {
14333 markRootSuspendedAtTime(root, expirationTime);
14334 var lastSuspendedTime = root.lastSuspendedTime;
14335
14336 if (expirationTime === lastSuspendedTime) {
14337 root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
14338 }
14339
14340 flushSuspensePriorityWarningInDEV(); // We have an acceptable loading state. We need to figure out if we
14341 // should immediately commit it or wait a bit.
14342 // If we have processed new updates during this render, we may now
14343 // have a new loading state ready. We want to ensure that we commit
14344 // that as soon as possible.
14345
14346 var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync;
14347
14348 if (hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
14349 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current)) {
14350 // If we have not processed any new updates during this pass, then
14351 // this is either a retry of an existing fallback state or a
14352 // hidden tree. Hidden trees shouldn't be batched with other work
14353 // and after that's fixed it can only be a retry. We're going to
14354 // throttle committing retries so that we don't show too many
14355 // loading states too quickly.
14356 var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
14357
14358 if (msUntilTimeout > 10) {
14359 if (workInProgressRootHasPendingPing) {
14360 var lastPingedTime = root.lastPingedTime;
14361
14362 if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
14363 // This render was pinged but we didn't get to restart
14364 // earlier so try restarting now instead.
14365 root.lastPingedTime = expirationTime;
14366 prepareFreshStack(root, expirationTime);
14367 break;
14368 }
14369 }
14370
14371 var nextTime = getNextRootExpirationTimeToWorkOn(root);
14372
14373 if (nextTime !== NoWork && nextTime !== expirationTime) {
14374 // There's additional work on this root.
14375 break;
14376 }
14377
14378 if (lastSuspendedTime !== NoWork && lastSuspendedTime !== expirationTime) {
14379 // We should prefer to render the fallback of at the last
14380 // suspended level. Ping the last suspended level to try
14381 // rendering it again.
14382 root.lastPingedTime = lastSuspendedTime;
14383 break;
14384 } // The render is suspended, it hasn't timed out, and there's no
14385 // lower priority work to do. Instead of committing the fallback
14386 // immediately, wait for more data to arrive.
14387
14388
14389 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
14390 break;
14391 }
14392 } // The work expired. Commit immediately.
14393
14394
14395 commitRoot(root);
14396 break;
14397 }
14398
14399 case RootSuspendedWithDelay:
14400 {
14401 markRootSuspendedAtTime(root, expirationTime);
14402 var _lastSuspendedTime = root.lastSuspendedTime;
14403
14404 if (expirationTime === _lastSuspendedTime) {
14405 root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
14406 }
14407
14408 flushSuspensePriorityWarningInDEV();
14409
14410 if ( // do not delay if we're inside an act() scope
14411 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current)) {
14412 // We're suspended in a state that should be avoided. We'll try to
14413 // avoid committing it for as long as the timeouts let us.
14414 if (workInProgressRootHasPendingPing) {
14415 var _lastPingedTime = root.lastPingedTime;
14416
14417 if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
14418 // This render was pinged but we didn't get to restart earlier
14419 // so try restarting now instead.
14420 root.lastPingedTime = expirationTime;
14421 prepareFreshStack(root, expirationTime);
14422 break;
14423 }
14424 }
14425
14426 var _nextTime = getNextRootExpirationTimeToWorkOn(root);
14427
14428 if (_nextTime !== NoWork && _nextTime !== expirationTime) {
14429 // There's additional work on this root.
14430 break;
14431 }
14432
14433 if (_lastSuspendedTime !== NoWork && _lastSuspendedTime !== expirationTime) {
14434 // We should prefer to render the fallback of at the last
14435 // suspended level. Ping the last suspended level to try
14436 // rendering it again.
14437 root.lastPingedTime = _lastSuspendedTime;
14438 break;
14439 }
14440
14441 var _msUntilTimeout;
14442
14443 if (workInProgressRootLatestSuspenseTimeout !== Sync) {
14444 // We have processed a suspense config whose expiration time we
14445 // can use as the timeout.
14446 _msUntilTimeout = expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
14447 } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
14448 // This should never normally happen because only new updates
14449 // cause delayed states, so we should have processed something.
14450 // However, this could also happen in an offscreen tree.
14451 _msUntilTimeout = 0;
14452 } else {
14453 // If we don't have a suspense config, we're going to use a
14454 // heuristic to determine how long we can suspend.
14455 var eventTimeMs = inferTimeFromExpirationTime(workInProgressRootLatestProcessedExpirationTime);
14456 var currentTimeMs = now();
14457 var timeUntilExpirationMs = expirationTimeToMs(expirationTime) - currentTimeMs;
14458 var timeElapsed = currentTimeMs - eventTimeMs;
14459
14460 if (timeElapsed < 0) {
14461 // We get this wrong some time since we estimate the time.
14462 timeElapsed = 0;
14463 }
14464
14465 _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
14466 // event time is exact instead of inferred from expiration time
14467 // we don't need this.
14468
14469 if (timeUntilExpirationMs < _msUntilTimeout) {
14470 _msUntilTimeout = timeUntilExpirationMs;
14471 }
14472 } // Don't bother with a very short suspense time.
14473
14474
14475 if (_msUntilTimeout > 10) {
14476 // The render is suspended, it hasn't timed out, and there's no
14477 // lower priority work to do. Instead of committing the fallback
14478 // immediately, wait for more data to arrive.
14479 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
14480 break;
14481 }
14482 } // The work expired. Commit immediately.
14483
14484
14485 commitRoot(root);
14486 break;
14487 }
14488
14489 case RootCompleted:
14490 {
14491 // The work completed. Ready to commit.
14492 if ( // do not delay if we're inside an act() scope
14493 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null) {
14494 // If we have exceeded the minimum loading delay, which probably
14495 // means we have shown a spinner already, we might have to suspend
14496 // a bit longer to ensure that the spinner is shown for
14497 // enough time.
14498 var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(workInProgressRootLatestProcessedExpirationTime, expirationTime, workInProgressRootCanSuspendUsingConfig);
14499
14500 if (_msUntilTimeout2 > 10) {
14501 markRootSuspendedAtTime(root, expirationTime);
14502 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout2);
14503 break;
14504 }
14505 }
14506
14507 commitRoot(root);
14508 break;
14509 }
14510
14511 default:
14512 {
14513 {
14514 {
14515 throw Error("Unknown root exit status.");
14516 }
14517 }
14518 }
14519 }
14520} // This is the entry point for synchronous tasks that don't go
14521// through Scheduler
14522
14523
14524function performSyncWorkOnRoot(root) {
14525 // Check if there's expired work on this root. Otherwise, render at Sync.
14526 var lastExpiredTime = root.lastExpiredTime;
14527 var expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
14528
14529 if (root.finishedExpirationTime === expirationTime) {
14530 // There's already a pending commit at this expiration time.
14531 // TODO: This is poorly factored. This case only exists for the
14532 // batch.commit() API.
14533 commitRoot(root);
14534 } else {
14535 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14536 {
14537 throw Error("Should not already be working.");
14538 }
14539 }
14540
14541 flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
14542 // and prepare a fresh one. Otherwise we'll continue where we left off.
14543
14544 if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
14545 prepareFreshStack(root, expirationTime);
14546 startWorkOnPendingInteractions(root, expirationTime);
14547 } // If we have a work-in-progress fiber, it means there's still work to do
14548 // in this root.
14549
14550
14551 if (workInProgress !== null) {
14552 var prevExecutionContext = executionContext;
14553 executionContext |= RenderContext;
14554 var prevDispatcher = pushDispatcher(root);
14555 var prevInteractions = pushInteractions(root);
14556 startWorkLoopTimer(workInProgress);
14557
14558 do {
14559 try {
14560 workLoopSync();
14561 break;
14562 } catch (thrownValue) {
14563 handleError(root, thrownValue);
14564 }
14565 } while (true);
14566
14567 resetContextDependencies();
14568 executionContext = prevExecutionContext;
14569 popDispatcher(prevDispatcher);
14570
14571 if (enableSchedulerTracing) {
14572 popInteractions(prevInteractions);
14573 }
14574
14575 if (workInProgressRootExitStatus === RootFatalErrored) {
14576 var fatalError = workInProgressRootFatalError;
14577 stopInterruptedWorkLoopTimer();
14578 prepareFreshStack(root, expirationTime);
14579 markRootSuspendedAtTime(root, expirationTime);
14580 ensureRootIsScheduled(root);
14581 throw fatalError;
14582 }
14583
14584 if (workInProgress !== null) {
14585 // This is a sync render, so we should have finished the whole tree.
14586 {
14587 {
14588 throw Error("Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue.");
14589 }
14590 }
14591 } else {
14592 // We now have a consistent tree. Because this is a sync render, we
14593 // will commit it even if something suspended.
14594 stopFinishedWorkLoopTimer();
14595 root.finishedWork = root.current.alternate;
14596 root.finishedExpirationTime = expirationTime;
14597 finishSyncRender(root, workInProgressRootExitStatus, expirationTime);
14598 } // Before exiting, make sure there's a callback scheduled for the next
14599 // pending level.
14600
14601
14602 ensureRootIsScheduled(root);
14603 }
14604 }
14605
14606 return null;
14607}
14608
14609function finishSyncRender(root, exitStatus, expirationTime) {
14610 // Set this to null to indicate there's no in-progress render.
14611 workInProgressRoot = null;
14612
14613 {
14614 if (exitStatus === RootSuspended || exitStatus === RootSuspendedWithDelay) {
14615 flushSuspensePriorityWarningInDEV();
14616 }
14617 }
14618
14619 commitRoot(root);
14620}
14621
14622
14623
14624
14625function syncUpdates(fn, a, b, c) {
14626 return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
14627}
14628
14629
14630
14631
14632
14633function flushSync(fn, a) {
14634 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
14635 {
14636 {
14637 throw Error("flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.");
14638 }
14639 }
14640 }
14641
14642 var prevExecutionContext = executionContext;
14643 executionContext |= BatchedContext;
14644
14645 try {
14646 return runWithPriority(ImmediatePriority, fn.bind(null, a));
14647 } finally {
14648 executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
14649 // Note that this will happen even if batchedUpdates is higher up
14650 // the stack.
14651
14652 flushSyncCallbackQueue();
14653 }
14654}
14655
14656
14657function prepareFreshStack(root, expirationTime) {
14658 root.finishedWork = null;
14659 root.finishedExpirationTime = NoWork;
14660 var timeoutHandle = root.timeoutHandle;
14661
14662 if (timeoutHandle !== noTimeout) {
14663 // The root previous suspended and scheduled a timeout to commit a fallback
14664 // state. Now that we have additional work, cancel the timeout.
14665 root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
14666
14667 cancelTimeout(timeoutHandle);
14668 }
14669
14670 if (workInProgress !== null) {
14671 var interruptedWork = workInProgress.return;
14672
14673 while (interruptedWork !== null) {
14674 unwindInterruptedWork(interruptedWork);
14675 interruptedWork = interruptedWork.return;
14676 }
14677 }
14678
14679 workInProgressRoot = root;
14680 workInProgress = createWorkInProgress(root.current, null, expirationTime);
14681 renderExpirationTime = expirationTime;
14682 workInProgressRootExitStatus = RootIncomplete;
14683 workInProgressRootFatalError = null;
14684 workInProgressRootLatestProcessedExpirationTime = Sync;
14685 workInProgressRootLatestSuspenseTimeout = Sync;
14686 workInProgressRootCanSuspendUsingConfig = null;
14687 workInProgressRootNextUnprocessedUpdateTime = NoWork;
14688 workInProgressRootHasPendingPing = false;
14689
14690 if (enableSchedulerTracing) {
14691 spawnedWorkDuringRender = null;
14692 }
14693
14694 {
14695 ReactStrictModeWarnings.discardPendingWarnings();
14696 componentsThatTriggeredHighPriSuspend = null;
14697 }
14698}
14699
14700function handleError(root, thrownValue) {
14701 do {
14702 try {
14703 // Reset module-level state that was set during the render phase.
14704 resetContextDependencies();
14705 resetHooks();
14706 resetCurrentFiber();
14707
14708 if (workInProgress === null || workInProgress.return === null) {
14709 // Expected to be working on a non-root fiber. This is a fatal error
14710 // because there's no ancestor that can handle it; the root is
14711 // supposed to capture all errors that weren't caught by an error
14712 // boundary.
14713 workInProgressRootExitStatus = RootFatalErrored;
14714 workInProgressRootFatalError = thrownValue;
14715 return null;
14716 }
14717
14718 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
14719 // Record the time spent rendering before an error was thrown. This
14720 // avoids inaccurate Profiler durations in the case of a
14721 // suspended render.
14722 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
14723 }
14724
14725 throwException(root, workInProgress.return, workInProgress, thrownValue, renderExpirationTime);
14726 workInProgress = completeUnitOfWork(workInProgress);
14727 } catch (yetAnotherThrownValue) {
14728 // Something in the return path also threw.
14729 thrownValue = yetAnotherThrownValue;
14730 continue;
14731 } // Return to the normal work loop.
14732
14733
14734 return;
14735 } while (true);
14736}
14737
14738function pushDispatcher(root) {
14739 var prevDispatcher = ReactCurrentDispatcher.current;
14740 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
14741
14742 if (prevDispatcher === null) {
14743 // The React isomorphic package does not include a default dispatcher.
14744 // Instead the first renderer will lazily attach one, in order to give
14745 // nicer error messages.
14746 return ContextOnlyDispatcher;
14747 } else {
14748 return prevDispatcher;
14749 }
14750}
14751
14752function popDispatcher(prevDispatcher) {
14753 ReactCurrentDispatcher.current = prevDispatcher;
14754}
14755
14756function pushInteractions(root) {
14757 if (enableSchedulerTracing) {
14758 var prevInteractions = tracing.__interactionsRef.current;
14759 tracing.__interactionsRef.current = root.memoizedInteractions;
14760 return prevInteractions;
14761 }
14762
14763 return null;
14764}
14765
14766function popInteractions(prevInteractions) {
14767 if (enableSchedulerTracing) {
14768 tracing.__interactionsRef.current = prevInteractions;
14769 }
14770}
14771
14772function markCommitTimeOfFallback() {
14773 globalMostRecentFallbackTime = now();
14774}
14775function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
14776 if (expirationTime < workInProgressRootLatestProcessedExpirationTime && expirationTime > Idle) {
14777 workInProgressRootLatestProcessedExpirationTime = expirationTime;
14778 }
14779
14780 if (suspenseConfig !== null) {
14781 if (expirationTime < workInProgressRootLatestSuspenseTimeout && expirationTime > Idle) {
14782 workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
14783
14784 workInProgressRootCanSuspendUsingConfig = suspenseConfig;
14785 }
14786 }
14787}
14788function markUnprocessedUpdateTime(expirationTime) {
14789 if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
14790 workInProgressRootNextUnprocessedUpdateTime = expirationTime;
14791 }
14792}
14793function renderDidSuspend() {
14794 if (workInProgressRootExitStatus === RootIncomplete) {
14795 workInProgressRootExitStatus = RootSuspended;
14796 }
14797}
14798function renderDidSuspendDelayIfPossible() {
14799 if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
14800 workInProgressRootExitStatus = RootSuspendedWithDelay;
14801 } // Check if there's a lower priority update somewhere else in the tree.
14802
14803
14804 if (workInProgressRootNextUnprocessedUpdateTime !== NoWork && workInProgressRoot !== null) {
14805 // Mark the current render as suspended, and then mark that there's a
14806 // pending update.
14807 // TODO: This should immediately interrupt the current render, instead
14808 // of waiting until the next time we yield.
14809 markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime);
14810 markRootUpdatedAtTime(workInProgressRoot, workInProgressRootNextUnprocessedUpdateTime);
14811 }
14812}
14813function renderDidError() {
14814 if (workInProgressRootExitStatus !== RootCompleted) {
14815 workInProgressRootExitStatus = RootErrored;
14816 }
14817} // Called during render to determine if anything has suspended.
14818// Returns false if we're not sure.
14819
14820function renderHasNotSuspendedYet() {
14821 // If something errored or completed, we can't really be sure,
14822 // so those are false.
14823 return workInProgressRootExitStatus === RootIncomplete;
14824}
14825
14826function inferTimeFromExpirationTime(expirationTime) {
14827 // We don't know exactly when the update was scheduled, but we can infer an
14828 // approximate start time from the expiration time.
14829 var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
14830 return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
14831}
14832
14833function inferTimeFromExpirationTimeWithSuspenseConfig(expirationTime, suspenseConfig) {
14834 // We don't know exactly when the update was scheduled, but we can infer an
14835 // approximate start time from the expiration time by subtracting the timeout
14836 // that was added to the event time.
14837 var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
14838 return earliestExpirationTimeMs - (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
14839} // The work loop is an extremely hot path. Tell Closure not to inline it.
14840
14841/** @noinline */
14842
14843
14844function workLoopSync() {
14845 // Already timed out, so perform work without checking if we need to yield.
14846 while (workInProgress !== null) {
14847 workInProgress = performUnitOfWork(workInProgress);
14848 }
14849}
14850/** @noinline */
14851
14852
14853function workLoopConcurrent() {
14854 // Perform work until Scheduler asks us to yield
14855 while (workInProgress !== null && !shouldYield()) {
14856 workInProgress = performUnitOfWork(workInProgress);
14857 }
14858}
14859
14860function performUnitOfWork(unitOfWork) {
14861 // The current, flushed, state of this fiber is the alternate. Ideally
14862 // nothing should rely on this, but relying on it here means that we don't
14863 // need an additional field on the work in progress.
14864 var current$$1 = unitOfWork.alternate;
14865 startWorkTimer(unitOfWork);
14866 setCurrentFiber(unitOfWork);
14867 var next;
14868
14869 if (enableProfilerTimer && (unitOfWork.mode & ProfileMode) !== NoMode) {
14870 startProfilerTimer(unitOfWork);
14871 next = beginWork$$1(current$$1, unitOfWork, renderExpirationTime);
14872 stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
14873 } else {
14874 next = beginWork$$1(current$$1, unitOfWork, renderExpirationTime);
14875 }
14876
14877 resetCurrentFiber();
14878 unitOfWork.memoizedProps = unitOfWork.pendingProps;
14879
14880 if (next === null) {
14881 // If this doesn't spawn new work, complete the current work.
14882 next = completeUnitOfWork(unitOfWork);
14883 }
14884
14885 ReactCurrentOwner$1.current = null;
14886 return next;
14887}
14888
14889function completeUnitOfWork(unitOfWork) {
14890 // Attempt to complete the current unit of work, then move to the next
14891 // sibling. If there are no more siblings, return to the parent fiber.
14892 workInProgress = unitOfWork;
14893
14894 do {
14895 // The current, flushed, state of this fiber is the alternate. Ideally
14896 // nothing should rely on this, but relying on it here means that we don't
14897 // need an additional field on the work in progress.
14898 var current$$1 = workInProgress.alternate;
14899 var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
14900
14901 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
14902 setCurrentFiber(workInProgress);
14903 var next = void 0;
14904
14905 if (!enableProfilerTimer || (workInProgress.mode & ProfileMode) === NoMode) {
14906 next = completeWork(current$$1, workInProgress, renderExpirationTime);
14907 } else {
14908 startProfilerTimer(workInProgress);
14909 next = completeWork(current$$1, workInProgress, renderExpirationTime); // Update render duration assuming we didn't error.
14910
14911 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
14912 }
14913
14914 stopWorkTimer(workInProgress);
14915 resetCurrentFiber();
14916 resetChildExpirationTime(workInProgress);
14917
14918 if (next !== null) {
14919 // Completing this fiber spawned new work. Work on that next.
14920 return next;
14921 }
14922
14923 if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
14924 (returnFiber.effectTag & Incomplete) === NoEffect) {
14925 // Append all the effects of the subtree and this fiber onto the effect
14926 // list of the parent. The completion order of the children affects the
14927 // side-effect order.
14928 if (returnFiber.firstEffect === null) {
14929 returnFiber.firstEffect = workInProgress.firstEffect;
14930 }
14931
14932 if (workInProgress.lastEffect !== null) {
14933 if (returnFiber.lastEffect !== null) {
14934 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
14935 }
14936
14937 returnFiber.lastEffect = workInProgress.lastEffect;
14938 } // If this fiber had side-effects, we append it AFTER the children's
14939 // side-effects. We can perform certain side-effects earlier if needed,
14940 // by doing multiple passes over the effect list. We don't want to
14941 // schedule our own side-effect on our own list because if end up
14942 // reusing children we'll schedule this effect onto itself since we're
14943 // at the end.
14944
14945
14946 var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
14947 // list. PerformedWork effect is read by React DevTools but shouldn't be
14948 // committed.
14949
14950 if (effectTag > PerformedWork) {
14951 if (returnFiber.lastEffect !== null) {
14952 returnFiber.lastEffect.nextEffect = workInProgress;
14953 } else {
14954 returnFiber.firstEffect = workInProgress;
14955 }
14956
14957 returnFiber.lastEffect = workInProgress;
14958 }
14959 }
14960 } else {
14961 // This fiber did not complete because something threw. Pop values off
14962 // the stack without entering the complete phase. If this is a boundary,
14963 // capture values if possible.
14964 var _next = unwindWork(workInProgress, renderExpirationTime); // Because this fiber did not complete, don't reset its expiration time.
14965
14966
14967 if (enableProfilerTimer && (workInProgress.mode & ProfileMode) !== NoMode) {
14968 // Record the render duration for the fiber that errored.
14969 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
14970
14971 var actualDuration = workInProgress.actualDuration;
14972 var child = workInProgress.child;
14973
14974 while (child !== null) {
14975 actualDuration += child.actualDuration;
14976 child = child.sibling;
14977 }
14978
14979 workInProgress.actualDuration = actualDuration;
14980 }
14981
14982 if (_next !== null) {
14983 // If completing this work spawned new work, do that next. We'll come
14984 // back here again.
14985 // Since we're restarting, remove anything that is not a host effect
14986 // from the effect tag.
14987 // TODO: The name stopFailedWorkTimer is misleading because Suspense
14988 // also captures and restarts.
14989 stopFailedWorkTimer(workInProgress);
14990 _next.effectTag &= HostEffectMask;
14991 return _next;
14992 }
14993
14994 stopWorkTimer(workInProgress);
14995
14996 if (returnFiber !== null) {
14997 // Mark the parent fiber as incomplete and clear its effect list.
14998 returnFiber.firstEffect = returnFiber.lastEffect = null;
14999 returnFiber.effectTag |= Incomplete;
15000 }
15001 }
15002
15003 var siblingFiber = workInProgress.sibling;
15004
15005 if (siblingFiber !== null) {
15006 // If there is more work to do in this returnFiber, do that next.
15007 return siblingFiber;
15008 } // Otherwise, return to the parent
15009
15010
15011 workInProgress = returnFiber;
15012 } while (workInProgress !== null); // We've reached the root.
15013
15014
15015 if (workInProgressRootExitStatus === RootIncomplete) {
15016 workInProgressRootExitStatus = RootCompleted;
15017 }
15018
15019 return null;
15020}
15021
15022function getRemainingExpirationTime(fiber) {
15023 var updateExpirationTime = fiber.expirationTime;
15024 var childExpirationTime = fiber.childExpirationTime;
15025 return updateExpirationTime > childExpirationTime ? updateExpirationTime : childExpirationTime;
15026}
15027
15028function resetChildExpirationTime(completedWork) {
15029 if (renderExpirationTime !== Never && completedWork.childExpirationTime === Never) {
15030 // The children of this component are hidden. Don't bubble their
15031 // expiration times.
15032 return;
15033 }
15034
15035 var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
15036
15037 if (enableProfilerTimer && (completedWork.mode & ProfileMode) !== NoMode) {
15038 // In profiling mode, resetChildExpirationTime is also used to reset
15039 // profiler durations.
15040 var actualDuration = completedWork.actualDuration;
15041 var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
15042 // only be updated if work is done on the fiber (i.e. it doesn't bailout).
15043 // When work is done, it should bubble to the parent's actualDuration. If
15044 // the fiber has not been cloned though, (meaning no work was done), then
15045 // this value will reflect the amount of time spent working on a previous
15046 // render. In that case it should not bubble. We determine whether it was
15047 // cloned by comparing the child pointer.
15048
15049 var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
15050 var child = completedWork.child;
15051
15052 while (child !== null) {
15053 var childUpdateExpirationTime = child.expirationTime;
15054 var childChildExpirationTime = child.childExpirationTime;
15055
15056 if (childUpdateExpirationTime > newChildExpirationTime) {
15057 newChildExpirationTime = childUpdateExpirationTime;
15058 }
15059
15060 if (childChildExpirationTime > newChildExpirationTime) {
15061 newChildExpirationTime = childChildExpirationTime;
15062 }
15063
15064 if (shouldBubbleActualDurations) {
15065 actualDuration += child.actualDuration;
15066 }
15067
15068 treeBaseDuration += child.treeBaseDuration;
15069 child = child.sibling;
15070 }
15071
15072 completedWork.actualDuration = actualDuration;
15073 completedWork.treeBaseDuration = treeBaseDuration;
15074 } else {
15075 var _child = completedWork.child;
15076
15077 while (_child !== null) {
15078 var _childUpdateExpirationTime = _child.expirationTime;
15079 var _childChildExpirationTime = _child.childExpirationTime;
15080
15081 if (_childUpdateExpirationTime > newChildExpirationTime) {
15082 newChildExpirationTime = _childUpdateExpirationTime;
15083 }
15084
15085 if (_childChildExpirationTime > newChildExpirationTime) {
15086 newChildExpirationTime = _childChildExpirationTime;
15087 }
15088
15089 _child = _child.sibling;
15090 }
15091 }
15092
15093 completedWork.childExpirationTime = newChildExpirationTime;
15094}
15095
15096function commitRoot(root) {
15097 var renderPriorityLevel = getCurrentPriorityLevel();
15098 runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root, renderPriorityLevel));
15099 return null;
15100}
15101
15102function commitRootImpl(root, renderPriorityLevel) {
15103 flushPassiveEffects();
15104 flushRenderPhaseStrictModeWarningsInDEV();
15105
15106 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
15107 {
15108 throw Error("Should not already be working.");
15109 }
15110 }
15111
15112 var finishedWork = root.finishedWork;
15113 var expirationTime = root.finishedExpirationTime;
15114
15115 if (finishedWork === null) {
15116 return null;
15117 }
15118
15119 root.finishedWork = null;
15120 root.finishedExpirationTime = NoWork;
15121
15122 if (!(finishedWork !== root.current)) {
15123 {
15124 throw Error("Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue.");
15125 }
15126 } // commitRoot never returns a continuation; it always finishes synchronously.
15127 // So we can clear these now to allow a new callback to be scheduled.
15128
15129
15130 root.callbackNode = null;
15131 root.callbackExpirationTime = NoWork;
15132 root.callbackPriority = NoPriority;
15133 root.nextKnownPendingLevel = NoWork;
15134 startCommitTimer(); // Update the first and last pending times on this root. The new first
15135 // pending time is whatever is left on the root fiber.
15136
15137 var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(finishedWork);
15138 markRootFinishedAtTime(root, expirationTime, remainingExpirationTimeBeforeCommit);
15139
15140 if (root === workInProgressRoot) {
15141 // We can reset these now that they are finished.
15142 workInProgressRoot = null;
15143 workInProgress = null;
15144 renderExpirationTime = NoWork;
15145 } else {} // This indicates that the last root we worked on is not the same one that
15146 // we're committing now. This most commonly happens when a suspended root
15147 // times out.
15148 // Get the list of effects.
15149
15150
15151 var firstEffect;
15152
15153 if (finishedWork.effectTag > PerformedWork) {
15154 // A fiber's effect list consists only of its children, not itself. So if
15155 // the root has an effect, we need to add it to the end of the list. The
15156 // resulting list is the set that would belong to the root's parent, if it
15157 // had one; that is, all the effects in the tree including the root.
15158 if (finishedWork.lastEffect !== null) {
15159 finishedWork.lastEffect.nextEffect = finishedWork;
15160 firstEffect = finishedWork.firstEffect;
15161 } else {
15162 firstEffect = finishedWork;
15163 }
15164 } else {
15165 // There is no effect on the root.
15166 firstEffect = finishedWork.firstEffect;
15167 }
15168
15169 if (firstEffect !== null) {
15170 var prevExecutionContext = executionContext;
15171 executionContext |= CommitContext;
15172 var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
15173
15174 ReactCurrentOwner$1.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
15175 // of the effect list for each phase: all mutation effects come before all
15176 // layout effects, and so on.
15177 // The first phase a "before mutation" phase. We use this phase to read the
15178 // state of the host tree right before we mutate it. This is where
15179 // getSnapshotBeforeUpdate is called.
15180
15181 startCommitSnapshotEffectsTimer();
15182 prepareForCommit(root.containerInfo);
15183 nextEffect = firstEffect;
15184
15185 do {
15186 {
15187 invokeGuardedCallback(null, commitBeforeMutationEffects, null);
15188
15189 if (hasCaughtError()) {
15190 if (!(nextEffect !== null)) {
15191 {
15192 throw Error("Should be working on an effect.");
15193 }
15194 }
15195
15196 var error = clearCaughtError();
15197 captureCommitPhaseError(nextEffect, error);
15198 nextEffect = nextEffect.nextEffect;
15199 }
15200 }
15201 } while (nextEffect !== null);
15202
15203 stopCommitSnapshotEffectsTimer();
15204
15205 if (enableProfilerTimer) {
15206 // Mark the current commit time to be shared by all Profilers in this
15207 // batch. This enables them to be grouped later.
15208 recordCommitTime();
15209 } // The next phase is the mutation phase, where we mutate the host tree.
15210
15211
15212 startCommitHostEffectsTimer();
15213 nextEffect = firstEffect;
15214
15215 do {
15216 {
15217 invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
15218
15219 if (hasCaughtError()) {
15220 if (!(nextEffect !== null)) {
15221 {
15222 throw Error("Should be working on an effect.");
15223 }
15224 }
15225
15226 var _error = clearCaughtError();
15227
15228 captureCommitPhaseError(nextEffect, _error);
15229 nextEffect = nextEffect.nextEffect;
15230 }
15231 }
15232 } while (nextEffect !== null);
15233
15234 stopCommitHostEffectsTimer();
15235 resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
15236 // the mutation phase, so that the previous tree is still current during
15237 // componentWillUnmount, but before the layout phase, so that the finished
15238 // work is current during componentDidMount/Update.
15239
15240 root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
15241 // the host tree after it's been mutated. The idiomatic use case for this is
15242 // layout, but class component lifecycles also fire here for legacy reasons.
15243
15244 startCommitLifeCyclesTimer();
15245 nextEffect = firstEffect;
15246
15247 do {
15248 {
15249 invokeGuardedCallback(null, commitLayoutEffects, null, root, expirationTime);
15250
15251 if (hasCaughtError()) {
15252 if (!(nextEffect !== null)) {
15253 {
15254 throw Error("Should be working on an effect.");
15255 }
15256 }
15257
15258 var _error2 = clearCaughtError();
15259
15260 captureCommitPhaseError(nextEffect, _error2);
15261 nextEffect = nextEffect.nextEffect;
15262 }
15263 }
15264 } while (nextEffect !== null);
15265
15266 stopCommitLifeCyclesTimer();
15267 nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
15268 // opportunity to paint.
15269
15270 requestPaint();
15271
15272 if (enableSchedulerTracing) {
15273 popInteractions(prevInteractions);
15274 }
15275
15276 executionContext = prevExecutionContext;
15277 } else {
15278 // No effects.
15279 root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
15280 // no effects.
15281 // TODO: Maybe there's a better way to report this.
15282
15283 startCommitSnapshotEffectsTimer();
15284 stopCommitSnapshotEffectsTimer();
15285
15286 if (enableProfilerTimer) {
15287 recordCommitTime();
15288 }
15289
15290 startCommitHostEffectsTimer();
15291 stopCommitHostEffectsTimer();
15292 startCommitLifeCyclesTimer();
15293 stopCommitLifeCyclesTimer();
15294 }
15295
15296 stopCommitTimer();
15297 var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
15298
15299 if (rootDoesHavePassiveEffects) {
15300 // This commit has passive effects. Stash a reference to them. But don't
15301 // schedule a callback until after flushing layout work.
15302 rootDoesHavePassiveEffects = false;
15303 rootWithPendingPassiveEffects = root;
15304 pendingPassiveEffectsExpirationTime = expirationTime;
15305 pendingPassiveEffectsRenderPriority = renderPriorityLevel;
15306 } else {
15307 // We are done with the effect chain at this point so let's clear the
15308 // nextEffect pointers to assist with GC. If we have passive effects, we'll
15309 // clear this in flushPassiveEffects.
15310 nextEffect = firstEffect;
15311
15312 while (nextEffect !== null) {
15313 var nextNextEffect = nextEffect.nextEffect;
15314 nextEffect.nextEffect = null;
15315 nextEffect = nextNextEffect;
15316 }
15317 } // Check if there's remaining work on this root
15318
15319
15320 var remainingExpirationTime = root.firstPendingTime;
15321
15322 if (remainingExpirationTime !== NoWork) {
15323 if (enableSchedulerTracing) {
15324 if (spawnedWorkDuringRender !== null) {
15325 var expirationTimes = spawnedWorkDuringRender;
15326 spawnedWorkDuringRender = null;
15327
15328 for (var i = 0; i < expirationTimes.length; i++) {
15329 scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
15330 }
15331 }
15332
15333 schedulePendingInteractions(root, remainingExpirationTime);
15334 }
15335 } else {
15336 // If there's no remaining work, we can clear the set of already failed
15337 // error boundaries.
15338 legacyErrorBoundariesThatAlreadyFailed = null;
15339 }
15340
15341 if (enableSchedulerTracing) {
15342 if (!rootDidHavePassiveEffects) {
15343 // If there are no passive effects, then we can complete the pending interactions.
15344 // Otherwise, we'll wait until after the passive effects are flushed.
15345 // Wait to do this until after remaining work has been scheduled,
15346 // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
15347 finishPendingInteractions(root, expirationTime);
15348 }
15349 }
15350
15351 if (remainingExpirationTime === Sync) {
15352 // Count the number of times the root synchronously re-renders without
15353 // finishing. If there are too many, it indicates an infinite update loop.
15354 if (root === rootWithNestedUpdates) {
15355 nestedUpdateCount++;
15356 } else {
15357 nestedUpdateCount = 0;
15358 rootWithNestedUpdates = root;
15359 }
15360 } else {
15361 nestedUpdateCount = 0;
15362 }
15363
15364 onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
15365 // additional work on this root is scheduled.
15366
15367 ensureRootIsScheduled(root);
15368
15369 if (hasUncaughtError) {
15370 hasUncaughtError = false;
15371 var _error3 = firstUncaughtError;
15372 firstUncaughtError = null;
15373 throw _error3;
15374 }
15375
15376 if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
15377 // This is a legacy edge case. We just committed the initial mount of
15378 // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
15379 // synchronously, but layout updates should be deferred until the end
15380 // of the batch.
15381 return null;
15382 } // If layout work was scheduled, flush it now.
15383
15384
15385 flushSyncCallbackQueue();
15386 return null;
15387}
15388
15389function commitBeforeMutationEffects() {
15390 while (nextEffect !== null) {
15391 var effectTag = nextEffect.effectTag;
15392
15393 if ((effectTag & Snapshot) !== NoEffect) {
15394 setCurrentFiber(nextEffect);
15395 recordEffect();
15396 var current$$1 = nextEffect.alternate;
15397 commitBeforeMutationLifeCycles(current$$1, nextEffect);
15398 resetCurrentFiber();
15399 }
15400
15401 if ((effectTag & Passive) !== NoEffect) {
15402 // If there are passive effects, schedule a callback to flush at
15403 // the earliest opportunity.
15404 if (!rootDoesHavePassiveEffects) {
15405 rootDoesHavePassiveEffects = true;
15406 scheduleCallback(NormalPriority, function () {
15407 flushPassiveEffects();
15408 return null;
15409 });
15410 }
15411 }
15412
15413 nextEffect = nextEffect.nextEffect;
15414 }
15415}
15416
15417function commitMutationEffects(root, renderPriorityLevel) {
15418 // TODO: Should probably move the bulk of this function to commitWork.
15419 while (nextEffect !== null) {
15420 setCurrentFiber(nextEffect);
15421 var effectTag = nextEffect.effectTag;
15422
15423 if (effectTag & ContentReset) {
15424 commitResetTextContent(nextEffect);
15425 }
15426
15427 if (effectTag & Ref) {
15428 var current$$1 = nextEffect.alternate;
15429
15430 if (current$$1 !== null) {
15431 commitDetachRef(current$$1);
15432 }
15433 } // The following switch statement is only concerned about placement,
15434 // updates, and deletions. To avoid needing to add a case for every possible
15435 // bitmap value, we remove the secondary effects from the effect tag and
15436 // switch on that value.
15437
15438
15439 var primaryEffectTag = effectTag & (Placement | Update | Deletion | Hydrating);
15440
15441 switch (primaryEffectTag) {
15442 case Placement:
15443 {
15444 commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
15445 // inserted, before any life-cycles like componentDidMount gets called.
15446 // TODO: findDOMNode doesn't rely on this any more but isMounted does
15447 // and isMounted is deprecated anyway so we should be able to kill this.
15448
15449 nextEffect.effectTag &= ~Placement;
15450 break;
15451 }
15452
15453 case PlacementAndUpdate:
15454 {
15455 // Placement
15456 commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
15457 // inserted, before any life-cycles like componentDidMount gets called.
15458
15459 nextEffect.effectTag &= ~Placement; // Update
15460
15461 var _current = nextEffect.alternate;
15462 commitWork(_current, nextEffect);
15463 break;
15464 }
15465
15466 case Hydrating:
15467 {
15468 nextEffect.effectTag &= ~Hydrating;
15469 break;
15470 }
15471
15472 case HydratingAndUpdate:
15473 {
15474 nextEffect.effectTag &= ~Hydrating; // Update
15475
15476 var _current2 = nextEffect.alternate;
15477 commitWork(_current2, nextEffect);
15478 break;
15479 }
15480
15481 case Update:
15482 {
15483 var _current3 = nextEffect.alternate;
15484 commitWork(_current3, nextEffect);
15485 break;
15486 }
15487
15488 case Deletion:
15489 {
15490 commitDeletion(root, nextEffect, renderPriorityLevel);
15491 break;
15492 }
15493 } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
15494
15495
15496 recordEffect();
15497 resetCurrentFiber();
15498 nextEffect = nextEffect.nextEffect;
15499 }
15500}
15501
15502function commitLayoutEffects(root, committedExpirationTime) {
15503 // TODO: Should probably move the bulk of this function to commitWork.
15504 while (nextEffect !== null) {
15505 setCurrentFiber(nextEffect);
15506 var effectTag = nextEffect.effectTag;
15507
15508 if (effectTag & (Update | Callback)) {
15509 recordEffect();
15510 var current$$1 = nextEffect.alternate;
15511 commitLifeCycles(root, current$$1, nextEffect, committedExpirationTime);
15512 }
15513
15514 if (effectTag & Ref) {
15515 recordEffect();
15516 commitAttachRef(nextEffect);
15517 }
15518
15519 resetCurrentFiber();
15520 nextEffect = nextEffect.nextEffect;
15521 }
15522}
15523
15524function flushPassiveEffects() {
15525 if (pendingPassiveEffectsRenderPriority !== NoPriority) {
15526 var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
15527 pendingPassiveEffectsRenderPriority = NoPriority;
15528 return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
15529 }
15530}
15531
15532function flushPassiveEffectsImpl() {
15533 if (rootWithPendingPassiveEffects === null) {
15534 return false;
15535 }
15536
15537 var root = rootWithPendingPassiveEffects;
15538 var expirationTime = pendingPassiveEffectsExpirationTime;
15539 rootWithPendingPassiveEffects = null;
15540 pendingPassiveEffectsExpirationTime = NoWork;
15541
15542 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
15543 {
15544 throw Error("Cannot flush passive effects while already rendering.");
15545 }
15546 }
15547
15548 var prevExecutionContext = executionContext;
15549 executionContext |= CommitContext;
15550 var prevInteractions = pushInteractions(root); // Note: This currently assumes there are no passive effects on the root
15551 // fiber, because the root is not part of its own effect list. This could
15552 // change in the future.
15553
15554 var effect = root.current.firstEffect;
15555
15556 while (effect !== null) {
15557 {
15558 setCurrentFiber(effect);
15559 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
15560
15561 if (hasCaughtError()) {
15562 if (!(effect !== null)) {
15563 {
15564 throw Error("Should be working on an effect.");
15565 }
15566 }
15567
15568 var error = clearCaughtError();
15569 captureCommitPhaseError(effect, error);
15570 }
15571
15572 resetCurrentFiber();
15573 }
15574
15575 var nextNextEffect = effect.nextEffect; // Remove nextEffect pointer to assist GC
15576
15577 effect.nextEffect = null;
15578 effect = nextNextEffect;
15579 }
15580
15581 if (enableSchedulerTracing) {
15582 popInteractions(prevInteractions);
15583 finishPendingInteractions(root, expirationTime);
15584 }
15585
15586 executionContext = prevExecutionContext;
15587 flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
15588 // exceeds the limit, we'll fire a warning.
15589
15590 nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
15591 return true;
15592}
15593
15594function isAlreadyFailedLegacyErrorBoundary(instance) {
15595 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
15596}
15597function markLegacyErrorBoundaryAsFailed(instance) {
15598 if (legacyErrorBoundariesThatAlreadyFailed === null) {
15599 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
15600 } else {
15601 legacyErrorBoundariesThatAlreadyFailed.add(instance);
15602 }
15603}
15604
15605function prepareToThrowUncaughtError(error) {
15606 if (!hasUncaughtError) {
15607 hasUncaughtError = true;
15608 firstUncaughtError = error;
15609 }
15610}
15611
15612var onUncaughtError = prepareToThrowUncaughtError;
15613
15614function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
15615 var errorInfo = createCapturedValue(error, sourceFiber);
15616 var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
15617 enqueueUpdate(rootFiber, update);
15618 var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
15619
15620 if (root !== null) {
15621 ensureRootIsScheduled(root);
15622 schedulePendingInteractions(root, Sync);
15623 }
15624}
15625
15626function captureCommitPhaseError(sourceFiber, error) {
15627 if (sourceFiber.tag === HostRoot) {
15628 // Error was thrown at the root. There is no parent, so the root
15629 // itself should capture it.
15630 captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
15631 return;
15632 }
15633
15634 var fiber = sourceFiber.return;
15635
15636 while (fiber !== null) {
15637 if (fiber.tag === HostRoot) {
15638 captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
15639 return;
15640 } else if (fiber.tag === ClassComponent) {
15641 var ctor = fiber.type;
15642 var instance = fiber.stateNode;
15643
15644 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
15645 var errorInfo = createCapturedValue(error, sourceFiber);
15646 var update = createClassErrorUpdate(fiber, errorInfo, // TODO: This is always sync
15647 Sync);
15648 enqueueUpdate(fiber, update);
15649 var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
15650
15651 if (root !== null) {
15652 ensureRootIsScheduled(root);
15653 schedulePendingInteractions(root, Sync);
15654 }
15655
15656 return;
15657 }
15658 }
15659
15660 fiber = fiber.return;
15661 }
15662}
15663function pingSuspendedRoot(root, thenable, suspendedTime) {
15664 var pingCache = root.pingCache;
15665
15666 if (pingCache !== null) {
15667 // The thenable resolved, so we no longer need to memoize, because it will
15668 // never be thrown again.
15669 pingCache.delete(thenable);
15670 }
15671
15672 if (workInProgressRoot === root && renderExpirationTime === suspendedTime) {
15673 // Received a ping at the same priority level at which we're currently
15674 // rendering. We might want to restart this render. This should mirror
15675 // the logic of whether or not a root suspends once it completes.
15676 // TODO: If we're rendering sync either due to Sync, Batched or expired,
15677 // we should probably never restart.
15678 // If we're suspended with delay, we'll always suspend so we can always
15679 // restart. If we're suspended without any updates, it might be a retry.
15680 // If it's early in the retry we can restart. We can't know for sure
15681 // whether we'll eventually process an update during this render pass,
15682 // but it's somewhat unlikely that we get to a ping before that, since
15683 // getting to the root most update is usually very fast.
15684 if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && workInProgressRootLatestProcessedExpirationTime === Sync && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
15685 // Restart from the root. Don't need to schedule a ping because
15686 // we're already working on this tree.
15687 prepareFreshStack(root, renderExpirationTime);
15688 } else {
15689 // Even though we can't restart right now, we might get an
15690 // opportunity later. So we mark this render as having a ping.
15691 workInProgressRootHasPendingPing = true;
15692 }
15693
15694 return;
15695 }
15696
15697 if (!isRootSuspendedAtTime(root, suspendedTime)) {
15698 // The root is no longer suspended at this time.
15699 return;
15700 }
15701
15702 var lastPingedTime = root.lastPingedTime;
15703
15704 if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
15705 // There's already a lower priority ping scheduled.
15706 return;
15707 } // Mark the time at which this ping was scheduled.
15708
15709
15710 root.lastPingedTime = suspendedTime;
15711
15712 if (root.finishedExpirationTime === suspendedTime) {
15713 // If there's a pending fallback waiting to commit, throw it away.
15714 root.finishedExpirationTime = NoWork;
15715 root.finishedWork = null;
15716 }
15717
15718 ensureRootIsScheduled(root);
15719 schedulePendingInteractions(root, suspendedTime);
15720}
15721
15722function retryTimedOutBoundary(boundaryFiber, retryTime) {
15723 // The boundary fiber (a Suspense component or SuspenseList component)
15724 // previously was rendered in its fallback state. One of the promises that
15725 // suspended it has resolved, which means at least part of the tree was
15726 // likely unblocked. Try rendering again, at a new expiration time.
15727 if (retryTime === NoWork) {
15728 var suspenseConfig = null; // Retries don't carry over the already committed update.
15729
15730 var currentTime = requestCurrentTimeForUpdate();
15731 retryTime = computeExpirationForFiber(currentTime, boundaryFiber, suspenseConfig);
15732 } // TODO: Special case idle priority?
15733
15734
15735 var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
15736
15737 if (root !== null) {
15738 ensureRootIsScheduled(root);
15739 schedulePendingInteractions(root, retryTime);
15740 }
15741}
15742
15743function retryDehydratedSuspenseBoundary(boundaryFiber) {
15744 var suspenseState = boundaryFiber.memoizedState;
15745 var retryTime = NoWork;
15746
15747 if (suspenseState !== null) {
15748 retryTime = suspenseState.retryTime;
15749 }
15750
15751 retryTimedOutBoundary(boundaryFiber, retryTime);
15752}
15753function resolveRetryThenable(boundaryFiber, thenable) {
15754 var retryTime = NoWork; // Default
15755
15756 var retryCache;
15757
15758 if (enableSuspenseServerRenderer) {
15759 switch (boundaryFiber.tag) {
15760 case SuspenseComponent:
15761 retryCache = boundaryFiber.stateNode;
15762 var suspenseState = boundaryFiber.memoizedState;
15763
15764 if (suspenseState !== null) {
15765 retryTime = suspenseState.retryTime;
15766 }
15767
15768 break;
15769
15770 case SuspenseListComponent:
15771 retryCache = boundaryFiber.stateNode;
15772 break;
15773
15774 default:
15775 {
15776 {
15777 throw Error("Pinged unknown suspense boundary type. This is probably a bug in React.");
15778 }
15779 }
15780
15781 }
15782 } else {
15783 retryCache = boundaryFiber.stateNode;
15784 }
15785
15786 if (retryCache !== null) {
15787 // The thenable resolved, so we no longer need to memoize, because it will
15788 // never be thrown again.
15789 retryCache.delete(thenable);
15790 }
15791
15792 retryTimedOutBoundary(boundaryFiber, retryTime);
15793} // Computes the next Just Noticeable Difference (JND) boundary.
15794// The theory is that a person can't tell the difference between small differences in time.
15795// Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
15796// difference in the experience. However, waiting for longer might mean that we can avoid
15797// showing an intermediate loading state. The longer we have already waited, the harder it
15798// is to tell small differences in time. Therefore, the longer we've already waited,
15799// the longer we can wait additionally. At some point we have to give up though.
15800// We pick a train model where the next boundary commits at a consistent schedule.
15801// These particular numbers are vague estimates. We expect to adjust them based on research.
15802
15803function jnd(timeElapsed) {
15804 return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
15805}
15806
15807function computeMsUntilSuspenseLoadingDelay(mostRecentEventTime, committedExpirationTime, suspenseConfig) {
15808 var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
15809
15810 if (busyMinDurationMs <= 0) {
15811 return 0;
15812 }
15813
15814 var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
15815
15816 var currentTimeMs = now();
15817 var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(mostRecentEventTime, suspenseConfig);
15818 var timeElapsed = currentTimeMs - eventTimeMs;
15819
15820 if (timeElapsed <= busyDelayMs) {
15821 // If we haven't yet waited longer than the initial delay, we don't
15822 // have to wait any additional time.
15823 return 0;
15824 }
15825
15826 var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
15827
15828 return msUntilTimeout;
15829}
15830
15831function checkForNestedUpdates() {
15832 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
15833 nestedUpdateCount = 0;
15834 rootWithNestedUpdates = null;
15835
15836 {
15837 {
15838 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.");
15839 }
15840 }
15841 }
15842
15843 {
15844 if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
15845 nestedPassiveUpdateCount = 0;
15846 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.');
15847 }
15848 }
15849}
15850
15851function flushRenderPhaseStrictModeWarningsInDEV() {
15852 {
15853 ReactStrictModeWarnings.flushLegacyContextWarning();
15854
15855 if (warnAboutDeprecatedLifecycles) {
15856 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
15857 }
15858 }
15859}
15860
15861function stopFinishedWorkLoopTimer() {
15862 var didCompleteRoot = true;
15863 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
15864 interruptedBy = null;
15865}
15866
15867function stopInterruptedWorkLoopTimer() {
15868 // TODO: Track which fiber caused the interruption.
15869 var didCompleteRoot = false;
15870 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
15871 interruptedBy = null;
15872}
15873
15874function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
15875 if (enableUserTimingAPI && workInProgressRoot !== null && updateExpirationTime > renderExpirationTime) {
15876 interruptedBy = fiberThatReceivedUpdate;
15877 }
15878}
15879
15880var didWarnStateUpdateForUnmountedComponent = null;
15881
15882function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
15883 {
15884 var tag = fiber.tag;
15885
15886 if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent) {
15887 // Only warn for user-defined components, not internal ones like Suspense.
15888 return;
15889 } // We show the whole stack but dedupe on the top component's name because
15890 // the problematic code almost always lies inside that component.
15891
15892
15893 var componentName = getComponentName(fiber.type) || 'ReactComponent';
15894
15895 if (didWarnStateUpdateForUnmountedComponent !== null) {
15896 if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
15897 return;
15898 }
15899
15900 didWarnStateUpdateForUnmountedComponent.add(componentName);
15901 } else {
15902 didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
15903 }
15904
15905 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));
15906 }
15907}
15908
15909var beginWork$$1;
15910
15911if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
15912 var dummyFiber = null;
15913
15914 beginWork$$1 = function (current$$1, unitOfWork, expirationTime) {
15915 // If a component throws an error, we replay it again in a synchronously
15916 // dispatched event, so that the debugger will treat it as an uncaught
15917 // error See ReactErrorUtils for more information.
15918 // Before entering the begin phase, copy the work-in-progress onto a dummy
15919 // fiber. If beginWork throws, we'll use this to reset the state.
15920 var originalWorkInProgressCopy = assignFiberPropertiesInDEV(dummyFiber, unitOfWork);
15921
15922 try {
15923 return beginWork$1(current$$1, unitOfWork, expirationTime);
15924 } catch (originalError) {
15925 if (originalError !== null && typeof originalError === 'object' && typeof originalError.then === 'function') {
15926 // Don't replay promises. Treat everything else like an error.
15927 throw originalError;
15928 } // Keep this code in sync with handleError; any changes here must have
15929 // corresponding changes there.
15930
15931
15932 resetContextDependencies();
15933 resetHooks(); // Don't reset current debug fiber, since we're about to work on the
15934 // same fiber again.
15935 // Unwind the failed stack frame
15936
15937 unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
15938
15939 assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
15940
15941 if (enableProfilerTimer && unitOfWork.mode & ProfileMode) {
15942 // Reset the profiler timer.
15943 startProfilerTimer(unitOfWork);
15944 } // Run beginWork again.
15945
15946
15947 invokeGuardedCallback(null, beginWork$1, null, current$$1, unitOfWork, expirationTime);
15948
15949 if (hasCaughtError()) {
15950 var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
15951 // Rethrow this error instead of the original one.
15952
15953 throw replayError;
15954 } else {
15955 // This branch is reachable if the render phase is impure.
15956 throw originalError;
15957 }
15958 }
15959 };
15960} else {
15961 beginWork$$1 = beginWork$1;
15962}
15963
15964var didWarnAboutUpdateInRender = false;
15965var didWarnAboutUpdateInGetChildContext = false;
15966
15967function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) {
15968 {
15969 if (fiber.tag === ClassComponent) {
15970 switch (phase) {
15971 case 'getChildContext':
15972 if (didWarnAboutUpdateInGetChildContext) {
15973 return;
15974 }
15975
15976 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
15977 didWarnAboutUpdateInGetChildContext = true;
15978 break;
15979
15980 case 'render':
15981 if (didWarnAboutUpdateInRender) {
15982 return;
15983 }
15984
15985 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.');
15986 didWarnAboutUpdateInRender = true;
15987 break;
15988 }
15989 }
15990 }
15991} // a 'shared' variable that changes when act() opens/closes in tests.
15992
15993
15994var IsThisRendererActing = {
15995 current: false
15996};
15997function warnIfNotScopedWithMatchingAct(fiber) {
15998 {
15999 if (warnsIfNotActing === true && IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
16000 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));
16001 }
16002 }
16003}
16004function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
16005 {
16006 if (warnsIfNotActing === true && (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
16007 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));
16008 }
16009 }
16010}
16011
16012function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
16013 {
16014 if (warnsIfNotActing === true && executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
16015 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));
16016 }
16017 }
16018}
16019
16020var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
16021
16022var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
16023// scheduler is the actual recommendation. The alternative could be a testing build,
16024// a new lib, or whatever; we dunno just yet. This message is for early adopters
16025// to get their tests right.
16026
16027function warnIfUnmockedScheduler(fiber) {
16028 {
16029 if (didWarnAboutUnmockedScheduler === false && Scheduler.unstable_flushAllWithoutAsserting === undefined) {
16030 if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) {
16031 didWarnAboutUnmockedScheduler = true;
16032 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');
16033 } else if (warnAboutUnmockedScheduler === true) {
16034 didWarnAboutUnmockedScheduler = true;
16035 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');
16036 }
16037 }
16038 }
16039}
16040var componentsThatTriggeredHighPriSuspend = null;
16041function checkForWrongSuspensePriorityInDEV(sourceFiber) {
16042 {
16043 var currentPriorityLevel = getCurrentPriorityLevel();
16044
16045 if ((sourceFiber.mode & ConcurrentMode) !== NoEffect && (currentPriorityLevel === UserBlockingPriority || currentPriorityLevel === ImmediatePriority)) {
16046 var workInProgressNode = sourceFiber;
16047
16048 while (workInProgressNode !== null) {
16049 // Add the component that triggered the suspense
16050 var current$$1 = workInProgressNode.alternate;
16051
16052 if (current$$1 !== null) {
16053 // TODO: warn component that triggers the high priority
16054 // suspend is the HostRoot
16055 switch (workInProgressNode.tag) {
16056 case ClassComponent:
16057 // Loop through the component's update queue and see whether the component
16058 // has triggered any high priority updates
16059 var updateQueue = current$$1.updateQueue;
16060
16061 if (updateQueue !== null) {
16062 var update = updateQueue.firstUpdate;
16063
16064 while (update !== null) {
16065 var priorityLevel = update.priority;
16066
16067 if (priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority) {
16068 if (componentsThatTriggeredHighPriSuspend === null) {
16069 componentsThatTriggeredHighPriSuspend = new Set([getComponentName(workInProgressNode.type)]);
16070 } else {
16071 componentsThatTriggeredHighPriSuspend.add(getComponentName(workInProgressNode.type));
16072 }
16073
16074 break;
16075 }
16076
16077 update = update.next;
16078 }
16079 }
16080
16081 break;
16082
16083 case FunctionComponent:
16084 case ForwardRef:
16085 case SimpleMemoComponent:
16086 if (workInProgressNode.memoizedState !== null && workInProgressNode.memoizedState.baseUpdate !== null) {
16087 var _update = workInProgressNode.memoizedState.baseUpdate; // Loop through the functional component's memoized state to see whether
16088 // the component has triggered any high pri updates
16089
16090 while (_update !== null) {
16091 var priority = _update.priority;
16092
16093 if (priority === UserBlockingPriority || priority === ImmediatePriority) {
16094 if (componentsThatTriggeredHighPriSuspend === null) {
16095 componentsThatTriggeredHighPriSuspend = new Set([getComponentName(workInProgressNode.type)]);
16096 } else {
16097 componentsThatTriggeredHighPriSuspend.add(getComponentName(workInProgressNode.type));
16098 }
16099
16100 break;
16101 }
16102
16103 if (_update.next === workInProgressNode.memoizedState.baseUpdate) {
16104 break;
16105 }
16106
16107 _update = _update.next;
16108 }
16109 }
16110
16111 break;
16112
16113 default:
16114 break;
16115 }
16116 }
16117
16118 workInProgressNode = workInProgressNode.return;
16119 }
16120 }
16121 }
16122}
16123
16124function flushSuspensePriorityWarningInDEV() {
16125 {
16126 if (componentsThatTriggeredHighPriSuspend !== null) {
16127 var componentNames = [];
16128 componentsThatTriggeredHighPriSuspend.forEach(function (name) {
16129 return componentNames.push(name);
16130 });
16131 componentsThatTriggeredHighPriSuspend = null;
16132
16133 if (componentNames.length > 0) {
16134 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
16135 componentNames.sort().join(', '));
16136 }
16137 }
16138 }
16139}
16140
16141function computeThreadID(root, expirationTime) {
16142 // Interaction threads are unique per root and expiration time.
16143 return expirationTime * 1000 + root.interactionThreadID;
16144}
16145
16146function markSpawnedWork(expirationTime) {
16147 if (!enableSchedulerTracing) {
16148 return;
16149 }
16150
16151 if (spawnedWorkDuringRender === null) {
16152 spawnedWorkDuringRender = [expirationTime];
16153 } else {
16154 spawnedWorkDuringRender.push(expirationTime);
16155 }
16156}
16157
16158function scheduleInteractions(root, expirationTime, interactions) {
16159 if (!enableSchedulerTracing) {
16160 return;
16161 }
16162
16163 if (interactions.size > 0) {
16164 var pendingInteractionMap = root.pendingInteractionMap;
16165 var pendingInteractions = pendingInteractionMap.get(expirationTime);
16166
16167 if (pendingInteractions != null) {
16168 interactions.forEach(function (interaction) {
16169 if (!pendingInteractions.has(interaction)) {
16170 // Update the pending async work count for previously unscheduled interaction.
16171 interaction.__count++;
16172 }
16173
16174 pendingInteractions.add(interaction);
16175 });
16176 } else {
16177 pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
16178
16179 interactions.forEach(function (interaction) {
16180 interaction.__count++;
16181 });
16182 }
16183
16184 var subscriber = tracing.__subscriberRef.current;
16185
16186 if (subscriber !== null) {
16187 var threadID = computeThreadID(root, expirationTime);
16188 subscriber.onWorkScheduled(interactions, threadID);
16189 }
16190 }
16191}
16192
16193function schedulePendingInteractions(root, expirationTime) {
16194 // This is called when work is scheduled on a root.
16195 // It associates the current interactions with the newly-scheduled expiration.
16196 // They will be restored when that expiration is later committed.
16197 if (!enableSchedulerTracing) {
16198 return;
16199 }
16200
16201 scheduleInteractions(root, expirationTime, tracing.__interactionsRef.current);
16202}
16203
16204function startWorkOnPendingInteractions(root, expirationTime) {
16205 // This is called when new work is started on a root.
16206 if (!enableSchedulerTracing) {
16207 return;
16208 } // Determine which interactions this batch of work currently includes, So that
16209 // we can accurately attribute time spent working on it, And so that cascading
16210 // work triggered during the render phase will be associated with it.
16211
16212
16213 var interactions = new Set();
16214 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
16215 if (scheduledExpirationTime >= expirationTime) {
16216 scheduledInteractions.forEach(function (interaction) {
16217 return interactions.add(interaction);
16218 });
16219 }
16220 }); // Store the current set of interactions on the FiberRoot for a few reasons:
16221 // We can re-use it in hot functions like performConcurrentWorkOnRoot()
16222 // without having to recalculate it. We will also use it in commitWork() to
16223 // pass to any Profiler onRender() hooks. This also provides DevTools with a
16224 // way to access it when the onCommitRoot() hook is called.
16225
16226 root.memoizedInteractions = interactions;
16227
16228 if (interactions.size > 0) {
16229 var subscriber = tracing.__subscriberRef.current;
16230
16231 if (subscriber !== null) {
16232 var threadID = computeThreadID(root, expirationTime);
16233
16234 try {
16235 subscriber.onWorkStarted(interactions, threadID);
16236 } catch (error) {
16237 // If the subscriber throws, rethrow it in a separate task
16238 scheduleCallback(ImmediatePriority, function () {
16239 throw error;
16240 });
16241 }
16242 }
16243 }
16244}
16245
16246function finishPendingInteractions(root, committedExpirationTime) {
16247 if (!enableSchedulerTracing) {
16248 return;
16249 }
16250
16251 var earliestRemainingTimeAfterCommit = root.firstPendingTime;
16252 var subscriber;
16253
16254 try {
16255 subscriber = tracing.__subscriberRef.current;
16256
16257 if (subscriber !== null && root.memoizedInteractions.size > 0) {
16258 var threadID = computeThreadID(root, committedExpirationTime);
16259 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
16260 }
16261 } catch (error) {
16262 // If the subscriber throws, rethrow it in a separate task
16263 scheduleCallback(ImmediatePriority, function () {
16264 throw error;
16265 });
16266 } finally {
16267 // Clear completed interactions from the pending Map.
16268 // Unless the render was suspended or cascading work was scheduled,
16269 // In which case– leave pending interactions until the subsequent render.
16270 var pendingInteractionMap = root.pendingInteractionMap;
16271 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
16272 // Only decrement the pending interaction count if we're done.
16273 // If there's still work at the current priority,
16274 // That indicates that we are waiting for suspense data.
16275 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
16276 pendingInteractionMap.delete(scheduledExpirationTime);
16277 scheduledInteractions.forEach(function (interaction) {
16278 interaction.__count--;
16279
16280 if (subscriber !== null && interaction.__count === 0) {
16281 try {
16282 subscriber.onInteractionScheduledWorkCompleted(interaction);
16283 } catch (error) {
16284 // If the subscriber throws, rethrow it in a separate task
16285 scheduleCallback(ImmediatePriority, function () {
16286 throw error;
16287 });
16288 }
16289 }
16290 });
16291 }
16292 });
16293 }
16294}
16295
16296var onCommitFiberRoot = null;
16297var onCommitFiberUnmount = null;
16298var hasLoggedError = false;
16299var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
16300function injectInternals(internals) {
16301 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
16302 // No DevTools
16303 return false;
16304 }
16305
16306 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
16307
16308 if (hook.isDisabled) {
16309 // This isn't a real property on the hook, but it can be set to opt out
16310 // of DevTools integration and associated warnings and logs.
16311 // https://github.com/facebook/react/issues/3877
16312 return true;
16313 }
16314
16315 if (!hook.supportsFiber) {
16316 {
16317 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');
16318 } // DevTools exists, even though it doesn't support Fiber.
16319
16320
16321 return true;
16322 }
16323
16324 try {
16325 var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
16326
16327 onCommitFiberRoot = function (root, expirationTime) {
16328 try {
16329 var didError = (root.current.effectTag & DidCapture) === DidCapture;
16330
16331 if (enableProfilerTimer) {
16332 var currentTime = getCurrentTime();
16333 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime);
16334 hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
16335 } else {
16336 hook.onCommitFiberRoot(rendererID, root, undefined, didError);
16337 }
16338 } catch (err) {
16339 if (true && !hasLoggedError) {
16340 hasLoggedError = true;
16341 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
16342 }
16343 }
16344 };
16345
16346 onCommitFiberUnmount = function (fiber) {
16347 try {
16348 hook.onCommitFiberUnmount(rendererID, fiber);
16349 } catch (err) {
16350 if (true && !hasLoggedError) {
16351 hasLoggedError = true;
16352 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
16353 }
16354 }
16355 };
16356 } catch (err) {
16357 // Catch all errors because it is unsafe to throw during initialization.
16358 {
16359 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
16360 }
16361 } // DevTools exists
16362
16363
16364 return true;
16365}
16366function onCommitRoot(root, expirationTime) {
16367 if (typeof onCommitFiberRoot === 'function') {
16368 onCommitFiberRoot(root, expirationTime);
16369 }
16370}
16371function onCommitUnmount(fiber) {
16372 if (typeof onCommitFiberUnmount === 'function') {
16373 onCommitFiberUnmount(fiber);
16374 }
16375}
16376
16377var hasBadMapPolyfill;
16378
16379{
16380 hasBadMapPolyfill = false;
16381
16382 try {
16383 var nonExtensibleObject = Object.preventExtensions({});
16384 var testMap = new Map([[nonExtensibleObject, null]]);
16385 var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
16386 // https://github.com/rollup/rollup/issues/1771
16387 // TODO: we can remove these if Rollup fixes the bug.
16388
16389 testMap.set(0, 0);
16390 testSet.add(0);
16391 } catch (e) {
16392 // TODO: Consider warning about bad polyfills
16393 hasBadMapPolyfill = true;
16394 }
16395}
16396
16397var debugCounter = 1;
16398
16399function FiberNode(tag, pendingProps, key, mode) {
16400 // Instance
16401 this.tag = tag;
16402 this.key = key;
16403 this.elementType = null;
16404 this.type = null;
16405 this.stateNode = null; // Fiber
16406
16407 this.return = null;
16408 this.child = null;
16409 this.sibling = null;
16410 this.index = 0;
16411 this.ref = null;
16412 this.pendingProps = pendingProps;
16413 this.memoizedProps = null;
16414 this.updateQueue = null;
16415 this.memoizedState = null;
16416 this.dependencies = null;
16417 this.mode = mode; // Effects
16418
16419 this.effectTag = NoEffect;
16420 this.nextEffect = null;
16421 this.firstEffect = null;
16422 this.lastEffect = null;
16423 this.expirationTime = NoWork;
16424 this.childExpirationTime = NoWork;
16425 this.alternate = null;
16426
16427 if (enableProfilerTimer) {
16428 // Note: The following is done to avoid a v8 performance cliff.
16429 //
16430 // Initializing the fields below to smis and later updating them with
16431 // double values will cause Fibers to end up having separate shapes.
16432 // This behavior/bug has something to do with Object.preventExtension().
16433 // Fortunately this only impacts DEV builds.
16434 // Unfortunately it makes React unusably slow for some applications.
16435 // To work around this, initialize the fields below with doubles.
16436 //
16437 // Learn more about this here:
16438 // https://github.com/facebook/react/issues/14365
16439 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
16440 this.actualDuration = Number.NaN;
16441 this.actualStartTime = Number.NaN;
16442 this.selfBaseDuration = Number.NaN;
16443 this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
16444 // This won't trigger the performance cliff mentioned above,
16445 // and it simplifies other profiler code (including DevTools).
16446
16447 this.actualDuration = 0;
16448 this.actualStartTime = -1;
16449 this.selfBaseDuration = 0;
16450 this.treeBaseDuration = 0;
16451 } // This is normally DEV-only except www when it adds listeners.
16452 // TODO: remove the User Timing integration in favor of Root Events.
16453
16454
16455 if (enableUserTimingAPI) {
16456 this._debugID = debugCounter++;
16457 this._debugIsCurrentlyTiming = false;
16458 }
16459
16460 {
16461 this._debugSource = null;
16462 this._debugOwner = null;
16463 this._debugNeedsRemount = false;
16464 this._debugHookTypes = null;
16465
16466 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
16467 Object.preventExtensions(this);
16468 }
16469 }
16470} // This is a constructor function, rather than a POJO constructor, still
16471// please ensure we do the following:
16472// 1) Nobody should add any instance methods on this. Instance methods can be
16473// more difficult to predict when they get optimized and they are almost
16474// never inlined properly in static compilers.
16475// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
16476// always know when it is a fiber.
16477// 3) We might want to experiment with using numeric keys since they are easier
16478// to optimize in a non-JIT environment.
16479// 4) We can easily go from a constructor to a createFiber object literal if that
16480// is faster.
16481// 5) It should be easy to port this to a C struct and keep a C implementation
16482// compatible.
16483
16484
16485var createFiber = function (tag, pendingProps, key, mode) {
16486 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
16487 return new FiberNode(tag, pendingProps, key, mode);
16488};
16489
16490function shouldConstruct(Component) {
16491 var prototype = Component.prototype;
16492 return !!(prototype && prototype.isReactComponent);
16493}
16494
16495function isSimpleFunctionComponent(type) {
16496 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
16497}
16498function resolveLazyComponentTag(Component) {
16499 if (typeof Component === 'function') {
16500 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
16501 } else if (Component !== undefined && Component !== null) {
16502 var $$typeof = Component.$$typeof;
16503
16504 if ($$typeof === REACT_FORWARD_REF_TYPE) {
16505 return ForwardRef;
16506 }
16507
16508 if ($$typeof === REACT_MEMO_TYPE) {
16509 return MemoComponent;
16510 }
16511 }
16512
16513 return IndeterminateComponent;
16514} // This is used to create an alternate fiber to do work on.
16515
16516function createWorkInProgress(current, pendingProps, expirationTime) {
16517 var workInProgress = current.alternate;
16518
16519 if (workInProgress === null) {
16520 // We use a double buffering pooling technique because we know that we'll
16521 // only ever need at most two versions of a tree. We pool the "other" unused
16522 // node that we're free to reuse. This is lazily created to avoid allocating
16523 // extra objects for things that are never updated. It also allow us to
16524 // reclaim the extra memory if needed.
16525 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
16526 workInProgress.elementType = current.elementType;
16527 workInProgress.type = current.type;
16528 workInProgress.stateNode = current.stateNode;
16529
16530 {
16531 // DEV-only fields
16532 workInProgress._debugID = current._debugID;
16533 workInProgress._debugSource = current._debugSource;
16534 workInProgress._debugOwner = current._debugOwner;
16535 workInProgress._debugHookTypes = current._debugHookTypes;
16536 }
16537
16538 workInProgress.alternate = current;
16539 current.alternate = workInProgress;
16540 } else {
16541 workInProgress.pendingProps = pendingProps; // We already have an alternate.
16542 // Reset the effect tag.
16543
16544 workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
16545
16546 workInProgress.nextEffect = null;
16547 workInProgress.firstEffect = null;
16548 workInProgress.lastEffect = null;
16549
16550 if (enableProfilerTimer) {
16551 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
16552 // This prevents time from endlessly accumulating in new commits.
16553 // This has the downside of resetting values for different priority renders,
16554 // But works for yielding (the common case) and should support resuming.
16555 workInProgress.actualDuration = 0;
16556 workInProgress.actualStartTime = -1;
16557 }
16558 }
16559
16560 workInProgress.childExpirationTime = current.childExpirationTime;
16561 workInProgress.expirationTime = current.expirationTime;
16562 workInProgress.child = current.child;
16563 workInProgress.memoizedProps = current.memoizedProps;
16564 workInProgress.memoizedState = current.memoizedState;
16565 workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
16566 // it cannot be shared with the current fiber.
16567
16568 var currentDependencies = current.dependencies;
16569 workInProgress.dependencies = currentDependencies === null ? null : {
16570 expirationTime: currentDependencies.expirationTime,
16571 firstContext: currentDependencies.firstContext,
16572 responders: currentDependencies.responders
16573 }; // These will be overridden during the parent's reconciliation
16574
16575 workInProgress.sibling = current.sibling;
16576 workInProgress.index = current.index;
16577 workInProgress.ref = current.ref;
16578
16579 if (enableProfilerTimer) {
16580 workInProgress.selfBaseDuration = current.selfBaseDuration;
16581 workInProgress.treeBaseDuration = current.treeBaseDuration;
16582 }
16583
16584 {
16585 workInProgress._debugNeedsRemount = current._debugNeedsRemount;
16586
16587 switch (workInProgress.tag) {
16588 case IndeterminateComponent:
16589 case FunctionComponent:
16590 case SimpleMemoComponent:
16591 workInProgress.type = resolveFunctionForHotReloading(current.type);
16592 break;
16593
16594 case ClassComponent:
16595 workInProgress.type = resolveClassForHotReloading(current.type);
16596 break;
16597
16598 case ForwardRef:
16599 workInProgress.type = resolveForwardRefForHotReloading(current.type);
16600 break;
16601
16602 default:
16603 break;
16604 }
16605 }
16606
16607 return workInProgress;
16608} // Used to reuse a Fiber for a second pass.
16609
16610function resetWorkInProgress(workInProgress, renderExpirationTime) {
16611 // This resets the Fiber to what createFiber or createWorkInProgress would
16612 // have set the values to before during the first pass. Ideally this wouldn't
16613 // be necessary but unfortunately many code paths reads from the workInProgress
16614 // when they should be reading from current and writing to workInProgress.
16615 // We assume pendingProps, index, key, ref, return are still untouched to
16616 // avoid doing another reconciliation.
16617 // Reset the effect tag but keep any Placement tags, since that's something
16618 // that child fiber is setting, not the reconciliation.
16619 workInProgress.effectTag &= Placement; // The effect list is no longer valid.
16620
16621 workInProgress.nextEffect = null;
16622 workInProgress.firstEffect = null;
16623 workInProgress.lastEffect = null;
16624 var current = workInProgress.alternate;
16625
16626 if (current === null) {
16627 // Reset to createFiber's initial values.
16628 workInProgress.childExpirationTime = NoWork;
16629 workInProgress.expirationTime = renderExpirationTime;
16630 workInProgress.child = null;
16631 workInProgress.memoizedProps = null;
16632 workInProgress.memoizedState = null;
16633 workInProgress.updateQueue = null;
16634 workInProgress.dependencies = null;
16635
16636 if (enableProfilerTimer) {
16637 // Note: We don't reset the actualTime counts. It's useful to accumulate
16638 // actual time across multiple render passes.
16639 workInProgress.selfBaseDuration = 0;
16640 workInProgress.treeBaseDuration = 0;
16641 }
16642 } else {
16643 // Reset to the cloned values that createWorkInProgress would've.
16644 workInProgress.childExpirationTime = current.childExpirationTime;
16645 workInProgress.expirationTime = current.expirationTime;
16646 workInProgress.child = current.child;
16647 workInProgress.memoizedProps = current.memoizedProps;
16648 workInProgress.memoizedState = current.memoizedState;
16649 workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
16650 // it cannot be shared with the current fiber.
16651
16652 var currentDependencies = current.dependencies;
16653 workInProgress.dependencies = currentDependencies === null ? null : {
16654 expirationTime: currentDependencies.expirationTime,
16655 firstContext: currentDependencies.firstContext,
16656 responders: currentDependencies.responders
16657 };
16658
16659 if (enableProfilerTimer) {
16660 // Note: We don't reset the actualTime counts. It's useful to accumulate
16661 // actual time across multiple render passes.
16662 workInProgress.selfBaseDuration = current.selfBaseDuration;
16663 workInProgress.treeBaseDuration = current.treeBaseDuration;
16664 }
16665 }
16666
16667 return workInProgress;
16668}
16669function createHostRootFiber(tag) {
16670 var mode;
16671
16672 if (tag === ConcurrentRoot) {
16673 mode = ConcurrentMode | BatchedMode | StrictMode;
16674 } else if (tag === BatchedRoot) {
16675 mode = BatchedMode | StrictMode;
16676 } else {
16677 mode = NoMode;
16678 }
16679
16680 if (enableProfilerTimer && isDevToolsPresent) {
16681 // Always collect profile timings when DevTools are present.
16682 // This enables DevTools to start capturing timing at any point–
16683 // Without some nodes in the tree having empty base times.
16684 mode |= ProfileMode;
16685 }
16686
16687 return createFiber(HostRoot, null, null, mode);
16688}
16689function createFiberFromTypeAndProps(type, // React$ElementType
16690key, pendingProps, owner, mode, expirationTime) {
16691 var fiber;
16692 var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
16693
16694 var resolvedType = type;
16695
16696 if (typeof type === 'function') {
16697 if (shouldConstruct(type)) {
16698 fiberTag = ClassComponent;
16699
16700 {
16701 resolvedType = resolveClassForHotReloading(resolvedType);
16702 }
16703 } else {
16704 {
16705 resolvedType = resolveFunctionForHotReloading(resolvedType);
16706 }
16707 }
16708 } else if (typeof type === 'string') {
16709 fiberTag = HostComponent;
16710 } else {
16711 getTag: switch (type) {
16712 case REACT_FRAGMENT_TYPE:
16713 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
16714
16715 case REACT_CONCURRENT_MODE_TYPE:
16716 fiberTag = Mode$1;
16717 mode |= ConcurrentMode | BatchedMode | StrictMode;
16718 break;
16719
16720 case REACT_STRICT_MODE_TYPE:
16721 fiberTag = Mode$1;
16722 mode |= StrictMode;
16723 break;
16724
16725 case REACT_PROFILER_TYPE:
16726 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
16727
16728 case REACT_SUSPENSE_TYPE:
16729 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
16730
16731 case REACT_SUSPENSE_LIST_TYPE:
16732 return createFiberFromSuspenseList(pendingProps, mode, expirationTime, key);
16733
16734 default:
16735 {
16736 if (typeof type === 'object' && type !== null) {
16737 switch (type.$$typeof) {
16738 case REACT_PROVIDER_TYPE:
16739 fiberTag = ContextProvider;
16740 break getTag;
16741
16742 case REACT_CONTEXT_TYPE:
16743 // This is a consumer
16744 fiberTag = ContextConsumer;
16745 break getTag;
16746
16747 case REACT_FORWARD_REF_TYPE:
16748 fiberTag = ForwardRef;
16749
16750 {
16751 resolvedType = resolveForwardRefForHotReloading(resolvedType);
16752 }
16753
16754 break getTag;
16755
16756 case REACT_MEMO_TYPE:
16757 fiberTag = MemoComponent;
16758 break getTag;
16759
16760 case REACT_LAZY_TYPE:
16761 fiberTag = LazyComponent;
16762 resolvedType = null;
16763 break getTag;
16764
16765 case REACT_FUNDAMENTAL_TYPE:
16766 if (enableFundamentalAPI) {
16767 return createFiberFromFundamental(type, pendingProps, mode, expirationTime, key);
16768 }
16769
16770 break;
16771
16772 case REACT_SCOPE_TYPE:
16773 if (enableScopeAPI) {
16774 return createFiberFromScope(type, pendingProps, mode, expirationTime, key);
16775 }
16776
16777 }
16778 }
16779
16780 var info = '';
16781
16782 {
16783 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
16784 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.';
16785 }
16786
16787 var ownerName = owner ? getComponentName(owner.type) : null;
16788
16789 if (ownerName) {
16790 info += '\n\nCheck the render method of `' + ownerName + '`.';
16791 }
16792 }
16793
16794 {
16795 {
16796 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);
16797 }
16798 }
16799 }
16800 }
16801 }
16802
16803 fiber = createFiber(fiberTag, pendingProps, key, mode);
16804 fiber.elementType = type;
16805 fiber.type = resolvedType;
16806 fiber.expirationTime = expirationTime;
16807 return fiber;
16808}
16809function createFiberFromElement(element, mode, expirationTime) {
16810 var owner = null;
16811
16812 {
16813 owner = element._owner;
16814 }
16815
16816 var type = element.type;
16817 var key = element.key;
16818 var pendingProps = element.props;
16819 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
16820
16821 {
16822 fiber._debugSource = element._source;
16823 fiber._debugOwner = element._owner;
16824 }
16825
16826 return fiber;
16827}
16828function createFiberFromFragment(elements, mode, expirationTime, key) {
16829 var fiber = createFiber(Fragment, elements, key, mode);
16830 fiber.expirationTime = expirationTime;
16831 return fiber;
16832}
16833function createFiberFromFundamental(fundamentalComponent, pendingProps, mode, expirationTime, key) {
16834 var fiber = createFiber(FundamentalComponent, pendingProps, key, mode);
16835 fiber.elementType = fundamentalComponent;
16836 fiber.type = fundamentalComponent;
16837 fiber.expirationTime = expirationTime;
16838 return fiber;
16839}
16840
16841function createFiberFromScope(scope, pendingProps, mode, expirationTime, key) {
16842 var fiber = createFiber(ScopeComponent, pendingProps, key, mode);
16843 fiber.type = scope;
16844 fiber.elementType = scope;
16845 fiber.expirationTime = expirationTime;
16846 return fiber;
16847}
16848
16849function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
16850 {
16851 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
16852 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
16853 }
16854 }
16855
16856 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
16857
16858 fiber.elementType = REACT_PROFILER_TYPE;
16859 fiber.type = REACT_PROFILER_TYPE;
16860 fiber.expirationTime = expirationTime;
16861 return fiber;
16862}
16863
16864function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
16865 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
16866 // This needs to be fixed in getComponentName so that it relies on the tag
16867 // instead.
16868
16869 fiber.type = REACT_SUSPENSE_TYPE;
16870 fiber.elementType = REACT_SUSPENSE_TYPE;
16871 fiber.expirationTime = expirationTime;
16872 return fiber;
16873}
16874function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
16875 var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
16876
16877 {
16878 // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
16879 // This needs to be fixed in getComponentName so that it relies on the tag
16880 // instead.
16881 fiber.type = REACT_SUSPENSE_LIST_TYPE;
16882 }
16883
16884 fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
16885 fiber.expirationTime = expirationTime;
16886 return fiber;
16887}
16888function createFiberFromText(content, mode, expirationTime) {
16889 var fiber = createFiber(HostText, content, null, mode);
16890 fiber.expirationTime = expirationTime;
16891 return fiber;
16892}
16893function createFiberFromHostInstanceForDeletion() {
16894 var fiber = createFiber(HostComponent, null, null, NoMode); // TODO: These should not need a type.
16895
16896 fiber.elementType = 'DELETED';
16897 fiber.type = 'DELETED';
16898 return fiber;
16899}
16900function createFiberFromDehydratedFragment(dehydratedNode) {
16901 var fiber = createFiber(DehydratedFragment, null, null, NoMode);
16902 fiber.stateNode = dehydratedNode;
16903 return fiber;
16904}
16905function createFiberFromPortal(portal, mode, expirationTime) {
16906 var pendingProps = portal.children !== null ? portal.children : [];
16907 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
16908 fiber.expirationTime = expirationTime;
16909 fiber.stateNode = {
16910 containerInfo: portal.containerInfo,
16911 pendingChildren: null,
16912 // Used by persistent updates
16913 implementation: portal.implementation
16914 };
16915 return fiber;
16916} // Used for stashing WIP properties to replay failed work in DEV.
16917
16918function assignFiberPropertiesInDEV(target, source) {
16919 if (target === null) {
16920 // This Fiber's initial properties will always be overwritten.
16921 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
16922 target = createFiber(IndeterminateComponent, null, null, NoMode);
16923 } // This is intentionally written as a list of all properties.
16924 // We tried to use Object.assign() instead but this is called in
16925 // the hottest path, and Object.assign() was too slow:
16926 // https://github.com/facebook/react/issues/12502
16927 // This code is DEV-only so size is not a concern.
16928
16929
16930 target.tag = source.tag;
16931 target.key = source.key;
16932 target.elementType = source.elementType;
16933 target.type = source.type;
16934 target.stateNode = source.stateNode;
16935 target.return = source.return;
16936 target.child = source.child;
16937 target.sibling = source.sibling;
16938 target.index = source.index;
16939 target.ref = source.ref;
16940 target.pendingProps = source.pendingProps;
16941 target.memoizedProps = source.memoizedProps;
16942 target.updateQueue = source.updateQueue;
16943 target.memoizedState = source.memoizedState;
16944 target.dependencies = source.dependencies;
16945 target.mode = source.mode;
16946 target.effectTag = source.effectTag;
16947 target.nextEffect = source.nextEffect;
16948 target.firstEffect = source.firstEffect;
16949 target.lastEffect = source.lastEffect;
16950 target.expirationTime = source.expirationTime;
16951 target.childExpirationTime = source.childExpirationTime;
16952 target.alternate = source.alternate;
16953
16954 if (enableProfilerTimer) {
16955 target.actualDuration = source.actualDuration;
16956 target.actualStartTime = source.actualStartTime;
16957 target.selfBaseDuration = source.selfBaseDuration;
16958 target.treeBaseDuration = source.treeBaseDuration;
16959 }
16960
16961 target._debugID = source._debugID;
16962 target._debugSource = source._debugSource;
16963 target._debugOwner = source._debugOwner;
16964 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
16965 target._debugNeedsRemount = source._debugNeedsRemount;
16966 target._debugHookTypes = source._debugHookTypes;
16967 return target;
16968}
16969
16970function FiberRootNode(containerInfo, tag, hydrate) {
16971 this.tag = tag;
16972 this.current = null;
16973 this.containerInfo = containerInfo;
16974 this.pendingChildren = null;
16975 this.pingCache = null;
16976 this.finishedExpirationTime = NoWork;
16977 this.finishedWork = null;
16978 this.timeoutHandle = noTimeout;
16979 this.context = null;
16980 this.pendingContext = null;
16981 this.hydrate = hydrate;
16982 this.callbackNode = null;
16983 this.callbackPriority = NoPriority;
16984 this.firstPendingTime = NoWork;
16985 this.firstSuspendedTime = NoWork;
16986 this.lastSuspendedTime = NoWork;
16987 this.nextKnownPendingLevel = NoWork;
16988 this.lastPingedTime = NoWork;
16989 this.lastExpiredTime = NoWork;
16990
16991 if (enableSchedulerTracing) {
16992 this.interactionThreadID = tracing.unstable_getThreadID();
16993 this.memoizedInteractions = new Set();
16994 this.pendingInteractionMap = new Map();
16995 }
16996
16997 if (enableSuspenseCallback) {
16998 this.hydrationCallbacks = null;
16999 }
17000}
17001
17002function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
17003 var root = new FiberRootNode(containerInfo, tag, hydrate);
17004
17005 if (enableSuspenseCallback) {
17006 root.hydrationCallbacks = hydrationCallbacks;
17007 } // Cyclic construction. This cheats the type system right now because
17008 // stateNode is any.
17009
17010
17011 var uninitializedFiber = createHostRootFiber(tag);
17012 root.current = uninitializedFiber;
17013 uninitializedFiber.stateNode = root;
17014 return root;
17015}
17016function isRootSuspendedAtTime(root, expirationTime) {
17017 var firstSuspendedTime = root.firstSuspendedTime;
17018 var lastSuspendedTime = root.lastSuspendedTime;
17019 return firstSuspendedTime !== NoWork && firstSuspendedTime >= expirationTime && lastSuspendedTime <= expirationTime;
17020}
17021function markRootSuspendedAtTime(root, expirationTime) {
17022 var firstSuspendedTime = root.firstSuspendedTime;
17023 var lastSuspendedTime = root.lastSuspendedTime;
17024
17025 if (firstSuspendedTime < expirationTime) {
17026 root.firstSuspendedTime = expirationTime;
17027 }
17028
17029 if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
17030 root.lastSuspendedTime = expirationTime;
17031 }
17032
17033 if (expirationTime <= root.lastPingedTime) {
17034 root.lastPingedTime = NoWork;
17035 }
17036
17037 if (expirationTime <= root.lastExpiredTime) {
17038 root.lastExpiredTime = NoWork;
17039 }
17040}
17041function markRootUpdatedAtTime(root, expirationTime) {
17042 // Update the range of pending times
17043 var firstPendingTime = root.firstPendingTime;
17044
17045 if (expirationTime > firstPendingTime) {
17046 root.firstPendingTime = expirationTime;
17047 } // Update the range of suspended times. Treat everything lower priority or
17048 // equal to this update as unsuspended.
17049
17050
17051 var firstSuspendedTime = root.firstSuspendedTime;
17052
17053 if (firstSuspendedTime !== NoWork) {
17054 if (expirationTime >= firstSuspendedTime) {
17055 // The entire suspended range is now unsuspended.
17056 root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
17057 } else if (expirationTime >= root.lastSuspendedTime) {
17058 root.lastSuspendedTime = expirationTime + 1;
17059 } // This is a pending level. Check if it's higher priority than the next
17060 // known pending level.
17061
17062
17063 if (expirationTime > root.nextKnownPendingLevel) {
17064 root.nextKnownPendingLevel = expirationTime;
17065 }
17066 }
17067}
17068function markRootFinishedAtTime(root, finishedExpirationTime, remainingExpirationTime) {
17069 // Update the range of pending times
17070 root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
17071 // equal to this update as unsuspended.
17072
17073 if (finishedExpirationTime <= root.lastSuspendedTime) {
17074 // The entire suspended range is now unsuspended.
17075 root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
17076 } else if (finishedExpirationTime <= root.firstSuspendedTime) {
17077 // Part of the suspended range is now unsuspended. Narrow the range to
17078 // include everything between the unsuspended time (non-inclusive) and the
17079 // last suspended time.
17080 root.firstSuspendedTime = finishedExpirationTime - 1;
17081 }
17082
17083 if (finishedExpirationTime <= root.lastPingedTime) {
17084 // Clear the pinged time
17085 root.lastPingedTime = NoWork;
17086 }
17087
17088 if (finishedExpirationTime <= root.lastExpiredTime) {
17089 // Clear the expired time
17090 root.lastExpiredTime = NoWork;
17091 }
17092}
17093function markRootExpiredAtTime(root, expirationTime) {
17094 var lastExpiredTime = root.lastExpiredTime;
17095
17096 if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
17097 root.lastExpiredTime = expirationTime;
17098 }
17099}
17100
17101// This lets us hook into Fiber to debug what it's doing.
17102// See https://github.com/facebook/react/pull/8033.
17103// This is not part of the public API, not even for React DevTools.
17104// You may only inject a debugTool if you work on React Fiber itself.
17105var ReactFiberInstrumentation = {
17106 debugTool: null
17107};
17108var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
17109
17110var didWarnAboutNestedUpdates;
17111{
17112 didWarnAboutNestedUpdates = false;
17113
17114}
17115
17116function getContextForSubtree(parentComponent) {
17117 if (!parentComponent) {
17118 return emptyContextObject;
17119 }
17120
17121 var fiber = get(parentComponent);
17122 var parentContext = findCurrentUnmaskedContext(fiber);
17123
17124 if (fiber.tag === ClassComponent) {
17125 var Component = fiber.type;
17126
17127 if (isContextProvider(Component)) {
17128 return processChildContext(fiber, Component, parentContext);
17129 }
17130 }
17131
17132 return parentContext;
17133}
17134
17135function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
17136 return createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks);
17137}
17138function updateContainer(element, container, parentComponent, callback) {
17139 var current$$1 = container.current;
17140 var currentTime = requestCurrentTimeForUpdate();
17141
17142 {
17143 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
17144 if ('undefined' !== typeof jest) {
17145 warnIfUnmockedScheduler(current$$1);
17146 warnIfNotScopedWithMatchingAct(current$$1);
17147 }
17148 }
17149
17150 var suspenseConfig = requestCurrentSuspenseConfig();
17151 var expirationTime = computeExpirationForFiber(currentTime, current$$1, suspenseConfig);
17152
17153 {
17154 if (ReactFiberInstrumentation_1.debugTool) {
17155 if (current$$1.alternate === null) {
17156 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
17157 } else if (element === null) {
17158 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
17159 } else {
17160 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
17161 }
17162 }
17163 }
17164
17165 var context = getContextForSubtree(parentComponent);
17166
17167 if (container.context === null) {
17168 container.context = context;
17169 } else {
17170 container.pendingContext = context;
17171 }
17172
17173 {
17174 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
17175 didWarnAboutNestedUpdates = true;
17176 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');
17177 }
17178 }
17179
17180 var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
17181 // being called "element".
17182
17183 update.payload = {
17184 element: element
17185 };
17186 callback = callback === undefined ? null : callback;
17187
17188 if (callback !== null) {
17189 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
17190 update.callback = callback;
17191 }
17192
17193 enqueueUpdate(current$$1, update);
17194 scheduleWork(current$$1, expirationTime);
17195 return expirationTime;
17196}
17197
17198
17199
17200
17201
17202
17203
17204
17205var shouldSuspendImpl = function (fiber) {
17206 return false;
17207};
17208
17209function shouldSuspend(fiber) {
17210 return shouldSuspendImpl(fiber);
17211}
17212var overrideHookState = null;
17213var overrideProps = null;
17214var scheduleUpdate = null;
17215var setSuspenseHandler = null;
17216
17217{
17218 var copyWithSetImpl = function (obj, path, idx, value) {
17219 if (idx >= path.length) {
17220 return value;
17221 }
17222
17223 var key = path[idx];
17224 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
17225
17226 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
17227 return updated;
17228 };
17229
17230 var copyWithSet = function (obj, path, value) {
17231 return copyWithSetImpl(obj, path, 0, value);
17232 }; // Support DevTools editable values for useState and useReducer.
17233
17234
17235 overrideHookState = function (fiber, id, path, value) {
17236 // For now, the "id" of stateful hooks is just the stateful hook index.
17237 // This may change in the future with e.g. nested hooks.
17238 var currentHook = fiber.memoizedState;
17239
17240 while (currentHook !== null && id > 0) {
17241 currentHook = currentHook.next;
17242 id--;
17243 }
17244
17245 if (currentHook !== null) {
17246 var newState = copyWithSet(currentHook.memoizedState, path, value);
17247 currentHook.memoizedState = newState;
17248 currentHook.baseState = newState; // We aren't actually adding an update to the queue,
17249 // because there is no update we can add for useReducer hooks that won't trigger an error.
17250 // (There's no appropriate action type for DevTools overrides.)
17251 // As a result though, React will see the scheduled update as a noop and bailout.
17252 // Shallow cloning props works as a workaround for now to bypass the bailout check.
17253
17254 fiber.memoizedProps = _assign({}, fiber.memoizedProps);
17255 scheduleWork(fiber, Sync);
17256 }
17257 }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
17258
17259
17260 overrideProps = function (fiber, path, value) {
17261 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
17262
17263 if (fiber.alternate) {
17264 fiber.alternate.pendingProps = fiber.pendingProps;
17265 }
17266
17267 scheduleWork(fiber, Sync);
17268 };
17269
17270 scheduleUpdate = function (fiber) {
17271 scheduleWork(fiber, Sync);
17272 };
17273
17274 setSuspenseHandler = function (newShouldSuspendImpl) {
17275 shouldSuspendImpl = newShouldSuspendImpl;
17276 };
17277}
17278
17279function injectIntoDevTools(devToolsConfig) {
17280 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
17281 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
17282 return injectInternals(_assign({}, devToolsConfig, {
17283 overrideHookState: overrideHookState,
17284 overrideProps: overrideProps,
17285 setSuspenseHandler: setSuspenseHandler,
17286 scheduleUpdate: scheduleUpdate,
17287 currentDispatcherRef: ReactCurrentDispatcher,
17288 findHostInstanceByFiber: function (fiber) {
17289 var hostFiber = findCurrentHostFiber(fiber);
17290
17291 if (hostFiber === null) {
17292 return null;
17293 }
17294
17295 return hostFiber.stateNode;
17296 },
17297 findFiberByHostInstance: function (instance) {
17298 if (!findFiberByHostInstance) {
17299 // Might not be implemented by the renderer.
17300 return null;
17301 }
17302
17303 return findFiberByHostInstance(instance);
17304 },
17305 // React Refresh
17306 findHostInstancesForRefresh: findHostInstancesForRefresh,
17307 scheduleRefresh: scheduleRefresh,
17308 scheduleRoot: scheduleRoot,
17309 setRefreshHandler: setRefreshHandler,
17310 // Enables DevTools to append owner stacks to error messages in DEV mode.
17311 getCurrentFiber: function () {
17312 return current;
17313 }
17314 }));
17315}
17316
17317// This file intentionally does *not* have the Flow annotation.
17318// Don't add it. See `./inline-typed.js` for an explanation.
17319
17320Mode.setCurrent( // Change to 'art/modes/dom' for easier debugging via SVG
17321FastNoSideEffects);
17322/** Declarative fill-type objects; API design not finalized */
17323
17324var slice = Array.prototype.slice;
17325
17326var LinearGradient =
17327/*#__PURE__*/
17328function () {
17329 function LinearGradient(stops, x1, y1, x2, y2) {
17330 this._args = slice.call(arguments);
17331 }
17332
17333 var _proto = LinearGradient.prototype;
17334
17335 _proto.applyFill = function applyFill(node) {
17336 node.fillLinear.apply(node, this._args);
17337 };
17338
17339 return LinearGradient;
17340}();
17341
17342var RadialGradient =
17343/*#__PURE__*/
17344function () {
17345 function RadialGradient(stops, fx, fy, rx, ry, cx, cy) {
17346 this._args = slice.call(arguments);
17347 }
17348
17349 var _proto2 = RadialGradient.prototype;
17350
17351 _proto2.applyFill = function applyFill(node) {
17352 node.fillRadial.apply(node, this._args);
17353 };
17354
17355 return RadialGradient;
17356}();
17357
17358var Pattern =
17359/*#__PURE__*/
17360function () {
17361 function Pattern(url, width, height, left, top) {
17362 this._args = slice.call(arguments);
17363 }
17364
17365 var _proto3 = Pattern.prototype;
17366
17367 _proto3.applyFill = function applyFill(node) {
17368 node.fillImage.apply(node, this._args);
17369 };
17370
17371 return Pattern;
17372}();
17373/** React Components */
17374
17375
17376var Surface =
17377/*#__PURE__*/
17378function (_React$Component) {
17379 _inheritsLoose(Surface, _React$Component);
17380
17381 function Surface() {
17382 return _React$Component.apply(this, arguments) || this;
17383 }
17384
17385 var _proto4 = Surface.prototype;
17386
17387 _proto4.componentDidMount = function componentDidMount() {
17388 var _this$props = this.props,
17389 height = _this$props.height,
17390 width = _this$props.width;
17391 this._surface = Mode.Surface(+width, +height, this._tagRef);
17392 this._mountNode = createContainer(this._surface, LegacyRoot, false, null);
17393 updateContainer(this.props.children, this._mountNode, this);
17394 };
17395
17396 _proto4.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
17397 var props = this.props;
17398
17399 if (props.height !== prevProps.height || props.width !== prevProps.width) {
17400 this._surface.resize(+props.width, +props.height);
17401 }
17402
17403 updateContainer(this.props.children, this._mountNode, this);
17404
17405 if (this._surface.render) {
17406 this._surface.render();
17407 }
17408 };
17409
17410 _proto4.componentWillUnmount = function componentWillUnmount() {
17411 updateContainer(null, this._mountNode, this);
17412 };
17413
17414 _proto4.render = function render() {
17415 var _this = this;
17416
17417 // This is going to be a placeholder because we don't know what it will
17418 // actually resolve to because ART may render canvas, vml or svg tags here.
17419 // We only allow a subset of properties since others might conflict with
17420 // ART's properties.
17421 var props = this.props; // TODO: ART's Canvas Mode overrides surface title and cursor
17422
17423 var Tag = Mode.Surface.tagName;
17424 return React.createElement(Tag, {
17425 ref: function (ref) {
17426 return _this._tagRef = ref;
17427 },
17428 accessKey: props.accessKey,
17429 className: props.className,
17430 draggable: props.draggable,
17431 role: props.role,
17432 style: props.style,
17433 tabIndex: props.tabIndex,
17434 title: props.title
17435 });
17436 };
17437
17438 return Surface;
17439}(React.Component);
17440
17441var Text =
17442/*#__PURE__*/
17443function (_React$Component2) {
17444 _inheritsLoose(Text, _React$Component2);
17445
17446 function Text(props) {
17447 var _this2;
17448
17449 _this2 = _React$Component2.call(this, props) || this; // We allow reading these props. Ideally we could expose the Text node as
17450 // ref directly.
17451
17452 ['height', 'width', 'x', 'y'].forEach(function (key) {
17453 Object.defineProperty(_assertThisInitialized(_this2), key, {
17454 get: function () {
17455 return this._text ? this._text[key] : undefined;
17456 }
17457 });
17458 });
17459 return _this2;
17460 }
17461
17462 var _proto5 = Text.prototype;
17463
17464 _proto5.render = function render() {
17465 var _this3 = this;
17466
17467 // This means you can't have children that render into strings...
17468 var T = TYPES.TEXT;
17469 return React.createElement(T, _extends({}, this.props, {
17470 ref: function (t) {
17471 return _this3._text = t;
17472 }
17473 }), childrenAsString(this.props.children));
17474 };
17475
17476 return Text;
17477}(React.Component);
17478
17479injectIntoDevTools({
17480 findFiberByHostInstance: function () {
17481 return null;
17482 },
17483 bundleType: 1,
17484 version: ReactVersion,
17485 rendererPackageName: 'react-art'
17486});
17487/** API */
17488
17489var ClippingRectangle = TYPES.CLIPPING_RECTANGLE;
17490var Group = TYPES.GROUP;
17491var Shape = TYPES.SHAPE;
17492var Path = Mode.Path;
17493
17494
17495var ReactART = Object.freeze({
17496 ClippingRectangle: ClippingRectangle,
17497 Group: Group,
17498 Shape: Shape,
17499 Path: Path,
17500 LinearGradient: LinearGradient,
17501 Pattern: Pattern,
17502 RadialGradient: RadialGradient,
17503 Surface: Surface,
17504 Text: Text,
17505 Transform: Transform
17506});
17507
17508var reactArt = ReactART;
17509
17510module.exports = reactArt;
17511 })();
17512}