UNPKG

484 kBJavaScriptView Raw
1/** @license React v16.8.1
2 * react-test-renderer.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
14 typeof define === 'function' && define.amd ? define(['react'], factory) :
15 (global.ReactTestRenderer = factory(global.React));
16}(this, (function (React) { 'use strict';
17
18/**
19 * Use invariant() to assert state which your program assumes to be true.
20 *
21 * Provide sprintf-style format (only %s is supported) and arguments
22 * to provide information about what broke and what you were
23 * expecting.
24 *
25 * The invariant message will be stripped in production, but the invariant
26 * will remain to ensure logic does not differ in production.
27 */
28
29var validateFormat = function () {};
30
31{
32 validateFormat = function (format) {
33 if (format === undefined) {
34 throw new Error('invariant requires an error message argument');
35 }
36 };
37}
38
39function invariant(condition, format, a, b, c, d, e, f) {
40 validateFormat(format);
41
42 if (!condition) {
43 var error = void 0;
44 if (format === undefined) {
45 error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
46 } else {
47 var args = [a, b, c, d, e, f];
48 var argIndex = 0;
49 error = new Error(format.replace(/%s/g, function () {
50 return args[argIndex++];
51 }));
52 error.name = 'Invariant Violation';
53 }
54
55 error.framesToPop = 1; // we don't care about invariant's own frame
56 throw error;
57 }
58}
59
60// Relying on the `invariant()` implementation lets us
61// preserve the format and params in the www builds.
62
63var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
64
65var _assign = ReactInternals.assign;
66
67/**
68 * Similar to invariant but only logs a warning if the condition is not met.
69 * This can be used to log issues in development environments in critical
70 * paths. Removing the logging code for production environments will keep the
71 * same logic and follow the same code paths.
72 */
73
74var warningWithoutStack = function () {};
75
76{
77 warningWithoutStack = function (condition, format) {
78 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
79 args[_key - 2] = arguments[_key];
80 }
81
82 if (format === undefined) {
83 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
84 }
85 if (args.length > 8) {
86 // Check before the condition to catch violations early.
87 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
88 }
89 if (condition) {
90 return;
91 }
92 if (typeof console !== 'undefined') {
93 var argsWithFormat = args.map(function (item) {
94 return '' + item;
95 });
96 argsWithFormat.unshift('Warning: ' + format);
97
98 // We intentionally don't use spread (or .apply) directly because it
99 // breaks IE9: https://github.com/facebook/react/issues/13610
100 Function.prototype.apply.call(console.error, console, argsWithFormat);
101 }
102 try {
103 // --- Welcome to debugging React ---
104 // This error was thrown as a convenience so that you can use this stack
105 // to find the callsite that caused this warning to fire.
106 var argIndex = 0;
107 var message = 'Warning: ' + format.replace(/%s/g, function () {
108 return args[argIndex++];
109 });
110 throw new Error(message);
111 } catch (x) {}
112 };
113}
114
115var warningWithoutStack$1 = warningWithoutStack;
116
117/**
118 * `ReactInstanceMap` maintains a mapping from a public facing stateful
119 * instance (key) and the internal representation (value). This allows public
120 * methods to accept the user facing instance as an argument and map them back
121 * to internal methods.
122 *
123 * Note that this module is currently shared and assumed to be stateless.
124 * If this becomes an actual Map, that will break.
125 */
126
127/**
128 * This API should be called `delete` but we'd have to make sure to always
129 * transform these to strings for IE support. When this transform is fully
130 * supported we can rename it.
131 */
132
133
134function get(key) {
135 return key._reactInternalFiber;
136}
137
138
139
140function set(key, value) {
141 key._reactInternalFiber = value;
142}
143
144var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
145
146// Prevent newer renderers from RTE when used with older react package versions.
147// Current owner and dispatcher used to share the same ref,
148// but PR #14548 split them out to better support the react-debug-tools package.
149if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
150 ReactSharedInternals.ReactCurrentDispatcher = {
151 current: null
152 };
153}
154
155// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
156// nor polyfill, then a plain number is used for performance.
157var hasSymbol = typeof Symbol === 'function' && Symbol.for;
158
159var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
160var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
161var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
162var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
163var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
164var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
165var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
166
167var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
168var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
169var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
170var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
171var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
172
173var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
174var FAUX_ITERATOR_SYMBOL = '@@iterator';
175
176function getIteratorFn(maybeIterable) {
177 if (maybeIterable === null || typeof maybeIterable !== 'object') {
178 return null;
179 }
180 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
181 if (typeof maybeIterator === 'function') {
182 return maybeIterator;
183 }
184 return null;
185}
186
187var Pending = 0;
188var Resolved = 1;
189var Rejected = 2;
190
191function refineResolvedLazyComponent(lazyComponent) {
192 return lazyComponent._status === Resolved ? lazyComponent._result : null;
193}
194
195function getWrappedName(outerType, innerType, wrapperName) {
196 var functionName = innerType.displayName || innerType.name || '';
197 return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
198}
199
200function getComponentName(type) {
201 if (type == null) {
202 // Host root, text node or just invalid type.
203 return null;
204 }
205 {
206 if (typeof type.tag === 'number') {
207 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
208 }
209 }
210 if (typeof type === 'function') {
211 return type.displayName || type.name || null;
212 }
213 if (typeof type === 'string') {
214 return type;
215 }
216 switch (type) {
217 case REACT_CONCURRENT_MODE_TYPE:
218 return 'ConcurrentMode';
219 case REACT_FRAGMENT_TYPE:
220 return 'Fragment';
221 case REACT_PORTAL_TYPE:
222 return 'Portal';
223 case REACT_PROFILER_TYPE:
224 return 'Profiler';
225 case REACT_STRICT_MODE_TYPE:
226 return 'StrictMode';
227 case REACT_SUSPENSE_TYPE:
228 return 'Suspense';
229 }
230 if (typeof type === 'object') {
231 switch (type.$$typeof) {
232 case REACT_CONTEXT_TYPE:
233 return 'Context.Consumer';
234 case REACT_PROVIDER_TYPE:
235 return 'Context.Provider';
236 case REACT_FORWARD_REF_TYPE:
237 return getWrappedName(type, type.render, 'ForwardRef');
238 case REACT_MEMO_TYPE:
239 return getComponentName(type.type);
240 case REACT_LAZY_TYPE:
241 {
242 var thenable = type;
243 var resolvedThenable = refineResolvedLazyComponent(thenable);
244 if (resolvedThenable) {
245 return getComponentName(resolvedThenable);
246 }
247 }
248 }
249 }
250 return null;
251}
252
253var FunctionComponent = 0;
254var ClassComponent = 1;
255var IndeterminateComponent = 2; // Before we know whether it is function or class
256var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
257var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
258var HostComponent = 5;
259var HostText = 6;
260var Fragment = 7;
261var Mode = 8;
262var ContextConsumer = 9;
263var ContextProvider = 10;
264var ForwardRef = 11;
265var Profiler = 12;
266var SuspenseComponent = 13;
267var MemoComponent = 14;
268var SimpleMemoComponent = 15;
269var LazyComponent = 16;
270var IncompleteClassComponent = 17;
271
272// Don't change these two values. They're used by React Dev Tools.
273var NoEffect = /* */0;
274var PerformedWork = /* */1;
275
276// You can change the rest (and add more).
277var Placement = /* */2;
278var Update = /* */4;
279var PlacementAndUpdate = /* */6;
280var Deletion = /* */8;
281var ContentReset = /* */16;
282var Callback = /* */32;
283var DidCapture = /* */64;
284var Ref = /* */128;
285var Snapshot = /* */256;
286var Passive = /* */512;
287
288// Passive & Update & Callback & Ref & Snapshot
289var LifecycleEffectMask = /* */932;
290
291// Union of all host effects
292var HostEffectMask = /* */1023;
293
294var Incomplete = /* */1024;
295var ShouldCapture = /* */2048;
296
297var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
298
299var MOUNTING = 1;
300var MOUNTED = 2;
301var UNMOUNTED = 3;
302
303function isFiberMountedImpl(fiber) {
304 var node = fiber;
305 if (!fiber.alternate) {
306 // If there is no alternate, this might be a new tree that isn't inserted
307 // yet. If it is, then it will have a pending insertion effect on it.
308 if ((node.effectTag & Placement) !== NoEffect) {
309 return MOUNTING;
310 }
311 while (node.return) {
312 node = node.return;
313 if ((node.effectTag & Placement) !== NoEffect) {
314 return MOUNTING;
315 }
316 }
317 } else {
318 while (node.return) {
319 node = node.return;
320 }
321 }
322 if (node.tag === HostRoot) {
323 // TODO: Check if this was a nested HostRoot when used with
324 // renderContainerIntoSubtree.
325 return MOUNTED;
326 }
327 // If we didn't hit the root, that means that we're in an disconnected tree
328 // that has been unmounted.
329 return UNMOUNTED;
330}
331
332function isFiberMounted(fiber) {
333 return isFiberMountedImpl(fiber) === MOUNTED;
334}
335
336function isMounted(component) {
337 {
338 var owner = ReactCurrentOwner.current;
339 if (owner !== null && owner.tag === ClassComponent) {
340 var ownerFiber = owner;
341 var instance = ownerFiber.stateNode;
342 !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;
343 instance._warnedAboutRefsInRender = true;
344 }
345 }
346
347 var fiber = get(component);
348 if (!fiber) {
349 return false;
350 }
351 return isFiberMountedImpl(fiber) === MOUNTED;
352}
353
354function assertIsMounted(fiber) {
355 !(isFiberMountedImpl(fiber) === MOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
356}
357
358function findCurrentFiberUsingSlowPath(fiber) {
359 var alternate = fiber.alternate;
360 if (!alternate) {
361 // If there is no alternate, then we only need to check if it is mounted.
362 var state = isFiberMountedImpl(fiber);
363 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
364 if (state === MOUNTING) {
365 return null;
366 }
367 return fiber;
368 }
369 // If we have two possible branches, we'll walk backwards up to the root
370 // to see what path the root points to. On the way we may hit one of the
371 // special cases and we'll deal with them.
372 var a = fiber;
373 var b = alternate;
374 while (true) {
375 var parentA = a.return;
376 var parentB = parentA ? parentA.alternate : null;
377 if (!parentA || !parentB) {
378 // We're at the root.
379 break;
380 }
381
382 // If both copies of the parent fiber point to the same child, we can
383 // assume that the child is current. This happens when we bailout on low
384 // priority: the bailed out fiber's child reuses the current child.
385 if (parentA.child === parentB.child) {
386 var child = parentA.child;
387 while (child) {
388 if (child === a) {
389 // We've determined that A is the current branch.
390 assertIsMounted(parentA);
391 return fiber;
392 }
393 if (child === b) {
394 // We've determined that B is the current branch.
395 assertIsMounted(parentA);
396 return alternate;
397 }
398 child = child.sibling;
399 }
400 // We should never have an alternate for any mounting node. So the only
401 // way this could possibly happen is if this was unmounted, if at all.
402 invariant(false, 'Unable to find node on an unmounted component.');
403 }
404
405 if (a.return !== b.return) {
406 // The return pointer of A and the return pointer of B point to different
407 // fibers. We assume that return pointers never criss-cross, so A must
408 // belong to the child set of A.return, and B must belong to the child
409 // set of B.return.
410 a = parentA;
411 b = parentB;
412 } else {
413 // The return pointers point to the same fiber. We'll have to use the
414 // default, slow path: scan the child sets of each parent alternate to see
415 // which child belongs to which set.
416 //
417 // Search parent A's child set
418 var didFindChild = false;
419 var _child = parentA.child;
420 while (_child) {
421 if (_child === a) {
422 didFindChild = true;
423 a = parentA;
424 b = parentB;
425 break;
426 }
427 if (_child === b) {
428 didFindChild = true;
429 b = parentA;
430 a = parentB;
431 break;
432 }
433 _child = _child.sibling;
434 }
435 if (!didFindChild) {
436 // Search parent B's child set
437 _child = parentB.child;
438 while (_child) {
439 if (_child === a) {
440 didFindChild = true;
441 a = parentB;
442 b = parentA;
443 break;
444 }
445 if (_child === b) {
446 didFindChild = true;
447 b = parentB;
448 a = parentA;
449 break;
450 }
451 _child = _child.sibling;
452 }
453 !didFindChild ? invariant(false, 'Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.') : void 0;
454 }
455 }
456
457 !(a.alternate === b) ? invariant(false, 'Return fibers should always be each others\' alternates. This error is likely caused by a bug in React. Please file an issue.') : void 0;
458 }
459 // If the root is not a host container, we're in a disconnected tree. I.e.
460 // unmounted.
461 !(a.tag === HostRoot) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
462 if (a.stateNode.current === a) {
463 // We've determined that A is the current branch.
464 return fiber;
465 }
466 // Otherwise B has to be current branch.
467 return alternate;
468}
469
470function findCurrentHostFiber(parent) {
471 var currentParent = findCurrentFiberUsingSlowPath(parent);
472 if (!currentParent) {
473 return null;
474 }
475
476 // Next we'll drill down this component to find the first HostComponent/Text.
477 var node = currentParent;
478 while (true) {
479 if (node.tag === HostComponent || node.tag === HostText) {
480 return node;
481 } else if (node.child) {
482 node.child.return = node;
483 node = node.child;
484 continue;
485 }
486 if (node === currentParent) {
487 return null;
488 }
489 while (!node.sibling) {
490 if (!node.return || node.return === currentParent) {
491 return null;
492 }
493 node = node.return;
494 }
495 node.sibling.return = node.return;
496 node = node.sibling;
497 }
498 // Flow needs the return null here, but ESLint complains about it.
499 // eslint-disable-next-line no-unreachable
500 return null;
501}
502
503/**
504 * Similar to invariant but only logs a warning if the condition is not met.
505 * This can be used to log issues in development environments in critical
506 * paths. Removing the logging code for production environments will keep the
507 * same logic and follow the same code paths.
508 */
509
510var warning = warningWithoutStack$1;
511
512{
513 warning = function (condition, format) {
514 if (condition) {
515 return;
516 }
517 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
518 var stack = ReactDebugCurrentFrame.getStackAddendum();
519 // eslint-disable-next-line react-internal/warning-and-invariant-args
520
521 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
522 args[_key - 2] = arguments[_key];
523 }
524
525 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
526 };
527}
528
529var warning$1 = warning;
530
531// Current virtual time
532var nowImplementation = function () {
533 return 0;
534};
535var scheduledCallback = null;
536var yieldedValues = [];
537
538var didStop = false;
539var expectedNumberOfYields = -1;
540
541function scheduleDeferredCallback$1(callback, options) {
542 scheduledCallback = callback;
543 var fakeCallbackId = 0;
544 return fakeCallbackId;
545}
546
547function cancelDeferredCallback$1(timeoutID) {
548 scheduledCallback = null;
549}
550
551function setNowImplementation(implementation) {
552 nowImplementation = implementation;
553}
554
555function shouldYield$1() {
556 if (expectedNumberOfYields !== -1 && yieldedValues.length >= expectedNumberOfYields) {
557 // We yielded at least as many values as expected. Stop rendering.
558 didStop = true;
559 return true;
560 }
561 // Keep rendering.
562 return false;
563}
564
565function flushAll() {
566 yieldedValues = [];
567 while (scheduledCallback !== null) {
568 var cb = scheduledCallback;
569 scheduledCallback = null;
570 cb();
571 }
572 var values = yieldedValues;
573 yieldedValues = [];
574 return values;
575}
576
577function flushNumberOfYields(count) {
578 expectedNumberOfYields = count;
579 didStop = false;
580 yieldedValues = [];
581 try {
582 while (scheduledCallback !== null && !didStop) {
583 var cb = scheduledCallback;
584 scheduledCallback = null;
585 cb();
586 }
587 return yieldedValues;
588 } finally {
589 expectedNumberOfYields = -1;
590 didStop = false;
591 yieldedValues = [];
592 }
593}
594
595function yieldValue(value) {
596 yieldedValues.push(value);
597}
598
599function clearYields() {
600 var values = yieldedValues;
601 yieldedValues = [];
602 return values;
603}
604
605// Renderers that don't support persistence
606// can re-export everything from this module.
607
608function shim() {
609 invariant(false, 'The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.');
610}
611
612// Persistence (when unsupported)
613var supportsPersistence = false;
614var cloneInstance = shim;
615var createContainerChildSet = shim;
616var appendChildToContainerChildSet = shim;
617var finalizeContainerChildren = shim;
618var replaceContainerChildren = shim;
619var cloneHiddenInstance = shim;
620var cloneUnhiddenInstance = shim;
621var createHiddenTextInstance = shim;
622
623// Renderers that don't support hydration
624// can re-export everything from this module.
625
626function shim$1() {
627 invariant(false, 'The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.');
628}
629
630// Hydration (when unsupported)
631var supportsHydration = false;
632var canHydrateInstance = shim$1;
633var canHydrateTextInstance = shim$1;
634var getNextHydratableSibling = shim$1;
635var getFirstHydratableChild = shim$1;
636var hydrateInstance = shim$1;
637var hydrateTextInstance = shim$1;
638var didNotMatchHydratedContainerTextInstance = shim$1;
639var didNotMatchHydratedTextInstance = shim$1;
640var didNotHydrateContainerInstance = shim$1;
641var didNotHydrateInstance = shim$1;
642var didNotFindHydratableContainerInstance = shim$1;
643var didNotFindHydratableContainerTextInstance = shim$1;
644var didNotFindHydratableInstance = shim$1;
645var didNotFindHydratableTextInstance = shim$1;
646
647var NO_CONTEXT = {};
648var UPDATE_SIGNAL = {};
649{
650 Object.freeze(NO_CONTEXT);
651 Object.freeze(UPDATE_SIGNAL);
652}
653
654function getPublicInstance(inst) {
655 switch (inst.tag) {
656 case 'INSTANCE':
657 var _createNodeMock = inst.rootContainerInstance.createNodeMock;
658 return _createNodeMock({
659 type: inst.type,
660 props: inst.props
661 });
662 default:
663 return inst;
664 }
665}
666
667function appendChild(parentInstance, child) {
668 {
669 !Array.isArray(parentInstance.children) ? warning$1(false, 'An invalid container has been provided. ' + 'This may indicate that another renderer is being used in addition to the test renderer. ' + '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' + 'This is not supported.') : void 0;
670 }
671 var index = parentInstance.children.indexOf(child);
672 if (index !== -1) {
673 parentInstance.children.splice(index, 1);
674 }
675 parentInstance.children.push(child);
676}
677
678function insertBefore(parentInstance, child, beforeChild) {
679 var index = parentInstance.children.indexOf(child);
680 if (index !== -1) {
681 parentInstance.children.splice(index, 1);
682 }
683 var beforeIndex = parentInstance.children.indexOf(beforeChild);
684 parentInstance.children.splice(beforeIndex, 0, child);
685}
686
687function removeChild(parentInstance, child) {
688 var index = parentInstance.children.indexOf(child);
689 parentInstance.children.splice(index, 1);
690}
691
692function getRootHostContext(rootContainerInstance) {
693 return NO_CONTEXT;
694}
695
696function getChildHostContext(parentHostContext, type, rootContainerInstance) {
697 return NO_CONTEXT;
698}
699
700function prepareForCommit(containerInfo) {
701 // noop
702}
703
704function resetAfterCommit(containerInfo) {
705 // noop
706}
707
708function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
709 return {
710 type: type,
711 props: props,
712 isHidden: false,
713 children: [],
714 rootContainerInstance: rootContainerInstance,
715 tag: 'INSTANCE'
716 };
717}
718
719function appendInitialChild(parentInstance, child) {
720 var index = parentInstance.children.indexOf(child);
721 if (index !== -1) {
722 parentInstance.children.splice(index, 1);
723 }
724 parentInstance.children.push(child);
725}
726
727function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
728 return false;
729}
730
731function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
732 return UPDATE_SIGNAL;
733}
734
735function shouldSetTextContent(type, props) {
736 return false;
737}
738
739function shouldDeprioritizeSubtree(type, props) {
740 return false;
741}
742
743function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
744 return {
745 text: text,
746 isHidden: false,
747 tag: 'TEXT'
748 };
749}
750
751var isPrimaryRenderer = false;
752// This approach enables `now` to be mocked by tests,
753// Even after the reconciler has initialized and read host config values.
754var now = function () {
755 return nowImplementation();
756};
757var scheduleDeferredCallback$$1 = scheduleDeferredCallback$1;
758var cancelDeferredCallback$$1 = cancelDeferredCallback$1;
759var shouldYield$$1 = shouldYield$1;
760
761var scheduleTimeout = setTimeout;
762var cancelTimeout = clearTimeout;
763var noTimeout = -1;
764var schedulePassiveEffects = scheduleDeferredCallback$$1;
765var cancelPassiveEffects = cancelDeferredCallback$$1;
766
767// -------------------
768// Mutation
769// -------------------
770
771var supportsMutation = true;
772
773function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
774 instance.type = type;
775 instance.props = newProps;
776}
777
778
779
780function commitTextUpdate(textInstance, oldText, newText) {
781 textInstance.text = newText;
782}
783
784function resetTextContent(testElement) {
785 // noop
786}
787
788var appendChildToContainer = appendChild;
789var insertInContainerBefore = insertBefore;
790var removeChildFromContainer = removeChild;
791
792function hideInstance(instance) {
793 instance.isHidden = true;
794}
795
796function hideTextInstance(textInstance) {
797 textInstance.isHidden = true;
798}
799
800function unhideInstance(instance, props) {
801 instance.isHidden = false;
802}
803
804function unhideTextInstance(textInstance, text) {
805 textInstance.isHidden = false;
806}
807
808/**
809 * Copyright (c) 2013-present, Facebook, Inc.
810 *
811 * This source code is licensed under the MIT license found in the
812 * LICENSE file in the root directory of this source tree.
813 */
814
815
816
817var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
818
819var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
820
821/**
822 * Copyright (c) 2013-present, Facebook, Inc.
823 *
824 * This source code is licensed under the MIT license found in the
825 * LICENSE file in the root directory of this source tree.
826 */
827
828
829
830var printWarning = function() {};
831
832{
833 var ReactPropTypesSecret = ReactPropTypesSecret_1;
834 var loggedTypeFailures = {};
835
836 printWarning = function(text) {
837 var message = 'Warning: ' + text;
838 if (typeof console !== 'undefined') {
839 console.error(message);
840 }
841 try {
842 // --- Welcome to debugging React ---
843 // This error was thrown as a convenience so that you can use this stack
844 // to find the callsite that caused this warning to fire.
845 throw new Error(message);
846 } catch (x) {}
847 };
848}
849
850/**
851 * Assert that the values match with the type specs.
852 * Error messages are memorized and will only be shown once.
853 *
854 * @param {object} typeSpecs Map of name to a ReactPropType
855 * @param {object} values Runtime values that need to be type-checked
856 * @param {string} location e.g. "prop", "context", "child context"
857 * @param {string} componentName Name of the component for error messages.
858 * @param {?Function} getStack Returns the component stack.
859 * @private
860 */
861function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
862 {
863 for (var typeSpecName in typeSpecs) {
864 if (typeSpecs.hasOwnProperty(typeSpecName)) {
865 var error;
866 // Prop type validation may throw. In case they do, we don't want to
867 // fail the render phase where it didn't fail before. So we log it.
868 // After these have been cleaned up, we'll let them throw.
869 try {
870 // This is intentionally an invariant that gets caught. It's the same
871 // behavior as without this statement except with a better message.
872 if (typeof typeSpecs[typeSpecName] !== 'function') {
873 var err = Error(
874 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
875 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
876 );
877 err.name = 'Invariant Violation';
878 throw err;
879 }
880 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
881 } catch (ex) {
882 error = ex;
883 }
884 if (error && !(error instanceof Error)) {
885 printWarning(
886 (componentName || 'React class') + ': type specification of ' +
887 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
888 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
889 'You may have forgotten to pass an argument to the type checker ' +
890 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
891 'shape all require an argument).'
892 );
893
894 }
895 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
896 // Only monitor this failure once because there tends to be a lot of the
897 // same error.
898 loggedTypeFailures[error.message] = true;
899
900 var stack = getStack ? getStack() : '';
901
902 printWarning(
903 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
904 );
905 }
906 }
907 }
908 }
909}
910
911var checkPropTypes_1 = checkPropTypes;
912
913var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
914
915var describeComponentFrame = function (name, source, ownerName) {
916 var sourceInfo = '';
917 if (source) {
918 var path = source.fileName;
919 var fileName = path.replace(BEFORE_SLASH_RE, '');
920 {
921 // In DEV, include code for a common special case:
922 // prefer "folder/index.js" instead of just "index.js".
923 if (/^index\./.test(fileName)) {
924 var match = path.match(BEFORE_SLASH_RE);
925 if (match) {
926 var pathBeforeSlash = match[1];
927 if (pathBeforeSlash) {
928 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
929 fileName = folderName + '/' + fileName;
930 }
931 }
932 }
933 }
934 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
935 } else if (ownerName) {
936 sourceInfo = ' (created by ' + ownerName + ')';
937 }
938 return '\n in ' + (name || 'Unknown') + sourceInfo;
939};
940
941var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
942
943function describeFiber(fiber) {
944 switch (fiber.tag) {
945 case HostRoot:
946 case HostPortal:
947 case HostText:
948 case Fragment:
949 case ContextProvider:
950 case ContextConsumer:
951 return '';
952 default:
953 var owner = fiber._debugOwner;
954 var source = fiber._debugSource;
955 var name = getComponentName(fiber.type);
956 var ownerName = null;
957 if (owner) {
958 ownerName = getComponentName(owner.type);
959 }
960 return describeComponentFrame(name, source, ownerName);
961 }
962}
963
964function getStackByFiberInDevAndProd(workInProgress) {
965 var info = '';
966 var node = workInProgress;
967 do {
968 info += describeFiber(node);
969 node = node.return;
970 } while (node);
971 return info;
972}
973
974var current = null;
975var phase = null;
976
977function getCurrentFiberOwnerNameInDevOrNull() {
978 {
979 if (current === null) {
980 return null;
981 }
982 var owner = current._debugOwner;
983 if (owner !== null && typeof owner !== 'undefined') {
984 return getComponentName(owner.type);
985 }
986 }
987 return null;
988}
989
990function getCurrentFiberStackInDev() {
991 {
992 if (current === null) {
993 return '';
994 }
995 // Safe because if current fiber exists, we are reconciling,
996 // and it is guaranteed to be the work-in-progress version.
997 return getStackByFiberInDevAndProd(current);
998 }
999 return '';
1000}
1001
1002function resetCurrentFiber() {
1003 {
1004 ReactDebugCurrentFrame.getCurrentStack = null;
1005 current = null;
1006 phase = null;
1007 }
1008}
1009
1010function setCurrentFiber(fiber) {
1011 {
1012 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1013 current = fiber;
1014 phase = null;
1015 }
1016}
1017
1018function setCurrentPhase(lifeCyclePhase) {
1019 {
1020 phase = lifeCyclePhase;
1021 }
1022}
1023
1024var debugRenderPhaseSideEffects = false;
1025var debugRenderPhaseSideEffectsForStrictMode = false;
1026var enableUserTimingAPI = true;
1027var warnAboutDeprecatedLifecycles = false;
1028var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
1029var enableProfilerTimer = false;
1030var enableSchedulerTracing = false;
1031
1032
1033
1034
1035
1036
1037// Only used in www builds.
1038
1039// Prefix measurements so that it's possible to filter them.
1040// Longer prefixes are hard to read in DevTools.
1041var reactEmoji = '\u269B';
1042var warningEmoji = '\u26D4';
1043var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
1044
1045// Keep track of current fiber so that we know the path to unwind on pause.
1046// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1047var currentFiber = null;
1048// If we're in the middle of user code, which fiber and method is it?
1049// Reusing `currentFiber` would be confusing for this because user code fiber
1050// can change during commit phase too, but we don't need to unwind it (since
1051// lifecycles in the commit phase don't resemble a tree).
1052var currentPhase = null;
1053var currentPhaseFiber = null;
1054// Did lifecycle hook schedule an update? This is often a performance problem,
1055// so we will keep track of it, and include it in the report.
1056// Track commits caused by cascading updates.
1057var isCommitting = false;
1058var hasScheduledUpdateInCurrentCommit = false;
1059var hasScheduledUpdateInCurrentPhase = false;
1060var commitCountInCurrentWorkLoop = 0;
1061var effectCountInCurrentCommit = 0;
1062var isWaitingForCallback = false;
1063// During commits, we only show a measurement once per method name
1064// to avoid stretch the commit phase with measurement overhead.
1065var labelsInCurrentCommit = new Set();
1066
1067var formatMarkName = function (markName) {
1068 return reactEmoji + ' ' + markName;
1069};
1070
1071var formatLabel = function (label, warning) {
1072 var prefix = warning ? warningEmoji + ' ' : reactEmoji + ' ';
1073 var suffix = warning ? ' Warning: ' + warning : '';
1074 return '' + prefix + label + suffix;
1075};
1076
1077var beginMark = function (markName) {
1078 performance.mark(formatMarkName(markName));
1079};
1080
1081var clearMark = function (markName) {
1082 performance.clearMarks(formatMarkName(markName));
1083};
1084
1085var endMark = function (label, markName, warning) {
1086 var formattedMarkName = formatMarkName(markName);
1087 var formattedLabel = formatLabel(label, warning);
1088 try {
1089 performance.measure(formattedLabel, formattedMarkName);
1090 } catch (err) {}
1091 // If previous mark was missing for some reason, this will throw.
1092 // This could only happen if React crashed in an unexpected place earlier.
1093 // Don't pile on with more errors.
1094
1095 // Clear marks immediately to avoid growing buffer.
1096 performance.clearMarks(formattedMarkName);
1097 performance.clearMeasures(formattedLabel);
1098};
1099
1100var getFiberMarkName = function (label, debugID) {
1101 return label + ' (#' + debugID + ')';
1102};
1103
1104var getFiberLabel = function (componentName, isMounted, phase) {
1105 if (phase === null) {
1106 // These are composite component total time measurements.
1107 return componentName + ' [' + (isMounted ? 'update' : 'mount') + ']';
1108 } else {
1109 // Composite component methods.
1110 return componentName + '.' + phase;
1111 }
1112};
1113
1114var beginFiberMark = function (fiber, phase) {
1115 var componentName = getComponentName(fiber.type) || 'Unknown';
1116 var debugID = fiber._debugID;
1117 var isMounted = fiber.alternate !== null;
1118 var label = getFiberLabel(componentName, isMounted, phase);
1119
1120 if (isCommitting && labelsInCurrentCommit.has(label)) {
1121 // During the commit phase, we don't show duplicate labels because
1122 // there is a fixed overhead for every measurement, and we don't
1123 // want to stretch the commit phase beyond necessary.
1124 return false;
1125 }
1126 labelsInCurrentCommit.add(label);
1127
1128 var markName = getFiberMarkName(label, debugID);
1129 beginMark(markName);
1130 return true;
1131};
1132
1133var clearFiberMark = function (fiber, phase) {
1134 var componentName = getComponentName(fiber.type) || 'Unknown';
1135 var debugID = fiber._debugID;
1136 var isMounted = fiber.alternate !== null;
1137 var label = getFiberLabel(componentName, isMounted, phase);
1138 var markName = getFiberMarkName(label, debugID);
1139 clearMark(markName);
1140};
1141
1142var endFiberMark = function (fiber, phase, warning) {
1143 var componentName = getComponentName(fiber.type) || 'Unknown';
1144 var debugID = fiber._debugID;
1145 var isMounted = fiber.alternate !== null;
1146 var label = getFiberLabel(componentName, isMounted, phase);
1147 var markName = getFiberMarkName(label, debugID);
1148 endMark(label, markName, warning);
1149};
1150
1151var shouldIgnoreFiber = function (fiber) {
1152 // Host components should be skipped in the timeline.
1153 // We could check typeof fiber.type, but does this work with RN?
1154 switch (fiber.tag) {
1155 case HostRoot:
1156 case HostComponent:
1157 case HostText:
1158 case HostPortal:
1159 case Fragment:
1160 case ContextProvider:
1161 case ContextConsumer:
1162 case Mode:
1163 return true;
1164 default:
1165 return false;
1166 }
1167};
1168
1169var clearPendingPhaseMeasurement = function () {
1170 if (currentPhase !== null && currentPhaseFiber !== null) {
1171 clearFiberMark(currentPhaseFiber, currentPhase);
1172 }
1173 currentPhaseFiber = null;
1174 currentPhase = null;
1175 hasScheduledUpdateInCurrentPhase = false;
1176};
1177
1178var pauseTimers = function () {
1179 // Stops all currently active measurements so that they can be resumed
1180 // if we continue in a later deferred loop from the same unit of work.
1181 var fiber = currentFiber;
1182 while (fiber) {
1183 if (fiber._debugIsCurrentlyTiming) {
1184 endFiberMark(fiber, null, null);
1185 }
1186 fiber = fiber.return;
1187 }
1188};
1189
1190var resumeTimersRecursively = function (fiber) {
1191 if (fiber.return !== null) {
1192 resumeTimersRecursively(fiber.return);
1193 }
1194 if (fiber._debugIsCurrentlyTiming) {
1195 beginFiberMark(fiber, null);
1196 }
1197};
1198
1199var resumeTimers = function () {
1200 // Resumes all measurements that were active during the last deferred loop.
1201 if (currentFiber !== null) {
1202 resumeTimersRecursively(currentFiber);
1203 }
1204};
1205
1206function recordEffect() {
1207 if (enableUserTimingAPI) {
1208 effectCountInCurrentCommit++;
1209 }
1210}
1211
1212function recordScheduleUpdate() {
1213 if (enableUserTimingAPI) {
1214 if (isCommitting) {
1215 hasScheduledUpdateInCurrentCommit = true;
1216 }
1217 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1218 hasScheduledUpdateInCurrentPhase = true;
1219 }
1220 }
1221}
1222
1223function startRequestCallbackTimer() {
1224 if (enableUserTimingAPI) {
1225 if (supportsUserTiming && !isWaitingForCallback) {
1226 isWaitingForCallback = true;
1227 beginMark('(Waiting for async callback...)');
1228 }
1229 }
1230}
1231
1232function stopRequestCallbackTimer(didExpire, expirationTime) {
1233 if (enableUserTimingAPI) {
1234 if (supportsUserTiming) {
1235 isWaitingForCallback = false;
1236 var warning = didExpire ? 'React was blocked by main thread' : null;
1237 endMark('(Waiting for async callback... will force flush in ' + expirationTime + ' ms)', '(Waiting for async callback...)', warning);
1238 }
1239 }
1240}
1241
1242function startWorkTimer(fiber) {
1243 if (enableUserTimingAPI) {
1244 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1245 return;
1246 }
1247 // If we pause, this is the fiber to unwind from.
1248 currentFiber = fiber;
1249 if (!beginFiberMark(fiber, null)) {
1250 return;
1251 }
1252 fiber._debugIsCurrentlyTiming = true;
1253 }
1254}
1255
1256function cancelWorkTimer(fiber) {
1257 if (enableUserTimingAPI) {
1258 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1259 return;
1260 }
1261 // Remember we shouldn't complete measurement for this fiber.
1262 // Otherwise flamechart will be deep even for small updates.
1263 fiber._debugIsCurrentlyTiming = false;
1264 clearFiberMark(fiber, null);
1265 }
1266}
1267
1268function stopWorkTimer(fiber) {
1269 if (enableUserTimingAPI) {
1270 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1271 return;
1272 }
1273 // If we pause, its parent is the fiber to unwind from.
1274 currentFiber = fiber.return;
1275 if (!fiber._debugIsCurrentlyTiming) {
1276 return;
1277 }
1278 fiber._debugIsCurrentlyTiming = false;
1279 endFiberMark(fiber, null, null);
1280 }
1281}
1282
1283function stopFailedWorkTimer(fiber) {
1284 if (enableUserTimingAPI) {
1285 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1286 return;
1287 }
1288 // If we pause, its parent is the fiber to unwind from.
1289 currentFiber = fiber.return;
1290 if (!fiber._debugIsCurrentlyTiming) {
1291 return;
1292 }
1293 fiber._debugIsCurrentlyTiming = false;
1294 var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1295 endFiberMark(fiber, null, warning);
1296 }
1297}
1298
1299function startPhaseTimer(fiber, phase) {
1300 if (enableUserTimingAPI) {
1301 if (!supportsUserTiming) {
1302 return;
1303 }
1304 clearPendingPhaseMeasurement();
1305 if (!beginFiberMark(fiber, phase)) {
1306 return;
1307 }
1308 currentPhaseFiber = fiber;
1309 currentPhase = phase;
1310 }
1311}
1312
1313function stopPhaseTimer() {
1314 if (enableUserTimingAPI) {
1315 if (!supportsUserTiming) {
1316 return;
1317 }
1318 if (currentPhase !== null && currentPhaseFiber !== null) {
1319 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1320 endFiberMark(currentPhaseFiber, currentPhase, warning);
1321 }
1322 currentPhase = null;
1323 currentPhaseFiber = null;
1324 }
1325}
1326
1327function startWorkLoopTimer(nextUnitOfWork) {
1328 if (enableUserTimingAPI) {
1329 currentFiber = nextUnitOfWork;
1330 if (!supportsUserTiming) {
1331 return;
1332 }
1333 commitCountInCurrentWorkLoop = 0;
1334 // This is top level call.
1335 // Any other measurements are performed within.
1336 beginMark('(React Tree Reconciliation)');
1337 // Resume any measurements that were in progress during the last loop.
1338 resumeTimers();
1339 }
1340}
1341
1342function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1343 if (enableUserTimingAPI) {
1344 if (!supportsUserTiming) {
1345 return;
1346 }
1347 var warning = null;
1348 if (interruptedBy !== null) {
1349 if (interruptedBy.tag === HostRoot) {
1350 warning = 'A top-level update interrupted the previous render';
1351 } else {
1352 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1353 warning = 'An update to ' + componentName + ' interrupted the previous render';
1354 }
1355 } else if (commitCountInCurrentWorkLoop > 1) {
1356 warning = 'There were cascading updates';
1357 }
1358 commitCountInCurrentWorkLoop = 0;
1359 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)';
1360 // Pause any measurements until the next loop.
1361 pauseTimers();
1362 endMark(label, '(React Tree Reconciliation)', warning);
1363 }
1364}
1365
1366function startCommitTimer() {
1367 if (enableUserTimingAPI) {
1368 if (!supportsUserTiming) {
1369 return;
1370 }
1371 isCommitting = true;
1372 hasScheduledUpdateInCurrentCommit = false;
1373 labelsInCurrentCommit.clear();
1374 beginMark('(Committing Changes)');
1375 }
1376}
1377
1378function stopCommitTimer() {
1379 if (enableUserTimingAPI) {
1380 if (!supportsUserTiming) {
1381 return;
1382 }
1383
1384 var warning = null;
1385 if (hasScheduledUpdateInCurrentCommit) {
1386 warning = 'Lifecycle hook scheduled a cascading update';
1387 } else if (commitCountInCurrentWorkLoop > 0) {
1388 warning = 'Caused by a cascading update in earlier commit';
1389 }
1390 hasScheduledUpdateInCurrentCommit = false;
1391 commitCountInCurrentWorkLoop++;
1392 isCommitting = false;
1393 labelsInCurrentCommit.clear();
1394
1395 endMark('(Committing Changes)', '(Committing Changes)', warning);
1396 }
1397}
1398
1399function startCommitSnapshotEffectsTimer() {
1400 if (enableUserTimingAPI) {
1401 if (!supportsUserTiming) {
1402 return;
1403 }
1404 effectCountInCurrentCommit = 0;
1405 beginMark('(Committing Snapshot Effects)');
1406 }
1407}
1408
1409function stopCommitSnapshotEffectsTimer() {
1410 if (enableUserTimingAPI) {
1411 if (!supportsUserTiming) {
1412 return;
1413 }
1414 var count = effectCountInCurrentCommit;
1415 effectCountInCurrentCommit = 0;
1416 endMark('(Committing Snapshot Effects: ' + count + ' Total)', '(Committing Snapshot Effects)', null);
1417 }
1418}
1419
1420function startCommitHostEffectsTimer() {
1421 if (enableUserTimingAPI) {
1422 if (!supportsUserTiming) {
1423 return;
1424 }
1425 effectCountInCurrentCommit = 0;
1426 beginMark('(Committing Host Effects)');
1427 }
1428}
1429
1430function stopCommitHostEffectsTimer() {
1431 if (enableUserTimingAPI) {
1432 if (!supportsUserTiming) {
1433 return;
1434 }
1435 var count = effectCountInCurrentCommit;
1436 effectCountInCurrentCommit = 0;
1437 endMark('(Committing Host Effects: ' + count + ' Total)', '(Committing Host Effects)', null);
1438 }
1439}
1440
1441function startCommitLifeCyclesTimer() {
1442 if (enableUserTimingAPI) {
1443 if (!supportsUserTiming) {
1444 return;
1445 }
1446 effectCountInCurrentCommit = 0;
1447 beginMark('(Calling Lifecycle Methods)');
1448 }
1449}
1450
1451function stopCommitLifeCyclesTimer() {
1452 if (enableUserTimingAPI) {
1453 if (!supportsUserTiming) {
1454 return;
1455 }
1456 var count = effectCountInCurrentCommit;
1457 effectCountInCurrentCommit = 0;
1458 endMark('(Calling Lifecycle Methods: ' + count + ' Total)', '(Calling Lifecycle Methods)', null);
1459 }
1460}
1461
1462var valueStack = [];
1463
1464var fiberStack = void 0;
1465
1466{
1467 fiberStack = [];
1468}
1469
1470var index = -1;
1471
1472function createCursor(defaultValue) {
1473 return {
1474 current: defaultValue
1475 };
1476}
1477
1478function pop(cursor, fiber) {
1479 if (index < 0) {
1480 {
1481 warningWithoutStack$1(false, 'Unexpected pop.');
1482 }
1483 return;
1484 }
1485
1486 {
1487 if (fiber !== fiberStack[index]) {
1488 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1489 }
1490 }
1491
1492 cursor.current = valueStack[index];
1493
1494 valueStack[index] = null;
1495
1496 {
1497 fiberStack[index] = null;
1498 }
1499
1500 index--;
1501}
1502
1503function push(cursor, value, fiber) {
1504 index++;
1505
1506 valueStack[index] = cursor.current;
1507
1508 {
1509 fiberStack[index] = fiber;
1510 }
1511
1512 cursor.current = value;
1513}
1514
1515function checkThatStackIsEmpty() {
1516 {
1517 if (index !== -1) {
1518 warningWithoutStack$1(false, 'Expected an empty stack. Something was not reset properly.');
1519 }
1520 }
1521}
1522
1523function resetStackAfterFatalErrorInDev() {
1524 {
1525 index = -1;
1526 valueStack.length = 0;
1527 fiberStack.length = 0;
1528 }
1529}
1530
1531var warnedAboutMissingGetChildContext = void 0;
1532
1533{
1534 warnedAboutMissingGetChildContext = {};
1535}
1536
1537var emptyContextObject = {};
1538{
1539 Object.freeze(emptyContextObject);
1540}
1541
1542// A cursor to the current merged context object on the stack.
1543var contextStackCursor = createCursor(emptyContextObject);
1544// A cursor to a boolean indicating whether the context has changed.
1545var didPerformWorkStackCursor = createCursor(false);
1546// Keep track of the previous context object that was on the stack.
1547// We use this to get access to the parent context after we have already
1548// pushed the next context provider, and now need to merge their contexts.
1549var previousContext = emptyContextObject;
1550
1551function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1552 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1553 // If the fiber is a context provider itself, when we read its context
1554 // we may have already pushed its own child context on the stack. A context
1555 // provider should not "see" its own child context. Therefore we read the
1556 // previous (parent) context instead for a context provider.
1557 return previousContext;
1558 }
1559 return contextStackCursor.current;
1560}
1561
1562function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1563 var instance = workInProgress.stateNode;
1564 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1565 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1566}
1567
1568function getMaskedContext(workInProgress, unmaskedContext) {
1569 var type = workInProgress.type;
1570 var contextTypes = type.contextTypes;
1571 if (!contextTypes) {
1572 return emptyContextObject;
1573 }
1574
1575 // Avoid recreating masked context unless unmasked context has changed.
1576 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1577 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1578 var instance = workInProgress.stateNode;
1579 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1580 return instance.__reactInternalMemoizedMaskedChildContext;
1581 }
1582
1583 var context = {};
1584 for (var key in contextTypes) {
1585 context[key] = unmaskedContext[key];
1586 }
1587
1588 {
1589 var name = getComponentName(type) || 'Unknown';
1590 checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1591 }
1592
1593 // Cache unmasked context so we can avoid recreating masked context unless necessary.
1594 // Context is created before the class component is instantiated so check for instance.
1595 if (instance) {
1596 cacheContext(workInProgress, unmaskedContext, context);
1597 }
1598
1599 return context;
1600}
1601
1602function hasContextChanged() {
1603 return didPerformWorkStackCursor.current;
1604}
1605
1606function isContextProvider(type) {
1607 var childContextTypes = type.childContextTypes;
1608 return childContextTypes !== null && childContextTypes !== undefined;
1609}
1610
1611function popContext(fiber) {
1612 pop(didPerformWorkStackCursor, fiber);
1613 pop(contextStackCursor, fiber);
1614}
1615
1616function popTopLevelContextObject(fiber) {
1617 pop(didPerformWorkStackCursor, fiber);
1618 pop(contextStackCursor, fiber);
1619}
1620
1621function pushTopLevelContextObject(fiber, context, didChange) {
1622 !(contextStackCursor.current === emptyContextObject) ? invariant(false, 'Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue.') : void 0;
1623
1624 push(contextStackCursor, context, fiber);
1625 push(didPerformWorkStackCursor, didChange, fiber);
1626}
1627
1628function processChildContext(fiber, type, parentContext) {
1629 var instance = fiber.stateNode;
1630 var childContextTypes = type.childContextTypes;
1631
1632 // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1633 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1634 if (typeof instance.getChildContext !== 'function') {
1635 {
1636 var componentName = getComponentName(type) || 'Unknown';
1637
1638 if (!warnedAboutMissingGetChildContext[componentName]) {
1639 warnedAboutMissingGetChildContext[componentName] = true;
1640 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);
1641 }
1642 }
1643 return parentContext;
1644 }
1645
1646 var childContext = void 0;
1647 {
1648 setCurrentPhase('getChildContext');
1649 }
1650 startPhaseTimer(fiber, 'getChildContext');
1651 childContext = instance.getChildContext();
1652 stopPhaseTimer();
1653 {
1654 setCurrentPhase(null);
1655 }
1656 for (var contextKey in childContext) {
1657 !(contextKey in childContextTypes) ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(type) || 'Unknown', contextKey) : void 0;
1658 }
1659 {
1660 var name = getComponentName(type) || 'Unknown';
1661 checkPropTypes_1(childContextTypes, childContext, 'child context', name,
1662 // In practice, there is one case in which we won't get a stack. It's when
1663 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1664 // context from the parent component instance. The stack will be missing
1665 // because it's outside of the reconciliation, and so the pointer has not
1666 // been set. This is rare and doesn't matter. We'll also remove that API.
1667 getCurrentFiberStackInDev);
1668 }
1669
1670 return _assign({}, parentContext, childContext);
1671}
1672
1673function pushContextProvider(workInProgress) {
1674 var instance = workInProgress.stateNode;
1675 // We push the context as early as possible to ensure stack integrity.
1676 // If the instance does not exist yet, we will push null at first,
1677 // and replace it on the stack later when invalidating the context.
1678 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject;
1679
1680 // Remember the parent context so we can merge with it later.
1681 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1682 previousContext = contextStackCursor.current;
1683 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1684 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1685
1686 return true;
1687}
1688
1689function invalidateContextProvider(workInProgress, type, didChange) {
1690 var instance = workInProgress.stateNode;
1691 !instance ? invariant(false, 'Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue.') : void 0;
1692
1693 if (didChange) {
1694 // Merge parent and own context.
1695 // Skip this if we're not updating due to sCU.
1696 // This avoids unnecessarily recomputing memoized values.
1697 var mergedContext = processChildContext(workInProgress, type, previousContext);
1698 instance.__reactInternalMemoizedMergedChildContext = mergedContext;
1699
1700 // Replace the old (or empty) context with the new one.
1701 // It is important to unwind the context in the reverse order.
1702 pop(didPerformWorkStackCursor, workInProgress);
1703 pop(contextStackCursor, workInProgress);
1704 // Now push the new context and mark that it has changed.
1705 push(contextStackCursor, mergedContext, workInProgress);
1706 push(didPerformWorkStackCursor, didChange, workInProgress);
1707 } else {
1708 pop(didPerformWorkStackCursor, workInProgress);
1709 push(didPerformWorkStackCursor, didChange, workInProgress);
1710 }
1711}
1712
1713function findCurrentUnmaskedContext(fiber) {
1714 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1715 // makes sense elsewhere
1716 !(isFiberMounted(fiber) && fiber.tag === ClassComponent) ? invariant(false, 'Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue.') : void 0;
1717
1718 var node = fiber;
1719 do {
1720 switch (node.tag) {
1721 case HostRoot:
1722 return node.stateNode.context;
1723 case ClassComponent:
1724 {
1725 var Component = node.type;
1726 if (isContextProvider(Component)) {
1727 return node.stateNode.__reactInternalMemoizedMergedChildContext;
1728 }
1729 break;
1730 }
1731 }
1732 node = node.return;
1733 } while (node !== null);
1734 invariant(false, 'Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.');
1735}
1736
1737var onCommitFiberRoot = null;
1738var onCommitFiberUnmount = null;
1739var hasLoggedError = false;
1740
1741function catchErrors(fn) {
1742 return function (arg) {
1743 try {
1744 return fn(arg);
1745 } catch (err) {
1746 if (true && !hasLoggedError) {
1747 hasLoggedError = true;
1748 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
1749 }
1750 }
1751 };
1752}
1753
1754var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
1755
1756function injectInternals(internals) {
1757 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
1758 // No DevTools
1759 return false;
1760 }
1761 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
1762 if (hook.isDisabled) {
1763 // This isn't a real property on the hook, but it can be set to opt out
1764 // of DevTools integration and associated warnings and logs.
1765 // https://github.com/facebook/react/issues/3877
1766 return true;
1767 }
1768 if (!hook.supportsFiber) {
1769 {
1770 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');
1771 }
1772 // DevTools exists, even though it doesn't support Fiber.
1773 return true;
1774 }
1775 try {
1776 var rendererID = hook.inject(internals);
1777 // We have successfully injected, so now it is safe to set up hooks.
1778 onCommitFiberRoot = catchErrors(function (root) {
1779 return hook.onCommitFiberRoot(rendererID, root);
1780 });
1781 onCommitFiberUnmount = catchErrors(function (fiber) {
1782 return hook.onCommitFiberUnmount(rendererID, fiber);
1783 });
1784 } catch (err) {
1785 // Catch all errors because it is unsafe to throw during initialization.
1786 {
1787 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
1788 }
1789 }
1790 // DevTools exists
1791 return true;
1792}
1793
1794function onCommitRoot(root) {
1795 if (typeof onCommitFiberRoot === 'function') {
1796 onCommitFiberRoot(root);
1797 }
1798}
1799
1800function onCommitUnmount(fiber) {
1801 if (typeof onCommitFiberUnmount === 'function') {
1802 onCommitFiberUnmount(fiber);
1803 }
1804}
1805
1806// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
1807// Math.pow(2, 30) - 1
1808// 0b111111111111111111111111111111
1809var maxSigned31BitInt = 1073741823;
1810
1811var NoWork = 0;
1812var Never = 1;
1813var Sync = maxSigned31BitInt;
1814
1815var UNIT_SIZE = 10;
1816var MAGIC_NUMBER_OFFSET = maxSigned31BitInt - 1;
1817
1818// 1 unit of expiration time represents 10ms.
1819function msToExpirationTime(ms) {
1820 // Always add an offset so that we don't clash with the magic number for NoWork.
1821 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
1822}
1823
1824function expirationTimeToMs(expirationTime) {
1825 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
1826}
1827
1828function ceiling(num, precision) {
1829 return ((num / precision | 0) + 1) * precision;
1830}
1831
1832function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
1833 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
1834}
1835
1836var LOW_PRIORITY_EXPIRATION = 5000;
1837var LOW_PRIORITY_BATCH_SIZE = 250;
1838
1839function computeAsyncExpiration(currentTime) {
1840 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
1841}
1842
1843// We intentionally set a higher expiration time for interactive updates in
1844// dev than in production.
1845//
1846// If the main thread is being blocked so long that you hit the expiration,
1847// it's a problem that could be solved with better scheduling.
1848//
1849// People will be more likely to notice this and fix it with the long
1850// expiration time in development.
1851//
1852// In production we opt for better UX at the risk of masking scheduling
1853// problems, by expiring fast.
1854var HIGH_PRIORITY_EXPIRATION = 500;
1855var HIGH_PRIORITY_BATCH_SIZE = 100;
1856
1857function computeInteractiveExpiration(currentTime) {
1858 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
1859}
1860
1861var NoContext = 0;
1862var ConcurrentMode = 1;
1863var StrictMode = 2;
1864var ProfileMode = 4;
1865
1866var hasBadMapPolyfill = void 0;
1867
1868{
1869 hasBadMapPolyfill = false;
1870 try {
1871 var nonExtensibleObject = Object.preventExtensions({});
1872 var testMap = new Map([[nonExtensibleObject, null]]);
1873 var testSet = new Set([nonExtensibleObject]);
1874 // This is necessary for Rollup to not consider these unused.
1875 // https://github.com/rollup/rollup/issues/1771
1876 // TODO: we can remove these if Rollup fixes the bug.
1877 testMap.set(0, 0);
1878 testSet.add(0);
1879 } catch (e) {
1880 // TODO: Consider warning about bad polyfills
1881 hasBadMapPolyfill = true;
1882 }
1883}
1884
1885// A Fiber is work on a Component that needs to be done or was done. There can
1886// be more than one per component.
1887
1888
1889var debugCounter = void 0;
1890
1891{
1892 debugCounter = 1;
1893}
1894
1895function FiberNode(tag, pendingProps, key, mode) {
1896 // Instance
1897 this.tag = tag;
1898 this.key = key;
1899 this.elementType = null;
1900 this.type = null;
1901 this.stateNode = null;
1902
1903 // Fiber
1904 this.return = null;
1905 this.child = null;
1906 this.sibling = null;
1907 this.index = 0;
1908
1909 this.ref = null;
1910
1911 this.pendingProps = pendingProps;
1912 this.memoizedProps = null;
1913 this.updateQueue = null;
1914 this.memoizedState = null;
1915 this.contextDependencies = null;
1916
1917 this.mode = mode;
1918
1919 // Effects
1920 this.effectTag = NoEffect;
1921 this.nextEffect = null;
1922
1923 this.firstEffect = null;
1924 this.lastEffect = null;
1925
1926 this.expirationTime = NoWork;
1927 this.childExpirationTime = NoWork;
1928
1929 this.alternate = null;
1930
1931 if (enableProfilerTimer) {
1932 // Note: The following is done to avoid a v8 performance cliff.
1933 //
1934 // Initializing the fields below to smis and later updating them with
1935 // double values will cause Fibers to end up having separate shapes.
1936 // This behavior/bug has something to do with Object.preventExtension().
1937 // Fortunately this only impacts DEV builds.
1938 // Unfortunately it makes React unusably slow for some applications.
1939 // To work around this, initialize the fields below with doubles.
1940 //
1941 // Learn more about this here:
1942 // https://github.com/facebook/react/issues/14365
1943 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
1944 this.actualDuration = Number.NaN;
1945 this.actualStartTime = Number.NaN;
1946 this.selfBaseDuration = Number.NaN;
1947 this.treeBaseDuration = Number.NaN;
1948
1949 // It's okay to replace the initial doubles with smis after initialization.
1950 // This won't trigger the performance cliff mentioned above,
1951 // and it simplifies other profiler code (including DevTools).
1952 this.actualDuration = 0;
1953 this.actualStartTime = -1;
1954 this.selfBaseDuration = 0;
1955 this.treeBaseDuration = 0;
1956 }
1957
1958 {
1959 this._debugID = debugCounter++;
1960 this._debugSource = null;
1961 this._debugOwner = null;
1962 this._debugIsCurrentlyTiming = false;
1963 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
1964 Object.preventExtensions(this);
1965 }
1966 }
1967}
1968
1969// This is a constructor function, rather than a POJO constructor, still
1970// please ensure we do the following:
1971// 1) Nobody should add any instance methods on this. Instance methods can be
1972// more difficult to predict when they get optimized and they are almost
1973// never inlined properly in static compilers.
1974// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
1975// always know when it is a fiber.
1976// 3) We might want to experiment with using numeric keys since they are easier
1977// to optimize in a non-JIT environment.
1978// 4) We can easily go from a constructor to a createFiber object literal if that
1979// is faster.
1980// 5) It should be easy to port this to a C struct and keep a C implementation
1981// compatible.
1982var createFiber = function (tag, pendingProps, key, mode) {
1983 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
1984 return new FiberNode(tag, pendingProps, key, mode);
1985};
1986
1987function shouldConstruct(Component) {
1988 var prototype = Component.prototype;
1989 return !!(prototype && prototype.isReactComponent);
1990}
1991
1992function isSimpleFunctionComponent(type) {
1993 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
1994}
1995
1996function resolveLazyComponentTag(Component) {
1997 if (typeof Component === 'function') {
1998 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
1999 } else if (Component !== undefined && Component !== null) {
2000 var $$typeof = Component.$$typeof;
2001 if ($$typeof === REACT_FORWARD_REF_TYPE) {
2002 return ForwardRef;
2003 }
2004 if ($$typeof === REACT_MEMO_TYPE) {
2005 return MemoComponent;
2006 }
2007 }
2008 return IndeterminateComponent;
2009}
2010
2011// This is used to create an alternate fiber to do work on.
2012function createWorkInProgress(current, pendingProps, expirationTime) {
2013 var workInProgress = current.alternate;
2014 if (workInProgress === null) {
2015 // We use a double buffering pooling technique because we know that we'll
2016 // only ever need at most two versions of a tree. We pool the "other" unused
2017 // node that we're free to reuse. This is lazily created to avoid allocating
2018 // extra objects for things that are never updated. It also allow us to
2019 // reclaim the extra memory if needed.
2020 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
2021 workInProgress.elementType = current.elementType;
2022 workInProgress.type = current.type;
2023 workInProgress.stateNode = current.stateNode;
2024
2025 {
2026 // DEV-only fields
2027 workInProgress._debugID = current._debugID;
2028 workInProgress._debugSource = current._debugSource;
2029 workInProgress._debugOwner = current._debugOwner;
2030 }
2031
2032 workInProgress.alternate = current;
2033 current.alternate = workInProgress;
2034 } else {
2035 workInProgress.pendingProps = pendingProps;
2036
2037 // We already have an alternate.
2038 // Reset the effect tag.
2039 workInProgress.effectTag = NoEffect;
2040
2041 // The effect list is no longer valid.
2042 workInProgress.nextEffect = null;
2043 workInProgress.firstEffect = null;
2044 workInProgress.lastEffect = null;
2045
2046 if (enableProfilerTimer) {
2047 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
2048 // This prevents time from endlessly accumulating in new commits.
2049 // This has the downside of resetting values for different priority renders,
2050 // But works for yielding (the common case) and should support resuming.
2051 workInProgress.actualDuration = 0;
2052 workInProgress.actualStartTime = -1;
2053 }
2054 }
2055
2056 workInProgress.childExpirationTime = current.childExpirationTime;
2057 workInProgress.expirationTime = current.expirationTime;
2058
2059 workInProgress.child = current.child;
2060 workInProgress.memoizedProps = current.memoizedProps;
2061 workInProgress.memoizedState = current.memoizedState;
2062 workInProgress.updateQueue = current.updateQueue;
2063 workInProgress.contextDependencies = current.contextDependencies;
2064
2065 // These will be overridden during the parent's reconciliation
2066 workInProgress.sibling = current.sibling;
2067 workInProgress.index = current.index;
2068 workInProgress.ref = current.ref;
2069
2070 if (enableProfilerTimer) {
2071 workInProgress.selfBaseDuration = current.selfBaseDuration;
2072 workInProgress.treeBaseDuration = current.treeBaseDuration;
2073 }
2074
2075 return workInProgress;
2076}
2077
2078function createHostRootFiber(isConcurrent) {
2079 var mode = isConcurrent ? ConcurrentMode | StrictMode : NoContext;
2080
2081 if (enableProfilerTimer && isDevToolsPresent) {
2082 // Always collect profile timings when DevTools are present.
2083 // This enables DevTools to start capturing timing at any point–
2084 // Without some nodes in the tree having empty base times.
2085 mode |= ProfileMode;
2086 }
2087
2088 return createFiber(HostRoot, null, null, mode);
2089}
2090
2091function createFiberFromTypeAndProps(type, // React$ElementType
2092key, pendingProps, owner, mode, expirationTime) {
2093 var fiber = void 0;
2094
2095 var fiberTag = IndeterminateComponent;
2096 // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
2097 var resolvedType = type;
2098 if (typeof type === 'function') {
2099 if (shouldConstruct(type)) {
2100 fiberTag = ClassComponent;
2101 }
2102 } else if (typeof type === 'string') {
2103 fiberTag = HostComponent;
2104 } else {
2105 getTag: switch (type) {
2106 case REACT_FRAGMENT_TYPE:
2107 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
2108 case REACT_CONCURRENT_MODE_TYPE:
2109 return createFiberFromMode(pendingProps, mode | ConcurrentMode | StrictMode, expirationTime, key);
2110 case REACT_STRICT_MODE_TYPE:
2111 return createFiberFromMode(pendingProps, mode | StrictMode, expirationTime, key);
2112 case REACT_PROFILER_TYPE:
2113 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
2114 case REACT_SUSPENSE_TYPE:
2115 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
2116 default:
2117 {
2118 if (typeof type === 'object' && type !== null) {
2119 switch (type.$$typeof) {
2120 case REACT_PROVIDER_TYPE:
2121 fiberTag = ContextProvider;
2122 break getTag;
2123 case REACT_CONTEXT_TYPE:
2124 // This is a consumer
2125 fiberTag = ContextConsumer;
2126 break getTag;
2127 case REACT_FORWARD_REF_TYPE:
2128 fiberTag = ForwardRef;
2129 break getTag;
2130 case REACT_MEMO_TYPE:
2131 fiberTag = MemoComponent;
2132 break getTag;
2133 case REACT_LAZY_TYPE:
2134 fiberTag = LazyComponent;
2135 resolvedType = null;
2136 break getTag;
2137 }
2138 }
2139 var info = '';
2140 {
2141 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2142 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.';
2143 }
2144 var ownerName = owner ? getComponentName(owner.type) : null;
2145 if (ownerName) {
2146 info += '\n\nCheck the render method of `' + ownerName + '`.';
2147 }
2148 }
2149 invariant(false, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s', type == null ? type : typeof type, info);
2150 }
2151 }
2152 }
2153
2154 fiber = createFiber(fiberTag, pendingProps, key, mode);
2155 fiber.elementType = type;
2156 fiber.type = resolvedType;
2157 fiber.expirationTime = expirationTime;
2158
2159 return fiber;
2160}
2161
2162function createFiberFromElement(element, mode, expirationTime) {
2163 var owner = null;
2164 {
2165 owner = element._owner;
2166 }
2167 var type = element.type;
2168 var key = element.key;
2169 var pendingProps = element.props;
2170 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
2171 {
2172 fiber._debugSource = element._source;
2173 fiber._debugOwner = element._owner;
2174 }
2175 return fiber;
2176}
2177
2178function createFiberFromFragment(elements, mode, expirationTime, key) {
2179 var fiber = createFiber(Fragment, elements, key, mode);
2180 fiber.expirationTime = expirationTime;
2181 return fiber;
2182}
2183
2184function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
2185 {
2186 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
2187 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
2188 }
2189 }
2190
2191 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode);
2192 // TODO: The Profiler fiber shouldn't have a type. It has a tag.
2193 fiber.elementType = REACT_PROFILER_TYPE;
2194 fiber.type = REACT_PROFILER_TYPE;
2195 fiber.expirationTime = expirationTime;
2196
2197 return fiber;
2198}
2199
2200function createFiberFromMode(pendingProps, mode, expirationTime, key) {
2201 var fiber = createFiber(Mode, pendingProps, key, mode);
2202
2203 // TODO: The Mode fiber shouldn't have a type. It has a tag.
2204 var type = (mode & ConcurrentMode) === NoContext ? REACT_STRICT_MODE_TYPE : REACT_CONCURRENT_MODE_TYPE;
2205 fiber.elementType = type;
2206 fiber.type = type;
2207
2208 fiber.expirationTime = expirationTime;
2209 return fiber;
2210}
2211
2212function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
2213 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode);
2214
2215 // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
2216 var type = REACT_SUSPENSE_TYPE;
2217 fiber.elementType = type;
2218 fiber.type = type;
2219
2220 fiber.expirationTime = expirationTime;
2221 return fiber;
2222}
2223
2224function createFiberFromText(content, mode, expirationTime) {
2225 var fiber = createFiber(HostText, content, null, mode);
2226 fiber.expirationTime = expirationTime;
2227 return fiber;
2228}
2229
2230function createFiberFromHostInstanceForDeletion() {
2231 var fiber = createFiber(HostComponent, null, null, NoContext);
2232 // TODO: These should not need a type.
2233 fiber.elementType = 'DELETED';
2234 fiber.type = 'DELETED';
2235 return fiber;
2236}
2237
2238function createFiberFromPortal(portal, mode, expirationTime) {
2239 var pendingProps = portal.children !== null ? portal.children : [];
2240 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
2241 fiber.expirationTime = expirationTime;
2242 fiber.stateNode = {
2243 containerInfo: portal.containerInfo,
2244 pendingChildren: null, // Used by persistent updates
2245 implementation: portal.implementation
2246 };
2247 return fiber;
2248}
2249
2250// Used for stashing WIP properties to replay failed work in DEV.
2251function assignFiberPropertiesInDEV(target, source) {
2252 if (target === null) {
2253 // This Fiber's initial properties will always be overwritten.
2254 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
2255 target = createFiber(IndeterminateComponent, null, null, NoContext);
2256 }
2257
2258 // This is intentionally written as a list of all properties.
2259 // We tried to use Object.assign() instead but this is called in
2260 // the hottest path, and Object.assign() was too slow:
2261 // https://github.com/facebook/react/issues/12502
2262 // This code is DEV-only so size is not a concern.
2263
2264 target.tag = source.tag;
2265 target.key = source.key;
2266 target.elementType = source.elementType;
2267 target.type = source.type;
2268 target.stateNode = source.stateNode;
2269 target.return = source.return;
2270 target.child = source.child;
2271 target.sibling = source.sibling;
2272 target.index = source.index;
2273 target.ref = source.ref;
2274 target.pendingProps = source.pendingProps;
2275 target.memoizedProps = source.memoizedProps;
2276 target.updateQueue = source.updateQueue;
2277 target.memoizedState = source.memoizedState;
2278 target.contextDependencies = source.contextDependencies;
2279 target.mode = source.mode;
2280 target.effectTag = source.effectTag;
2281 target.nextEffect = source.nextEffect;
2282 target.firstEffect = source.firstEffect;
2283 target.lastEffect = source.lastEffect;
2284 target.expirationTime = source.expirationTime;
2285 target.childExpirationTime = source.childExpirationTime;
2286 target.alternate = source.alternate;
2287 if (enableProfilerTimer) {
2288 target.actualDuration = source.actualDuration;
2289 target.actualStartTime = source.actualStartTime;
2290 target.selfBaseDuration = source.selfBaseDuration;
2291 target.treeBaseDuration = source.treeBaseDuration;
2292 }
2293 target._debugID = source._debugID;
2294 target._debugSource = source._debugSource;
2295 target._debugOwner = source._debugOwner;
2296 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
2297 return target;
2298}
2299
2300var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2301
2302var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing;
2303var __interactionsRef = _ReactInternals$Sched.__interactionsRef;
2304var __subscriberRef = _ReactInternals$Sched.__subscriberRef;
2305var unstable_clear = _ReactInternals$Sched.unstable_clear;
2306var unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent;
2307var unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID;
2308var unstable_subscribe = _ReactInternals$Sched.unstable_subscribe;
2309var unstable_trace = _ReactInternals$Sched.unstable_trace;
2310var unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe;
2311var unstable_wrap = _ReactInternals$Sched.unstable_wrap;
2312
2313// TODO: This should be lifted into the renderer.
2314
2315
2316// The following attributes are only used by interaction tracing builds.
2317// They enable interactions to be associated with their async work,
2318// And expose interaction metadata to the React DevTools Profiler plugin.
2319// Note that these attributes are only defined when the enableSchedulerTracing flag is enabled.
2320
2321
2322// Exported FiberRoot type includes all properties,
2323// To avoid requiring potentially error-prone :any casts throughout the project.
2324// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracing is true).
2325// The types are defined separately within this file to ensure they stay in sync.
2326// (We don't have to use an inline :any cast when enableSchedulerTracing is disabled.)
2327
2328
2329function createFiberRoot(containerInfo, isConcurrent, hydrate) {
2330 // Cyclic construction. This cheats the type system right now because
2331 // stateNode is any.
2332 var uninitializedFiber = createHostRootFiber(isConcurrent);
2333
2334 var root = void 0;
2335 if (enableSchedulerTracing) {
2336 root = {
2337 current: uninitializedFiber,
2338 containerInfo: containerInfo,
2339 pendingChildren: null,
2340
2341 earliestPendingTime: NoWork,
2342 latestPendingTime: NoWork,
2343 earliestSuspendedTime: NoWork,
2344 latestSuspendedTime: NoWork,
2345 latestPingedTime: NoWork,
2346
2347 pingCache: null,
2348
2349 didError: false,
2350
2351 pendingCommitExpirationTime: NoWork,
2352 finishedWork: null,
2353 timeoutHandle: noTimeout,
2354 context: null,
2355 pendingContext: null,
2356 hydrate: hydrate,
2357 nextExpirationTimeToWorkOn: NoWork,
2358 expirationTime: NoWork,
2359 firstBatch: null,
2360 nextScheduledRoot: null,
2361
2362 interactionThreadID: unstable_getThreadID(),
2363 memoizedInteractions: new Set(),
2364 pendingInteractionMap: new Map()
2365 };
2366 } else {
2367 root = {
2368 current: uninitializedFiber,
2369 containerInfo: containerInfo,
2370 pendingChildren: null,
2371
2372 pingCache: null,
2373
2374 earliestPendingTime: NoWork,
2375 latestPendingTime: NoWork,
2376 earliestSuspendedTime: NoWork,
2377 latestSuspendedTime: NoWork,
2378 latestPingedTime: NoWork,
2379
2380 didError: false,
2381
2382 pendingCommitExpirationTime: NoWork,
2383 finishedWork: null,
2384 timeoutHandle: noTimeout,
2385 context: null,
2386 pendingContext: null,
2387 hydrate: hydrate,
2388 nextExpirationTimeToWorkOn: NoWork,
2389 expirationTime: NoWork,
2390 firstBatch: null,
2391 nextScheduledRoot: null
2392 };
2393 }
2394
2395 uninitializedFiber.stateNode = root;
2396
2397 // The reason for the way the Flow types are structured in this file,
2398 // Is to avoid needing :any casts everywhere interaction tracing fields are used.
2399 // Unfortunately that requires an :any cast for non-interaction tracing capable builds.
2400 // $FlowFixMe Remove this :any cast and replace it with something better.
2401 return root;
2402}
2403
2404var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
2405 var funcArgs = Array.prototype.slice.call(arguments, 3);
2406 try {
2407 func.apply(context, funcArgs);
2408 } catch (error) {
2409 this.onError(error);
2410 }
2411};
2412
2413{
2414 // In DEV mode, we swap out invokeGuardedCallback for a special version
2415 // that plays more nicely with the browser's DevTools. The idea is to preserve
2416 // "Pause on exceptions" behavior. Because React wraps all user-provided
2417 // functions in invokeGuardedCallback, and the production version of
2418 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
2419 // like caught exceptions, and the DevTools won't pause unless the developer
2420 // takes the extra step of enabling pause on caught exceptions. This is
2421 // untintuitive, though, because even though React has caught the error, from
2422 // the developer's perspective, the error is uncaught.
2423 //
2424 // To preserve the expected "Pause on exceptions" behavior, we don't use a
2425 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
2426 // DOM node, and call the user-provided callback from inside an event handler
2427 // for that fake event. If the callback throws, the error is "captured" using
2428 // a global event handler. But because the error happens in a different
2429 // event loop context, it does not interrupt the normal program flow.
2430 // Effectively, this gives us try-catch behavior without actually using
2431 // try-catch. Neat!
2432
2433 // Check that the browser supports the APIs we need to implement our special
2434 // DEV version of invokeGuardedCallback
2435 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
2436 var fakeNode = document.createElement('react');
2437
2438 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
2439 // If document doesn't exist we know for sure we will crash in this method
2440 // when we call document.createEvent(). However this can cause confusing
2441 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
2442 // So we preemptively throw with a better message instead.
2443 !(typeof document !== 'undefined') ? invariant(false, '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.') : void 0;
2444 var evt = document.createEvent('Event');
2445
2446 // Keeps track of whether the user-provided callback threw an error. We
2447 // set this to true at the beginning, then set it to false right after
2448 // calling the function. If the function errors, `didError` will never be
2449 // set to false. This strategy works even if the browser is flaky and
2450 // fails to call our global error handler, because it doesn't rely on
2451 // the error event at all.
2452 var didError = true;
2453
2454 // Keeps track of the value of window.event so that we can reset it
2455 // during the callback to let user code access window.event in the
2456 // browsers that support it.
2457 var windowEvent = window.event;
2458
2459 // Keeps track of the descriptor of window.event to restore it after event
2460 // dispatching: https://github.com/facebook/react/issues/13688
2461 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
2462
2463 // Create an event handler for our fake event. We will synchronously
2464 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
2465 // call the user-provided callback.
2466 var funcArgs = Array.prototype.slice.call(arguments, 3);
2467 function callCallback() {
2468 // We immediately remove the callback from event listeners so that
2469 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
2470 // nested call would trigger the fake event handlers of any call higher
2471 // in the stack.
2472 fakeNode.removeEventListener(evtType, callCallback, false);
2473
2474 // We check for window.hasOwnProperty('event') to prevent the
2475 // window.event assignment in both IE <= 10 as they throw an error
2476 // "Member not found" in strict mode, and in Firefox which does not
2477 // support window.event.
2478 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
2479 window.event = windowEvent;
2480 }
2481
2482 func.apply(context, funcArgs);
2483 didError = false;
2484 }
2485
2486 // Create a global error event handler. We use this to capture the value
2487 // that was thrown. It's possible that this error handler will fire more
2488 // than once; for example, if non-React code also calls `dispatchEvent`
2489 // and a handler for that event throws. We should be resilient to most of
2490 // those cases. Even if our error event handler fires more than once, the
2491 // last error event is always used. If the callback actually does error,
2492 // we know that the last error event is the correct one, because it's not
2493 // possible for anything else to have happened in between our callback
2494 // erroring and the code that follows the `dispatchEvent` call below. If
2495 // the callback doesn't error, but the error event was fired, we know to
2496 // ignore it because `didError` will be false, as described above.
2497 var error = void 0;
2498 // Use this to track whether the error event is ever called.
2499 var didSetError = false;
2500 var isCrossOriginError = false;
2501
2502 function handleWindowError(event) {
2503 error = event.error;
2504 didSetError = true;
2505 if (error === null && event.colno === 0 && event.lineno === 0) {
2506 isCrossOriginError = true;
2507 }
2508 if (event.defaultPrevented) {
2509 // Some other error handler has prevented default.
2510 // Browsers silence the error report if this happens.
2511 // We'll remember this to later decide whether to log it or not.
2512 if (error != null && typeof error === 'object') {
2513 try {
2514 error._suppressLogging = true;
2515 } catch (inner) {
2516 // Ignore.
2517 }
2518 }
2519 }
2520 }
2521
2522 // Create a fake event type.
2523 var evtType = 'react-' + (name ? name : 'invokeguardedcallback');
2524
2525 // Attach our event handlers
2526 window.addEventListener('error', handleWindowError);
2527 fakeNode.addEventListener(evtType, callCallback, false);
2528
2529 // Synchronously dispatch our fake event. If the user-provided function
2530 // errors, it will trigger our global error handler.
2531 evt.initEvent(evtType, false, false);
2532 fakeNode.dispatchEvent(evt);
2533
2534 if (windowEventDescriptor) {
2535 Object.defineProperty(window, 'event', windowEventDescriptor);
2536 }
2537
2538 if (didError) {
2539 if (!didSetError) {
2540 // The callback errored, but the error event never fired.
2541 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.');
2542 } else if (isCrossOriginError) {
2543 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.');
2544 }
2545 this.onError(error);
2546 }
2547
2548 // Remove our event listeners
2549 window.removeEventListener('error', handleWindowError);
2550 };
2551
2552 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
2553 }
2554}
2555
2556var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
2557
2558// Used by Fiber to simulate a try-catch.
2559var hasError = false;
2560var caughtError = null;
2561
2562var reporter = {
2563 onError: function (error) {
2564 hasError = true;
2565 caughtError = error;
2566 }
2567};
2568
2569/**
2570 * Call a function while guarding against errors that happens within it.
2571 * Returns an error if it throws, otherwise null.
2572 *
2573 * In production, this is implemented using a try-catch. The reason we don't
2574 * use a try-catch directly is so that we can swap out a different
2575 * implementation in DEV mode.
2576 *
2577 * @param {String} name of the guard to use for logging or debugging
2578 * @param {Function} func The function to invoke
2579 * @param {*} context The context to use when calling the function
2580 * @param {...*} args Arguments for function
2581 */
2582function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
2583 hasError = false;
2584 caughtError = null;
2585 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
2586}
2587
2588/**
2589 * Same as invokeGuardedCallback, but instead of returning an error, it stores
2590 * it in a global so it can be rethrown by `rethrowCaughtError` later.
2591 * TODO: See if caughtError and rethrowError can be unified.
2592 *
2593 * @param {String} name of the guard to use for logging or debugging
2594 * @param {Function} func The function to invoke
2595 * @param {*} context The context to use when calling the function
2596 * @param {...*} args Arguments for function
2597 */
2598
2599
2600/**
2601 * During execution of guarded functions we will capture the first error which
2602 * we will rethrow to be handled by the top level error handler.
2603 */
2604
2605
2606function hasCaughtError() {
2607 return hasError;
2608}
2609
2610function clearCaughtError() {
2611 if (hasError) {
2612 var error = caughtError;
2613 hasError = false;
2614 caughtError = null;
2615 return error;
2616 } else {
2617 invariant(false, 'clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.');
2618 }
2619}
2620
2621/**
2622 * Forked from fbjs/warning:
2623 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2624 *
2625 * Only change is we use console.warn instead of console.error,
2626 * and do nothing when 'console' is not supported.
2627 * This really simplifies the code.
2628 * ---
2629 * Similar to invariant but only logs a warning if the condition is not met.
2630 * This can be used to log issues in development environments in critical
2631 * paths. Removing the logging code for production environments will keep the
2632 * same logic and follow the same code paths.
2633 */
2634
2635var lowPriorityWarning = function () {};
2636
2637{
2638 var printWarning$1 = function (format) {
2639 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2640 args[_key - 1] = arguments[_key];
2641 }
2642
2643 var argIndex = 0;
2644 var message = 'Warning: ' + format.replace(/%s/g, function () {
2645 return args[argIndex++];
2646 });
2647 if (typeof console !== 'undefined') {
2648 console.warn(message);
2649 }
2650 try {
2651 // --- Welcome to debugging React ---
2652 // This error was thrown as a convenience so that you can use this stack
2653 // to find the callsite that caused this warning to fire.
2654 throw new Error(message);
2655 } catch (x) {}
2656 };
2657
2658 lowPriorityWarning = function (condition, format) {
2659 if (format === undefined) {
2660 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
2661 }
2662 if (!condition) {
2663 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2664 args[_key2 - 2] = arguments[_key2];
2665 }
2666
2667 printWarning$1.apply(undefined, [format].concat(args));
2668 }
2669 };
2670}
2671
2672var lowPriorityWarning$1 = lowPriorityWarning;
2673
2674var ReactStrictModeWarnings = {
2675 discardPendingWarnings: function () {},
2676 flushPendingDeprecationWarnings: function () {},
2677 flushPendingUnsafeLifecycleWarnings: function () {},
2678 recordDeprecationWarnings: function (fiber, instance) {},
2679 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2680 recordLegacyContextWarning: function (fiber, instance) {},
2681 flushLegacyContextWarning: function () {}
2682};
2683
2684{
2685 var LIFECYCLE_SUGGESTIONS = {
2686 UNSAFE_componentWillMount: 'componentDidMount',
2687 UNSAFE_componentWillReceiveProps: 'static getDerivedStateFromProps',
2688 UNSAFE_componentWillUpdate: 'componentDidUpdate'
2689 };
2690
2691 var pendingComponentWillMountWarnings = [];
2692 var pendingComponentWillReceivePropsWarnings = [];
2693 var pendingComponentWillUpdateWarnings = [];
2694 var pendingUnsafeLifecycleWarnings = new Map();
2695 var pendingLegacyContextWarning = new Map();
2696
2697 // Tracks components we have already warned about.
2698 var didWarnAboutDeprecatedLifecycles = new Set();
2699 var didWarnAboutUnsafeLifecycles = new Set();
2700 var didWarnAboutLegacyContext = new Set();
2701
2702 var setToSortedString = function (set) {
2703 var array = [];
2704 set.forEach(function (value) {
2705 array.push(value);
2706 });
2707 return array.sort().join(', ');
2708 };
2709
2710 ReactStrictModeWarnings.discardPendingWarnings = function () {
2711 pendingComponentWillMountWarnings = [];
2712 pendingComponentWillReceivePropsWarnings = [];
2713 pendingComponentWillUpdateWarnings = [];
2714 pendingUnsafeLifecycleWarnings = new Map();
2715 pendingLegacyContextWarning = new Map();
2716 };
2717
2718 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2719 pendingUnsafeLifecycleWarnings.forEach(function (lifecycleWarningsMap, strictRoot) {
2720 var lifecyclesWarningMessages = [];
2721
2722 Object.keys(lifecycleWarningsMap).forEach(function (lifecycle) {
2723 var lifecycleWarnings = lifecycleWarningsMap[lifecycle];
2724 if (lifecycleWarnings.length > 0) {
2725 var componentNames = new Set();
2726 lifecycleWarnings.forEach(function (fiber) {
2727 componentNames.add(getComponentName(fiber.type) || 'Component');
2728 didWarnAboutUnsafeLifecycles.add(fiber.type);
2729 });
2730
2731 var formatted = lifecycle.replace('UNSAFE_', '');
2732 var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle];
2733 var sortedComponentNames = setToSortedString(componentNames);
2734
2735 lifecyclesWarningMessages.push(formatted + ': Please update the following components to use ' + (suggestion + ' instead: ' + sortedComponentNames));
2736 }
2737 });
2738
2739 if (lifecyclesWarningMessages.length > 0) {
2740 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2741
2742 warningWithoutStack$1(false, 'Unsafe lifecycle methods were found within a strict-mode tree:%s' + '\n\n%s' + '\n\nLearn more about this warning here:' + '\nhttps://fb.me/react-strict-mode-warnings', strictRootComponentStack, lifecyclesWarningMessages.join('\n\n'));
2743 }
2744 });
2745
2746 pendingUnsafeLifecycleWarnings = new Map();
2747 };
2748
2749 var findStrictRoot = function (fiber) {
2750 var maybeStrictRoot = null;
2751
2752 var node = fiber;
2753 while (node !== null) {
2754 if (node.mode & StrictMode) {
2755 maybeStrictRoot = node;
2756 }
2757 node = node.return;
2758 }
2759
2760 return maybeStrictRoot;
2761 };
2762
2763 ReactStrictModeWarnings.flushPendingDeprecationWarnings = function () {
2764 if (pendingComponentWillMountWarnings.length > 0) {
2765 var uniqueNames = new Set();
2766 pendingComponentWillMountWarnings.forEach(function (fiber) {
2767 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2768 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2769 });
2770
2771 var sortedNames = setToSortedString(uniqueNames);
2772
2773 lowPriorityWarning$1(false, 'componentWillMount is deprecated and will be removed in the next major version. ' + 'Use componentDidMount instead. As a temporary workaround, ' + 'you can rename to UNSAFE_componentWillMount.' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here:' + '\nhttps://fb.me/react-async-component-lifecycle-hooks', sortedNames);
2774
2775 pendingComponentWillMountWarnings = [];
2776 }
2777
2778 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2779 var _uniqueNames = new Set();
2780 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2781 _uniqueNames.add(getComponentName(fiber.type) || 'Component');
2782 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2783 });
2784
2785 var _sortedNames = setToSortedString(_uniqueNames);
2786
2787 lowPriorityWarning$1(false, 'componentWillReceiveProps is deprecated and will be removed in the next major version. ' + 'Use static getDerivedStateFromProps instead.' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here:' + '\nhttps://fb.me/react-async-component-lifecycle-hooks', _sortedNames);
2788
2789 pendingComponentWillReceivePropsWarnings = [];
2790 }
2791
2792 if (pendingComponentWillUpdateWarnings.length > 0) {
2793 var _uniqueNames2 = new Set();
2794 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2795 _uniqueNames2.add(getComponentName(fiber.type) || 'Component');
2796 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2797 });
2798
2799 var _sortedNames2 = setToSortedString(_uniqueNames2);
2800
2801 lowPriorityWarning$1(false, 'componentWillUpdate is deprecated and will be removed in the next major version. ' + 'Use componentDidUpdate instead. As a temporary workaround, ' + 'you can rename to UNSAFE_componentWillUpdate.' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here:' + '\nhttps://fb.me/react-async-component-lifecycle-hooks', _sortedNames2);
2802
2803 pendingComponentWillUpdateWarnings = [];
2804 }
2805 };
2806
2807 ReactStrictModeWarnings.recordDeprecationWarnings = function (fiber, instance) {
2808 // Dedup strategy: Warn once per component.
2809 if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) {
2810 return;
2811 }
2812
2813 // Don't warn about react-lifecycles-compat polyfilled components.
2814 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
2815 pendingComponentWillMountWarnings.push(fiber);
2816 }
2817 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2818 pendingComponentWillReceivePropsWarnings.push(fiber);
2819 }
2820 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2821 pendingComponentWillUpdateWarnings.push(fiber);
2822 }
2823 };
2824
2825 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2826 var strictRoot = findStrictRoot(fiber);
2827 if (strictRoot === null) {
2828 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.');
2829 return;
2830 }
2831
2832 // Dedup strategy: Warn once per component.
2833 // This is difficult to track any other way since component names
2834 // are often vague and are likely to collide between 3rd party libraries.
2835 // An expand property is probably okay to use here since it's DEV-only,
2836 // and will only be set in the event of serious warnings.
2837 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2838 return;
2839 }
2840
2841 var warningsForRoot = void 0;
2842 if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) {
2843 warningsForRoot = {
2844 UNSAFE_componentWillMount: [],
2845 UNSAFE_componentWillReceiveProps: [],
2846 UNSAFE_componentWillUpdate: []
2847 };
2848
2849 pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot);
2850 } else {
2851 warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot);
2852 }
2853
2854 var unsafeLifecycles = [];
2855 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillMount === 'function') {
2856 unsafeLifecycles.push('UNSAFE_componentWillMount');
2857 }
2858 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2859 unsafeLifecycles.push('UNSAFE_componentWillReceiveProps');
2860 }
2861 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillUpdate === 'function') {
2862 unsafeLifecycles.push('UNSAFE_componentWillUpdate');
2863 }
2864
2865 if (unsafeLifecycles.length > 0) {
2866 unsafeLifecycles.forEach(function (lifecycle) {
2867 warningsForRoot[lifecycle].push(fiber);
2868 });
2869 }
2870 };
2871
2872 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2873 var strictRoot = findStrictRoot(fiber);
2874 if (strictRoot === null) {
2875 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.');
2876 return;
2877 }
2878
2879 // Dedup strategy: Warn once per component.
2880 if (didWarnAboutLegacyContext.has(fiber.type)) {
2881 return;
2882 }
2883
2884 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2885
2886 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2887 if (warningsForRoot === undefined) {
2888 warningsForRoot = [];
2889 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2890 }
2891 warningsForRoot.push(fiber);
2892 }
2893 };
2894
2895 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2896 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2897 var uniqueNames = new Set();
2898 fiberArray.forEach(function (fiber) {
2899 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2900 didWarnAboutLegacyContext.add(fiber.type);
2901 });
2902
2903 var sortedNames = setToSortedString(uniqueNames);
2904 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2905
2906 warningWithoutStack$1(false, 'Legacy context API has been detected within a strict-mode tree: %s' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here:' + '\nhttps://fb.me/react-strict-mode-warnings', strictRootComponentStack, sortedNames);
2907 });
2908 };
2909}
2910
2911// This lets us hook into Fiber to debug what it's doing.
2912// See https://github.com/facebook/react/pull/8033.
2913// This is not part of the public API, not even for React DevTools.
2914// You may only inject a debugTool if you work on React Fiber itself.
2915var ReactFiberInstrumentation = {
2916 debugTool: null
2917};
2918
2919var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
2920
2921// TODO: Offscreen updates should never suspend. However, a promise that
2922// suspended inside an offscreen subtree should be able to ping at the priority
2923// of the outer render.
2924
2925function markPendingPriorityLevel(root, expirationTime) {
2926 // If there's a gap between completing a failed root and retrying it,
2927 // additional updates may be scheduled. Clear `didError`, in case the update
2928 // is sufficient to fix the error.
2929 root.didError = false;
2930
2931 // Update the latest and earliest pending times
2932 var earliestPendingTime = root.earliestPendingTime;
2933 if (earliestPendingTime === NoWork) {
2934 // No other pending updates.
2935 root.earliestPendingTime = root.latestPendingTime = expirationTime;
2936 } else {
2937 if (earliestPendingTime < expirationTime) {
2938 // This is the earliest pending update.
2939 root.earliestPendingTime = expirationTime;
2940 } else {
2941 var latestPendingTime = root.latestPendingTime;
2942 if (latestPendingTime > expirationTime) {
2943 // This is the latest pending update
2944 root.latestPendingTime = expirationTime;
2945 }
2946 }
2947 }
2948 findNextExpirationTimeToWorkOn(expirationTime, root);
2949}
2950
2951function markCommittedPriorityLevels(root, earliestRemainingTime) {
2952 root.didError = false;
2953
2954 if (earliestRemainingTime === NoWork) {
2955 // Fast path. There's no remaining work. Clear everything.
2956 root.earliestPendingTime = NoWork;
2957 root.latestPendingTime = NoWork;
2958 root.earliestSuspendedTime = NoWork;
2959 root.latestSuspendedTime = NoWork;
2960 root.latestPingedTime = NoWork;
2961 findNextExpirationTimeToWorkOn(NoWork, root);
2962 return;
2963 }
2964
2965 if (earliestRemainingTime < root.latestPingedTime) {
2966 root.latestPingedTime = NoWork;
2967 }
2968
2969 // Let's see if the previous latest known pending level was just flushed.
2970 var latestPendingTime = root.latestPendingTime;
2971 if (latestPendingTime !== NoWork) {
2972 if (latestPendingTime > earliestRemainingTime) {
2973 // We've flushed all the known pending levels.
2974 root.earliestPendingTime = root.latestPendingTime = NoWork;
2975 } else {
2976 var earliestPendingTime = root.earliestPendingTime;
2977 if (earliestPendingTime > earliestRemainingTime) {
2978 // We've flushed the earliest known pending level. Set this to the
2979 // latest pending time.
2980 root.earliestPendingTime = root.latestPendingTime;
2981 }
2982 }
2983 }
2984
2985 // Now let's handle the earliest remaining level in the whole tree. We need to
2986 // decide whether to treat it as a pending level or as suspended. Check
2987 // it falls within the range of known suspended levels.
2988
2989 var earliestSuspendedTime = root.earliestSuspendedTime;
2990 if (earliestSuspendedTime === NoWork) {
2991 // There's no suspended work. Treat the earliest remaining level as a
2992 // pending level.
2993 markPendingPriorityLevel(root, earliestRemainingTime);
2994 findNextExpirationTimeToWorkOn(NoWork, root);
2995 return;
2996 }
2997
2998 var latestSuspendedTime = root.latestSuspendedTime;
2999 if (earliestRemainingTime < latestSuspendedTime) {
3000 // The earliest remaining level is later than all the suspended work. That
3001 // means we've flushed all the suspended work.
3002 root.earliestSuspendedTime = NoWork;
3003 root.latestSuspendedTime = NoWork;
3004 root.latestPingedTime = NoWork;
3005
3006 // There's no suspended work. Treat the earliest remaining level as a
3007 // pending level.
3008 markPendingPriorityLevel(root, earliestRemainingTime);
3009 findNextExpirationTimeToWorkOn(NoWork, root);
3010 return;
3011 }
3012
3013 if (earliestRemainingTime > earliestSuspendedTime) {
3014 // The earliest remaining time is earlier than all the suspended work.
3015 // Treat it as a pending update.
3016 markPendingPriorityLevel(root, earliestRemainingTime);
3017 findNextExpirationTimeToWorkOn(NoWork, root);
3018 return;
3019 }
3020
3021 // The earliest remaining time falls within the range of known suspended
3022 // levels. We should treat this as suspended work.
3023 findNextExpirationTimeToWorkOn(NoWork, root);
3024}
3025
3026function hasLowerPriorityWork(root, erroredExpirationTime) {
3027 var latestPendingTime = root.latestPendingTime;
3028 var latestSuspendedTime = root.latestSuspendedTime;
3029 var latestPingedTime = root.latestPingedTime;
3030 return latestPendingTime !== NoWork && latestPendingTime < erroredExpirationTime || latestSuspendedTime !== NoWork && latestSuspendedTime < erroredExpirationTime || latestPingedTime !== NoWork && latestPingedTime < erroredExpirationTime;
3031}
3032
3033function isPriorityLevelSuspended(root, expirationTime) {
3034 var earliestSuspendedTime = root.earliestSuspendedTime;
3035 var latestSuspendedTime = root.latestSuspendedTime;
3036 return earliestSuspendedTime !== NoWork && expirationTime <= earliestSuspendedTime && expirationTime >= latestSuspendedTime;
3037}
3038
3039function markSuspendedPriorityLevel(root, suspendedTime) {
3040 root.didError = false;
3041 clearPing(root, suspendedTime);
3042
3043 // First, check the known pending levels and update them if needed.
3044 var earliestPendingTime = root.earliestPendingTime;
3045 var latestPendingTime = root.latestPendingTime;
3046 if (earliestPendingTime === suspendedTime) {
3047 if (latestPendingTime === suspendedTime) {
3048 // Both known pending levels were suspended. Clear them.
3049 root.earliestPendingTime = root.latestPendingTime = NoWork;
3050 } else {
3051 // The earliest pending level was suspended. Clear by setting it to the
3052 // latest pending level.
3053 root.earliestPendingTime = latestPendingTime;
3054 }
3055 } else if (latestPendingTime === suspendedTime) {
3056 // The latest pending level was suspended. Clear by setting it to the
3057 // latest pending level.
3058 root.latestPendingTime = earliestPendingTime;
3059 }
3060
3061 // Finally, update the known suspended levels.
3062 var earliestSuspendedTime = root.earliestSuspendedTime;
3063 var latestSuspendedTime = root.latestSuspendedTime;
3064 if (earliestSuspendedTime === NoWork) {
3065 // No other suspended levels.
3066 root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime;
3067 } else {
3068 if (earliestSuspendedTime < suspendedTime) {
3069 // This is the earliest suspended level.
3070 root.earliestSuspendedTime = suspendedTime;
3071 } else if (latestSuspendedTime > suspendedTime) {
3072 // This is the latest suspended level
3073 root.latestSuspendedTime = suspendedTime;
3074 }
3075 }
3076
3077 findNextExpirationTimeToWorkOn(suspendedTime, root);
3078}
3079
3080function markPingedPriorityLevel(root, pingedTime) {
3081 root.didError = false;
3082
3083 // TODO: When we add back resuming, we need to ensure the progressed work
3084 // is thrown out and not reused during the restarted render. One way to
3085 // invalidate the progressed work is to restart at expirationTime + 1.
3086 var latestPingedTime = root.latestPingedTime;
3087 if (latestPingedTime === NoWork || latestPingedTime > pingedTime) {
3088 root.latestPingedTime = pingedTime;
3089 }
3090 findNextExpirationTimeToWorkOn(pingedTime, root);
3091}
3092
3093function clearPing(root, completedTime) {
3094 var latestPingedTime = root.latestPingedTime;
3095 if (latestPingedTime >= completedTime) {
3096 root.latestPingedTime = NoWork;
3097 }
3098}
3099
3100function findEarliestOutstandingPriorityLevel(root, renderExpirationTime) {
3101 var earliestExpirationTime = renderExpirationTime;
3102
3103 var earliestPendingTime = root.earliestPendingTime;
3104 var earliestSuspendedTime = root.earliestSuspendedTime;
3105 if (earliestPendingTime > earliestExpirationTime) {
3106 earliestExpirationTime = earliestPendingTime;
3107 }
3108 if (earliestSuspendedTime > earliestExpirationTime) {
3109 earliestExpirationTime = earliestSuspendedTime;
3110 }
3111 return earliestExpirationTime;
3112}
3113
3114function didExpireAtExpirationTime(root, currentTime) {
3115 var expirationTime = root.expirationTime;
3116 if (expirationTime !== NoWork && currentTime <= expirationTime) {
3117 // The root has expired. Flush all work up to the current time.
3118 root.nextExpirationTimeToWorkOn = currentTime;
3119 }
3120}
3121
3122function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
3123 var earliestSuspendedTime = root.earliestSuspendedTime;
3124 var latestSuspendedTime = root.latestSuspendedTime;
3125 var earliestPendingTime = root.earliestPendingTime;
3126 var latestPingedTime = root.latestPingedTime;
3127
3128 // Work on the earliest pending time. Failing that, work on the latest
3129 // pinged time.
3130 var nextExpirationTimeToWorkOn = earliestPendingTime !== NoWork ? earliestPendingTime : latestPingedTime;
3131
3132 // If there is no pending or pinged work, check if there's suspended work
3133 // that's lower priority than what we just completed.
3134 if (nextExpirationTimeToWorkOn === NoWork && (completedExpirationTime === NoWork || latestSuspendedTime < completedExpirationTime)) {
3135 // The lowest priority suspended work is the work most likely to be
3136 // committed next. Let's start rendering it again, so that if it times out,
3137 // it's ready to commit.
3138 nextExpirationTimeToWorkOn = latestSuspendedTime;
3139 }
3140
3141 var expirationTime = nextExpirationTimeToWorkOn;
3142 if (expirationTime !== NoWork && earliestSuspendedTime > expirationTime) {
3143 // Expire using the earliest known expiration time.
3144 expirationTime = earliestSuspendedTime;
3145 }
3146
3147 root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn;
3148 root.expirationTime = expirationTime;
3149}
3150
3151/**
3152 * inlined Object.is polyfill to avoid requiring consumers ship their own
3153 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3154 */
3155function is(x, y) {
3156 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
3157 ;
3158}
3159
3160var hasOwnProperty = Object.prototype.hasOwnProperty;
3161
3162/**
3163 * Performs equality by iterating through keys on an object and returning false
3164 * when any key has values which are not strictly equal between the arguments.
3165 * Returns true when the values of all keys are strictly equal.
3166 */
3167function shallowEqual(objA, objB) {
3168 if (is(objA, objB)) {
3169 return true;
3170 }
3171
3172 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
3173 return false;
3174 }
3175
3176 var keysA = Object.keys(objA);
3177 var keysB = Object.keys(objB);
3178
3179 if (keysA.length !== keysB.length) {
3180 return false;
3181 }
3182
3183 // Test for A's keys different from B.
3184 for (var i = 0; i < keysA.length; i++) {
3185 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
3186 return false;
3187 }
3188 }
3189
3190 return true;
3191}
3192
3193function resolveDefaultProps(Component, baseProps) {
3194 if (Component && Component.defaultProps) {
3195 // Resolve default props. Taken from ReactElement
3196 var props = _assign({}, baseProps);
3197 var defaultProps = Component.defaultProps;
3198 for (var propName in defaultProps) {
3199 if (props[propName] === undefined) {
3200 props[propName] = defaultProps[propName];
3201 }
3202 }
3203 return props;
3204 }
3205 return baseProps;
3206}
3207
3208function readLazyComponentType(lazyComponent) {
3209 var status = lazyComponent._status;
3210 var result = lazyComponent._result;
3211 switch (status) {
3212 case Resolved:
3213 {
3214 var Component = result;
3215 return Component;
3216 }
3217 case Rejected:
3218 {
3219 var error = result;
3220 throw error;
3221 }
3222 case Pending:
3223 {
3224 var thenable = result;
3225 throw thenable;
3226 }
3227 default:
3228 {
3229 lazyComponent._status = Pending;
3230 var ctor = lazyComponent._ctor;
3231 var _thenable = ctor();
3232 _thenable.then(function (moduleObject) {
3233 if (lazyComponent._status === Pending) {
3234 var defaultExport = moduleObject.default;
3235 {
3236 if (defaultExport === undefined) {
3237 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);
3238 }
3239 }
3240 lazyComponent._status = Resolved;
3241 lazyComponent._result = defaultExport;
3242 }
3243 }, function (error) {
3244 if (lazyComponent._status === Pending) {
3245 lazyComponent._status = Rejected;
3246 lazyComponent._result = error;
3247 }
3248 });
3249 // Handle synchronous thenables.
3250 switch (lazyComponent._status) {
3251 case Resolved:
3252 return lazyComponent._result;
3253 case Rejected:
3254 throw lazyComponent._result;
3255 }
3256 lazyComponent._result = _thenable;
3257 throw _thenable;
3258 }
3259 }
3260}
3261
3262var fakeInternalInstance = {};
3263var isArray$1 = Array.isArray;
3264
3265// React.Component uses a shared frozen object by default.
3266// We'll use it to determine whether we need to initialize legacy refs.
3267var emptyRefsObject = new React.Component().refs;
3268
3269var didWarnAboutStateAssignmentForComponent = void 0;
3270var didWarnAboutUninitializedState = void 0;
3271var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0;
3272var didWarnAboutLegacyLifecyclesAndDerivedState = void 0;
3273var didWarnAboutUndefinedDerivedState = void 0;
3274var warnOnUndefinedDerivedState = void 0;
3275var warnOnInvalidCallback = void 0;
3276var didWarnAboutDirectlyAssigningPropsToState = void 0;
3277var didWarnAboutContextTypeAndContextTypes = void 0;
3278var didWarnAboutInvalidateContextType = void 0;
3279
3280{
3281 didWarnAboutStateAssignmentForComponent = new Set();
3282 didWarnAboutUninitializedState = new Set();
3283 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3284 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3285 didWarnAboutDirectlyAssigningPropsToState = new Set();
3286 didWarnAboutUndefinedDerivedState = new Set();
3287 didWarnAboutContextTypeAndContextTypes = new Set();
3288 didWarnAboutInvalidateContextType = new Set();
3289
3290 var didWarnOnInvalidCallback = new Set();
3291
3292 warnOnInvalidCallback = function (callback, callerName) {
3293 if (callback === null || typeof callback === 'function') {
3294 return;
3295 }
3296 var key = callerName + '_' + callback;
3297 if (!didWarnOnInvalidCallback.has(key)) {
3298 didWarnOnInvalidCallback.add(key);
3299 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
3300 }
3301 };
3302
3303 warnOnUndefinedDerivedState = function (type, partialState) {
3304 if (partialState === undefined) {
3305 var componentName = getComponentName(type) || 'Component';
3306 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
3307 didWarnAboutUndefinedDerivedState.add(componentName);
3308 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
3309 }
3310 }
3311 };
3312
3313 // This is so gross but it's at least non-critical and can be removed if
3314 // it causes problems. This is meant to give a nicer error message for
3315 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
3316 // ...)) which otherwise throws a "_processChildContext is not a function"
3317 // exception.
3318 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
3319 enumerable: false,
3320 value: function () {
3321 invariant(false, '_processChildContext is not available in React 16+. This likely means you have multiple copies of React and are attempting to nest a React 15 tree inside a React 16 tree using unstable_renderSubtreeIntoContainer, which isn\'t supported. Try to make sure you have only one copy of React (and ideally, switch to ReactDOM.createPortal).');
3322 }
3323 });
3324 Object.freeze(fakeInternalInstance);
3325}
3326
3327function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
3328 var prevState = workInProgress.memoizedState;
3329
3330 {
3331 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3332 // Invoke the function an extra time to help detect side-effects.
3333 getDerivedStateFromProps(nextProps, prevState);
3334 }
3335 }
3336
3337 var partialState = getDerivedStateFromProps(nextProps, prevState);
3338
3339 {
3340 warnOnUndefinedDerivedState(ctor, partialState);
3341 }
3342 // Merge the partial state and the previous state.
3343 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
3344 workInProgress.memoizedState = memoizedState;
3345
3346 // Once the update queue is empty, persist the derived state onto the
3347 // base state.
3348 var updateQueue = workInProgress.updateQueue;
3349 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
3350 updateQueue.baseState = memoizedState;
3351 }
3352}
3353
3354var classComponentUpdater = {
3355 isMounted: isMounted,
3356 enqueueSetState: function (inst, payload, callback) {
3357 var fiber = get(inst);
3358 var currentTime = requestCurrentTime();
3359 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3360
3361 var update = createUpdate(expirationTime);
3362 update.payload = payload;
3363 if (callback !== undefined && callback !== null) {
3364 {
3365 warnOnInvalidCallback(callback, 'setState');
3366 }
3367 update.callback = callback;
3368 }
3369
3370 flushPassiveEffects$1();
3371 enqueueUpdate(fiber, update);
3372 scheduleWork(fiber, expirationTime);
3373 },
3374 enqueueReplaceState: function (inst, payload, callback) {
3375 var fiber = get(inst);
3376 var currentTime = requestCurrentTime();
3377 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3378
3379 var update = createUpdate(expirationTime);
3380 update.tag = ReplaceState;
3381 update.payload = payload;
3382
3383 if (callback !== undefined && callback !== null) {
3384 {
3385 warnOnInvalidCallback(callback, 'replaceState');
3386 }
3387 update.callback = callback;
3388 }
3389
3390 flushPassiveEffects$1();
3391 enqueueUpdate(fiber, update);
3392 scheduleWork(fiber, expirationTime);
3393 },
3394 enqueueForceUpdate: function (inst, callback) {
3395 var fiber = get(inst);
3396 var currentTime = requestCurrentTime();
3397 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3398
3399 var update = createUpdate(expirationTime);
3400 update.tag = ForceUpdate;
3401
3402 if (callback !== undefined && callback !== null) {
3403 {
3404 warnOnInvalidCallback(callback, 'forceUpdate');
3405 }
3406 update.callback = callback;
3407 }
3408
3409 flushPassiveEffects$1();
3410 enqueueUpdate(fiber, update);
3411 scheduleWork(fiber, expirationTime);
3412 }
3413};
3414
3415function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
3416 var instance = workInProgress.stateNode;
3417 if (typeof instance.shouldComponentUpdate === 'function') {
3418 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
3419 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
3420 stopPhaseTimer();
3421
3422 {
3423 !(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;
3424 }
3425
3426 return shouldUpdate;
3427 }
3428
3429 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
3430 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
3431 }
3432
3433 return true;
3434}
3435
3436function checkClassInstance(workInProgress, ctor, newProps) {
3437 var instance = workInProgress.stateNode;
3438 {
3439 var name = getComponentName(ctor) || 'Component';
3440 var renderPresent = instance.render;
3441
3442 if (!renderPresent) {
3443 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
3444 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
3445 } else {
3446 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
3447 }
3448 }
3449
3450 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
3451 !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;
3452 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
3453 !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;
3454 var noInstancePropTypes = !instance.propTypes;
3455 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
3456 var noInstanceContextType = !instance.contextType;
3457 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
3458 var noInstanceContextTypes = !instance.contextTypes;
3459 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
3460
3461 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
3462 didWarnAboutContextTypeAndContextTypes.add(ctor);
3463 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
3464 }
3465
3466 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
3467 !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;
3468 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
3469 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');
3470 }
3471 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
3472 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
3473 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
3474 !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;
3475 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
3476 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
3477 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
3478 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
3479 var hasMutatedProps = instance.props !== newProps;
3480 !(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;
3481 var noInstanceDefaultProps = !instance.defaultProps;
3482 !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;
3483
3484 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
3485 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
3486 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
3487 }
3488
3489 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
3490 !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;
3491 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
3492 !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;
3493 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
3494 !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;
3495 var _state = instance.state;
3496 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
3497 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
3498 }
3499 if (typeof instance.getChildContext === 'function') {
3500 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
3501 }
3502 }
3503}
3504
3505function adoptClassInstance(workInProgress, instance) {
3506 instance.updater = classComponentUpdater;
3507 workInProgress.stateNode = instance;
3508 // The instance needs access to the fiber so that it can schedule updates
3509 set(instance, workInProgress);
3510 {
3511 instance._reactInternalInstance = fakeInternalInstance;
3512 }
3513}
3514
3515function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
3516 var isLegacyContextConsumer = false;
3517 var unmaskedContext = emptyContextObject;
3518 var context = null;
3519 var contextType = ctor.contextType;
3520 if (typeof contextType === 'object' && contextType !== null) {
3521 {
3522 if (contextType.$$typeof !== REACT_CONTEXT_TYPE && !didWarnAboutInvalidateContextType.has(ctor)) {
3523 didWarnAboutInvalidateContextType.add(ctor);
3524 warningWithoutStack$1(false, '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'Did you accidentally pass the Context.Provider instead?', getComponentName(ctor) || 'Component');
3525 }
3526 }
3527
3528 context = readContext(contextType);
3529 } else {
3530 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3531 var contextTypes = ctor.contextTypes;
3532 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
3533 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
3534 }
3535
3536 // Instantiate twice to help detect side-effects.
3537 {
3538 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3539 new ctor(props, context); // eslint-disable-line no-new
3540 }
3541 }
3542
3543 var instance = new ctor(props, context);
3544 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
3545 adoptClassInstance(workInProgress, instance);
3546
3547 {
3548 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
3549 var componentName = getComponentName(ctor) || 'Component';
3550 if (!didWarnAboutUninitializedState.has(componentName)) {
3551 didWarnAboutUninitializedState.add(componentName);
3552 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);
3553 }
3554 }
3555
3556 // If new component APIs are defined, "unsafe" lifecycles won't be called.
3557 // Warn about these lifecycles if they are present.
3558 // Don't warn about react-lifecycles-compat polyfilled methods though.
3559 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
3560 var foundWillMountName = null;
3561 var foundWillReceivePropsName = null;
3562 var foundWillUpdateName = null;
3563 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
3564 foundWillMountName = 'componentWillMount';
3565 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
3566 foundWillMountName = 'UNSAFE_componentWillMount';
3567 }
3568 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
3569 foundWillReceivePropsName = 'componentWillReceiveProps';
3570 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3571 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
3572 }
3573 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
3574 foundWillUpdateName = 'componentWillUpdate';
3575 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3576 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
3577 }
3578 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
3579 var _componentName = getComponentName(ctor) || 'Component';
3580 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
3581 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
3582 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
3583 warningWithoutStack$1(false, 'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' + '%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-async-component-lifecycle-hooks', _componentName, newApiName, foundWillMountName !== null ? '\n ' + foundWillMountName : '', foundWillReceivePropsName !== null ? '\n ' + foundWillReceivePropsName : '', foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '');
3584 }
3585 }
3586 }
3587 }
3588
3589 // Cache unmasked context so we can avoid recreating masked context unless necessary.
3590 // ReactFiberContext usually updates this cache but can't for newly-created instances.
3591 if (isLegacyContextConsumer) {
3592 cacheContext(workInProgress, unmaskedContext, context);
3593 }
3594
3595 return instance;
3596}
3597
3598function callComponentWillMount(workInProgress, instance) {
3599 startPhaseTimer(workInProgress, 'componentWillMount');
3600 var oldState = instance.state;
3601
3602 if (typeof instance.componentWillMount === 'function') {
3603 instance.componentWillMount();
3604 }
3605 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3606 instance.UNSAFE_componentWillMount();
3607 }
3608
3609 stopPhaseTimer();
3610
3611 if (oldState !== instance.state) {
3612 {
3613 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');
3614 }
3615 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3616 }
3617}
3618
3619function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
3620 var oldState = instance.state;
3621 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
3622 if (typeof instance.componentWillReceiveProps === 'function') {
3623 instance.componentWillReceiveProps(newProps, nextContext);
3624 }
3625 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3626 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
3627 }
3628 stopPhaseTimer();
3629
3630 if (instance.state !== oldState) {
3631 {
3632 var componentName = getComponentName(workInProgress.type) || 'Component';
3633 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
3634 didWarnAboutStateAssignmentForComponent.add(componentName);
3635 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
3636 }
3637 }
3638 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3639 }
3640}
3641
3642// Invokes the mount life-cycles on a previously never rendered instance.
3643function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3644 {
3645 checkClassInstance(workInProgress, ctor, newProps);
3646 }
3647
3648 var instance = workInProgress.stateNode;
3649 instance.props = newProps;
3650 instance.state = workInProgress.memoizedState;
3651 instance.refs = emptyRefsObject;
3652
3653 var contextType = ctor.contextType;
3654 if (typeof contextType === 'object' && contextType !== null) {
3655 instance.context = readContext(contextType);
3656 } else {
3657 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3658 instance.context = getMaskedContext(workInProgress, unmaskedContext);
3659 }
3660
3661 {
3662 if (instance.state === newProps) {
3663 var componentName = getComponentName(ctor) || 'Component';
3664 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
3665 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
3666 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);
3667 }
3668 }
3669
3670 if (workInProgress.mode & StrictMode) {
3671 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
3672
3673 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
3674 }
3675
3676 if (warnAboutDeprecatedLifecycles) {
3677 ReactStrictModeWarnings.recordDeprecationWarnings(workInProgress, instance);
3678 }
3679 }
3680
3681 var updateQueue = workInProgress.updateQueue;
3682 if (updateQueue !== null) {
3683 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3684 instance.state = workInProgress.memoizedState;
3685 }
3686
3687 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3688 if (typeof getDerivedStateFromProps === 'function') {
3689 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3690 instance.state = workInProgress.memoizedState;
3691 }
3692
3693 // In order to support react-lifecycles-compat polyfilled components,
3694 // Unsafe lifecycles should not be invoked for components using the new APIs.
3695 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3696 callComponentWillMount(workInProgress, instance);
3697 // If we had additional state updates during this life-cycle, let's
3698 // process them now.
3699 updateQueue = workInProgress.updateQueue;
3700 if (updateQueue !== null) {
3701 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3702 instance.state = workInProgress.memoizedState;
3703 }
3704 }
3705
3706 if (typeof instance.componentDidMount === 'function') {
3707 workInProgress.effectTag |= Update;
3708 }
3709}
3710
3711function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3712 var instance = workInProgress.stateNode;
3713
3714 var oldProps = workInProgress.memoizedProps;
3715 instance.props = oldProps;
3716
3717 var oldContext = instance.context;
3718 var contextType = ctor.contextType;
3719 var nextContext = void 0;
3720 if (typeof contextType === 'object' && contextType !== null) {
3721 nextContext = readContext(contextType);
3722 } else {
3723 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3724 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
3725 }
3726
3727 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3728 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3729
3730 // Note: During these life-cycles, instance.props/instance.state are what
3731 // ever the previously attempted to render - not the "current". However,
3732 // during componentDidUpdate we pass the "current" props.
3733
3734 // In order to support react-lifecycles-compat polyfilled components,
3735 // Unsafe lifecycles should not be invoked for components using the new APIs.
3736 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3737 if (oldProps !== newProps || oldContext !== nextContext) {
3738 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3739 }
3740 }
3741
3742 resetHasForceUpdateBeforeProcessing();
3743
3744 var oldState = workInProgress.memoizedState;
3745 var newState = instance.state = oldState;
3746 var updateQueue = workInProgress.updateQueue;
3747 if (updateQueue !== null) {
3748 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3749 newState = workInProgress.memoizedState;
3750 }
3751 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3752 // If an update was already in progress, we should schedule an Update
3753 // effect even though we're bailing out, so that cWU/cDU are called.
3754 if (typeof instance.componentDidMount === 'function') {
3755 workInProgress.effectTag |= Update;
3756 }
3757 return false;
3758 }
3759
3760 if (typeof getDerivedStateFromProps === 'function') {
3761 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3762 newState = workInProgress.memoizedState;
3763 }
3764
3765 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3766
3767 if (shouldUpdate) {
3768 // In order to support react-lifecycles-compat polyfilled components,
3769 // Unsafe lifecycles should not be invoked for components using the new APIs.
3770 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3771 startPhaseTimer(workInProgress, 'componentWillMount');
3772 if (typeof instance.componentWillMount === 'function') {
3773 instance.componentWillMount();
3774 }
3775 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3776 instance.UNSAFE_componentWillMount();
3777 }
3778 stopPhaseTimer();
3779 }
3780 if (typeof instance.componentDidMount === 'function') {
3781 workInProgress.effectTag |= Update;
3782 }
3783 } else {
3784 // If an update was already in progress, we should schedule an Update
3785 // effect even though we're bailing out, so that cWU/cDU are called.
3786 if (typeof instance.componentDidMount === 'function') {
3787 workInProgress.effectTag |= Update;
3788 }
3789
3790 // If shouldComponentUpdate returned false, we should still update the
3791 // memoized state to indicate that this work can be reused.
3792 workInProgress.memoizedProps = newProps;
3793 workInProgress.memoizedState = newState;
3794 }
3795
3796 // Update the existing instance's state, props, and context pointers even
3797 // if shouldComponentUpdate returns false.
3798 instance.props = newProps;
3799 instance.state = newState;
3800 instance.context = nextContext;
3801
3802 return shouldUpdate;
3803}
3804
3805// Invokes the update life-cycles and returns false if it shouldn't rerender.
3806function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
3807 var instance = workInProgress.stateNode;
3808
3809 var oldProps = workInProgress.memoizedProps;
3810 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
3811
3812 var oldContext = instance.context;
3813 var contextType = ctor.contextType;
3814 var nextContext = void 0;
3815 if (typeof contextType === 'object' && contextType !== null) {
3816 nextContext = readContext(contextType);
3817 } else {
3818 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3819 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
3820 }
3821
3822 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3823 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3824
3825 // Note: During these life-cycles, instance.props/instance.state are what
3826 // ever the previously attempted to render - not the "current". However,
3827 // during componentDidUpdate we pass the "current" props.
3828
3829 // In order to support react-lifecycles-compat polyfilled components,
3830 // Unsafe lifecycles should not be invoked for components using the new APIs.
3831 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3832 if (oldProps !== newProps || oldContext !== nextContext) {
3833 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3834 }
3835 }
3836
3837 resetHasForceUpdateBeforeProcessing();
3838
3839 var oldState = workInProgress.memoizedState;
3840 var newState = instance.state = oldState;
3841 var updateQueue = workInProgress.updateQueue;
3842 if (updateQueue !== null) {
3843 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3844 newState = workInProgress.memoizedState;
3845 }
3846
3847 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3848 // If an update was already in progress, we should schedule an Update
3849 // effect even though we're bailing out, so that cWU/cDU are called.
3850 if (typeof instance.componentDidUpdate === 'function') {
3851 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3852 workInProgress.effectTag |= Update;
3853 }
3854 }
3855 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3856 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3857 workInProgress.effectTag |= Snapshot;
3858 }
3859 }
3860 return false;
3861 }
3862
3863 if (typeof getDerivedStateFromProps === 'function') {
3864 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3865 newState = workInProgress.memoizedState;
3866 }
3867
3868 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3869
3870 if (shouldUpdate) {
3871 // In order to support react-lifecycles-compat polyfilled components,
3872 // Unsafe lifecycles should not be invoked for components using the new APIs.
3873 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
3874 startPhaseTimer(workInProgress, 'componentWillUpdate');
3875 if (typeof instance.componentWillUpdate === 'function') {
3876 instance.componentWillUpdate(newProps, newState, nextContext);
3877 }
3878 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3879 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
3880 }
3881 stopPhaseTimer();
3882 }
3883 if (typeof instance.componentDidUpdate === 'function') {
3884 workInProgress.effectTag |= Update;
3885 }
3886 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3887 workInProgress.effectTag |= Snapshot;
3888 }
3889 } else {
3890 // If an update was already in progress, we should schedule an Update
3891 // effect even though we're bailing out, so that cWU/cDU are called.
3892 if (typeof instance.componentDidUpdate === 'function') {
3893 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3894 workInProgress.effectTag |= Update;
3895 }
3896 }
3897 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3898 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3899 workInProgress.effectTag |= Snapshot;
3900 }
3901 }
3902
3903 // If shouldComponentUpdate returned false, we should still update the
3904 // memoized props/state to indicate that this work can be reused.
3905 workInProgress.memoizedProps = newProps;
3906 workInProgress.memoizedState = newState;
3907 }
3908
3909 // Update the existing instance's state, props, and context pointers even
3910 // if shouldComponentUpdate returns false.
3911 instance.props = newProps;
3912 instance.state = newState;
3913 instance.context = nextContext;
3914
3915 return shouldUpdate;
3916}
3917
3918var didWarnAboutMaps = void 0;
3919var didWarnAboutGenerators = void 0;
3920var didWarnAboutStringRefInStrictMode = void 0;
3921var ownerHasKeyUseWarning = void 0;
3922var ownerHasFunctionTypeWarning = void 0;
3923var warnForMissingKey = function (child) {};
3924
3925{
3926 didWarnAboutMaps = false;
3927 didWarnAboutGenerators = false;
3928 didWarnAboutStringRefInStrictMode = {};
3929
3930 /**
3931 * Warn if there's no key explicitly set on dynamic arrays of children or
3932 * object keys are not valid. This allows us to keep track of children between
3933 * updates.
3934 */
3935 ownerHasKeyUseWarning = {};
3936 ownerHasFunctionTypeWarning = {};
3937
3938 warnForMissingKey = function (child) {
3939 if (child === null || typeof child !== 'object') {
3940 return;
3941 }
3942 if (!child._store || child._store.validated || child.key != null) {
3943 return;
3944 }
3945 !(typeof child._store === 'object') ? invariant(false, 'React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue.') : void 0;
3946 child._store.validated = true;
3947
3948 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
3949 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
3950 return;
3951 }
3952 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
3953
3954 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
3955 };
3956}
3957
3958var isArray = Array.isArray;
3959
3960function coerceRef(returnFiber, current$$1, element) {
3961 var mixedRef = element.ref;
3962 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
3963 {
3964 if (returnFiber.mode & StrictMode) {
3965 var componentName = getComponentName(returnFiber.type) || 'Component';
3966 if (!didWarnAboutStringRefInStrictMode[componentName]) {
3967 warningWithoutStack$1(false, 'A string ref, "%s", has been found within a strict mode tree. ' + 'String refs are a source of potential bugs and should be avoided. ' + 'We recommend using createRef() instead.' + '\n%s' + '\n\nLearn more about using refs safely here:' + '\nhttps://fb.me/react-strict-mode-string-ref', mixedRef, getStackByFiberInDevAndProd(returnFiber));
3968 didWarnAboutStringRefInStrictMode[componentName] = true;
3969 }
3970 }
3971 }
3972
3973 if (element._owner) {
3974 var owner = element._owner;
3975 var inst = void 0;
3976 if (owner) {
3977 var ownerFiber = owner;
3978 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Function components cannot have refs. Did you mean to use React.forwardRef()?') : void 0;
3979 inst = ownerFiber.stateNode;
3980 }
3981 !inst ? invariant(false, 'Missing owner for string ref %s. This error is likely caused by a bug in React. Please file an issue.', mixedRef) : void 0;
3982 var stringRef = '' + mixedRef;
3983 // Check if previous string ref matches new string ref
3984 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
3985 return current$$1.ref;
3986 }
3987 var ref = function (value) {
3988 var refs = inst.refs;
3989 if (refs === emptyRefsObject) {
3990 // This is a lazy pooled frozen object, so we need to initialize.
3991 refs = inst.refs = {};
3992 }
3993 if (value === null) {
3994 delete refs[stringRef];
3995 } else {
3996 refs[stringRef] = value;
3997 }
3998 };
3999 ref._stringRef = stringRef;
4000 return ref;
4001 } else {
4002 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.') : void 0;
4003 !element._owner ? invariant(false, 'Element ref was specified as a string (%s) but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a 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.', mixedRef) : void 0;
4004 }
4005 }
4006 return mixedRef;
4007}
4008
4009function throwOnInvalidObjectType(returnFiber, newChild) {
4010 if (returnFiber.type !== 'textarea') {
4011 var addendum = '';
4012 {
4013 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
4014 }
4015 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);
4016 }
4017}
4018
4019function warnOnFunctionType() {
4020 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();
4021
4022 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
4023 return;
4024 }
4025 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
4026
4027 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.');
4028}
4029
4030// This wrapper function exists because I expect to clone the code in each path
4031// to be able to optimize each path individually by branching early. This needs
4032// a compiler or we can do it manually. Helpers that don't need this branching
4033// live outside of this function.
4034function ChildReconciler(shouldTrackSideEffects) {
4035 function deleteChild(returnFiber, childToDelete) {
4036 if (!shouldTrackSideEffects) {
4037 // Noop.
4038 return;
4039 }
4040 // Deletions are added in reversed order so we add it to the front.
4041 // At this point, the return fiber's effect list is empty except for
4042 // deletions, so we can just append the deletion to the list. The remaining
4043 // effects aren't added until the complete phase. Once we implement
4044 // resuming, this may not be true.
4045 var last = returnFiber.lastEffect;
4046 if (last !== null) {
4047 last.nextEffect = childToDelete;
4048 returnFiber.lastEffect = childToDelete;
4049 } else {
4050 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
4051 }
4052 childToDelete.nextEffect = null;
4053 childToDelete.effectTag = Deletion;
4054 }
4055
4056 function deleteRemainingChildren(returnFiber, currentFirstChild) {
4057 if (!shouldTrackSideEffects) {
4058 // Noop.
4059 return null;
4060 }
4061
4062 // TODO: For the shouldClone case, this could be micro-optimized a bit by
4063 // assuming that after the first child we've already added everything.
4064 var childToDelete = currentFirstChild;
4065 while (childToDelete !== null) {
4066 deleteChild(returnFiber, childToDelete);
4067 childToDelete = childToDelete.sibling;
4068 }
4069 return null;
4070 }
4071
4072 function mapRemainingChildren(returnFiber, currentFirstChild) {
4073 // Add the remaining children to a temporary map so that we can find them by
4074 // keys quickly. Implicit (null) keys get added to this set with their index
4075 var existingChildren = new Map();
4076
4077 var existingChild = currentFirstChild;
4078 while (existingChild !== null) {
4079 if (existingChild.key !== null) {
4080 existingChildren.set(existingChild.key, existingChild);
4081 } else {
4082 existingChildren.set(existingChild.index, existingChild);
4083 }
4084 existingChild = existingChild.sibling;
4085 }
4086 return existingChildren;
4087 }
4088
4089 function useFiber(fiber, pendingProps, expirationTime) {
4090 // We currently set sibling to null and index to 0 here because it is easy
4091 // to forget to do before returning it. E.g. for the single child case.
4092 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4093 clone.index = 0;
4094 clone.sibling = null;
4095 return clone;
4096 }
4097
4098 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4099 newFiber.index = newIndex;
4100 if (!shouldTrackSideEffects) {
4101 // Noop.
4102 return lastPlacedIndex;
4103 }
4104 var current$$1 = newFiber.alternate;
4105 if (current$$1 !== null) {
4106 var oldIndex = current$$1.index;
4107 if (oldIndex < lastPlacedIndex) {
4108 // This is a move.
4109 newFiber.effectTag = Placement;
4110 return lastPlacedIndex;
4111 } else {
4112 // This item can stay in place.
4113 return oldIndex;
4114 }
4115 } else {
4116 // This is an insertion.
4117 newFiber.effectTag = Placement;
4118 return lastPlacedIndex;
4119 }
4120 }
4121
4122 function placeSingleChild(newFiber) {
4123 // This is simpler for the single child case. We only need to do a
4124 // placement for inserting new children.
4125 if (shouldTrackSideEffects && newFiber.alternate === null) {
4126 newFiber.effectTag = Placement;
4127 }
4128 return newFiber;
4129 }
4130
4131 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4132 if (current$$1 === null || current$$1.tag !== HostText) {
4133 // Insert
4134 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4135 created.return = returnFiber;
4136 return created;
4137 } else {
4138 // Update
4139 var existing = useFiber(current$$1, textContent, expirationTime);
4140 existing.return = returnFiber;
4141 return existing;
4142 }
4143 }
4144
4145 function updateElement(returnFiber, current$$1, element, expirationTime) {
4146 if (current$$1 !== null && current$$1.elementType === element.type) {
4147 // Move based on index
4148 var existing = useFiber(current$$1, element.props, expirationTime);
4149 existing.ref = coerceRef(returnFiber, current$$1, element);
4150 existing.return = returnFiber;
4151 {
4152 existing._debugSource = element._source;
4153 existing._debugOwner = element._owner;
4154 }
4155 return existing;
4156 } else {
4157 // Insert
4158 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
4159 created.ref = coerceRef(returnFiber, current$$1, element);
4160 created.return = returnFiber;
4161 return created;
4162 }
4163 }
4164
4165 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
4166 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
4167 // Insert
4168 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4169 created.return = returnFiber;
4170 return created;
4171 } else {
4172 // Update
4173 var existing = useFiber(current$$1, portal.children || [], expirationTime);
4174 existing.return = returnFiber;
4175 return existing;
4176 }
4177 }
4178
4179 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
4180 if (current$$1 === null || current$$1.tag !== Fragment) {
4181 // Insert
4182 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
4183 created.return = returnFiber;
4184 return created;
4185 } else {
4186 // Update
4187 var existing = useFiber(current$$1, fragment, expirationTime);
4188 existing.return = returnFiber;
4189 return existing;
4190 }
4191 }
4192
4193 function createChild(returnFiber, newChild, expirationTime) {
4194 if (typeof newChild === 'string' || typeof newChild === 'number') {
4195 // Text nodes don't have keys. If the previous node is implicitly keyed
4196 // we can continue to replace it without aborting even if it is not a text
4197 // node.
4198 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
4199 created.return = returnFiber;
4200 return created;
4201 }
4202
4203 if (typeof newChild === 'object' && newChild !== null) {
4204 switch (newChild.$$typeof) {
4205 case REACT_ELEMENT_TYPE:
4206 {
4207 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
4208 _created.ref = coerceRef(returnFiber, null, newChild);
4209 _created.return = returnFiber;
4210 return _created;
4211 }
4212 case REACT_PORTAL_TYPE:
4213 {
4214 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
4215 _created2.return = returnFiber;
4216 return _created2;
4217 }
4218 }
4219
4220 if (isArray(newChild) || getIteratorFn(newChild)) {
4221 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
4222 _created3.return = returnFiber;
4223 return _created3;
4224 }
4225
4226 throwOnInvalidObjectType(returnFiber, newChild);
4227 }
4228
4229 {
4230 if (typeof newChild === 'function') {
4231 warnOnFunctionType();
4232 }
4233 }
4234
4235 return null;
4236 }
4237
4238 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
4239 // Update the fiber if the keys match, otherwise return null.
4240
4241 var key = oldFiber !== null ? oldFiber.key : null;
4242
4243 if (typeof newChild === 'string' || typeof newChild === 'number') {
4244 // Text nodes don't have keys. If the previous node is implicitly keyed
4245 // we can continue to replace it without aborting even if it is not a text
4246 // node.
4247 if (key !== null) {
4248 return null;
4249 }
4250 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
4251 }
4252
4253 if (typeof newChild === 'object' && newChild !== null) {
4254 switch (newChild.$$typeof) {
4255 case REACT_ELEMENT_TYPE:
4256 {
4257 if (newChild.key === key) {
4258 if (newChild.type === REACT_FRAGMENT_TYPE) {
4259 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
4260 }
4261 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
4262 } else {
4263 return null;
4264 }
4265 }
4266 case REACT_PORTAL_TYPE:
4267 {
4268 if (newChild.key === key) {
4269 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
4270 } else {
4271 return null;
4272 }
4273 }
4274 }
4275
4276 if (isArray(newChild) || getIteratorFn(newChild)) {
4277 if (key !== null) {
4278 return null;
4279 }
4280
4281 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
4282 }
4283
4284 throwOnInvalidObjectType(returnFiber, newChild);
4285 }
4286
4287 {
4288 if (typeof newChild === 'function') {
4289 warnOnFunctionType();
4290 }
4291 }
4292
4293 return null;
4294 }
4295
4296 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
4297 if (typeof newChild === 'string' || typeof newChild === 'number') {
4298 // Text nodes don't have keys, so we neither have to check the old nor
4299 // new node for the key. If both are text nodes, they match.
4300 var matchedFiber = existingChildren.get(newIdx) || null;
4301 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
4302 }
4303
4304 if (typeof newChild === 'object' && newChild !== null) {
4305 switch (newChild.$$typeof) {
4306 case REACT_ELEMENT_TYPE:
4307 {
4308 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4309 if (newChild.type === REACT_FRAGMENT_TYPE) {
4310 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
4311 }
4312 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
4313 }
4314 case REACT_PORTAL_TYPE:
4315 {
4316 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4317 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
4318 }
4319 }
4320
4321 if (isArray(newChild) || getIteratorFn(newChild)) {
4322 var _matchedFiber3 = existingChildren.get(newIdx) || null;
4323 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
4324 }
4325
4326 throwOnInvalidObjectType(returnFiber, newChild);
4327 }
4328
4329 {
4330 if (typeof newChild === 'function') {
4331 warnOnFunctionType();
4332 }
4333 }
4334
4335 return null;
4336 }
4337
4338 /**
4339 * Warns if there is a duplicate or missing key
4340 */
4341 function warnOnInvalidKey(child, knownKeys) {
4342 {
4343 if (typeof child !== 'object' || child === null) {
4344 return knownKeys;
4345 }
4346 switch (child.$$typeof) {
4347 case REACT_ELEMENT_TYPE:
4348 case REACT_PORTAL_TYPE:
4349 warnForMissingKey(child);
4350 var key = child.key;
4351 if (typeof key !== 'string') {
4352 break;
4353 }
4354 if (knownKeys === null) {
4355 knownKeys = new Set();
4356 knownKeys.add(key);
4357 break;
4358 }
4359 if (!knownKeys.has(key)) {
4360 knownKeys.add(key);
4361 break;
4362 }
4363 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);
4364 break;
4365 default:
4366 break;
4367 }
4368 }
4369 return knownKeys;
4370 }
4371
4372 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
4373 // This algorithm can't optimize by searching from boths ends since we
4374 // don't have backpointers on fibers. I'm trying to see how far we can get
4375 // with that model. If it ends up not being worth the tradeoffs, we can
4376 // add it later.
4377
4378 // Even with a two ended optimization, we'd want to optimize for the case
4379 // where there are few changes and brute force the comparison instead of
4380 // going for the Map. It'd like to explore hitting that path first in
4381 // forward-only mode and only go for the Map once we notice that we need
4382 // lots of look ahead. This doesn't handle reversal as well as two ended
4383 // search but that's unusual. Besides, for the two ended optimization to
4384 // work on Iterables, we'd need to copy the whole set.
4385
4386 // In this first iteration, we'll just live with hitting the bad case
4387 // (adding everything to a Map) in for every insert/move.
4388
4389 // If you change this code, also update reconcileChildrenIterator() which
4390 // uses the same algorithm.
4391
4392 {
4393 // First, validate keys.
4394 var knownKeys = null;
4395 for (var i = 0; i < newChildren.length; i++) {
4396 var child = newChildren[i];
4397 knownKeys = warnOnInvalidKey(child, knownKeys);
4398 }
4399 }
4400
4401 var resultingFirstChild = null;
4402 var previousNewFiber = null;
4403
4404 var oldFiber = currentFirstChild;
4405 var lastPlacedIndex = 0;
4406 var newIdx = 0;
4407 var nextOldFiber = null;
4408 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
4409 if (oldFiber.index > newIdx) {
4410 nextOldFiber = oldFiber;
4411 oldFiber = null;
4412 } else {
4413 nextOldFiber = oldFiber.sibling;
4414 }
4415 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
4416 if (newFiber === null) {
4417 // TODO: This breaks on empty slots like null children. That's
4418 // unfortunate because it triggers the slow path all the time. We need
4419 // a better way to communicate whether this was a miss or null,
4420 // boolean, undefined, etc.
4421 if (oldFiber === null) {
4422 oldFiber = nextOldFiber;
4423 }
4424 break;
4425 }
4426 if (shouldTrackSideEffects) {
4427 if (oldFiber && newFiber.alternate === null) {
4428 // We matched the slot, but we didn't reuse the existing fiber, so we
4429 // need to delete the existing child.
4430 deleteChild(returnFiber, oldFiber);
4431 }
4432 }
4433 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4434 if (previousNewFiber === null) {
4435 // TODO: Move out of the loop. This only happens for the first run.
4436 resultingFirstChild = newFiber;
4437 } else {
4438 // TODO: Defer siblings if we're not at the right index for this slot.
4439 // I.e. if we had null values before, then we want to defer this
4440 // for each null value. However, we also don't want to call updateSlot
4441 // with the previous one.
4442 previousNewFiber.sibling = newFiber;
4443 }
4444 previousNewFiber = newFiber;
4445 oldFiber = nextOldFiber;
4446 }
4447
4448 if (newIdx === newChildren.length) {
4449 // We've reached the end of the new children. We can delete the rest.
4450 deleteRemainingChildren(returnFiber, oldFiber);
4451 return resultingFirstChild;
4452 }
4453
4454 if (oldFiber === null) {
4455 // If we don't have any more existing children we can choose a fast path
4456 // since the rest will all be insertions.
4457 for (; newIdx < newChildren.length; newIdx++) {
4458 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
4459 if (!_newFiber) {
4460 continue;
4461 }
4462 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
4463 if (previousNewFiber === null) {
4464 // TODO: Move out of the loop. This only happens for the first run.
4465 resultingFirstChild = _newFiber;
4466 } else {
4467 previousNewFiber.sibling = _newFiber;
4468 }
4469 previousNewFiber = _newFiber;
4470 }
4471 return resultingFirstChild;
4472 }
4473
4474 // Add all children to a key map for quick lookups.
4475 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4476
4477 // Keep scanning and use the map to restore deleted items as moves.
4478 for (; newIdx < newChildren.length; newIdx++) {
4479 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
4480 if (_newFiber2) {
4481 if (shouldTrackSideEffects) {
4482 if (_newFiber2.alternate !== null) {
4483 // The new fiber is a work in progress, but if there exists a
4484 // current, that means that we reused the fiber. We need to delete
4485 // it from the child list so that we don't add it to the deletion
4486 // list.
4487 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
4488 }
4489 }
4490 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
4491 if (previousNewFiber === null) {
4492 resultingFirstChild = _newFiber2;
4493 } else {
4494 previousNewFiber.sibling = _newFiber2;
4495 }
4496 previousNewFiber = _newFiber2;
4497 }
4498 }
4499
4500 if (shouldTrackSideEffects) {
4501 // Any existing children that weren't consumed above were deleted. We need
4502 // to add them to the deletion list.
4503 existingChildren.forEach(function (child) {
4504 return deleteChild(returnFiber, child);
4505 });
4506 }
4507
4508 return resultingFirstChild;
4509 }
4510
4511 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
4512 // This is the same implementation as reconcileChildrenArray(),
4513 // but using the iterator instead.
4514
4515 var iteratorFn = getIteratorFn(newChildrenIterable);
4516 !(typeof iteratorFn === 'function') ? invariant(false, 'An object is not an iterable. This error is likely caused by a bug in React. Please file an issue.') : void 0;
4517
4518 {
4519 // We don't support rendering Generators because it's a mutation.
4520 // See https://github.com/facebook/react/issues/12995
4521 if (typeof Symbol === 'function' &&
4522 // $FlowFixMe Flow doesn't know about toStringTag
4523 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
4524 !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;
4525 didWarnAboutGenerators = true;
4526 }
4527
4528 // Warn about using Maps as children
4529 if (newChildrenIterable.entries === iteratorFn) {
4530 !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;
4531 didWarnAboutMaps = true;
4532 }
4533
4534 // First, validate keys.
4535 // We'll get a different iterator later for the main pass.
4536 var _newChildren = iteratorFn.call(newChildrenIterable);
4537 if (_newChildren) {
4538 var knownKeys = null;
4539 var _step = _newChildren.next();
4540 for (; !_step.done; _step = _newChildren.next()) {
4541 var child = _step.value;
4542 knownKeys = warnOnInvalidKey(child, knownKeys);
4543 }
4544 }
4545 }
4546
4547 var newChildren = iteratorFn.call(newChildrenIterable);
4548 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
4549
4550 var resultingFirstChild = null;
4551 var previousNewFiber = null;
4552
4553 var oldFiber = currentFirstChild;
4554 var lastPlacedIndex = 0;
4555 var newIdx = 0;
4556 var nextOldFiber = null;
4557
4558 var step = newChildren.next();
4559 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
4560 if (oldFiber.index > newIdx) {
4561 nextOldFiber = oldFiber;
4562 oldFiber = null;
4563 } else {
4564 nextOldFiber = oldFiber.sibling;
4565 }
4566 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
4567 if (newFiber === null) {
4568 // TODO: This breaks on empty slots like null children. That's
4569 // unfortunate because it triggers the slow path all the time. We need
4570 // a better way to communicate whether this was a miss or null,
4571 // boolean, undefined, etc.
4572 if (!oldFiber) {
4573 oldFiber = nextOldFiber;
4574 }
4575 break;
4576 }
4577 if (shouldTrackSideEffects) {
4578 if (oldFiber && newFiber.alternate === null) {
4579 // We matched the slot, but we didn't reuse the existing fiber, so we
4580 // need to delete the existing child.
4581 deleteChild(returnFiber, oldFiber);
4582 }
4583 }
4584 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4585 if (previousNewFiber === null) {
4586 // TODO: Move out of the loop. This only happens for the first run.
4587 resultingFirstChild = newFiber;
4588 } else {
4589 // TODO: Defer siblings if we're not at the right index for this slot.
4590 // I.e. if we had null values before, then we want to defer this
4591 // for each null value. However, we also don't want to call updateSlot
4592 // with the previous one.
4593 previousNewFiber.sibling = newFiber;
4594 }
4595 previousNewFiber = newFiber;
4596 oldFiber = nextOldFiber;
4597 }
4598
4599 if (step.done) {
4600 // We've reached the end of the new children. We can delete the rest.
4601 deleteRemainingChildren(returnFiber, oldFiber);
4602 return resultingFirstChild;
4603 }
4604
4605 if (oldFiber === null) {
4606 // If we don't have any more existing children we can choose a fast path
4607 // since the rest will all be insertions.
4608 for (; !step.done; newIdx++, step = newChildren.next()) {
4609 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
4610 if (_newFiber3 === null) {
4611 continue;
4612 }
4613 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
4614 if (previousNewFiber === null) {
4615 // TODO: Move out of the loop. This only happens for the first run.
4616 resultingFirstChild = _newFiber3;
4617 } else {
4618 previousNewFiber.sibling = _newFiber3;
4619 }
4620 previousNewFiber = _newFiber3;
4621 }
4622 return resultingFirstChild;
4623 }
4624
4625 // Add all children to a key map for quick lookups.
4626 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4627
4628 // Keep scanning and use the map to restore deleted items as moves.
4629 for (; !step.done; newIdx++, step = newChildren.next()) {
4630 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
4631 if (_newFiber4 !== null) {
4632 if (shouldTrackSideEffects) {
4633 if (_newFiber4.alternate !== null) {
4634 // The new fiber is a work in progress, but if there exists a
4635 // current, that means that we reused the fiber. We need to delete
4636 // it from the child list so that we don't add it to the deletion
4637 // list.
4638 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
4639 }
4640 }
4641 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
4642 if (previousNewFiber === null) {
4643 resultingFirstChild = _newFiber4;
4644 } else {
4645 previousNewFiber.sibling = _newFiber4;
4646 }
4647 previousNewFiber = _newFiber4;
4648 }
4649 }
4650
4651 if (shouldTrackSideEffects) {
4652 // Any existing children that weren't consumed above were deleted. We need
4653 // to add them to the deletion list.
4654 existingChildren.forEach(function (child) {
4655 return deleteChild(returnFiber, child);
4656 });
4657 }
4658
4659 return resultingFirstChild;
4660 }
4661
4662 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
4663 // There's no need to check for keys on text nodes since we don't have a
4664 // way to define them.
4665 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
4666 // We already have an existing node so let's just update it and delete
4667 // the rest.
4668 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
4669 var existing = useFiber(currentFirstChild, textContent, expirationTime);
4670 existing.return = returnFiber;
4671 return existing;
4672 }
4673 // The existing first child is not a text node so we need to create one
4674 // and delete the existing ones.
4675 deleteRemainingChildren(returnFiber, currentFirstChild);
4676 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4677 created.return = returnFiber;
4678 return created;
4679 }
4680
4681 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
4682 var key = element.key;
4683 var child = currentFirstChild;
4684 while (child !== null) {
4685 // TODO: If key === null and child.key === null, then this only applies to
4686 // the first item in the list.
4687 if (child.key === key) {
4688 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type) {
4689 deleteRemainingChildren(returnFiber, child.sibling);
4690 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
4691 existing.ref = coerceRef(returnFiber, child, element);
4692 existing.return = returnFiber;
4693 {
4694 existing._debugSource = element._source;
4695 existing._debugOwner = element._owner;
4696 }
4697 return existing;
4698 } else {
4699 deleteRemainingChildren(returnFiber, child);
4700 break;
4701 }
4702 } else {
4703 deleteChild(returnFiber, child);
4704 }
4705 child = child.sibling;
4706 }
4707
4708 if (element.type === REACT_FRAGMENT_TYPE) {
4709 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
4710 created.return = returnFiber;
4711 return created;
4712 } else {
4713 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
4714 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
4715 _created4.return = returnFiber;
4716 return _created4;
4717 }
4718 }
4719
4720 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
4721 var key = portal.key;
4722 var child = currentFirstChild;
4723 while (child !== null) {
4724 // TODO: If key === null and child.key === null, then this only applies to
4725 // the first item in the list.
4726 if (child.key === key) {
4727 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
4728 deleteRemainingChildren(returnFiber, child.sibling);
4729 var existing = useFiber(child, portal.children || [], expirationTime);
4730 existing.return = returnFiber;
4731 return existing;
4732 } else {
4733 deleteRemainingChildren(returnFiber, child);
4734 break;
4735 }
4736 } else {
4737 deleteChild(returnFiber, child);
4738 }
4739 child = child.sibling;
4740 }
4741
4742 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4743 created.return = returnFiber;
4744 return created;
4745 }
4746
4747 // This API will tag the children with the side-effect of the reconciliation
4748 // itself. They will be added to the side-effect list as we pass through the
4749 // children and the parent.
4750 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
4751 // This function is not recursive.
4752 // If the top level item is an array, we treat it as a set of children,
4753 // not as a fragment. Nested arrays on the other hand will be treated as
4754 // fragment nodes. Recursion happens at the normal flow.
4755
4756 // Handle top level unkeyed fragments as if they were arrays.
4757 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
4758 // We treat the ambiguous cases above the same.
4759 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
4760 if (isUnkeyedTopLevelFragment) {
4761 newChild = newChild.props.children;
4762 }
4763
4764 // Handle object types
4765 var isObject = typeof newChild === 'object' && newChild !== null;
4766
4767 if (isObject) {
4768 switch (newChild.$$typeof) {
4769 case REACT_ELEMENT_TYPE:
4770 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
4771 case REACT_PORTAL_TYPE:
4772 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
4773 }
4774 }
4775
4776 if (typeof newChild === 'string' || typeof newChild === 'number') {
4777 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
4778 }
4779
4780 if (isArray(newChild)) {
4781 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
4782 }
4783
4784 if (getIteratorFn(newChild)) {
4785 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
4786 }
4787
4788 if (isObject) {
4789 throwOnInvalidObjectType(returnFiber, newChild);
4790 }
4791
4792 {
4793 if (typeof newChild === 'function') {
4794 warnOnFunctionType();
4795 }
4796 }
4797 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
4798 // If the new child is undefined, and the return fiber is a composite
4799 // component, throw an error. If Fiber return types are disabled,
4800 // we already threw above.
4801 switch (returnFiber.tag) {
4802 case ClassComponent:
4803 {
4804 {
4805 var instance = returnFiber.stateNode;
4806 if (instance.render._isMockFunction) {
4807 // We allow auto-mocks to proceed as if they're returning null.
4808 break;
4809 }
4810 }
4811 }
4812 // Intentionally fall through to the next case, which handles both
4813 // functions and classes
4814 // eslint-disable-next-lined no-fallthrough
4815 case FunctionComponent:
4816 {
4817 var Component = returnFiber.type;
4818 invariant(false, '%s(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.', Component.displayName || Component.name || 'Component');
4819 }
4820 }
4821 }
4822
4823 // Remaining cases are all treated as empty.
4824 return deleteRemainingChildren(returnFiber, currentFirstChild);
4825 }
4826
4827 return reconcileChildFibers;
4828}
4829
4830var reconcileChildFibers = ChildReconciler(true);
4831var mountChildFibers = ChildReconciler(false);
4832
4833function cloneChildFibers(current$$1, workInProgress) {
4834 !(current$$1 === null || workInProgress.child === current$$1.child) ? invariant(false, 'Resuming work not yet implemented.') : void 0;
4835
4836 if (workInProgress.child === null) {
4837 return;
4838 }
4839
4840 var currentChild = workInProgress.child;
4841 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4842 workInProgress.child = newChild;
4843
4844 newChild.return = workInProgress;
4845 while (currentChild.sibling !== null) {
4846 currentChild = currentChild.sibling;
4847 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4848 newChild.return = workInProgress;
4849 }
4850 newChild.sibling = null;
4851}
4852
4853var NO_CONTEXT$1 = {};
4854
4855var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
4856var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
4857var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
4858
4859function requiredContext(c) {
4860 !(c !== NO_CONTEXT$1) ? invariant(false, 'Expected host context to exist. This error is likely caused by a bug in React. Please file an issue.') : void 0;
4861 return c;
4862}
4863
4864function getRootHostContainer() {
4865 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4866 return rootInstance;
4867}
4868
4869function pushHostContainer(fiber, nextRootInstance) {
4870 // Push current root instance onto the stack;
4871 // This allows us to reset root when portals are popped.
4872 push(rootInstanceStackCursor, nextRootInstance, fiber);
4873 // Track the context and the Fiber that provided it.
4874 // This enables us to pop only Fibers that provide unique contexts.
4875 push(contextFiberStackCursor, fiber, fiber);
4876
4877 // Finally, we need to push the host context to the stack.
4878 // However, we can't just call getRootHostContext() and push it because
4879 // we'd have a different number of entries on the stack depending on
4880 // whether getRootHostContext() throws somewhere in renderer code or not.
4881 // So we push an empty value first. This lets us safely unwind on errors.
4882 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
4883 var nextRootContext = getRootHostContext(nextRootInstance);
4884 // Now that we know this function doesn't throw, replace it.
4885 pop(contextStackCursor$1, fiber);
4886 push(contextStackCursor$1, nextRootContext, fiber);
4887}
4888
4889function popHostContainer(fiber) {
4890 pop(contextStackCursor$1, fiber);
4891 pop(contextFiberStackCursor, fiber);
4892 pop(rootInstanceStackCursor, fiber);
4893}
4894
4895function getHostContext() {
4896 var context = requiredContext(contextStackCursor$1.current);
4897 return context;
4898}
4899
4900function pushHostContext(fiber) {
4901 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4902 var context = requiredContext(contextStackCursor$1.current);
4903 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
4904
4905 // Don't push this Fiber's context unless it's unique.
4906 if (context === nextContext) {
4907 return;
4908 }
4909
4910 // Track the context and the Fiber that provided it.
4911 // This enables us to pop only Fibers that provide unique contexts.
4912 push(contextFiberStackCursor, fiber, fiber);
4913 push(contextStackCursor$1, nextContext, fiber);
4914}
4915
4916function popHostContext(fiber) {
4917 // Do not pop unless this Fiber provided the current context.
4918 // pushHostContext() only pushes Fibers that provide unique contexts.
4919 if (contextFiberStackCursor.current !== fiber) {
4920 return;
4921 }
4922
4923 pop(contextStackCursor$1, fiber);
4924 pop(contextFiberStackCursor, fiber);
4925}
4926
4927var NoEffect$1 = /* */0;
4928var UnmountSnapshot = /* */2;
4929var UnmountMutation = /* */4;
4930var MountMutation = /* */8;
4931var UnmountLayout = /* */16;
4932var MountLayout = /* */32;
4933var MountPassive = /* */64;
4934var UnmountPassive = /* */128;
4935
4936var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
4937
4938
4939var didWarnAboutMismatchedHooksForComponent = void 0;
4940{
4941 didWarnAboutMismatchedHooksForComponent = new Set();
4942}
4943
4944// These are set right before calling the component.
4945var renderExpirationTime = NoWork;
4946// The work-in-progress fiber. I've named it differently to distinguish it from
4947// the work-in-progress hook.
4948var currentlyRenderingFiber$1 = null;
4949
4950// Hooks are stored as a linked list on the fiber's memoizedState field. The
4951// current hook list is the list that belongs to the current fiber. The
4952// work-in-progress hook list is a new list that will be added to the
4953// work-in-progress fiber.
4954var firstCurrentHook = null;
4955var currentHook = null;
4956var nextCurrentHook = null;
4957var firstWorkInProgressHook = null;
4958var workInProgressHook = null;
4959var nextWorkInProgressHook = null;
4960
4961var remainingExpirationTime = NoWork;
4962var componentUpdateQueue = null;
4963var sideEffectTag = 0;
4964
4965// Updates scheduled during render will trigger an immediate re-render at the
4966// end of the current pass. We can't store these updates on the normal queue,
4967// because if the work is aborted, they should be discarded. Because this is
4968// a relatively rare case, we also don't want to add an additional field to
4969// either the hook or queue object types. So we store them in a lazily create
4970// map of queue -> render-phase updates, which are discarded once the component
4971// completes without re-rendering.
4972
4973// Whether an update was scheduled during the currently executing render pass.
4974var didScheduleRenderPhaseUpdate = false;
4975// Lazily created map of render-phase updates
4976var renderPhaseUpdates = null;
4977// Counter to prevent infinite loops.
4978var numberOfReRenders = 0;
4979var RE_RENDER_LIMIT = 25;
4980
4981// In DEV, this is the name of the currently executing primitive hook
4982var currentHookNameInDev = null;
4983
4984function warnOnHookMismatchInDev() {
4985 {
4986 var componentName = getComponentName(currentlyRenderingFiber$1.type);
4987 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
4988 didWarnAboutMismatchedHooksForComponent.add(componentName);
4989
4990 var secondColumnStart = 22;
4991
4992 var table = '';
4993 var prevHook = firstCurrentHook;
4994 var nextHook = firstWorkInProgressHook;
4995 var n = 1;
4996 while (prevHook !== null && nextHook !== null) {
4997 var oldHookName = prevHook._debugType;
4998 var newHookName = nextHook._debugType;
4999
5000 var row = n + '. ' + oldHookName;
5001
5002 // Extra space so second column lines up
5003 // lol @ IE not supporting String#repeat
5004 while (row.length < secondColumnStart) {
5005 row += ' ';
5006 }
5007
5008 row += newHookName + '\n';
5009
5010 table += row;
5011 prevHook = prevHook.next;
5012 nextHook = nextHook.next;
5013 n++;
5014 }
5015
5016 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);
5017 }
5018 }
5019}
5020
5021function throwInvalidHookError() {
5022 invariant(false, 'Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)');
5023}
5024
5025function areHookInputsEqual(nextDeps, prevDeps) {
5026 if (prevDeps === null) {
5027 {
5028 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);
5029 }
5030 return false;
5031 }
5032
5033 {
5034 // Don't bother comparing lengths in prod because these arrays should be
5035 // passed inline.
5036 if (nextDeps.length !== prevDeps.length) {
5037 warning$1(false, 'The final argument passed to %s changed size between renders. The ' + 'order and size of this array must remain constant.\n\n' + 'Previous: %s\n' + 'Incoming: %s', currentHookNameInDev, '[' + nextDeps.join(', ') + ']', '[' + prevDeps.join(', ') + ']');
5038 }
5039 }
5040 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
5041 if (is(nextDeps[i], prevDeps[i])) {
5042 continue;
5043 }
5044 return false;
5045 }
5046 return true;
5047}
5048
5049function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
5050 renderExpirationTime = nextRenderExpirationTime;
5051 currentlyRenderingFiber$1 = workInProgress;
5052 firstCurrentHook = nextCurrentHook = current !== null ? current.memoizedState : null;
5053
5054 // The following should have already been reset
5055 // currentHook = null;
5056 // workInProgressHook = null;
5057
5058 // remainingExpirationTime = NoWork;
5059 // componentUpdateQueue = null;
5060
5061 // didScheduleRenderPhaseUpdate = false;
5062 // renderPhaseUpdates = null;
5063 // numberOfReRenders = 0;
5064 // sideEffectTag = 0;
5065
5066 {
5067 ReactCurrentDispatcher$1.current = nextCurrentHook === null ? HooksDispatcherOnMountInDEV : HooksDispatcherOnUpdateInDEV;
5068 }
5069
5070 var children = Component(props, refOrContext);
5071
5072 if (didScheduleRenderPhaseUpdate) {
5073 do {
5074 didScheduleRenderPhaseUpdate = false;
5075 numberOfReRenders += 1;
5076
5077 // Start over from the beginning of the list
5078 firstCurrentHook = nextCurrentHook = current !== null ? current.memoizedState : null;
5079 nextWorkInProgressHook = firstWorkInProgressHook;
5080
5081 currentHook = null;
5082 workInProgressHook = null;
5083 componentUpdateQueue = null;
5084
5085 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
5086
5087 children = Component(props, refOrContext);
5088 } while (didScheduleRenderPhaseUpdate);
5089
5090 renderPhaseUpdates = null;
5091 numberOfReRenders = 0;
5092 }
5093
5094 {
5095 currentHookNameInDev = null;
5096 }
5097
5098 // We can assume the previous dispatcher is always this one, since we set it
5099 // at the beginning of the render phase and there's no re-entrancy.
5100 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5101
5102 var renderedWork = currentlyRenderingFiber$1;
5103
5104 renderedWork.memoizedState = firstWorkInProgressHook;
5105 renderedWork.expirationTime = remainingExpirationTime;
5106 renderedWork.updateQueue = componentUpdateQueue;
5107 renderedWork.effectTag |= sideEffectTag;
5108
5109 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
5110
5111 renderExpirationTime = NoWork;
5112 currentlyRenderingFiber$1 = null;
5113
5114 firstCurrentHook = null;
5115 currentHook = null;
5116 nextCurrentHook = null;
5117 firstWorkInProgressHook = null;
5118 workInProgressHook = null;
5119 nextWorkInProgressHook = null;
5120
5121 remainingExpirationTime = NoWork;
5122 componentUpdateQueue = null;
5123 sideEffectTag = 0;
5124
5125 // These were reset above
5126 // didScheduleRenderPhaseUpdate = false;
5127 // renderPhaseUpdates = null;
5128 // numberOfReRenders = 0;
5129
5130 !!didRenderTooFewHooks ? invariant(false, 'Rendered fewer hooks than expected. This may be caused by an accidental early return statement.') : void 0;
5131
5132 return children;
5133}
5134
5135function bailoutHooks(current, workInProgress, expirationTime) {
5136 workInProgress.updateQueue = current.updateQueue;
5137 workInProgress.effectTag &= ~(Passive | Update);
5138 if (current.expirationTime <= expirationTime) {
5139 current.expirationTime = NoWork;
5140 }
5141}
5142
5143function resetHooks() {
5144 // We can assume the previous dispatcher is always this one, since we set it
5145 // at the beginning of the render phase and there's no re-entrancy.
5146 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5147
5148 // This is used to reset the state of this module when a component throws.
5149 // It's also called inside mountIndeterminateComponent if we determine the
5150 // component is a module-style component.
5151 renderExpirationTime = NoWork;
5152 currentlyRenderingFiber$1 = null;
5153
5154 firstCurrentHook = null;
5155 currentHook = null;
5156 nextCurrentHook = null;
5157 firstWorkInProgressHook = null;
5158 workInProgressHook = null;
5159 nextWorkInProgressHook = null;
5160
5161 remainingExpirationTime = NoWork;
5162 componentUpdateQueue = null;
5163 sideEffectTag = 0;
5164
5165 {
5166 currentHookNameInDev = null;
5167 }
5168
5169 didScheduleRenderPhaseUpdate = false;
5170 renderPhaseUpdates = null;
5171 numberOfReRenders = 0;
5172}
5173
5174function mountWorkInProgressHook() {
5175 var hook = {
5176 memoizedState: null,
5177
5178 baseState: null,
5179 queue: null,
5180 baseUpdate: null,
5181
5182 next: null
5183 };
5184
5185 {
5186 hook._debugType = currentHookNameInDev;
5187 if (currentlyRenderingFiber$1 !== null && currentlyRenderingFiber$1.alternate !== null) {
5188 warning$1(false, '%s: Rendered more hooks than during the previous render. This is ' + 'not currently supported and may lead to unexpected behavior.', getComponentName(currentlyRenderingFiber$1.type));
5189 }
5190 }
5191 if (workInProgressHook === null) {
5192 // This is the first hook in the list
5193 firstWorkInProgressHook = workInProgressHook = hook;
5194 } else {
5195 // Append to the end of the list
5196 workInProgressHook = workInProgressHook.next = hook;
5197 }
5198 return workInProgressHook;
5199}
5200
5201function updateWorkInProgressHook() {
5202 // This function is used both for updates and for re-renders triggered by a
5203 // render phase update. It assumes there is either a current hook we can
5204 // clone, or a work-in-progress hook from a previous render pass that we can
5205 // use as a base. When we reach the end of the base list, we must switch to
5206 // the dispatcher used for mounts.
5207 if (nextWorkInProgressHook !== null) {
5208 // There's already a work-in-progress. Reuse it.
5209 workInProgressHook = nextWorkInProgressHook;
5210 nextWorkInProgressHook = workInProgressHook.next;
5211
5212 currentHook = nextCurrentHook;
5213 nextCurrentHook = currentHook !== null ? currentHook.next : null;
5214 } else {
5215 // Clone from the current hook.
5216 !(nextCurrentHook !== null) ? invariant(false, 'Rendered more hooks than during the previous render.') : void 0;
5217 currentHook = nextCurrentHook;
5218
5219 var newHook = {
5220 memoizedState: currentHook.memoizedState,
5221
5222 baseState: currentHook.baseState,
5223 queue: currentHook.queue,
5224 baseUpdate: currentHook.baseUpdate,
5225
5226 next: null
5227 };
5228
5229 if (workInProgressHook === null) {
5230 // This is the first hook in the list.
5231 workInProgressHook = firstWorkInProgressHook = newHook;
5232 } else {
5233 // Append to the end of the list.
5234 workInProgressHook = workInProgressHook.next = newHook;
5235 }
5236 nextCurrentHook = currentHook.next;
5237
5238 {
5239 newHook._debugType = currentHookNameInDev;
5240 if (currentHookNameInDev !== currentHook._debugType) {
5241 warnOnHookMismatchInDev();
5242 }
5243 }
5244 }
5245 return workInProgressHook;
5246}
5247
5248function createFunctionComponentUpdateQueue() {
5249 return {
5250 lastEffect: null
5251 };
5252}
5253
5254function basicStateReducer(state, action) {
5255 return typeof action === 'function' ? action(state) : action;
5256}
5257
5258function mountContext(context, observedBits) {
5259 {
5260 mountWorkInProgressHook();
5261 }
5262 return readContext(context, observedBits);
5263}
5264
5265function updateContext(context, observedBits) {
5266 {
5267 updateWorkInProgressHook();
5268 }
5269 return readContext(context, observedBits);
5270}
5271
5272function mountReducer(reducer, initialArg, init) {
5273 var hook = mountWorkInProgressHook();
5274 var initialState = void 0;
5275 if (init !== undefined) {
5276 initialState = init(initialArg);
5277 } else {
5278 initialState = initialArg;
5279 }
5280 hook.memoizedState = hook.baseState = initialState;
5281 var queue = hook.queue = {
5282 last: null,
5283 dispatch: null,
5284 eagerReducer: reducer,
5285 eagerState: initialState
5286 };
5287 var dispatch = queue.dispatch = dispatchAction.bind(null,
5288 // Flow doesn't know this is non-null, but we do.
5289 currentlyRenderingFiber$1, queue);
5290 return [hook.memoizedState, dispatch];
5291}
5292
5293function updateReducer(reducer, initialArg, init) {
5294 var hook = updateWorkInProgressHook();
5295 var queue = hook.queue;
5296 !(queue !== null) ? invariant(false, 'Should have a queue. This is likely a bug in React. Please file an issue.') : void 0;
5297
5298 if (numberOfReRenders > 0) {
5299 // This is a re-render. Apply the new render phase updates to the previous
5300 var _dispatch = queue.dispatch;
5301 if (renderPhaseUpdates !== null) {
5302 // Render phase updates are stored in a map of queue -> linked list
5303 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5304 if (firstRenderPhaseUpdate !== undefined) {
5305 renderPhaseUpdates.delete(queue);
5306 var newState = hook.memoizedState;
5307 var update = firstRenderPhaseUpdate;
5308 do {
5309 // Process this render phase update. We don't have to check the
5310 // priority because it will always be the same as the current
5311 // render's.
5312 var _action = update.action;
5313 newState = reducer(newState, _action);
5314 update = update.next;
5315 } while (update !== null);
5316
5317 // Mark that the fiber performed work, but only if the new state is
5318 // different from the current state.
5319 if (!is(newState, hook.memoizedState)) {
5320 markWorkInProgressReceivedUpdate();
5321 }
5322
5323 hook.memoizedState = newState;
5324
5325 // Don't persist the state accumlated from the render phase updates to
5326 // the base state unless the queue is empty.
5327 // TODO: Not sure if this is the desired semantics, but it's what we
5328 // do for gDSFP. I can't remember why.
5329 if (hook.baseUpdate === queue.last) {
5330 hook.baseState = newState;
5331 }
5332
5333 return [newState, _dispatch];
5334 }
5335 }
5336 return [hook.memoizedState, _dispatch];
5337 }
5338
5339 // The last update in the entire queue
5340 var last = queue.last;
5341 // The last update that is part of the base state.
5342 var baseUpdate = hook.baseUpdate;
5343 var baseState = hook.baseState;
5344
5345 // Find the first unprocessed update.
5346 var first = void 0;
5347 if (baseUpdate !== null) {
5348 if (last !== null) {
5349 // For the first update, the queue is a circular linked list where
5350 // `queue.last.next = queue.first`. Once the first update commits, and
5351 // the `baseUpdate` is no longer empty, we can unravel the list.
5352 last.next = null;
5353 }
5354 first = baseUpdate.next;
5355 } else {
5356 first = last !== null ? last.next : null;
5357 }
5358 if (first !== null) {
5359 var _newState = baseState;
5360 var newBaseState = null;
5361 var newBaseUpdate = null;
5362 var prevUpdate = baseUpdate;
5363 var _update = first;
5364 var didSkip = false;
5365 do {
5366 var updateExpirationTime = _update.expirationTime;
5367 if (updateExpirationTime < renderExpirationTime) {
5368 // Priority is insufficient. Skip this update. If this is the first
5369 // skipped update, the previous update/state is the new base
5370 // update/state.
5371 if (!didSkip) {
5372 didSkip = true;
5373 newBaseUpdate = prevUpdate;
5374 newBaseState = _newState;
5375 }
5376 // Update the remaining priority in the queue.
5377 if (updateExpirationTime > remainingExpirationTime) {
5378 remainingExpirationTime = updateExpirationTime;
5379 }
5380 } else {
5381 // Process this update.
5382 if (_update.eagerReducer === reducer) {
5383 // If this update was processed eagerly, and its reducer matches the
5384 // current reducer, we can use the eagerly computed state.
5385 _newState = _update.eagerState;
5386 } else {
5387 var _action2 = _update.action;
5388 _newState = reducer(_newState, _action2);
5389 }
5390 }
5391 prevUpdate = _update;
5392 _update = _update.next;
5393 } while (_update !== null && _update !== first);
5394
5395 if (!didSkip) {
5396 newBaseUpdate = prevUpdate;
5397 newBaseState = _newState;
5398 }
5399
5400 // Mark that the fiber performed work, but only if the new state is
5401 // different from the current state.
5402 if (!is(_newState, hook.memoizedState)) {
5403 markWorkInProgressReceivedUpdate();
5404 }
5405
5406 hook.memoizedState = _newState;
5407 hook.baseUpdate = newBaseUpdate;
5408 hook.baseState = newBaseState;
5409
5410 queue.eagerReducer = reducer;
5411 queue.eagerState = _newState;
5412 }
5413
5414 var dispatch = queue.dispatch;
5415 return [hook.memoizedState, dispatch];
5416}
5417
5418function mountState(initialState) {
5419 var hook = mountWorkInProgressHook();
5420 if (typeof initialState === 'function') {
5421 initialState = initialState();
5422 }
5423 hook.memoizedState = hook.baseState = initialState;
5424 var queue = hook.queue = {
5425 last: null,
5426 dispatch: null,
5427 eagerReducer: basicStateReducer,
5428 eagerState: initialState
5429 };
5430 var dispatch = queue.dispatch = dispatchAction.bind(null,
5431 // Flow doesn't know this is non-null, but we do.
5432 currentlyRenderingFiber$1, queue);
5433 return [hook.memoizedState, dispatch];
5434}
5435
5436function updateState(initialState) {
5437 return updateReducer(basicStateReducer, initialState);
5438}
5439
5440function pushEffect(tag, create, destroy, deps) {
5441 var effect = {
5442 tag: tag,
5443 create: create,
5444 destroy: destroy,
5445 deps: deps,
5446 // Circular
5447 next: null
5448 };
5449 if (componentUpdateQueue === null) {
5450 componentUpdateQueue = createFunctionComponentUpdateQueue();
5451 componentUpdateQueue.lastEffect = effect.next = effect;
5452 } else {
5453 var _lastEffect = componentUpdateQueue.lastEffect;
5454 if (_lastEffect === null) {
5455 componentUpdateQueue.lastEffect = effect.next = effect;
5456 } else {
5457 var firstEffect = _lastEffect.next;
5458 _lastEffect.next = effect;
5459 effect.next = firstEffect;
5460 componentUpdateQueue.lastEffect = effect;
5461 }
5462 }
5463 return effect;
5464}
5465
5466function mountRef(initialValue) {
5467 var hook = mountWorkInProgressHook();
5468 var ref = { current: initialValue };
5469 {
5470 Object.seal(ref);
5471 }
5472 hook.memoizedState = ref;
5473 return ref;
5474}
5475
5476function updateRef(initialValue) {
5477 var hook = updateWorkInProgressHook();
5478 return hook.memoizedState;
5479}
5480
5481function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5482 var hook = mountWorkInProgressHook();
5483 var nextDeps = deps === undefined ? null : deps;
5484 sideEffectTag |= fiberEffectTag;
5485 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
5486}
5487
5488function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5489 var hook = updateWorkInProgressHook();
5490 var nextDeps = deps === undefined ? null : deps;
5491 var destroy = undefined;
5492
5493 if (currentHook !== null) {
5494 var prevEffect = currentHook.memoizedState;
5495 destroy = prevEffect.destroy;
5496 if (nextDeps !== null) {
5497 var prevDeps = prevEffect.deps;
5498 if (areHookInputsEqual(nextDeps, prevDeps)) {
5499 pushEffect(NoEffect$1, create, destroy, nextDeps);
5500 return;
5501 }
5502 }
5503 }
5504
5505 sideEffectTag |= fiberEffectTag;
5506 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
5507}
5508
5509function mountEffect(create, deps) {
5510 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5511}
5512
5513function updateEffect(create, deps) {
5514 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5515}
5516
5517function mountLayoutEffect(create, deps) {
5518 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5519}
5520
5521function updateLayoutEffect(create, deps) {
5522 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5523}
5524
5525function imperativeHandleEffect(create, ref) {
5526 if (typeof ref === 'function') {
5527 var refCallback = ref;
5528 var _inst = create();
5529 refCallback(_inst);
5530 return function () {
5531 refCallback(null);
5532 };
5533 } else if (ref !== null && ref !== undefined) {
5534 var refObject = ref;
5535 {
5536 !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;
5537 }
5538 var _inst2 = create();
5539 refObject.current = _inst2;
5540 return function () {
5541 refObject.current = null;
5542 };
5543 }
5544}
5545
5546function mountImperativeHandle(ref, create, deps) {
5547 {
5548 !(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;
5549 }
5550
5551 // TODO: If deps are provided, should we skip comparing the ref itself?
5552 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : [ref];
5553
5554 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5555}
5556
5557function updateImperativeHandle(ref, create, deps) {
5558 {
5559 !(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;
5560 }
5561
5562 // TODO: If deps are provided, should we skip comparing the ref itself?
5563 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : [ref];
5564
5565 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5566}
5567
5568function mountDebugValue(value, formatterFn) {
5569 // This hook is normally a no-op.
5570 // The react-debug-hooks package injects its own implementation
5571 // so that e.g. DevTools can display custom hook values.
5572}
5573
5574var updateDebugValue = mountDebugValue;
5575
5576function mountCallback(callback, deps) {
5577 var hook = mountWorkInProgressHook();
5578 var nextDeps = deps === undefined ? null : deps;
5579 hook.memoizedState = [callback, nextDeps];
5580 return callback;
5581}
5582
5583function updateCallback(callback, deps) {
5584 var hook = updateWorkInProgressHook();
5585 var nextDeps = deps === undefined ? null : deps;
5586 var prevState = hook.memoizedState;
5587 if (prevState !== null) {
5588 if (nextDeps !== null) {
5589 var prevDeps = prevState[1];
5590 if (areHookInputsEqual(nextDeps, prevDeps)) {
5591 return prevState[0];
5592 }
5593 }
5594 }
5595 hook.memoizedState = [callback, nextDeps];
5596 return callback;
5597}
5598
5599function mountMemo(nextCreate, deps) {
5600 var hook = mountWorkInProgressHook();
5601 var nextDeps = deps === undefined ? null : deps;
5602 var nextValue = nextCreate();
5603 hook.memoizedState = [nextValue, nextDeps];
5604 return nextValue;
5605}
5606
5607function updateMemo(nextCreate, deps) {
5608 var hook = updateWorkInProgressHook();
5609 var nextDeps = deps === undefined ? null : deps;
5610 var prevState = hook.memoizedState;
5611 if (prevState !== null) {
5612 // Assume these are defined. If they're not, areHookInputsEqual will warn.
5613 if (nextDeps !== null) {
5614 var prevDeps = prevState[1];
5615 if (areHookInputsEqual(nextDeps, prevDeps)) {
5616 return prevState[0];
5617 }
5618 }
5619 }
5620 var nextValue = nextCreate();
5621 hook.memoizedState = [nextValue, nextDeps];
5622 return nextValue;
5623}
5624
5625// in a test-like environment, we want to warn if dispatchAction()
5626// is called outside of a batchedUpdates/TestUtils.act(...) call.
5627var shouldWarnForUnbatchedSetState = false;
5628
5629{
5630 // jest isnt' a 'global', it's just exposed to tests via a wrapped function
5631 // further, this isn't a test file, so flow doesn't recognize the symbol. So...
5632 // $FlowExpectedError - because requirements don't give a damn about your type sigs.
5633 if ('undefined' !== typeof jest) {
5634 shouldWarnForUnbatchedSetState = true;
5635 }
5636}
5637
5638function dispatchAction(fiber, queue, action) {
5639 !(numberOfReRenders < RE_RENDER_LIMIT) ? invariant(false, 'Too many re-renders. React limits the number of renders to prevent an infinite loop.') : void 0;
5640
5641 {
5642 !(arguments.length <= 3) ? warning$1(false, "State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().') : void 0;
5643 }
5644
5645 var alternate = fiber.alternate;
5646 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
5647 // This is a render phase update. Stash it in a lazily-created map of
5648 // queue -> linked list of updates. After this render pass, we'll restart
5649 // and apply the stashed updates on top of the work-in-progress hook.
5650 didScheduleRenderPhaseUpdate = true;
5651 var update = {
5652 expirationTime: renderExpirationTime,
5653 action: action,
5654 eagerReducer: null,
5655 eagerState: null,
5656 next: null
5657 };
5658 if (renderPhaseUpdates === null) {
5659 renderPhaseUpdates = new Map();
5660 }
5661 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5662 if (firstRenderPhaseUpdate === undefined) {
5663 renderPhaseUpdates.set(queue, update);
5664 } else {
5665 // Append the update to the end of the list.
5666 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
5667 while (lastRenderPhaseUpdate.next !== null) {
5668 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
5669 }
5670 lastRenderPhaseUpdate.next = update;
5671 }
5672 } else {
5673 flushPassiveEffects$1();
5674
5675 var currentTime = requestCurrentTime();
5676 var _expirationTime = computeExpirationForFiber(currentTime, fiber);
5677
5678 var _update2 = {
5679 expirationTime: _expirationTime,
5680 action: action,
5681 eagerReducer: null,
5682 eagerState: null,
5683 next: null
5684 };
5685
5686 // Append the update to the end of the list.
5687 var _last = queue.last;
5688 if (_last === null) {
5689 // This is the first update. Create a circular list.
5690 _update2.next = _update2;
5691 } else {
5692 var first = _last.next;
5693 if (first !== null) {
5694 // Still circular.
5695 _update2.next = first;
5696 }
5697 _last.next = _update2;
5698 }
5699 queue.last = _update2;
5700
5701 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
5702 // The queue is currently empty, which means we can eagerly compute the
5703 // next state before entering the render phase. If the new state is the
5704 // same as the current state, we may be able to bail out entirely.
5705 var _eagerReducer = queue.eagerReducer;
5706 if (_eagerReducer !== null) {
5707 var prevDispatcher = void 0;
5708 {
5709 prevDispatcher = ReactCurrentDispatcher$1.current;
5710 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5711 }
5712 try {
5713 var currentState = queue.eagerState;
5714 var _eagerState = _eagerReducer(currentState, action);
5715 // Stash the eagerly computed state, and the reducer used to compute
5716 // it, on the update object. If the reducer hasn't changed by the
5717 // time we enter the render phase, then the eager state can be used
5718 // without calling the reducer again.
5719 _update2.eagerReducer = _eagerReducer;
5720 _update2.eagerState = _eagerState;
5721 if (is(_eagerState, currentState)) {
5722 // Fast path. We can bail out without scheduling React to re-render.
5723 // It's still possible that we'll need to rebase this update later,
5724 // if the component re-renders for a different reason and by that
5725 // time the reducer has changed.
5726 return;
5727 }
5728 } catch (error) {
5729 // Suppress the error. It will throw again in the render phase.
5730 } finally {
5731 {
5732 ReactCurrentDispatcher$1.current = prevDispatcher;
5733 }
5734 }
5735 }
5736 }
5737 {
5738 if (shouldWarnForUnbatchedSetState === true) {
5739 warnIfNotCurrentlyBatchingInDev(fiber);
5740 }
5741 }
5742 scheduleWork(fiber, _expirationTime);
5743 }
5744}
5745
5746var ContextOnlyDispatcher = {
5747 readContext: readContext,
5748
5749 useCallback: throwInvalidHookError,
5750 useContext: throwInvalidHookError,
5751 useEffect: throwInvalidHookError,
5752 useImperativeHandle: throwInvalidHookError,
5753 useLayoutEffect: throwInvalidHookError,
5754 useMemo: throwInvalidHookError,
5755 useReducer: throwInvalidHookError,
5756 useRef: throwInvalidHookError,
5757 useState: throwInvalidHookError,
5758 useDebugValue: throwInvalidHookError
5759};
5760
5761var HooksDispatcherOnMountInDEV = null;
5762var HooksDispatcherOnUpdateInDEV = null;
5763var InvalidNestedHooksDispatcherOnMountInDEV = null;
5764var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
5765
5766{
5767 var warnInvalidContextAccess = function () {
5768 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().');
5769 };
5770
5771 var warnInvalidHookAccess = function () {
5772 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');
5773 };
5774
5775 HooksDispatcherOnMountInDEV = {
5776 readContext: function (context, observedBits) {
5777 return readContext(context, observedBits);
5778 },
5779 useCallback: function (callback, deps) {
5780 currentHookNameInDev = 'useCallback';
5781 return mountCallback(callback, deps);
5782 },
5783 useContext: function (context, observedBits) {
5784 currentHookNameInDev = 'useContext';
5785 return mountContext(context, observedBits);
5786 },
5787 useEffect: function (create, deps) {
5788 currentHookNameInDev = 'useEffect';
5789 return mountEffect(create, deps);
5790 },
5791 useImperativeHandle: function (ref, create, deps) {
5792 currentHookNameInDev = 'useImperativeHandle';
5793 return mountImperativeHandle(ref, create, deps);
5794 },
5795 useLayoutEffect: function (create, deps) {
5796 currentHookNameInDev = 'useLayoutEffect';
5797 return mountLayoutEffect(create, deps);
5798 },
5799 useMemo: function (create, deps) {
5800 currentHookNameInDev = 'useMemo';
5801 var prevDispatcher = ReactCurrentDispatcher$1.current;
5802 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5803 try {
5804 return mountMemo(create, deps);
5805 } finally {
5806 ReactCurrentDispatcher$1.current = prevDispatcher;
5807 }
5808 },
5809 useReducer: function (reducer, initialArg, init) {
5810 currentHookNameInDev = 'useReducer';
5811 var prevDispatcher = ReactCurrentDispatcher$1.current;
5812 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5813 try {
5814 return mountReducer(reducer, initialArg, init);
5815 } finally {
5816 ReactCurrentDispatcher$1.current = prevDispatcher;
5817 }
5818 },
5819 useRef: function (initialValue) {
5820 currentHookNameInDev = 'useRef';
5821 return mountRef(initialValue);
5822 },
5823 useState: function (initialState) {
5824 currentHookNameInDev = 'useState';
5825 var prevDispatcher = ReactCurrentDispatcher$1.current;
5826 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5827 try {
5828 return mountState(initialState);
5829 } finally {
5830 ReactCurrentDispatcher$1.current = prevDispatcher;
5831 }
5832 },
5833 useDebugValue: function (value, formatterFn) {
5834 currentHookNameInDev = 'useDebugValue';
5835 return mountDebugValue(value, formatterFn);
5836 }
5837 };
5838
5839 HooksDispatcherOnUpdateInDEV = {
5840 readContext: function (context, observedBits) {
5841 return readContext(context, observedBits);
5842 },
5843 useCallback: function (callback, deps) {
5844 currentHookNameInDev = 'useCallback';
5845 return updateCallback(callback, deps);
5846 },
5847 useContext: function (context, observedBits) {
5848 currentHookNameInDev = 'useContext';
5849 return updateContext(context, observedBits);
5850 },
5851 useEffect: function (create, deps) {
5852 currentHookNameInDev = 'useEffect';
5853 return updateEffect(create, deps);
5854 },
5855 useImperativeHandle: function (ref, create, deps) {
5856 currentHookNameInDev = 'useImperativeHandle';
5857 return updateImperativeHandle(ref, create, deps);
5858 },
5859 useLayoutEffect: function (create, deps) {
5860 currentHookNameInDev = 'useLayoutEffect';
5861 return updateLayoutEffect(create, deps);
5862 },
5863 useMemo: function (create, deps) {
5864 currentHookNameInDev = 'useMemo';
5865 var prevDispatcher = ReactCurrentDispatcher$1.current;
5866 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5867 try {
5868 return updateMemo(create, deps);
5869 } finally {
5870 ReactCurrentDispatcher$1.current = prevDispatcher;
5871 }
5872 },
5873 useReducer: function (reducer, initialArg, init) {
5874 currentHookNameInDev = 'useReducer';
5875 var prevDispatcher = ReactCurrentDispatcher$1.current;
5876 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5877 try {
5878 return updateReducer(reducer, initialArg, init);
5879 } finally {
5880 ReactCurrentDispatcher$1.current = prevDispatcher;
5881 }
5882 },
5883 useRef: function (initialValue) {
5884 currentHookNameInDev = 'useRef';
5885 return updateRef(initialValue);
5886 },
5887 useState: function (initialState) {
5888 currentHookNameInDev = 'useState';
5889 var prevDispatcher = ReactCurrentDispatcher$1.current;
5890 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5891 try {
5892 return updateState(initialState);
5893 } finally {
5894 ReactCurrentDispatcher$1.current = prevDispatcher;
5895 }
5896 },
5897 useDebugValue: function (value, formatterFn) {
5898 currentHookNameInDev = 'useDebugValue';
5899 return updateDebugValue(value, formatterFn);
5900 }
5901 };
5902
5903 InvalidNestedHooksDispatcherOnMountInDEV = {
5904 readContext: function (context, observedBits) {
5905 warnInvalidContextAccess();
5906 return readContext(context, observedBits);
5907 },
5908 useCallback: function (callback, deps) {
5909 currentHookNameInDev = 'useCallback';
5910 warnInvalidHookAccess();
5911 return mountCallback(callback, deps);
5912 },
5913 useContext: function (context, observedBits) {
5914 currentHookNameInDev = 'useContext';
5915 warnInvalidHookAccess();
5916 return mountContext(context, observedBits);
5917 },
5918 useEffect: function (create, deps) {
5919 currentHookNameInDev = 'useEffect';
5920 warnInvalidHookAccess();
5921 return mountEffect(create, deps);
5922 },
5923 useImperativeHandle: function (ref, create, deps) {
5924 currentHookNameInDev = 'useImperativeHandle';
5925 warnInvalidHookAccess();
5926 return mountImperativeHandle(ref, create, deps);
5927 },
5928 useLayoutEffect: function (create, deps) {
5929 currentHookNameInDev = 'useLayoutEffect';
5930 warnInvalidHookAccess();
5931 return mountLayoutEffect(create, deps);
5932 },
5933 useMemo: function (create, deps) {
5934 currentHookNameInDev = 'useMemo';
5935 warnInvalidHookAccess();
5936 var prevDispatcher = ReactCurrentDispatcher$1.current;
5937 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5938 try {
5939 return mountMemo(create, deps);
5940 } finally {
5941 ReactCurrentDispatcher$1.current = prevDispatcher;
5942 }
5943 },
5944 useReducer: function (reducer, initialArg, init) {
5945 currentHookNameInDev = 'useReducer';
5946 warnInvalidHookAccess();
5947 var prevDispatcher = ReactCurrentDispatcher$1.current;
5948 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5949 try {
5950 return mountReducer(reducer, initialArg, init);
5951 } finally {
5952 ReactCurrentDispatcher$1.current = prevDispatcher;
5953 }
5954 },
5955 useRef: function (initialValue) {
5956 currentHookNameInDev = 'useRef';
5957 warnInvalidHookAccess();
5958 return mountRef(initialValue);
5959 },
5960 useState: function (initialState) {
5961 currentHookNameInDev = 'useState';
5962 warnInvalidHookAccess();
5963 var prevDispatcher = ReactCurrentDispatcher$1.current;
5964 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5965 try {
5966 return mountState(initialState);
5967 } finally {
5968 ReactCurrentDispatcher$1.current = prevDispatcher;
5969 }
5970 },
5971 useDebugValue: function (value, formatterFn) {
5972 currentHookNameInDev = 'useDebugValue';
5973 warnInvalidHookAccess();
5974 return mountDebugValue(value, formatterFn);
5975 }
5976 };
5977
5978 InvalidNestedHooksDispatcherOnUpdateInDEV = {
5979 readContext: function (context, observedBits) {
5980 warnInvalidContextAccess();
5981 return readContext(context, observedBits);
5982 },
5983 useCallback: function (callback, deps) {
5984 currentHookNameInDev = 'useCallback';
5985 warnInvalidHookAccess();
5986 return updateCallback(callback, deps);
5987 },
5988 useContext: function (context, observedBits) {
5989 currentHookNameInDev = 'useContext';
5990 warnInvalidHookAccess();
5991 return updateContext(context, observedBits);
5992 },
5993 useEffect: function (create, deps) {
5994 currentHookNameInDev = 'useEffect';
5995 warnInvalidHookAccess();
5996 return updateEffect(create, deps);
5997 },
5998 useImperativeHandle: function (ref, create, deps) {
5999 currentHookNameInDev = 'useImperativeHandle';
6000 warnInvalidHookAccess();
6001 return updateImperativeHandle(ref, create, deps);
6002 },
6003 useLayoutEffect: function (create, deps) {
6004 currentHookNameInDev = 'useLayoutEffect';
6005 warnInvalidHookAccess();
6006 return updateLayoutEffect(create, deps);
6007 },
6008 useMemo: function (create, deps) {
6009 currentHookNameInDev = 'useMemo';
6010 warnInvalidHookAccess();
6011 var prevDispatcher = ReactCurrentDispatcher$1.current;
6012 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6013 try {
6014 return updateMemo(create, deps);
6015 } finally {
6016 ReactCurrentDispatcher$1.current = prevDispatcher;
6017 }
6018 },
6019 useReducer: function (reducer, initialArg, init) {
6020 currentHookNameInDev = 'useReducer';
6021 warnInvalidHookAccess();
6022 var prevDispatcher = ReactCurrentDispatcher$1.current;
6023 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6024 try {
6025 return updateReducer(reducer, initialArg, init);
6026 } finally {
6027 ReactCurrentDispatcher$1.current = prevDispatcher;
6028 }
6029 },
6030 useRef: function (initialValue) {
6031 currentHookNameInDev = 'useRef';
6032 warnInvalidHookAccess();
6033 return updateRef(initialValue);
6034 },
6035 useState: function (initialState) {
6036 currentHookNameInDev = 'useState';
6037 warnInvalidHookAccess();
6038 var prevDispatcher = ReactCurrentDispatcher$1.current;
6039 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6040 try {
6041 return updateState(initialState);
6042 } finally {
6043 ReactCurrentDispatcher$1.current = prevDispatcher;
6044 }
6045 },
6046 useDebugValue: function (value, formatterFn) {
6047 currentHookNameInDev = 'useDebugValue';
6048 warnInvalidHookAccess();
6049 return updateDebugValue(value, formatterFn);
6050 }
6051 };
6052}
6053
6054var commitTime = 0;
6055var profilerStartTime = -1;
6056
6057function getCommitTime() {
6058 return commitTime;
6059}
6060
6061function recordCommitTime() {
6062 if (!enableProfilerTimer) {
6063 return;
6064 }
6065 commitTime = now();
6066}
6067
6068function startProfilerTimer(fiber) {
6069 if (!enableProfilerTimer) {
6070 return;
6071 }
6072
6073 profilerStartTime = now();
6074
6075 if (fiber.actualStartTime < 0) {
6076 fiber.actualStartTime = now();
6077 }
6078}
6079
6080function stopProfilerTimerIfRunning(fiber) {
6081 if (!enableProfilerTimer) {
6082 return;
6083 }
6084 profilerStartTime = -1;
6085}
6086
6087function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
6088 if (!enableProfilerTimer) {
6089 return;
6090 }
6091
6092 if (profilerStartTime >= 0) {
6093 var elapsedTime = now() - profilerStartTime;
6094 fiber.actualDuration += elapsedTime;
6095 if (overrideBaseTime) {
6096 fiber.selfBaseDuration = elapsedTime;
6097 }
6098 profilerStartTime = -1;
6099 }
6100}
6101
6102// The deepest Fiber on the stack involved in a hydration context.
6103// This may have been an insertion or a hydration.
6104var hydrationParentFiber = null;
6105var nextHydratableInstance = null;
6106var isHydrating = false;
6107
6108function enterHydrationState(fiber) {
6109 if (!supportsHydration) {
6110 return false;
6111 }
6112
6113 var parentInstance = fiber.stateNode.containerInfo;
6114 nextHydratableInstance = getFirstHydratableChild(parentInstance);
6115 hydrationParentFiber = fiber;
6116 isHydrating = true;
6117 return true;
6118}
6119
6120function deleteHydratableInstance(returnFiber, instance) {
6121 {
6122 switch (returnFiber.tag) {
6123 case HostRoot:
6124 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
6125 break;
6126 case HostComponent:
6127 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
6128 break;
6129 }
6130 }
6131
6132 var childToDelete = createFiberFromHostInstanceForDeletion();
6133 childToDelete.stateNode = instance;
6134 childToDelete.return = returnFiber;
6135 childToDelete.effectTag = Deletion;
6136
6137 // This might seem like it belongs on progressedFirstDeletion. However,
6138 // these children are not part of the reconciliation list of children.
6139 // Even if we abort and rereconcile the children, that will try to hydrate
6140 // again and the nodes are still in the host tree so these will be
6141 // recreated.
6142 if (returnFiber.lastEffect !== null) {
6143 returnFiber.lastEffect.nextEffect = childToDelete;
6144 returnFiber.lastEffect = childToDelete;
6145 } else {
6146 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
6147 }
6148}
6149
6150function insertNonHydratedInstance(returnFiber, fiber) {
6151 fiber.effectTag |= Placement;
6152 {
6153 switch (returnFiber.tag) {
6154 case HostRoot:
6155 {
6156 var parentContainer = returnFiber.stateNode.containerInfo;
6157 switch (fiber.tag) {
6158 case HostComponent:
6159 var type = fiber.type;
6160 var props = fiber.pendingProps;
6161 didNotFindHydratableContainerInstance(parentContainer, type, props);
6162 break;
6163 case HostText:
6164 var text = fiber.pendingProps;
6165 didNotFindHydratableContainerTextInstance(parentContainer, text);
6166 break;
6167 }
6168 break;
6169 }
6170 case HostComponent:
6171 {
6172 var parentType = returnFiber.type;
6173 var parentProps = returnFiber.memoizedProps;
6174 var parentInstance = returnFiber.stateNode;
6175 switch (fiber.tag) {
6176 case HostComponent:
6177 var _type = fiber.type;
6178 var _props = fiber.pendingProps;
6179 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
6180 break;
6181 case HostText:
6182 var _text = fiber.pendingProps;
6183 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
6184 break;
6185 }
6186 break;
6187 }
6188 default:
6189 return;
6190 }
6191 }
6192}
6193
6194function tryHydrate(fiber, nextInstance) {
6195 switch (fiber.tag) {
6196 case HostComponent:
6197 {
6198 var type = fiber.type;
6199 var props = fiber.pendingProps;
6200 var instance = canHydrateInstance(nextInstance, type, props);
6201 if (instance !== null) {
6202 fiber.stateNode = instance;
6203 return true;
6204 }
6205 return false;
6206 }
6207 case HostText:
6208 {
6209 var text = fiber.pendingProps;
6210 var textInstance = canHydrateTextInstance(nextInstance, text);
6211 if (textInstance !== null) {
6212 fiber.stateNode = textInstance;
6213 return true;
6214 }
6215 return false;
6216 }
6217 default:
6218 return false;
6219 }
6220}
6221
6222function tryToClaimNextHydratableInstance(fiber) {
6223 if (!isHydrating) {
6224 return;
6225 }
6226 var nextInstance = nextHydratableInstance;
6227 if (!nextInstance) {
6228 // Nothing to hydrate. Make it an insertion.
6229 insertNonHydratedInstance(hydrationParentFiber, fiber);
6230 isHydrating = false;
6231 hydrationParentFiber = fiber;
6232 return;
6233 }
6234 var firstAttemptedInstance = nextInstance;
6235 if (!tryHydrate(fiber, nextInstance)) {
6236 // If we can't hydrate this instance let's try the next one.
6237 // We use this as a heuristic. It's based on intuition and not data so it
6238 // might be flawed or unnecessary.
6239 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
6240 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
6241 // Nothing to hydrate. Make it an insertion.
6242 insertNonHydratedInstance(hydrationParentFiber, fiber);
6243 isHydrating = false;
6244 hydrationParentFiber = fiber;
6245 return;
6246 }
6247 // We matched the next one, we'll now assume that the first one was
6248 // superfluous and we'll delete it. Since we can't eagerly delete it
6249 // we'll have to schedule a deletion. To do that, this node needs a dummy
6250 // fiber associated with it.
6251 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
6252 }
6253 hydrationParentFiber = fiber;
6254 nextHydratableInstance = getFirstHydratableChild(nextInstance);
6255}
6256
6257function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
6258 if (!supportsHydration) {
6259 invariant(false, 'Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6260 }
6261
6262 var instance = fiber.stateNode;
6263 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber);
6264 // TODO: Type this specific to this type of component.
6265 fiber.updateQueue = updatePayload;
6266 // If the update payload indicates that there is a change or if there
6267 // is a new ref we mark this as an update.
6268 if (updatePayload !== null) {
6269 return true;
6270 }
6271 return false;
6272}
6273
6274function prepareToHydrateHostTextInstance(fiber) {
6275 if (!supportsHydration) {
6276 invariant(false, 'Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6277 }
6278
6279 var textInstance = fiber.stateNode;
6280 var textContent = fiber.memoizedProps;
6281 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
6282 {
6283 if (shouldUpdate) {
6284 // We assume that prepareToHydrateHostTextInstance is called in a context where the
6285 // hydration parent is the parent host component of this host text.
6286 var returnFiber = hydrationParentFiber;
6287 if (returnFiber !== null) {
6288 switch (returnFiber.tag) {
6289 case HostRoot:
6290 {
6291 var parentContainer = returnFiber.stateNode.containerInfo;
6292 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
6293 break;
6294 }
6295 case HostComponent:
6296 {
6297 var parentType = returnFiber.type;
6298 var parentProps = returnFiber.memoizedProps;
6299 var parentInstance = returnFiber.stateNode;
6300 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
6301 break;
6302 }
6303 }
6304 }
6305 }
6306 }
6307 return shouldUpdate;
6308}
6309
6310function popToNextHostParent(fiber) {
6311 var parent = fiber.return;
6312 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot) {
6313 parent = parent.return;
6314 }
6315 hydrationParentFiber = parent;
6316}
6317
6318function popHydrationState(fiber) {
6319 if (!supportsHydration) {
6320 return false;
6321 }
6322 if (fiber !== hydrationParentFiber) {
6323 // We're deeper than the current hydration context, inside an inserted
6324 // tree.
6325 return false;
6326 }
6327 if (!isHydrating) {
6328 // If we're not currently hydrating but we're in a hydration context, then
6329 // we were an insertion and now need to pop up reenter hydration of our
6330 // siblings.
6331 popToNextHostParent(fiber);
6332 isHydrating = true;
6333 return false;
6334 }
6335
6336 var type = fiber.type;
6337
6338 // If we have any remaining hydratable nodes, we need to delete them now.
6339 // We only do this deeper than head and body since they tend to have random
6340 // other nodes in them. We also ignore components with pure text content in
6341 // side of them.
6342 // TODO: Better heuristic.
6343 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
6344 var nextInstance = nextHydratableInstance;
6345 while (nextInstance) {
6346 deleteHydratableInstance(fiber, nextInstance);
6347 nextInstance = getNextHydratableSibling(nextInstance);
6348 }
6349 }
6350
6351 popToNextHostParent(fiber);
6352 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
6353 return true;
6354}
6355
6356function resetHydrationState() {
6357 if (!supportsHydration) {
6358 return;
6359 }
6360
6361 hydrationParentFiber = null;
6362 nextHydratableInstance = null;
6363 isHydrating = false;
6364}
6365
6366var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
6367
6368var didReceiveUpdate = false;
6369
6370var didWarnAboutBadClass = void 0;
6371var didWarnAboutContextTypeOnFunctionComponent = void 0;
6372var didWarnAboutGetDerivedStateOnFunctionComponent = void 0;
6373var didWarnAboutFunctionRefs = void 0;
6374var didWarnAboutReassigningProps = void 0;
6375
6376{
6377 didWarnAboutBadClass = {};
6378 didWarnAboutContextTypeOnFunctionComponent = {};
6379 didWarnAboutGetDerivedStateOnFunctionComponent = {};
6380 didWarnAboutFunctionRefs = {};
6381 didWarnAboutReassigningProps = false;
6382}
6383
6384function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6385 if (current$$1 === null) {
6386 // If this is a fresh new component that hasn't been rendered yet, we
6387 // won't update its child set by applying minimal side-effects. Instead,
6388 // we will add them all to the child before it gets rendered. That means
6389 // we can optimize this reconciliation pass by not tracking side-effects.
6390 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6391 } else {
6392 // If the current child is the same as the work in progress, it means that
6393 // we haven't yet started any work on these children. Therefore, we use
6394 // the clone algorithm to create a copy of all the current children.
6395
6396 // If we had any progressed work already, that is invalid at this point so
6397 // let's throw it out.
6398 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
6399 }
6400}
6401
6402function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6403 // This function is fork of reconcileChildren. It's used in cases where we
6404 // want to reconcile without matching against the existing set. This has the
6405 // effect of all current children being unmounted; even if the type and key
6406 // are the same, the old child is unmounted and a new child is created.
6407 //
6408 // To do this, we're going to go through the reconcile algorithm twice. In
6409 // the first pass, we schedule a deletion for all the current children by
6410 // passing null.
6411 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
6412 // In the second pass, we mount the new children. The trick here is that we
6413 // pass null in place of where we usually pass the current child set. This has
6414 // the effect of remounting all children regardless of whether their their
6415 // identity matches.
6416 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6417}
6418
6419function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6420 {
6421 if (workInProgress.type !== workInProgress.elementType) {
6422 // Lazy component props can't be validated in createElement
6423 // because they're only guaranteed to be resolved here.
6424 var innerPropTypes = Component.propTypes;
6425 if (innerPropTypes) {
6426 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6427 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6428 }
6429 }
6430 }
6431
6432 var render = Component.render;
6433 var ref = workInProgress.ref;
6434
6435 // The rest is a fork of updateFunctionComponent
6436 var nextChildren = void 0;
6437 prepareToReadContext(workInProgress, renderExpirationTime);
6438 {
6439 ReactCurrentOwner$2.current = workInProgress;
6440 setCurrentPhase('render');
6441 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6442 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6443 // Only double-render components with Hooks
6444 if (workInProgress.memoizedState !== null) {
6445 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6446 }
6447 }
6448 setCurrentPhase(null);
6449 }
6450
6451 if (current$$1 !== null && !didReceiveUpdate) {
6452 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6453 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6454 }
6455
6456 // React DevTools reads this flag.
6457 workInProgress.effectTag |= PerformedWork;
6458 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6459 return workInProgress.child;
6460}
6461
6462function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6463 if (current$$1 === null) {
6464 var type = Component.type;
6465 if (isSimpleFunctionComponent(type) && Component.compare === null &&
6466 // SimpleMemoComponent codepath doesn't resolve outer props either.
6467 Component.defaultProps === undefined) {
6468 // If this is a plain function component without default props,
6469 // and with only the default shallow comparison, we upgrade it
6470 // to a SimpleMemoComponent to allow fast path updates.
6471 workInProgress.tag = SimpleMemoComponent;
6472 workInProgress.type = type;
6473 {
6474 validateFunctionComponentInDev(workInProgress, type);
6475 }
6476 return updateSimpleMemoComponent(current$$1, workInProgress, type, nextProps, updateExpirationTime, renderExpirationTime);
6477 }
6478 {
6479 var innerPropTypes = type.propTypes;
6480 if (innerPropTypes) {
6481 // Inner memo component props aren't currently validated in createElement.
6482 // We could move it there, but we'd still need this for lazy code path.
6483 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6484 'prop', getComponentName(type), getCurrentFiberStackInDev);
6485 }
6486 }
6487 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
6488 child.ref = workInProgress.ref;
6489 child.return = workInProgress;
6490 workInProgress.child = child;
6491 return child;
6492 }
6493 {
6494 var _type = Component.type;
6495 var _innerPropTypes = _type.propTypes;
6496 if (_innerPropTypes) {
6497 // Inner memo component props aren't currently validated in createElement.
6498 // We could move it there, but we'd still need this for lazy code path.
6499 checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
6500 'prop', getComponentName(_type), getCurrentFiberStackInDev);
6501 }
6502 }
6503 var currentChild = current$$1.child; // This is always exactly one child
6504 if (updateExpirationTime < renderExpirationTime) {
6505 // This will be the props with resolved defaultProps,
6506 // unlike current.memoizedProps which will be the unresolved ones.
6507 var prevProps = currentChild.memoizedProps;
6508 // Default to shallow comparison
6509 var compare = Component.compare;
6510 compare = compare !== null ? compare : shallowEqual;
6511 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6512 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6513 }
6514 }
6515 // React DevTools reads this flag.
6516 workInProgress.effectTag |= PerformedWork;
6517 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
6518 newChild.ref = workInProgress.ref;
6519 newChild.return = workInProgress;
6520 workInProgress.child = newChild;
6521 return newChild;
6522}
6523
6524function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6525 {
6526 if (workInProgress.type !== workInProgress.elementType) {
6527 // Lazy component props can't be validated in createElement
6528 // because they're only guaranteed to be resolved here.
6529 var outerMemoType = workInProgress.elementType;
6530 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
6531 // We warn when you define propTypes on lazy()
6532 // so let's just skip over it to find memo() outer wrapper.
6533 // Inner props for memo are validated later.
6534 outerMemoType = refineResolvedLazyComponent(outerMemoType);
6535 }
6536 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
6537 if (outerPropTypes) {
6538 checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
6539 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
6540 }
6541 // Inner propTypes will be validated in the function component path.
6542 }
6543 }
6544 if (current$$1 !== null) {
6545 var prevProps = current$$1.memoizedProps;
6546 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6547 didReceiveUpdate = false;
6548 if (updateExpirationTime < renderExpirationTime) {
6549 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6550 }
6551 }
6552 }
6553 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6554}
6555
6556function updateFragment(current$$1, workInProgress, renderExpirationTime) {
6557 var nextChildren = workInProgress.pendingProps;
6558 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6559 return workInProgress.child;
6560}
6561
6562function updateMode(current$$1, workInProgress, renderExpirationTime) {
6563 var nextChildren = workInProgress.pendingProps.children;
6564 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6565 return workInProgress.child;
6566}
6567
6568function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
6569 if (enableProfilerTimer) {
6570 workInProgress.effectTag |= Update;
6571 }
6572 var nextProps = workInProgress.pendingProps;
6573 var nextChildren = nextProps.children;
6574 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6575 return workInProgress.child;
6576}
6577
6578function markRef(current$$1, workInProgress) {
6579 var ref = workInProgress.ref;
6580 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
6581 // Schedule a Ref effect
6582 workInProgress.effectTag |= Ref;
6583 }
6584}
6585
6586function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6587 {
6588 if (workInProgress.type !== workInProgress.elementType) {
6589 // Lazy component props can't be validated in createElement
6590 // because they're only guaranteed to be resolved here.
6591 var innerPropTypes = Component.propTypes;
6592 if (innerPropTypes) {
6593 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6594 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6595 }
6596 }
6597 }
6598
6599 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
6600 var context = getMaskedContext(workInProgress, unmaskedContext);
6601
6602 var nextChildren = void 0;
6603 prepareToReadContext(workInProgress, renderExpirationTime);
6604 {
6605 ReactCurrentOwner$2.current = workInProgress;
6606 setCurrentPhase('render');
6607 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6608 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6609 // Only double-render components with Hooks
6610 if (workInProgress.memoizedState !== null) {
6611 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6612 }
6613 }
6614 setCurrentPhase(null);
6615 }
6616
6617 if (current$$1 !== null && !didReceiveUpdate) {
6618 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6619 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6620 }
6621
6622 // React DevTools reads this flag.
6623 workInProgress.effectTag |= PerformedWork;
6624 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6625 return workInProgress.child;
6626}
6627
6628function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6629 {
6630 if (workInProgress.type !== workInProgress.elementType) {
6631 // Lazy component props can't be validated in createElement
6632 // because they're only guaranteed to be resolved here.
6633 var innerPropTypes = Component.propTypes;
6634 if (innerPropTypes) {
6635 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6636 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6637 }
6638 }
6639 }
6640
6641 // Push context providers early to prevent context stack mismatches.
6642 // During mounting we don't know the child context yet as the instance doesn't exist.
6643 // We will invalidate the child context in finishClassComponent() right after rendering.
6644 var hasContext = void 0;
6645 if (isContextProvider(Component)) {
6646 hasContext = true;
6647 pushContextProvider(workInProgress);
6648 } else {
6649 hasContext = false;
6650 }
6651 prepareToReadContext(workInProgress, renderExpirationTime);
6652
6653 var instance = workInProgress.stateNode;
6654 var shouldUpdate = void 0;
6655 if (instance === null) {
6656 if (current$$1 !== null) {
6657 // An class component without an instance only mounts if it suspended
6658 // inside a non- concurrent tree, in an inconsistent state. We want to
6659 // tree it like a new mount, even though an empty version of it already
6660 // committed. Disconnect the alternate pointers.
6661 current$$1.alternate = null;
6662 workInProgress.alternate = null;
6663 // Since this is conceptually a new fiber, schedule a Placement effect
6664 workInProgress.effectTag |= Placement;
6665 }
6666 // In the initial pass we might need to construct the instance.
6667 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6668 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6669 shouldUpdate = true;
6670 } else if (current$$1 === null) {
6671 // In a resume, we'll already have an instance we can reuse.
6672 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6673 } else {
6674 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6675 }
6676 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
6677 {
6678 var inst = workInProgress.stateNode;
6679 if (inst.props !== nextProps) {
6680 !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;
6681 didWarnAboutReassigningProps = true;
6682 }
6683 }
6684 return nextUnitOfWork;
6685}
6686
6687function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
6688 // Refs should update even if shouldComponentUpdate returns false
6689 markRef(current$$1, workInProgress);
6690
6691 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
6692
6693 if (!shouldUpdate && !didCaptureError) {
6694 // Context providers should defer to sCU for rendering
6695 if (hasContext) {
6696 invalidateContextProvider(workInProgress, Component, false);
6697 }
6698
6699 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6700 }
6701
6702 var instance = workInProgress.stateNode;
6703
6704 // Rerender
6705 ReactCurrentOwner$2.current = workInProgress;
6706 var nextChildren = void 0;
6707 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
6708 // If we captured an error, but getDerivedStateFrom catch is not defined,
6709 // unmount all the children. componentDidCatch will schedule an update to
6710 // re-render a fallback. This is temporary until we migrate everyone to
6711 // the new API.
6712 // TODO: Warn in a future release.
6713 nextChildren = null;
6714
6715 if (enableProfilerTimer) {
6716 stopProfilerTimerIfRunning(workInProgress);
6717 }
6718 } else {
6719 {
6720 setCurrentPhase('render');
6721 nextChildren = instance.render();
6722 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6723 instance.render();
6724 }
6725 setCurrentPhase(null);
6726 }
6727 }
6728
6729 // React DevTools reads this flag.
6730 workInProgress.effectTag |= PerformedWork;
6731 if (current$$1 !== null && didCaptureError) {
6732 // If we're recovering from an error, reconcile without reusing any of
6733 // the existing children. Conceptually, the normal children and the children
6734 // that are shown on error are two different sets, so we shouldn't reuse
6735 // normal children even if their identities match.
6736 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
6737 } else {
6738 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6739 }
6740
6741 // Memoize state using the values we just used to render.
6742 // TODO: Restructure so we never read values from the instance.
6743 workInProgress.memoizedState = instance.state;
6744
6745 // The context might have changed so we need to recalculate it.
6746 if (hasContext) {
6747 invalidateContextProvider(workInProgress, Component, true);
6748 }
6749
6750 return workInProgress.child;
6751}
6752
6753function pushHostRootContext(workInProgress) {
6754 var root = workInProgress.stateNode;
6755 if (root.pendingContext) {
6756 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
6757 } else if (root.context) {
6758 // Should always be set
6759 pushTopLevelContextObject(workInProgress, root.context, false);
6760 }
6761 pushHostContainer(workInProgress, root.containerInfo);
6762}
6763
6764function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
6765 pushHostRootContext(workInProgress);
6766 var updateQueue = workInProgress.updateQueue;
6767 !(updateQueue !== null) ? invariant(false, '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.') : void 0;
6768 var nextProps = workInProgress.pendingProps;
6769 var prevState = workInProgress.memoizedState;
6770 var prevChildren = prevState !== null ? prevState.element : null;
6771 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
6772 var nextState = workInProgress.memoizedState;
6773 // Caution: React DevTools currently depends on this property
6774 // being called "element".
6775 var nextChildren = nextState.element;
6776 if (nextChildren === prevChildren) {
6777 // If the state is the same as before, that's a bailout because we had
6778 // no work that expires at this time.
6779 resetHydrationState();
6780 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6781 }
6782 var root = workInProgress.stateNode;
6783 if ((current$$1 === null || current$$1.child === null) && root.hydrate && enterHydrationState(workInProgress)) {
6784 // If we don't have any current children this might be the first pass.
6785 // We always try to hydrate. If this isn't a hydration pass there won't
6786 // be any children to hydrate which is effectively the same thing as
6787 // not hydrating.
6788
6789 // This is a bit of a hack. We track the host root as a placement to
6790 // know that we're currently in a mounting state. That way isMounted
6791 // works as expected. We must reset this before committing.
6792 // TODO: Delete this when we delete isMounted and findDOMNode.
6793 workInProgress.effectTag |= Placement;
6794
6795 // Ensure that children mount into this root without tracking
6796 // side-effects. This ensures that we don't store Placement effects on
6797 // nodes that will be hydrated.
6798 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6799 } else {
6800 // Otherwise reset hydration state in case we aborted and resumed another
6801 // root.
6802 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6803 resetHydrationState();
6804 }
6805 return workInProgress.child;
6806}
6807
6808function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
6809 pushHostContext(workInProgress);
6810
6811 if (current$$1 === null) {
6812 tryToClaimNextHydratableInstance(workInProgress);
6813 }
6814
6815 var type = workInProgress.type;
6816 var nextProps = workInProgress.pendingProps;
6817 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
6818
6819 var nextChildren = nextProps.children;
6820 var isDirectTextChild = shouldSetTextContent(type, nextProps);
6821
6822 if (isDirectTextChild) {
6823 // We special case a direct text child of a host node. This is a common
6824 // case. We won't handle it as a reified child. We will instead handle
6825 // this in the host environment that also have access to this prop. That
6826 // avoids allocating another HostText fiber and traversing it.
6827 nextChildren = null;
6828 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
6829 // If we're switching from a direct text child to a normal child, or to
6830 // empty, we need to schedule the text content to be reset.
6831 workInProgress.effectTag |= ContentReset;
6832 }
6833
6834 markRef(current$$1, workInProgress);
6835
6836 // Check the host config to see if the children are offscreen/hidden.
6837 if (renderExpirationTime !== Never && workInProgress.mode & ConcurrentMode && shouldDeprioritizeSubtree(type, nextProps)) {
6838 // Schedule this fiber to re-render at offscreen priority. Then bailout.
6839 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
6840 return null;
6841 }
6842
6843 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6844 return workInProgress.child;
6845}
6846
6847function updateHostText(current$$1, workInProgress) {
6848 if (current$$1 === null) {
6849 tryToClaimNextHydratableInstance(workInProgress);
6850 }
6851 // Nothing to do here. This is terminal. We'll do the completion step
6852 // immediately after.
6853 return null;
6854}
6855
6856function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
6857 if (_current !== null) {
6858 // An lazy component only mounts if it suspended inside a non-
6859 // concurrent tree, in an inconsistent state. We want to treat it like
6860 // a new mount, even though an empty version of it already committed.
6861 // Disconnect the alternate pointers.
6862 _current.alternate = null;
6863 workInProgress.alternate = null;
6864 // Since this is conceptually a new fiber, schedule a Placement effect
6865 workInProgress.effectTag |= Placement;
6866 }
6867
6868 var props = workInProgress.pendingProps;
6869 // We can't start a User Timing measurement with correct label yet.
6870 // Cancel and resume right after we know the tag.
6871 cancelWorkTimer(workInProgress);
6872 var Component = readLazyComponentType(elementType);
6873 // Store the unwrapped component in the type.
6874 workInProgress.type = Component;
6875 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
6876 startWorkTimer(workInProgress);
6877 var resolvedProps = resolveDefaultProps(Component, props);
6878 var child = void 0;
6879 switch (resolvedTag) {
6880 case FunctionComponent:
6881 {
6882 {
6883 validateFunctionComponentInDev(workInProgress, Component);
6884 }
6885 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
6886 break;
6887 }
6888 case ClassComponent:
6889 {
6890 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
6891 break;
6892 }
6893 case ForwardRef:
6894 {
6895 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
6896 break;
6897 }
6898 case MemoComponent:
6899 {
6900 {
6901 if (workInProgress.type !== workInProgress.elementType) {
6902 var outerPropTypes = Component.propTypes;
6903 if (outerPropTypes) {
6904 checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
6905 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6906 }
6907 }
6908 }
6909 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
6910 updateExpirationTime, renderExpirationTime);
6911 break;
6912 }
6913 default:
6914 {
6915 var hint = '';
6916 {
6917 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
6918 hint = ' Did you wrap a component in React.lazy() more than once?';
6919 }
6920 }
6921 // This message intentionally doesn't mention ForwardRef or MemoComponent
6922 // because the fact that it's a separate type of work is an
6923 // implementation detail.
6924 invariant(false, 'Element type is invalid. Received a promise that resolves to: %s. Lazy element type must resolve to a class or function.%s', Component, hint);
6925 }
6926 }
6927 return child;
6928}
6929
6930function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
6931 if (_current !== null) {
6932 // An incomplete component only mounts if it suspended inside a non-
6933 // concurrent tree, in an inconsistent state. We want to treat it like
6934 // a new mount, even though an empty version of it already committed.
6935 // Disconnect the alternate pointers.
6936 _current.alternate = null;
6937 workInProgress.alternate = null;
6938 // Since this is conceptually a new fiber, schedule a Placement effect
6939 workInProgress.effectTag |= Placement;
6940 }
6941
6942 // Promote the fiber to a class and try rendering again.
6943 workInProgress.tag = ClassComponent;
6944
6945 // The rest of this function is a fork of `updateClassComponent`
6946
6947 // Push context providers early to prevent context stack mismatches.
6948 // During mounting we don't know the child context yet as the instance doesn't exist.
6949 // We will invalidate the child context in finishClassComponent() right after rendering.
6950 var hasContext = void 0;
6951 if (isContextProvider(Component)) {
6952 hasContext = true;
6953 pushContextProvider(workInProgress);
6954 } else {
6955 hasContext = false;
6956 }
6957 prepareToReadContext(workInProgress, renderExpirationTime);
6958
6959 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6960 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6961
6962 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
6963}
6964
6965function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
6966 if (_current !== null) {
6967 // An indeterminate component only mounts if it suspended inside a non-
6968 // concurrent tree, in an inconsistent state. We want to treat it like
6969 // a new mount, even though an empty version of it already committed.
6970 // Disconnect the alternate pointers.
6971 _current.alternate = null;
6972 workInProgress.alternate = null;
6973 // Since this is conceptually a new fiber, schedule a Placement effect
6974 workInProgress.effectTag |= Placement;
6975 }
6976
6977 var props = workInProgress.pendingProps;
6978 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
6979 var context = getMaskedContext(workInProgress, unmaskedContext);
6980
6981 prepareToReadContext(workInProgress, renderExpirationTime);
6982
6983 var value = void 0;
6984
6985 {
6986 if (Component.prototype && typeof Component.prototype.render === 'function') {
6987 var componentName = getComponentName(Component) || 'Unknown';
6988
6989 if (!didWarnAboutBadClass[componentName]) {
6990 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);
6991 didWarnAboutBadClass[componentName] = true;
6992 }
6993 }
6994
6995 if (workInProgress.mode & StrictMode) {
6996 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
6997 }
6998
6999 ReactCurrentOwner$2.current = workInProgress;
7000 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7001 }
7002 // React DevTools reads this flag.
7003 workInProgress.effectTag |= PerformedWork;
7004
7005 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
7006 // Proceed under the assumption that this is a class instance
7007 workInProgress.tag = ClassComponent;
7008
7009 // Throw out any hooks that were used.
7010 resetHooks();
7011
7012 // Push context providers early to prevent context stack mismatches.
7013 // During mounting we don't know the child context yet as the instance doesn't exist.
7014 // We will invalidate the child context in finishClassComponent() right after rendering.
7015 var hasContext = false;
7016 if (isContextProvider(Component)) {
7017 hasContext = true;
7018 pushContextProvider(workInProgress);
7019 } else {
7020 hasContext = false;
7021 }
7022
7023 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
7024
7025 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
7026 if (typeof getDerivedStateFromProps === 'function') {
7027 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
7028 }
7029
7030 adoptClassInstance(workInProgress, value);
7031 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
7032 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7033 } else {
7034 // Proceed under the assumption that this is a function component
7035 workInProgress.tag = FunctionComponent;
7036 {
7037 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
7038 // Only double-render components with Hooks
7039 if (workInProgress.memoizedState !== null) {
7040 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7041 }
7042 }
7043 }
7044 reconcileChildren(null, workInProgress, value, renderExpirationTime);
7045 {
7046 validateFunctionComponentInDev(workInProgress, Component);
7047 }
7048 return workInProgress.child;
7049 }
7050}
7051
7052function validateFunctionComponentInDev(workInProgress, Component) {
7053 if (Component) {
7054 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
7055 }
7056 if (workInProgress.ref !== null) {
7057 var info = '';
7058 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
7059 if (ownerName) {
7060 info += '\n\nCheck the render method of `' + ownerName + '`.';
7061 }
7062
7063 var warningKey = ownerName || workInProgress._debugID || '';
7064 var debugSource = workInProgress._debugSource;
7065 if (debugSource) {
7066 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
7067 }
7068 if (!didWarnAboutFunctionRefs[warningKey]) {
7069 didWarnAboutFunctionRefs[warningKey] = true;
7070 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);
7071 }
7072 }
7073
7074 if (typeof Component.getDerivedStateFromProps === 'function') {
7075 var componentName = getComponentName(Component) || 'Unknown';
7076
7077 if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) {
7078 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', componentName);
7079 didWarnAboutGetDerivedStateOnFunctionComponent[componentName] = true;
7080 }
7081 }
7082
7083 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
7084 var _componentName = getComponentName(Component) || 'Unknown';
7085
7086 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName]) {
7087 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName);
7088 didWarnAboutContextTypeOnFunctionComponent[_componentName] = true;
7089 }
7090 }
7091}
7092
7093function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7094 var mode = workInProgress.mode;
7095 var nextProps = workInProgress.pendingProps;
7096
7097 // We should attempt to render the primary children unless this boundary
7098 // already suspended during this render (`alreadyCaptured` is true).
7099 var nextState = workInProgress.memoizedState;
7100
7101 var nextDidTimeout = void 0;
7102 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7103 // This is the first attempt.
7104 nextState = null;
7105 nextDidTimeout = false;
7106 } else {
7107 // Something in this boundary's subtree already suspended. Switch to
7108 // rendering the fallback children.
7109 nextState = {
7110 timedOutAt: nextState !== null ? nextState.timedOutAt : NoWork
7111 };
7112 nextDidTimeout = true;
7113 workInProgress.effectTag &= ~DidCapture;
7114 }
7115
7116 // This next part is a bit confusing. If the children timeout, we switch to
7117 // showing the fallback children in place of the "primary" children.
7118 // However, we don't want to delete the primary children because then their
7119 // state will be lost (both the React state and the host state, e.g.
7120 // uncontrolled form inputs). Instead we keep them mounted and hide them.
7121 // Both the fallback children AND the primary children are rendered at the
7122 // same time. Once the primary children are un-suspended, we can delete
7123 // the fallback children — don't need to preserve their state.
7124 //
7125 // The two sets of children are siblings in the host environment, but
7126 // semantically, for purposes of reconciliation, they are two separate sets.
7127 // So we store them using two fragment fibers.
7128 //
7129 // However, we want to avoid allocating extra fibers for every placeholder.
7130 // They're only necessary when the children time out, because that's the
7131 // only time when both sets are mounted.
7132 //
7133 // So, the extra fragment fibers are only used if the children time out.
7134 // Otherwise, we render the primary children directly. This requires some
7135 // custom reconciliation logic to preserve the state of the primary
7136 // children. It's essentially a very basic form of re-parenting.
7137
7138 // `child` points to the child fiber. In the normal case, this is the first
7139 // fiber of the primary children set. In the timed-out case, it's a
7140 // a fragment fiber containing the primary children.
7141 var child = void 0;
7142 // `next` points to the next fiber React should render. In the normal case,
7143 // it's the same as `child`: the first fiber of the primary children set.
7144 // In the timed-out case, it's a fragment fiber containing the *fallback*
7145 // children -- we skip over the primary children entirely.
7146 var next = void 0;
7147 if (current$$1 === null) {
7148 // This is the initial mount. This branch is pretty simple because there's
7149 // no previous state that needs to be preserved.
7150 if (nextDidTimeout) {
7151 // Mount separate fragments for primary and fallback children.
7152 var nextFallbackChildren = nextProps.fallback;
7153 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
7154
7155 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7156 // Outside of concurrent mode, we commit the effects from the
7157 var progressedState = workInProgress.memoizedState;
7158 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
7159 primaryChildFragment.child = progressedPrimaryChild;
7160 }
7161
7162 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
7163 primaryChildFragment.sibling = fallbackChildFragment;
7164 child = primaryChildFragment;
7165 // Skip the primary children, and continue working on the
7166 // fallback children.
7167 next = fallbackChildFragment;
7168 child.return = next.return = workInProgress;
7169 } else {
7170 // Mount the primary children without an intermediate fragment fiber.
7171 var nextPrimaryChildren = nextProps.children;
7172 child = next = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
7173 }
7174 } else {
7175 // This is an update. This branch is more complicated because we need to
7176 // ensure the state of the primary children is preserved.
7177 var prevState = current$$1.memoizedState;
7178 var prevDidTimeout = prevState !== null;
7179 if (prevDidTimeout) {
7180 // The current tree already timed out. That means each child set is
7181 var currentPrimaryChildFragment = current$$1.child;
7182 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
7183 if (nextDidTimeout) {
7184 // Still timed out. Reuse the current primary children by cloning
7185 // its fragment. We're going to skip over these entirely.
7186 var _nextFallbackChildren = nextProps.fallback;
7187 var _primaryChildFragment = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
7188
7189 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7190 // Outside of concurrent mode, we commit the effects from the
7191 var _progressedState = workInProgress.memoizedState;
7192 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
7193 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
7194 _primaryChildFragment.child = _progressedPrimaryChild;
7195 }
7196 }
7197
7198 // Because primaryChildFragment is a new fiber that we're inserting as the
7199 // parent of a new tree, we need to set its treeBaseDuration.
7200 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7201 // treeBaseDuration is the sum of all the child tree base durations.
7202 var treeBaseDuration = 0;
7203 var hiddenChild = _primaryChildFragment.child;
7204 while (hiddenChild !== null) {
7205 treeBaseDuration += hiddenChild.treeBaseDuration;
7206 hiddenChild = hiddenChild.sibling;
7207 }
7208 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
7209 }
7210
7211 // Clone the fallback child fragment, too. These we'll continue
7212 // working on.
7213 var _fallbackChildFragment = _primaryChildFragment.sibling = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren, currentFallbackChildFragment.expirationTime);
7214 child = _primaryChildFragment;
7215 _primaryChildFragment.childExpirationTime = NoWork;
7216 // Skip the primary children, and continue working on the
7217 // fallback children.
7218 next = _fallbackChildFragment;
7219 child.return = next.return = workInProgress;
7220 } else {
7221 // No longer suspended. Switch back to showing the primary children,
7222 // and remove the intermediate fragment fiber.
7223 var _nextPrimaryChildren = nextProps.children;
7224 var currentPrimaryChild = currentPrimaryChildFragment.child;
7225 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime);
7226
7227 // If this render doesn't suspend, we need to delete the fallback
7228 // children. Wait until the complete phase, after we've confirmed the
7229 // fallback is no longer needed.
7230 // TODO: Would it be better to store the fallback fragment on
7231 // the stateNode?
7232
7233 // Continue rendering the children, like we normally do.
7234 child = next = primaryChild;
7235 }
7236 } else {
7237 // The current tree has not already timed out. That means the primary
7238 // children are not wrapped in a fragment fiber.
7239 var _currentPrimaryChild = current$$1.child;
7240 if (nextDidTimeout) {
7241 // Timed out. Wrap the children in a fragment fiber to keep them
7242 // separate from the fallback children.
7243 var _nextFallbackChildren2 = nextProps.fallback;
7244 var _primaryChildFragment2 = createFiberFromFragment(
7245 // It shouldn't matter what the pending props are because we aren't
7246 // going to render this fragment.
7247 null, mode, NoWork, null);
7248 _primaryChildFragment2.child = _currentPrimaryChild;
7249
7250 // Even though we're creating a new fiber, there are no new children,
7251 // because we're reusing an already mounted tree. So we don't need to
7252 // schedule a placement.
7253 // primaryChildFragment.effectTag |= Placement;
7254
7255 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7256 // Outside of concurrent mode, we commit the effects from the
7257 var _progressedState2 = workInProgress.memoizedState;
7258 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
7259 _primaryChildFragment2.child = _progressedPrimaryChild2;
7260 }
7261
7262 // Because primaryChildFragment is a new fiber that we're inserting as the
7263 // parent of a new tree, we need to set its treeBaseDuration.
7264 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7265 // treeBaseDuration is the sum of all the child tree base durations.
7266 var _treeBaseDuration = 0;
7267 var _hiddenChild = _primaryChildFragment2.child;
7268 while (_hiddenChild !== null) {
7269 _treeBaseDuration += _hiddenChild.treeBaseDuration;
7270 _hiddenChild = _hiddenChild.sibling;
7271 }
7272 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
7273 }
7274
7275 // Create a fragment from the fallback children, too.
7276 var _fallbackChildFragment2 = _primaryChildFragment2.sibling = createFiberFromFragment(_nextFallbackChildren2, mode, renderExpirationTime, null);
7277 _fallbackChildFragment2.effectTag |= Placement;
7278 child = _primaryChildFragment2;
7279 _primaryChildFragment2.childExpirationTime = NoWork;
7280 // Skip the primary children, and continue working on the
7281 // fallback children.
7282 next = _fallbackChildFragment2;
7283 child.return = next.return = workInProgress;
7284 } else {
7285 // Still haven't timed out. Continue rendering the children, like we
7286 // normally do.
7287 var _nextPrimaryChildren2 = nextProps.children;
7288 next = child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
7289 }
7290 }
7291 workInProgress.stateNode = current$$1.stateNode;
7292 }
7293
7294 workInProgress.memoizedState = nextState;
7295 workInProgress.child = child;
7296 return next;
7297}
7298
7299function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
7300 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7301 var nextChildren = workInProgress.pendingProps;
7302 if (current$$1 === null) {
7303 // Portals are special because we don't append the children during mount
7304 // but at commit. Therefore we need to track insertions which the normal
7305 // flow doesn't do during mount. This doesn't happen at the root because
7306 // the root always starts with a "current" with a null child.
7307 // TODO: Consider unifying this with how the root works.
7308 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7309 } else {
7310 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7311 }
7312 return workInProgress.child;
7313}
7314
7315function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
7316 var providerType = workInProgress.type;
7317 var context = providerType._context;
7318
7319 var newProps = workInProgress.pendingProps;
7320 var oldProps = workInProgress.memoizedProps;
7321
7322 var newValue = newProps.value;
7323
7324 {
7325 var providerPropTypes = workInProgress.type.propTypes;
7326
7327 if (providerPropTypes) {
7328 checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
7329 }
7330 }
7331
7332 pushProvider(workInProgress, newValue);
7333
7334 if (oldProps !== null) {
7335 var oldValue = oldProps.value;
7336 var changedBits = calculateChangedBits(context, newValue, oldValue);
7337 if (changedBits === 0) {
7338 // No change. Bailout early if children are the same.
7339 if (oldProps.children === newProps.children && !hasContextChanged()) {
7340 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7341 }
7342 } else {
7343 // The context value changed. Search for matching consumers and schedule
7344 // them to update.
7345 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
7346 }
7347 }
7348
7349 var newChildren = newProps.children;
7350 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7351 return workInProgress.child;
7352}
7353
7354var hasWarnedAboutUsingContextAsConsumer = false;
7355
7356function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
7357 var context = workInProgress.type;
7358 // The logic below for Context differs depending on PROD or DEV mode. In
7359 // DEV mode, we create a separate object for Context.Consumer that acts
7360 // like a proxy to Context. This proxy object adds unnecessary code in PROD
7361 // so we use the old behaviour (Context.Consumer references Context) to
7362 // reduce size and overhead. The separate object references context via
7363 // a property called "_context", which also gives us the ability to check
7364 // in DEV mode if this property exists or not and warn if it does not.
7365 {
7366 if (context._context === undefined) {
7367 // This may be because it's a Context (rather than a Consumer).
7368 // Or it may be because it's older React where they're the same thing.
7369 // We only want to warn if we're sure it's a new React.
7370 if (context !== context.Consumer) {
7371 if (!hasWarnedAboutUsingContextAsConsumer) {
7372 hasWarnedAboutUsingContextAsConsumer = true;
7373 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?');
7374 }
7375 }
7376 } else {
7377 context = context._context;
7378 }
7379 }
7380 var newProps = workInProgress.pendingProps;
7381 var render = newProps.children;
7382
7383 {
7384 !(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;
7385 }
7386
7387 prepareToReadContext(workInProgress, renderExpirationTime);
7388 var newValue = readContext(context, newProps.unstable_observedBits);
7389 var newChildren = void 0;
7390 {
7391 ReactCurrentOwner$2.current = workInProgress;
7392 setCurrentPhase('render');
7393 newChildren = render(newValue);
7394 setCurrentPhase(null);
7395 }
7396
7397 // React DevTools reads this flag.
7398 workInProgress.effectTag |= PerformedWork;
7399 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7400 return workInProgress.child;
7401}
7402
7403function markWorkInProgressReceivedUpdate() {
7404 didReceiveUpdate = true;
7405}
7406
7407function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
7408 cancelWorkTimer(workInProgress);
7409
7410 if (current$$1 !== null) {
7411 // Reuse previous context list
7412 workInProgress.contextDependencies = current$$1.contextDependencies;
7413 }
7414
7415 if (enableProfilerTimer) {
7416 // Don't update "base" render times for bailouts.
7417 stopProfilerTimerIfRunning(workInProgress);
7418 }
7419
7420 // Check if the children have any pending work.
7421 var childExpirationTime = workInProgress.childExpirationTime;
7422 if (childExpirationTime < renderExpirationTime) {
7423 // The children don't have any work either. We can skip them.
7424 // TODO: Once we add back resuming, we should check if the children are
7425 // a work-in-progress set. If so, we need to transfer their effects.
7426 return null;
7427 } else {
7428 // This fiber doesn't have work, but its subtree does. Clone the child
7429 // fibers and continue.
7430 cloneChildFibers(current$$1, workInProgress);
7431 return workInProgress.child;
7432 }
7433}
7434
7435function beginWork(current$$1, workInProgress, renderExpirationTime) {
7436 var updateExpirationTime = workInProgress.expirationTime;
7437
7438 if (current$$1 !== null) {
7439 var oldProps = current$$1.memoizedProps;
7440 var newProps = workInProgress.pendingProps;
7441
7442 if (oldProps !== newProps || hasContextChanged()) {
7443 // If props or context changed, mark the fiber as having performed work.
7444 // This may be unset if the props are determined to be equal later (memo).
7445 didReceiveUpdate = true;
7446 } else if (updateExpirationTime < renderExpirationTime) {
7447 didReceiveUpdate = false;
7448 // This fiber does not have any pending work. Bailout without entering
7449 // the begin phase. There's still some bookkeeping we that needs to be done
7450 // in this optimized path, mostly pushing stuff onto the stack.
7451 switch (workInProgress.tag) {
7452 case HostRoot:
7453 pushHostRootContext(workInProgress);
7454 resetHydrationState();
7455 break;
7456 case HostComponent:
7457 pushHostContext(workInProgress);
7458 break;
7459 case ClassComponent:
7460 {
7461 var Component = workInProgress.type;
7462 if (isContextProvider(Component)) {
7463 pushContextProvider(workInProgress);
7464 }
7465 break;
7466 }
7467 case HostPortal:
7468 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7469 break;
7470 case ContextProvider:
7471 {
7472 var newValue = workInProgress.memoizedProps.value;
7473 pushProvider(workInProgress, newValue);
7474 break;
7475 }
7476 case Profiler:
7477 if (enableProfilerTimer) {
7478 workInProgress.effectTag |= Update;
7479 }
7480 break;
7481 case SuspenseComponent:
7482 {
7483 var state = workInProgress.memoizedState;
7484 var didTimeout = state !== null;
7485 if (didTimeout) {
7486 // If this boundary is currently timed out, we need to decide
7487 // whether to retry the primary children, or to skip over it and
7488 // go straight to the fallback. Check the priority of the primary
7489 var primaryChildFragment = workInProgress.child;
7490 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
7491 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
7492 // The primary children have pending work. Use the normal path
7493 // to attempt to render the primary children again.
7494 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7495 } else {
7496 // The primary children do not have pending work with sufficient
7497 // priority. Bailout.
7498 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7499 if (child !== null) {
7500 // The fallback children have pending work. Skip over the
7501 // primary children and work on the fallback.
7502 return child.sibling;
7503 } else {
7504 return null;
7505 }
7506 }
7507 }
7508 break;
7509 }
7510 }
7511 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7512 }
7513 } else {
7514 didReceiveUpdate = false;
7515 }
7516
7517 // Before entering the begin phase, clear the expiration time.
7518 workInProgress.expirationTime = NoWork;
7519
7520 switch (workInProgress.tag) {
7521 case IndeterminateComponent:
7522 {
7523 var elementType = workInProgress.elementType;
7524 return mountIndeterminateComponent(current$$1, workInProgress, elementType, renderExpirationTime);
7525 }
7526 case LazyComponent:
7527 {
7528 var _elementType = workInProgress.elementType;
7529 return mountLazyComponent(current$$1, workInProgress, _elementType, updateExpirationTime, renderExpirationTime);
7530 }
7531 case FunctionComponent:
7532 {
7533 var _Component = workInProgress.type;
7534 var unresolvedProps = workInProgress.pendingProps;
7535 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
7536 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
7537 }
7538 case ClassComponent:
7539 {
7540 var _Component2 = workInProgress.type;
7541 var _unresolvedProps = workInProgress.pendingProps;
7542 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
7543 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
7544 }
7545 case HostRoot:
7546 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
7547 case HostComponent:
7548 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
7549 case HostText:
7550 return updateHostText(current$$1, workInProgress);
7551 case SuspenseComponent:
7552 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7553 case HostPortal:
7554 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
7555 case ForwardRef:
7556 {
7557 var type = workInProgress.type;
7558 var _unresolvedProps2 = workInProgress.pendingProps;
7559 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
7560 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
7561 }
7562 case Fragment:
7563 return updateFragment(current$$1, workInProgress, renderExpirationTime);
7564 case Mode:
7565 return updateMode(current$$1, workInProgress, renderExpirationTime);
7566 case Profiler:
7567 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
7568 case ContextProvider:
7569 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
7570 case ContextConsumer:
7571 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
7572 case MemoComponent:
7573 {
7574 var _type2 = workInProgress.type;
7575 var _unresolvedProps3 = workInProgress.pendingProps;
7576 // Resolve outer props first, then resolve inner props.
7577 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
7578 {
7579 if (workInProgress.type !== workInProgress.elementType) {
7580 var outerPropTypes = _type2.propTypes;
7581 if (outerPropTypes) {
7582 checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
7583 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
7584 }
7585 }
7586 }
7587 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
7588 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
7589 }
7590 case SimpleMemoComponent:
7591 {
7592 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
7593 }
7594 case IncompleteClassComponent:
7595 {
7596 var _Component3 = workInProgress.type;
7597 var _unresolvedProps4 = workInProgress.pendingProps;
7598 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
7599 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
7600 }
7601 default:
7602 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
7603 }
7604}
7605
7606var valueCursor = createCursor(null);
7607
7608var rendererSigil = void 0;
7609{
7610 // Use this to detect multiple renderers using the same context
7611 rendererSigil = {};
7612}
7613
7614var currentlyRenderingFiber = null;
7615var lastContextDependency = null;
7616var lastContextWithAllBitsObserved = null;
7617
7618var isDisallowedContextReadInDEV = false;
7619
7620function resetContextDependences() {
7621 // This is called right before React yields execution, to ensure `readContext`
7622 // cannot be called outside the render phase.
7623 currentlyRenderingFiber = null;
7624 lastContextDependency = null;
7625 lastContextWithAllBitsObserved = null;
7626 {
7627 isDisallowedContextReadInDEV = false;
7628 }
7629}
7630
7631function enterDisallowedContextReadInDEV() {
7632 {
7633 isDisallowedContextReadInDEV = true;
7634 }
7635}
7636
7637function exitDisallowedContextReadInDEV() {
7638 {
7639 isDisallowedContextReadInDEV = false;
7640 }
7641}
7642
7643function pushProvider(providerFiber, nextValue) {
7644 var context = providerFiber.type._context;
7645
7646 if (isPrimaryRenderer) {
7647 push(valueCursor, context._currentValue, providerFiber);
7648
7649 context._currentValue = nextValue;
7650 {
7651 !(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;
7652 context._currentRenderer = rendererSigil;
7653 }
7654 } else {
7655 push(valueCursor, context._currentValue2, providerFiber);
7656
7657 context._currentValue2 = nextValue;
7658 {
7659 !(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;
7660 context._currentRenderer2 = rendererSigil;
7661 }
7662 }
7663}
7664
7665function popProvider(providerFiber) {
7666 var currentValue = valueCursor.current;
7667
7668 pop(valueCursor, providerFiber);
7669
7670 var context = providerFiber.type._context;
7671 if (isPrimaryRenderer) {
7672 context._currentValue = currentValue;
7673 } else {
7674 context._currentValue2 = currentValue;
7675 }
7676}
7677
7678function calculateChangedBits(context, newValue, oldValue) {
7679 if (is(oldValue, newValue)) {
7680 // No change
7681 return 0;
7682 } else {
7683 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : maxSigned31BitInt;
7684
7685 {
7686 !((changedBits & maxSigned31BitInt) === changedBits) ? warning$1(false, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits) : void 0;
7687 }
7688 return changedBits | 0;
7689 }
7690}
7691
7692function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
7693 var fiber = workInProgress.child;
7694 if (fiber !== null) {
7695 // Set the return pointer of the child to the work-in-progress fiber.
7696 fiber.return = workInProgress;
7697 }
7698 while (fiber !== null) {
7699 var nextFiber = void 0;
7700
7701 // Visit this fiber.
7702 var list = fiber.contextDependencies;
7703 if (list !== null) {
7704 nextFiber = fiber.child;
7705
7706 var dependency = list.first;
7707 while (dependency !== null) {
7708 // Check if the context matches.
7709 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
7710 // Match! Schedule an update on this fiber.
7711
7712 if (fiber.tag === ClassComponent) {
7713 // Schedule a force update on the work-in-progress.
7714 var update = createUpdate(renderExpirationTime);
7715 update.tag = ForceUpdate;
7716 // TODO: Because we don't have a work-in-progress, this will add the
7717 // update to the current fiber, too, which means it will persist even if
7718 // this render is thrown away. Since it's a race condition, not sure it's
7719 // worth fixing.
7720 enqueueUpdate(fiber, update);
7721 }
7722
7723 if (fiber.expirationTime < renderExpirationTime) {
7724 fiber.expirationTime = renderExpirationTime;
7725 }
7726 var alternate = fiber.alternate;
7727 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
7728 alternate.expirationTime = renderExpirationTime;
7729 }
7730 // Update the child expiration time of all the ancestors, including
7731 // the alternates.
7732 var node = fiber.return;
7733 while (node !== null) {
7734 alternate = node.alternate;
7735 if (node.childExpirationTime < renderExpirationTime) {
7736 node.childExpirationTime = renderExpirationTime;
7737 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
7738 alternate.childExpirationTime = renderExpirationTime;
7739 }
7740 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
7741 alternate.childExpirationTime = renderExpirationTime;
7742 } else {
7743 // Neither alternate was updated, which means the rest of the
7744 // ancestor path already has sufficient priority.
7745 break;
7746 }
7747 node = node.return;
7748 }
7749
7750 // Mark the expiration time on the list, too.
7751 if (list.expirationTime < renderExpirationTime) {
7752 list.expirationTime = renderExpirationTime;
7753 }
7754
7755 // Since we already found a match, we can stop traversing the
7756 // dependency list.
7757 break;
7758 }
7759 dependency = dependency.next;
7760 }
7761 } else if (fiber.tag === ContextProvider) {
7762 // Don't scan deeper if this is a matching provider
7763 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
7764 } else {
7765 // Traverse down.
7766 nextFiber = fiber.child;
7767 }
7768
7769 if (nextFiber !== null) {
7770 // Set the return pointer of the child to the work-in-progress fiber.
7771 nextFiber.return = fiber;
7772 } else {
7773 // No child. Traverse to next sibling.
7774 nextFiber = fiber;
7775 while (nextFiber !== null) {
7776 if (nextFiber === workInProgress) {
7777 // We're back to the root of this subtree. Exit.
7778 nextFiber = null;
7779 break;
7780 }
7781 var sibling = nextFiber.sibling;
7782 if (sibling !== null) {
7783 // Set the return pointer of the sibling to the work-in-progress fiber.
7784 sibling.return = nextFiber.return;
7785 nextFiber = sibling;
7786 break;
7787 }
7788 // No more siblings. Traverse up.
7789 nextFiber = nextFiber.return;
7790 }
7791 }
7792 fiber = nextFiber;
7793 }
7794}
7795
7796function prepareToReadContext(workInProgress, renderExpirationTime) {
7797 currentlyRenderingFiber = workInProgress;
7798 lastContextDependency = null;
7799 lastContextWithAllBitsObserved = null;
7800
7801 var currentDependencies = workInProgress.contextDependencies;
7802 if (currentDependencies !== null && currentDependencies.expirationTime >= renderExpirationTime) {
7803 // Context list has a pending update. Mark that this fiber performed work.
7804 markWorkInProgressReceivedUpdate();
7805 }
7806
7807 // Reset the work-in-progress list
7808 workInProgress.contextDependencies = null;
7809}
7810
7811function readContext(context, observedBits) {
7812 {
7813 // This warning would fire if you read context inside a Hook like useMemo.
7814 // Unlike the class check below, it's not enforced in production for perf.
7815 !!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;
7816 }
7817
7818 if (lastContextWithAllBitsObserved === context) {
7819 // Nothing to do. We already observe everything in this context.
7820 } else if (observedBits === false || observedBits === 0) {
7821 // Do not observe any updates.
7822 } else {
7823 var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types.
7824 if (typeof observedBits !== 'number' || observedBits === maxSigned31BitInt) {
7825 // Observe all updates.
7826 lastContextWithAllBitsObserved = context;
7827 resolvedObservedBits = maxSigned31BitInt;
7828 } else {
7829 resolvedObservedBits = observedBits;
7830 }
7831
7832 var contextItem = {
7833 context: context,
7834 observedBits: resolvedObservedBits,
7835 next: null
7836 };
7837
7838 if (lastContextDependency === null) {
7839 !(currentlyRenderingFiber !== null) ? invariant(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;
7840
7841 // This is the first dependency for this component. Create a new list.
7842 lastContextDependency = contextItem;
7843 currentlyRenderingFiber.contextDependencies = {
7844 first: contextItem,
7845 expirationTime: NoWork
7846 };
7847 } else {
7848 // Append a new context item.
7849 lastContextDependency = lastContextDependency.next = contextItem;
7850 }
7851 }
7852 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
7853}
7854
7855// UpdateQueue is a linked list of prioritized updates.
7856//
7857// Like fibers, update queues come in pairs: a current queue, which represents
7858// the visible state of the screen, and a work-in-progress queue, which can be
7859// mutated and processed asynchronously before it is committed — a form of
7860// double buffering. If a work-in-progress render is discarded before finishing,
7861// we create a new work-in-progress by cloning the current queue.
7862//
7863// Both queues share a persistent, singly-linked list structure. To schedule an
7864// update, we append it to the end of both queues. Each queue maintains a
7865// pointer to first update in the persistent list that hasn't been processed.
7866// The work-in-progress pointer always has a position equal to or greater than
7867// the current queue, since we always work on that one. The current queue's
7868// pointer is only updated during the commit phase, when we swap in the
7869// work-in-progress.
7870//
7871// For example:
7872//
7873// Current pointer: A - B - C - D - E - F
7874// Work-in-progress pointer: D - E - F
7875// ^
7876// The work-in-progress queue has
7877// processed more updates than current.
7878//
7879// The reason we append to both queues is because otherwise we might drop
7880// updates without ever processing them. For example, if we only add updates to
7881// the work-in-progress queue, some updates could be lost whenever a work-in
7882// -progress render restarts by cloning from current. Similarly, if we only add
7883// updates to the current queue, the updates will be lost whenever an already
7884// in-progress queue commits and swaps with the current queue. However, by
7885// adding to both queues, we guarantee that the update will be part of the next
7886// work-in-progress. (And because the work-in-progress queue becomes the
7887// current queue once it commits, there's no danger of applying the same
7888// update twice.)
7889//
7890// Prioritization
7891// --------------
7892//
7893// Updates are not sorted by priority, but by insertion; new updates are always
7894// appended to the end of the list.
7895//
7896// The priority is still important, though. When processing the update queue
7897// during the render phase, only the updates with sufficient priority are
7898// included in the result. If we skip an update because it has insufficient
7899// priority, it remains in the queue to be processed later, during a lower
7900// priority render. Crucially, all updates subsequent to a skipped update also
7901// remain in the queue *regardless of their priority*. That means high priority
7902// updates are sometimes processed twice, at two separate priorities. We also
7903// keep track of a base state, that represents the state before the first
7904// update in the queue is applied.
7905//
7906// For example:
7907//
7908// Given a base state of '', and the following queue of updates
7909//
7910// A1 - B2 - C1 - D2
7911//
7912// where the number indicates the priority, and the update is applied to the
7913// previous state by appending a letter, React will process these updates as
7914// two separate renders, one per distinct priority level:
7915//
7916// First render, at priority 1:
7917// Base state: ''
7918// Updates: [A1, C1]
7919// Result state: 'AC'
7920//
7921// Second render, at priority 2:
7922// Base state: 'A' <- The base state does not include C1,
7923// because B2 was skipped.
7924// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
7925// Result state: 'ABCD'
7926//
7927// Because we process updates in insertion order, and rebase high priority
7928// updates when preceding updates are skipped, the final result is deterministic
7929// regardless of priority. Intermediate state may vary according to system
7930// resources, but the final state is always the same.
7931
7932var UpdateState = 0;
7933var ReplaceState = 1;
7934var ForceUpdate = 2;
7935var CaptureUpdate = 3;
7936
7937// Global state that is reset at the beginning of calling `processUpdateQueue`.
7938// It should only be read right after calling `processUpdateQueue`, via
7939// `checkHasForceUpdateAfterProcessing`.
7940var hasForceUpdate = false;
7941
7942var didWarnUpdateInsideUpdate = void 0;
7943var currentlyProcessingQueue = void 0;
7944var resetCurrentlyProcessingQueue = void 0;
7945{
7946 didWarnUpdateInsideUpdate = false;
7947 currentlyProcessingQueue = null;
7948 resetCurrentlyProcessingQueue = function () {
7949 currentlyProcessingQueue = null;
7950 };
7951}
7952
7953function createUpdateQueue(baseState) {
7954 var queue = {
7955 baseState: baseState,
7956 firstUpdate: null,
7957 lastUpdate: null,
7958 firstCapturedUpdate: null,
7959 lastCapturedUpdate: null,
7960 firstEffect: null,
7961 lastEffect: null,
7962 firstCapturedEffect: null,
7963 lastCapturedEffect: null
7964 };
7965 return queue;
7966}
7967
7968function cloneUpdateQueue(currentQueue) {
7969 var queue = {
7970 baseState: currentQueue.baseState,
7971 firstUpdate: currentQueue.firstUpdate,
7972 lastUpdate: currentQueue.lastUpdate,
7973
7974 // TODO: With resuming, if we bail out and resuse the child tree, we should
7975 // keep these effects.
7976 firstCapturedUpdate: null,
7977 lastCapturedUpdate: null,
7978
7979 firstEffect: null,
7980 lastEffect: null,
7981
7982 firstCapturedEffect: null,
7983 lastCapturedEffect: null
7984 };
7985 return queue;
7986}
7987
7988function createUpdate(expirationTime) {
7989 return {
7990 expirationTime: expirationTime,
7991
7992 tag: UpdateState,
7993 payload: null,
7994 callback: null,
7995
7996 next: null,
7997 nextEffect: null
7998 };
7999}
8000
8001function appendUpdateToQueue(queue, update) {
8002 // Append the update to the end of the list.
8003 if (queue.lastUpdate === null) {
8004 // Queue is empty
8005 queue.firstUpdate = queue.lastUpdate = update;
8006 } else {
8007 queue.lastUpdate.next = update;
8008 queue.lastUpdate = update;
8009 }
8010}
8011
8012function enqueueUpdate(fiber, update) {
8013 // Update queues are created lazily.
8014 var alternate = fiber.alternate;
8015 var queue1 = void 0;
8016 var queue2 = void 0;
8017 if (alternate === null) {
8018 // There's only one fiber.
8019 queue1 = fiber.updateQueue;
8020 queue2 = null;
8021 if (queue1 === null) {
8022 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8023 }
8024 } else {
8025 // There are two owners.
8026 queue1 = fiber.updateQueue;
8027 queue2 = alternate.updateQueue;
8028 if (queue1 === null) {
8029 if (queue2 === null) {
8030 // Neither fiber has an update queue. Create new ones.
8031 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8032 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
8033 } else {
8034 // Only one fiber has an update queue. Clone to create a new one.
8035 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
8036 }
8037 } else {
8038 if (queue2 === null) {
8039 // Only one fiber has an update queue. Clone to create a new one.
8040 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
8041 } else {
8042 // Both owners have an update queue.
8043 }
8044 }
8045 }
8046 if (queue2 === null || queue1 === queue2) {
8047 // There's only a single queue.
8048 appendUpdateToQueue(queue1, update);
8049 } else {
8050 // There are two queues. We need to append the update to both queues,
8051 // while accounting for the persistent structure of the list — we don't
8052 // want the same update to be added multiple times.
8053 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
8054 // One of the queues is not empty. We must add the update to both queues.
8055 appendUpdateToQueue(queue1, update);
8056 appendUpdateToQueue(queue2, update);
8057 } else {
8058 // Both queues are non-empty. The last update is the same in both lists,
8059 // because of structural sharing. So, only append to one of the lists.
8060 appendUpdateToQueue(queue1, update);
8061 // But we still need to update the `lastUpdate` pointer of queue2.
8062 queue2.lastUpdate = update;
8063 }
8064 }
8065
8066 {
8067 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
8068 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.');
8069 didWarnUpdateInsideUpdate = true;
8070 }
8071 }
8072}
8073
8074function enqueueCapturedUpdate(workInProgress, update) {
8075 // Captured updates go into a separate list, and only on the work-in-
8076 // progress queue.
8077 var workInProgressQueue = workInProgress.updateQueue;
8078 if (workInProgressQueue === null) {
8079 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
8080 } else {
8081 // TODO: I put this here rather than createWorkInProgress so that we don't
8082 // clone the queue unnecessarily. There's probably a better way to
8083 // structure this.
8084 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
8085 }
8086
8087 // Append the update to the end of the list.
8088 if (workInProgressQueue.lastCapturedUpdate === null) {
8089 // This is the first render phase update
8090 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
8091 } else {
8092 workInProgressQueue.lastCapturedUpdate.next = update;
8093 workInProgressQueue.lastCapturedUpdate = update;
8094 }
8095}
8096
8097function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
8098 var current = workInProgress.alternate;
8099 if (current !== null) {
8100 // If the work-in-progress queue is equal to the current queue,
8101 // we need to clone it first.
8102 if (queue === current.updateQueue) {
8103 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
8104 }
8105 }
8106 return queue;
8107}
8108
8109function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
8110 switch (update.tag) {
8111 case ReplaceState:
8112 {
8113 var _payload = update.payload;
8114 if (typeof _payload === 'function') {
8115 // Updater function
8116 {
8117 enterDisallowedContextReadInDEV();
8118 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8119 _payload.call(instance, prevState, nextProps);
8120 }
8121 }
8122 var nextState = _payload.call(instance, prevState, nextProps);
8123 {
8124 exitDisallowedContextReadInDEV();
8125 }
8126 return nextState;
8127 }
8128 // State object
8129 return _payload;
8130 }
8131 case CaptureUpdate:
8132 {
8133 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
8134 }
8135 // Intentional fallthrough
8136 case UpdateState:
8137 {
8138 var _payload2 = update.payload;
8139 var partialState = void 0;
8140 if (typeof _payload2 === 'function') {
8141 // Updater function
8142 {
8143 enterDisallowedContextReadInDEV();
8144 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8145 _payload2.call(instance, prevState, nextProps);
8146 }
8147 }
8148 partialState = _payload2.call(instance, prevState, nextProps);
8149 {
8150 exitDisallowedContextReadInDEV();
8151 }
8152 } else {
8153 // Partial state object
8154 partialState = _payload2;
8155 }
8156 if (partialState === null || partialState === undefined) {
8157 // Null and undefined are treated as no-ops.
8158 return prevState;
8159 }
8160 // Merge the partial state and the previous state.
8161 return _assign({}, prevState, partialState);
8162 }
8163 case ForceUpdate:
8164 {
8165 hasForceUpdate = true;
8166 return prevState;
8167 }
8168 }
8169 return prevState;
8170}
8171
8172function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
8173 hasForceUpdate = false;
8174
8175 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
8176
8177 {
8178 currentlyProcessingQueue = queue;
8179 }
8180
8181 // These values may change as we process the queue.
8182 var newBaseState = queue.baseState;
8183 var newFirstUpdate = null;
8184 var newExpirationTime = NoWork;
8185
8186 // Iterate through the list of updates to compute the result.
8187 var update = queue.firstUpdate;
8188 var resultState = newBaseState;
8189 while (update !== null) {
8190 var updateExpirationTime = update.expirationTime;
8191 if (updateExpirationTime < renderExpirationTime) {
8192 // This update does not have sufficient priority. Skip it.
8193 if (newFirstUpdate === null) {
8194 // This is the first skipped update. It will be the first update in
8195 // the new list.
8196 newFirstUpdate = update;
8197 // Since this is the first update that was skipped, the current result
8198 // is the new base state.
8199 newBaseState = resultState;
8200 }
8201 // Since this update will remain in the list, update the remaining
8202 // expiration time.
8203 if (newExpirationTime < updateExpirationTime) {
8204 newExpirationTime = updateExpirationTime;
8205 }
8206 } else {
8207 // This update does have sufficient priority. Process it and compute
8208 // a new result.
8209 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8210 var _callback = update.callback;
8211 if (_callback !== null) {
8212 workInProgress.effectTag |= Callback;
8213 // Set this to null, in case it was mutated during an aborted render.
8214 update.nextEffect = null;
8215 if (queue.lastEffect === null) {
8216 queue.firstEffect = queue.lastEffect = update;
8217 } else {
8218 queue.lastEffect.nextEffect = update;
8219 queue.lastEffect = update;
8220 }
8221 }
8222 }
8223 // Continue to the next update.
8224 update = update.next;
8225 }
8226
8227 // Separately, iterate though the list of captured updates.
8228 var newFirstCapturedUpdate = null;
8229 update = queue.firstCapturedUpdate;
8230 while (update !== null) {
8231 var _updateExpirationTime = update.expirationTime;
8232 if (_updateExpirationTime < renderExpirationTime) {
8233 // This update does not have sufficient priority. Skip it.
8234 if (newFirstCapturedUpdate === null) {
8235 // This is the first skipped captured update. It will be the first
8236 // update in the new list.
8237 newFirstCapturedUpdate = update;
8238 // If this is the first update that was skipped, the current result is
8239 // the new base state.
8240 if (newFirstUpdate === null) {
8241 newBaseState = resultState;
8242 }
8243 }
8244 // Since this update will remain in the list, update the remaining
8245 // expiration time.
8246 if (newExpirationTime < _updateExpirationTime) {
8247 newExpirationTime = _updateExpirationTime;
8248 }
8249 } else {
8250 // This update does have sufficient priority. Process it and compute
8251 // a new result.
8252 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8253 var _callback2 = update.callback;
8254 if (_callback2 !== null) {
8255 workInProgress.effectTag |= Callback;
8256 // Set this to null, in case it was mutated during an aborted render.
8257 update.nextEffect = null;
8258 if (queue.lastCapturedEffect === null) {
8259 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
8260 } else {
8261 queue.lastCapturedEffect.nextEffect = update;
8262 queue.lastCapturedEffect = update;
8263 }
8264 }
8265 }
8266 update = update.next;
8267 }
8268
8269 if (newFirstUpdate === null) {
8270 queue.lastUpdate = null;
8271 }
8272 if (newFirstCapturedUpdate === null) {
8273 queue.lastCapturedUpdate = null;
8274 } else {
8275 workInProgress.effectTag |= Callback;
8276 }
8277 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
8278 // We processed every update, without skipping. That means the new base
8279 // state is the same as the result state.
8280 newBaseState = resultState;
8281 }
8282
8283 queue.baseState = newBaseState;
8284 queue.firstUpdate = newFirstUpdate;
8285 queue.firstCapturedUpdate = newFirstCapturedUpdate;
8286
8287 // Set the remaining expiration time to be whatever is remaining in the queue.
8288 // This should be fine because the only two other things that contribute to
8289 // expiration time are props and context. We're already in the middle of the
8290 // begin phase by the time we start processing the queue, so we've already
8291 // dealt with the props. Context in components that specify
8292 // shouldComponentUpdate is tricky; but we'll have to account for
8293 // that regardless.
8294 workInProgress.expirationTime = newExpirationTime;
8295 workInProgress.memoizedState = resultState;
8296
8297 {
8298 currentlyProcessingQueue = null;
8299 }
8300}
8301
8302function callCallback(callback, context) {
8303 !(typeof callback === 'function') ? invariant(false, 'Invalid argument passed as callback. Expected a function. Instead received: %s', callback) : void 0;
8304 callback.call(context);
8305}
8306
8307function resetHasForceUpdateBeforeProcessing() {
8308 hasForceUpdate = false;
8309}
8310
8311function checkHasForceUpdateAfterProcessing() {
8312 return hasForceUpdate;
8313}
8314
8315function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
8316 // If the finished render included captured updates, and there are still
8317 // lower priority updates left over, we need to keep the captured updates
8318 // in the queue so that they are rebased and not dropped once we process the
8319 // queue again at the lower priority.
8320 if (finishedQueue.firstCapturedUpdate !== null) {
8321 // Join the captured update list to the end of the normal list.
8322 if (finishedQueue.lastUpdate !== null) {
8323 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
8324 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
8325 }
8326 // Clear the list of captured updates.
8327 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
8328 }
8329
8330 // Commit the effects
8331 commitUpdateEffects(finishedQueue.firstEffect, instance);
8332 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
8333
8334 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
8335 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
8336}
8337
8338function commitUpdateEffects(effect, instance) {
8339 while (effect !== null) {
8340 var _callback3 = effect.callback;
8341 if (_callback3 !== null) {
8342 effect.callback = null;
8343 callCallback(_callback3, instance);
8344 }
8345 effect = effect.nextEffect;
8346 }
8347}
8348
8349function createCapturedValue(value, source) {
8350 // If the value is an error, call this function immediately after it is thrown
8351 // so the stack is accurate.
8352 return {
8353 value: value,
8354 source: source,
8355 stack: getStackByFiberInDevAndProd(source)
8356 };
8357}
8358
8359function markUpdate(workInProgress) {
8360 // Tag the fiber with an update effect. This turns a Placement into
8361 // a PlacementAndUpdate.
8362 workInProgress.effectTag |= Update;
8363}
8364
8365function markRef$1(workInProgress) {
8366 workInProgress.effectTag |= Ref;
8367}
8368
8369var appendAllChildren = void 0;
8370var updateHostContainer = void 0;
8371var updateHostComponent$1 = void 0;
8372var updateHostText$1 = void 0;
8373if (supportsMutation) {
8374 // Mutation mode
8375
8376 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8377 // We only have the top Fiber that was created but we need recurse down its
8378 // children to find all the terminal nodes.
8379 var node = workInProgress.child;
8380 while (node !== null) {
8381 if (node.tag === HostComponent || node.tag === HostText) {
8382 appendInitialChild(parent, node.stateNode);
8383 } else if (node.tag === HostPortal) {
8384 // If we have a portal child, then we don't want to traverse
8385 // down its children. Instead, we'll get insertions from each child in
8386 // the portal directly.
8387 } else if (node.child !== null) {
8388 node.child.return = node;
8389 node = node.child;
8390 continue;
8391 }
8392 if (node === workInProgress) {
8393 return;
8394 }
8395 while (node.sibling === null) {
8396 if (node.return === null || node.return === workInProgress) {
8397 return;
8398 }
8399 node = node.return;
8400 }
8401 node.sibling.return = node.return;
8402 node = node.sibling;
8403 }
8404 };
8405
8406 updateHostContainer = function (workInProgress) {
8407 // Noop
8408 };
8409 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8410 // If we have an alternate, that means this is an update and we need to
8411 // schedule a side-effect to do the updates.
8412 var oldProps = current.memoizedProps;
8413 if (oldProps === newProps) {
8414 // In mutation mode, this is sufficient for a bailout because
8415 // we won't touch this node even if children changed.
8416 return;
8417 }
8418
8419 // If we get updated because one of our children updated, we don't
8420 // have newProps so we'll have to reuse them.
8421 // TODO: Split the update API as separate for the props vs. children.
8422 // Even better would be if children weren't special cased at all tho.
8423 var instance = workInProgress.stateNode;
8424 var currentHostContext = getHostContext();
8425 // TODO: Experiencing an error where oldProps is null. Suggests a host
8426 // component is hitting the resume path. Figure out why. Possibly
8427 // related to `hidden`.
8428 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8429 // TODO: Type this specific to this type of component.
8430 workInProgress.updateQueue = updatePayload;
8431 // If the update payload indicates that there is a change or if there
8432 // is a new ref we mark this as an update. All the work is done in commitWork.
8433 if (updatePayload) {
8434 markUpdate(workInProgress);
8435 }
8436 };
8437 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8438 // If the text differs, mark it as an update. All the work in done in commitWork.
8439 if (oldText !== newText) {
8440 markUpdate(workInProgress);
8441 }
8442 };
8443} else if (supportsPersistence) {
8444 // Persistent host tree mode
8445
8446 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8447 // We only have the top Fiber that was created but we need recurse down its
8448 // children to find all the terminal nodes.
8449 var node = workInProgress.child;
8450 while (node !== null) {
8451 // eslint-disable-next-line no-labels
8452 branches: if (node.tag === HostComponent) {
8453 var instance = node.stateNode;
8454 if (needsVisibilityToggle) {
8455 var props = node.memoizedProps;
8456 var type = node.type;
8457 if (isHidden) {
8458 // This child is inside a timed out tree. Hide it.
8459 instance = cloneHiddenInstance(instance, type, props, node);
8460 } else {
8461 // This child was previously inside a timed out tree. If it was not
8462 // updated during this render, it may need to be unhidden. Clone
8463 // again to be sure.
8464 instance = cloneUnhiddenInstance(instance, type, props, node);
8465 }
8466 node.stateNode = instance;
8467 }
8468 appendInitialChild(parent, instance);
8469 } else if (node.tag === HostText) {
8470 var _instance = node.stateNode;
8471 if (needsVisibilityToggle) {
8472 var text = node.memoizedProps;
8473 var rootContainerInstance = getRootHostContainer();
8474 var currentHostContext = getHostContext();
8475 if (isHidden) {
8476 _instance = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8477 } else {
8478 _instance = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8479 }
8480 node.stateNode = _instance;
8481 }
8482 appendInitialChild(parent, _instance);
8483 } else if (node.tag === HostPortal) {
8484 // If we have a portal child, then we don't want to traverse
8485 // down its children. Instead, we'll get insertions from each child in
8486 // the portal directly.
8487 } else if (node.tag === SuspenseComponent) {
8488 var current = node.alternate;
8489 if (current !== null) {
8490 var oldState = current.memoizedState;
8491 var newState = node.memoizedState;
8492 var oldIsHidden = oldState !== null;
8493 var newIsHidden = newState !== null;
8494 if (oldIsHidden !== newIsHidden) {
8495 // The placeholder either just timed out or switched back to the normal
8496 // children after having previously timed out. Toggle the visibility of
8497 // the direct host children.
8498 var primaryChildParent = newIsHidden ? node.child : node;
8499 if (primaryChildParent !== null) {
8500 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
8501 }
8502 // eslint-disable-next-line no-labels
8503 break branches;
8504 }
8505 }
8506 if (node.child !== null) {
8507 // Continue traversing like normal
8508 node.child.return = node;
8509 node = node.child;
8510 continue;
8511 }
8512 } else if (node.child !== null) {
8513 node.child.return = node;
8514 node = node.child;
8515 continue;
8516 }
8517 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8518 node = node;
8519 if (node === workInProgress) {
8520 return;
8521 }
8522 while (node.sibling === null) {
8523 if (node.return === null || node.return === workInProgress) {
8524 return;
8525 }
8526 node = node.return;
8527 }
8528 node.sibling.return = node.return;
8529 node = node.sibling;
8530 }
8531 };
8532
8533 // An unfortunate fork of appendAllChildren because we have two different parent types.
8534 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
8535 // We only have the top Fiber that was created but we need recurse down its
8536 // children to find all the terminal nodes.
8537 var node = workInProgress.child;
8538 while (node !== null) {
8539 // eslint-disable-next-line no-labels
8540 branches: if (node.tag === HostComponent) {
8541 var instance = node.stateNode;
8542 if (needsVisibilityToggle) {
8543 var props = node.memoizedProps;
8544 var type = node.type;
8545 if (isHidden) {
8546 // This child is inside a timed out tree. Hide it.
8547 instance = cloneHiddenInstance(instance, type, props, node);
8548 } else {
8549 // This child was previously inside a timed out tree. If it was not
8550 // updated during this render, it may need to be unhidden. Clone
8551 // again to be sure.
8552 instance = cloneUnhiddenInstance(instance, type, props, node);
8553 }
8554 node.stateNode = instance;
8555 }
8556 appendChildToContainerChildSet(containerChildSet, instance);
8557 } else if (node.tag === HostText) {
8558 var _instance2 = node.stateNode;
8559 if (needsVisibilityToggle) {
8560 var text = node.memoizedProps;
8561 var rootContainerInstance = getRootHostContainer();
8562 var currentHostContext = getHostContext();
8563 if (isHidden) {
8564 _instance2 = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8565 } else {
8566 _instance2 = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8567 }
8568 node.stateNode = _instance2;
8569 }
8570 appendChildToContainerChildSet(containerChildSet, _instance2);
8571 } else if (node.tag === HostPortal) {
8572 // If we have a portal child, then we don't want to traverse
8573 // down its children. Instead, we'll get insertions from each child in
8574 // the portal directly.
8575 } else if (node.tag === SuspenseComponent) {
8576 var current = node.alternate;
8577 if (current !== null) {
8578 var oldState = current.memoizedState;
8579 var newState = node.memoizedState;
8580 var oldIsHidden = oldState !== null;
8581 var newIsHidden = newState !== null;
8582 if (oldIsHidden !== newIsHidden) {
8583 // The placeholder either just timed out or switched back to the normal
8584 // children after having previously timed out. Toggle the visibility of
8585 // the direct host children.
8586 var primaryChildParent = newIsHidden ? node.child : node;
8587 if (primaryChildParent !== null) {
8588 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
8589 }
8590 // eslint-disable-next-line no-labels
8591 break branches;
8592 }
8593 }
8594 if (node.child !== null) {
8595 // Continue traversing like normal
8596 node.child.return = node;
8597 node = node.child;
8598 continue;
8599 }
8600 } else if (node.child !== null) {
8601 node.child.return = node;
8602 node = node.child;
8603 continue;
8604 }
8605 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8606 node = node;
8607 if (node === workInProgress) {
8608 return;
8609 }
8610 while (node.sibling === null) {
8611 if (node.return === null || node.return === workInProgress) {
8612 return;
8613 }
8614 node = node.return;
8615 }
8616 node.sibling.return = node.return;
8617 node = node.sibling;
8618 }
8619 };
8620 updateHostContainer = function (workInProgress) {
8621 var portalOrRoot = workInProgress.stateNode;
8622 var childrenUnchanged = workInProgress.firstEffect === null;
8623 if (childrenUnchanged) {
8624 // No changes, just reuse the existing instance.
8625 } else {
8626 var container = portalOrRoot.containerInfo;
8627 var newChildSet = createContainerChildSet(container);
8628 // If children might have changed, we have to add them all to the set.
8629 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
8630 portalOrRoot.pendingChildren = newChildSet;
8631 // Schedule an update on the container to swap out the container.
8632 markUpdate(workInProgress);
8633 finalizeContainerChildren(container, newChildSet);
8634 }
8635 };
8636 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8637 var currentInstance = current.stateNode;
8638 var oldProps = current.memoizedProps;
8639 // If there are no effects associated with this node, then none of our children had any updates.
8640 // This guarantees that we can reuse all of them.
8641 var childrenUnchanged = workInProgress.firstEffect === null;
8642 if (childrenUnchanged && oldProps === newProps) {
8643 // No changes, just reuse the existing instance.
8644 // Note that this might release a previous clone.
8645 workInProgress.stateNode = currentInstance;
8646 return;
8647 }
8648 var recyclableInstance = workInProgress.stateNode;
8649 var currentHostContext = getHostContext();
8650 var updatePayload = null;
8651 if (oldProps !== newProps) {
8652 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8653 }
8654 if (childrenUnchanged && updatePayload === null) {
8655 // No changes, just reuse the existing instance.
8656 // Note that this might release a previous clone.
8657 workInProgress.stateNode = currentInstance;
8658 return;
8659 }
8660 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
8661 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
8662 markUpdate(workInProgress);
8663 }
8664 workInProgress.stateNode = newInstance;
8665 if (childrenUnchanged) {
8666 // If there are no other effects in this tree, we need to flag this node as having one.
8667 // Even though we're not going to use it for anything.
8668 // Otherwise parents won't know that there are new children to propagate upwards.
8669 markUpdate(workInProgress);
8670 } else {
8671 // If children might have changed, we have to add them all to the set.
8672 appendAllChildren(newInstance, workInProgress, false, false);
8673 }
8674 };
8675 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8676 if (oldText !== newText) {
8677 // If the text content differs, we'll create a new text instance for it.
8678 var rootContainerInstance = getRootHostContainer();
8679 var currentHostContext = getHostContext();
8680 workInProgress.stateNode = createTextInstance(newText, rootContainerInstance, currentHostContext, workInProgress);
8681 // We'll have to mark it as having an effect, even though we won't use the effect for anything.
8682 // This lets the parents know that at least one of their children has changed.
8683 markUpdate(workInProgress);
8684 }
8685 };
8686} else {
8687 // No host operations
8688 updateHostContainer = function (workInProgress) {
8689 // Noop
8690 };
8691 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8692 // Noop
8693 };
8694 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8695 // Noop
8696 };
8697}
8698
8699function completeWork(current, workInProgress, renderExpirationTime) {
8700 var newProps = workInProgress.pendingProps;
8701
8702 switch (workInProgress.tag) {
8703 case IndeterminateComponent:
8704 break;
8705 case LazyComponent:
8706 break;
8707 case SimpleMemoComponent:
8708 case FunctionComponent:
8709 break;
8710 case ClassComponent:
8711 {
8712 var Component = workInProgress.type;
8713 if (isContextProvider(Component)) {
8714 popContext(workInProgress);
8715 }
8716 break;
8717 }
8718 case HostRoot:
8719 {
8720 popHostContainer(workInProgress);
8721 popTopLevelContextObject(workInProgress);
8722 var fiberRoot = workInProgress.stateNode;
8723 if (fiberRoot.pendingContext) {
8724 fiberRoot.context = fiberRoot.pendingContext;
8725 fiberRoot.pendingContext = null;
8726 }
8727 if (current === null || current.child === null) {
8728 // If we hydrated, pop so that we can delete any remaining children
8729 // that weren't hydrated.
8730 popHydrationState(workInProgress);
8731 // This resets the hacky state to fix isMounted before committing.
8732 // TODO: Delete this when we delete isMounted and findDOMNode.
8733 workInProgress.effectTag &= ~Placement;
8734 }
8735 updateHostContainer(workInProgress);
8736 break;
8737 }
8738 case HostComponent:
8739 {
8740 popHostContext(workInProgress);
8741 var rootContainerInstance = getRootHostContainer();
8742 var type = workInProgress.type;
8743 if (current !== null && workInProgress.stateNode != null) {
8744 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
8745
8746 if (current.ref !== workInProgress.ref) {
8747 markRef$1(workInProgress);
8748 }
8749 } else {
8750 if (!newProps) {
8751 !(workInProgress.stateNode !== null) ? invariant(false, 'We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.') : void 0;
8752 // This can happen when we abort work.
8753 break;
8754 }
8755
8756 var currentHostContext = getHostContext();
8757 // TODO: Move createInstance to beginWork and keep it on a context
8758 // "stack" as the parent. Then append children as we go in beginWork
8759 // or completeWork depending on we want to add then top->down or
8760 // bottom->up. Top->down is faster in IE11.
8761 var wasHydrated = popHydrationState(workInProgress);
8762 if (wasHydrated) {
8763 // TODO: Move this and createInstance step into the beginPhase
8764 // to consolidate.
8765 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
8766 // If changes to the hydrated node needs to be applied at the
8767 // commit-phase we mark this as such.
8768 markUpdate(workInProgress);
8769 }
8770 } else {
8771 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
8772
8773 appendAllChildren(instance, workInProgress, false, false);
8774
8775 // Certain renderers require commit-time effects for initial mount.
8776 // (eg DOM renderer supports auto-focus for certain elements).
8777 // Make sure such renderers get scheduled for later work.
8778 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
8779 markUpdate(workInProgress);
8780 }
8781 workInProgress.stateNode = instance;
8782 }
8783
8784 if (workInProgress.ref !== null) {
8785 // If there is a ref on a host node we need to schedule a callback
8786 markRef$1(workInProgress);
8787 }
8788 }
8789 break;
8790 }
8791 case HostText:
8792 {
8793 var newText = newProps;
8794 if (current && workInProgress.stateNode != null) {
8795 var oldText = current.memoizedProps;
8796 // If we have an alternate, that means this is an update and we need
8797 // to schedule a side-effect to do the updates.
8798 updateHostText$1(current, workInProgress, oldText, newText);
8799 } else {
8800 if (typeof newText !== 'string') {
8801 !(workInProgress.stateNode !== null) ? invariant(false, 'We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.') : void 0;
8802 // This can happen when we abort work.
8803 }
8804 var _rootContainerInstance = getRootHostContainer();
8805 var _currentHostContext = getHostContext();
8806 var _wasHydrated = popHydrationState(workInProgress);
8807 if (_wasHydrated) {
8808 if (prepareToHydrateHostTextInstance(workInProgress)) {
8809 markUpdate(workInProgress);
8810 }
8811 } else {
8812 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
8813 }
8814 }
8815 break;
8816 }
8817 case ForwardRef:
8818 break;
8819 case SuspenseComponent:
8820 {
8821 var nextState = workInProgress.memoizedState;
8822 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
8823 // Something suspended. Re-render with the fallback children.
8824 workInProgress.expirationTime = renderExpirationTime;
8825 // Do not reset the effect list.
8826 return workInProgress;
8827 }
8828
8829 var nextDidTimeout = nextState !== null;
8830 var prevDidTimeout = current !== null && current.memoizedState !== null;
8831
8832 if (current !== null && !nextDidTimeout && prevDidTimeout) {
8833 // We just switched from the fallback to the normal children. Delete
8834 // the fallback.
8835 // TODO: Would it be better to store the fallback fragment on
8836 var currentFallbackChild = current.child.sibling;
8837 if (currentFallbackChild !== null) {
8838 // Deletions go at the beginning of the return fiber's effect list
8839 var first = workInProgress.firstEffect;
8840 if (first !== null) {
8841 workInProgress.firstEffect = currentFallbackChild;
8842 currentFallbackChild.nextEffect = first;
8843 } else {
8844 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
8845 currentFallbackChild.nextEffect = null;
8846 }
8847 currentFallbackChild.effectTag = Deletion;
8848 }
8849 }
8850
8851 if (nextDidTimeout || prevDidTimeout) {
8852 // If the children are hidden, or if they were previous hidden, schedule
8853 // an effect to toggle their visibility. This is also used to attach a
8854 // retry listener to the promise.
8855 workInProgress.effectTag |= Update;
8856 }
8857 break;
8858 }
8859 case Fragment:
8860 break;
8861 case Mode:
8862 break;
8863 case Profiler:
8864 break;
8865 case HostPortal:
8866 popHostContainer(workInProgress);
8867 updateHostContainer(workInProgress);
8868 break;
8869 case ContextProvider:
8870 // Pop provider fiber
8871 popProvider(workInProgress);
8872 break;
8873 case ContextConsumer:
8874 break;
8875 case MemoComponent:
8876 break;
8877 case IncompleteClassComponent:
8878 {
8879 // Same as class component case. I put it down here so that the tags are
8880 // sequential to ensure this switch is compiled to a jump table.
8881 var _Component = workInProgress.type;
8882 if (isContextProvider(_Component)) {
8883 popContext(workInProgress);
8884 }
8885 break;
8886 }
8887 default:
8888 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
8889 }
8890
8891 return null;
8892}
8893
8894function shouldCaptureSuspense(workInProgress) {
8895 // In order to capture, the Suspense component must have a fallback prop.
8896 if (workInProgress.memoizedProps.fallback === undefined) {
8897 return false;
8898 }
8899 // If it was the primary children that just suspended, capture and render the
8900 // fallback. Otherwise, don't capture and bubble to the next boundary.
8901 var nextState = workInProgress.memoizedState;
8902 return nextState === null;
8903}
8904
8905// This module is forked in different environments.
8906// By default, return `true` to log errors to the console.
8907// Forks can return `false` if this isn't desirable.
8908function showErrorDialog(capturedError) {
8909 return true;
8910}
8911
8912function logCapturedError(capturedError) {
8913 var logError = showErrorDialog(capturedError);
8914
8915 // Allow injected showErrorDialog() to prevent default console.error logging.
8916 // This enables renderers like ReactNative to better manage redbox behavior.
8917 if (logError === false) {
8918 return;
8919 }
8920
8921 var error = capturedError.error;
8922 {
8923 var componentName = capturedError.componentName,
8924 componentStack = capturedError.componentStack,
8925 errorBoundaryName = capturedError.errorBoundaryName,
8926 errorBoundaryFound = capturedError.errorBoundaryFound,
8927 willRetry = capturedError.willRetry;
8928
8929 // Browsers support silencing uncaught errors by calling
8930 // `preventDefault()` in window `error` handler.
8931 // We record this information as an expando on the error.
8932
8933 if (error != null && error._suppressLogging) {
8934 if (errorBoundaryFound && willRetry) {
8935 // The error is recoverable and was silenced.
8936 // Ignore it and don't print the stack addendum.
8937 // This is handy for testing error boundaries without noise.
8938 return;
8939 }
8940 // The error is fatal. Since the silencing might have
8941 // been accidental, we'll surface it anyway.
8942 // However, the browser would have silenced the original error
8943 // so we'll print it first, and then print the stack addendum.
8944 console.error(error);
8945 // For a more detailed description of this block, see:
8946 // https://github.com/facebook/react/pull/13384
8947 }
8948
8949 var componentNameMessage = componentName ? 'The above error occurred in the <' + componentName + '> component:' : 'The above error occurred in one of your React components:';
8950
8951 var errorBoundaryMessage = void 0;
8952 // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
8953 if (errorBoundaryFound && errorBoundaryName) {
8954 if (willRetry) {
8955 errorBoundaryMessage = 'React will try to recreate this component tree from scratch ' + ('using the error boundary you provided, ' + errorBoundaryName + '.');
8956 } else {
8957 errorBoundaryMessage = 'This error was initially handled by the error boundary ' + errorBoundaryName + '.\n' + 'Recreating the tree from scratch failed so React will unmount the tree.';
8958 }
8959 } else {
8960 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.';
8961 }
8962 var combinedMessage = '' + componentNameMessage + componentStack + '\n\n' + ('' + errorBoundaryMessage);
8963
8964 // In development, we provide our own message with just the component stack.
8965 // We don't include the original error message and JS stack because the browser
8966 // has already printed it. Even if the application swallows the error, it is still
8967 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
8968 console.error(combinedMessage);
8969 }
8970}
8971
8972var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
8973{
8974 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
8975}
8976
8977var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
8978
8979function logError(boundary, errorInfo) {
8980 var source = errorInfo.source;
8981 var stack = errorInfo.stack;
8982 if (stack === null && source !== null) {
8983 stack = getStackByFiberInDevAndProd(source);
8984 }
8985
8986 var capturedError = {
8987 componentName: source !== null ? getComponentName(source.type) : null,
8988 componentStack: stack !== null ? stack : '',
8989 error: errorInfo.value,
8990 errorBoundary: null,
8991 errorBoundaryName: null,
8992 errorBoundaryFound: false,
8993 willRetry: false
8994 };
8995
8996 if (boundary !== null && boundary.tag === ClassComponent) {
8997 capturedError.errorBoundary = boundary.stateNode;
8998 capturedError.errorBoundaryName = getComponentName(boundary.type);
8999 capturedError.errorBoundaryFound = true;
9000 capturedError.willRetry = true;
9001 }
9002
9003 try {
9004 logCapturedError(capturedError);
9005 } catch (e) {
9006 // This method must not throw, or React internal state will get messed up.
9007 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
9008 // we want to report this error outside of the normal stack as a last resort.
9009 // https://github.com/facebook/react/issues/13188
9010 setTimeout(function () {
9011 throw e;
9012 });
9013 }
9014}
9015
9016var callComponentWillUnmountWithTimer = function (current$$1, instance) {
9017 startPhaseTimer(current$$1, 'componentWillUnmount');
9018 instance.props = current$$1.memoizedProps;
9019 instance.state = current$$1.memoizedState;
9020 instance.componentWillUnmount();
9021 stopPhaseTimer();
9022};
9023
9024// Capture errors so they don't interrupt unmounting.
9025function safelyCallComponentWillUnmount(current$$1, instance) {
9026 {
9027 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
9028 if (hasCaughtError()) {
9029 var unmountError = clearCaughtError();
9030 captureCommitPhaseError(current$$1, unmountError);
9031 }
9032 }
9033}
9034
9035function safelyDetachRef(current$$1) {
9036 var ref = current$$1.ref;
9037 if (ref !== null) {
9038 if (typeof ref === 'function') {
9039 {
9040 invokeGuardedCallback(null, ref, null, null);
9041 if (hasCaughtError()) {
9042 var refError = clearCaughtError();
9043 captureCommitPhaseError(current$$1, refError);
9044 }
9045 }
9046 } else {
9047 ref.current = null;
9048 }
9049 }
9050}
9051
9052function safelyCallDestroy(current$$1, destroy) {
9053 {
9054 invokeGuardedCallback(null, destroy, null);
9055 if (hasCaughtError()) {
9056 var error = clearCaughtError();
9057 captureCommitPhaseError(current$$1, error);
9058 }
9059 }
9060}
9061
9062function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
9063 switch (finishedWork.tag) {
9064 case FunctionComponent:
9065 case ForwardRef:
9066 case SimpleMemoComponent:
9067 {
9068 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
9069 return;
9070 }
9071 case ClassComponent:
9072 {
9073 if (finishedWork.effectTag & Snapshot) {
9074 if (current$$1 !== null) {
9075 var prevProps = current$$1.memoizedProps;
9076 var prevState = current$$1.memoizedState;
9077 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
9078 var instance = finishedWork.stateNode;
9079 // We could update instance props and state here,
9080 // but instead we rely on them being set during last render.
9081 // TODO: revisit this when we implement resuming.
9082 {
9083 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9084 !(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;
9085 !(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;
9086 }
9087 }
9088 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
9089 {
9090 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
9091 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
9092 didWarnSet.add(finishedWork.type);
9093 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
9094 }
9095 }
9096 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
9097 stopPhaseTimer();
9098 }
9099 }
9100 return;
9101 }
9102 case HostRoot:
9103 case HostComponent:
9104 case HostText:
9105 case HostPortal:
9106 case IncompleteClassComponent:
9107 // Nothing to do for these component types
9108 return;
9109 default:
9110 {
9111 invariant(false, 'This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue.');
9112 }
9113 }
9114}
9115
9116function commitHookEffectList(unmountTag, mountTag, finishedWork) {
9117 var updateQueue = finishedWork.updateQueue;
9118 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
9119 if (lastEffect !== null) {
9120 var firstEffect = lastEffect.next;
9121 var effect = firstEffect;
9122 do {
9123 if ((effect.tag & unmountTag) !== NoEffect$1) {
9124 // Unmount
9125 var destroy = effect.destroy;
9126 effect.destroy = undefined;
9127 if (destroy !== undefined) {
9128 destroy();
9129 }
9130 }
9131 if ((effect.tag & mountTag) !== NoEffect$1) {
9132 // Mount
9133 var create = effect.create;
9134 effect.destroy = create();
9135
9136 {
9137 var _destroy = effect.destroy;
9138 if (_destroy !== undefined && typeof _destroy !== 'function') {
9139 var addendum = void 0;
9140 if (_destroy === null) {
9141 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
9142 } else if (typeof _destroy.then === 'function') {
9143 addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, you may write an async function separately ' + 'and then call it from inside the effect:\n\n' + 'async function fetchComment(commentId) {\n' + ' // You can await here\n' + '}\n\n' + 'useEffect(() => {\n' + ' fetchComment(commentId);\n' + '}, [commentId]);\n\n' + 'In the future, React will provide a more idiomatic solution for data fetching ' + "that doesn't involve writing effects manually.";
9144 } else {
9145 addendum = ' You returned: ' + _destroy;
9146 }
9147 warningWithoutStack$1(false, 'An Effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
9148 }
9149 }
9150 }
9151 effect = effect.next;
9152 } while (effect !== firstEffect);
9153 }
9154}
9155
9156function commitPassiveHookEffects(finishedWork) {
9157 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
9158 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
9159}
9160
9161function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
9162 switch (finishedWork.tag) {
9163 case FunctionComponent:
9164 case ForwardRef:
9165 case SimpleMemoComponent:
9166 {
9167 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
9168 break;
9169 }
9170 case ClassComponent:
9171 {
9172 var instance = finishedWork.stateNode;
9173 if (finishedWork.effectTag & Update) {
9174 if (current$$1 === null) {
9175 startPhaseTimer(finishedWork, 'componentDidMount');
9176 // We could update instance props and state here,
9177 // but instead we rely on them being set during last render.
9178 // TODO: revisit this when we implement resuming.
9179 {
9180 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9181 !(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;
9182 !(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;
9183 }
9184 }
9185 instance.componentDidMount();
9186 stopPhaseTimer();
9187 } else {
9188 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
9189 var prevState = current$$1.memoizedState;
9190 startPhaseTimer(finishedWork, 'componentDidUpdate');
9191 // We could update instance props and state here,
9192 // but instead we rely on them being set during last render.
9193 // TODO: revisit this when we implement resuming.
9194 {
9195 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9196 !(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;
9197 !(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;
9198 }
9199 }
9200 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
9201 stopPhaseTimer();
9202 }
9203 }
9204 var updateQueue = finishedWork.updateQueue;
9205 if (updateQueue !== null) {
9206 {
9207 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9208 !(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;
9209 !(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;
9210 }
9211 }
9212 // We could update instance props and state here,
9213 // but instead we rely on them being set during last render.
9214 // TODO: revisit this when we implement resuming.
9215 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
9216 }
9217 return;
9218 }
9219 case HostRoot:
9220 {
9221 var _updateQueue = finishedWork.updateQueue;
9222 if (_updateQueue !== null) {
9223 var _instance = null;
9224 if (finishedWork.child !== null) {
9225 switch (finishedWork.child.tag) {
9226 case HostComponent:
9227 _instance = getPublicInstance(finishedWork.child.stateNode);
9228 break;
9229 case ClassComponent:
9230 _instance = finishedWork.child.stateNode;
9231 break;
9232 }
9233 }
9234 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
9235 }
9236 return;
9237 }
9238 case HostComponent:
9239 {
9240 var _instance2 = finishedWork.stateNode;
9241
9242 // Renderers may schedule work to be done after host components are mounted
9243 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
9244 // These effects should only be committed when components are first mounted,
9245 // aka when there is no current/alternate.
9246 if (current$$1 === null && finishedWork.effectTag & Update) {
9247 var type = finishedWork.type;
9248 var props = finishedWork.memoizedProps;
9249
9250 }
9251
9252 return;
9253 }
9254 case HostText:
9255 {
9256 // We have no life-cycles associated with text.
9257 return;
9258 }
9259 case HostPortal:
9260 {
9261 // We have no life-cycles associated with portals.
9262 return;
9263 }
9264 case Profiler:
9265 {
9266 if (enableProfilerTimer) {
9267 var onRender = finishedWork.memoizedProps.onRender;
9268
9269 if (enableSchedulerTracing) {
9270 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
9271 } else {
9272 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
9273 }
9274 }
9275 return;
9276 }
9277 case SuspenseComponent:
9278 break;
9279 case IncompleteClassComponent:
9280 break;
9281 default:
9282 {
9283 invariant(false, 'This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue.');
9284 }
9285 }
9286}
9287
9288function hideOrUnhideAllChildren(finishedWork, isHidden) {
9289 if (supportsMutation) {
9290 // We only have the top Fiber that was inserted but we need recurse down its
9291 var node = finishedWork;
9292 while (true) {
9293 if (node.tag === HostComponent) {
9294 var instance = node.stateNode;
9295 if (isHidden) {
9296 hideInstance(instance);
9297 } else {
9298 unhideInstance(node.stateNode, node.memoizedProps);
9299 }
9300 } else if (node.tag === HostText) {
9301 var _instance3 = node.stateNode;
9302 if (isHidden) {
9303 hideTextInstance(_instance3);
9304 } else {
9305 unhideTextInstance(_instance3, node.memoizedProps);
9306 }
9307 } else if (node.tag === SuspenseComponent && node.memoizedState !== null) {
9308 // Found a nested Suspense component that timed out. Skip over the
9309 var fallbackChildFragment = node.child.sibling;
9310 fallbackChildFragment.return = node;
9311 node = fallbackChildFragment;
9312 continue;
9313 } else if (node.child !== null) {
9314 node.child.return = node;
9315 node = node.child;
9316 continue;
9317 }
9318 if (node === finishedWork) {
9319 return;
9320 }
9321 while (node.sibling === null) {
9322 if (node.return === null || node.return === finishedWork) {
9323 return;
9324 }
9325 node = node.return;
9326 }
9327 node.sibling.return = node.return;
9328 node = node.sibling;
9329 }
9330 }
9331}
9332
9333function commitAttachRef(finishedWork) {
9334 var ref = finishedWork.ref;
9335 if (ref !== null) {
9336 var instance = finishedWork.stateNode;
9337 var instanceToUse = void 0;
9338 switch (finishedWork.tag) {
9339 case HostComponent:
9340 instanceToUse = getPublicInstance(instance);
9341 break;
9342 default:
9343 instanceToUse = instance;
9344 }
9345 if (typeof ref === 'function') {
9346 ref(instanceToUse);
9347 } else {
9348 {
9349 if (!ref.hasOwnProperty('current')) {
9350 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
9351 }
9352 }
9353
9354 ref.current = instanceToUse;
9355 }
9356 }
9357}
9358
9359function commitDetachRef(current$$1) {
9360 var currentRef = current$$1.ref;
9361 if (currentRef !== null) {
9362 if (typeof currentRef === 'function') {
9363 currentRef(null);
9364 } else {
9365 currentRef.current = null;
9366 }
9367 }
9368}
9369
9370// User-originating errors (lifecycles and refs) should not interrupt
9371// deletion, so don't let them throw. Host-originating errors should
9372// interrupt deletion, so it's okay
9373function commitUnmount(current$$1) {
9374 onCommitUnmount(current$$1);
9375
9376 switch (current$$1.tag) {
9377 case FunctionComponent:
9378 case ForwardRef:
9379 case MemoComponent:
9380 case SimpleMemoComponent:
9381 {
9382 var updateQueue = current$$1.updateQueue;
9383 if (updateQueue !== null) {
9384 var lastEffect = updateQueue.lastEffect;
9385 if (lastEffect !== null) {
9386 var firstEffect = lastEffect.next;
9387 var effect = firstEffect;
9388 do {
9389 var destroy = effect.destroy;
9390 if (destroy !== undefined) {
9391 safelyCallDestroy(current$$1, destroy);
9392 }
9393 effect = effect.next;
9394 } while (effect !== firstEffect);
9395 }
9396 }
9397 break;
9398 }
9399 case ClassComponent:
9400 {
9401 safelyDetachRef(current$$1);
9402 var instance = current$$1.stateNode;
9403 if (typeof instance.componentWillUnmount === 'function') {
9404 safelyCallComponentWillUnmount(current$$1, instance);
9405 }
9406 return;
9407 }
9408 case HostComponent:
9409 {
9410 safelyDetachRef(current$$1);
9411 return;
9412 }
9413 case HostPortal:
9414 {
9415 // TODO: this is recursive.
9416 // We are also not using this parent because
9417 // the portal will get pushed immediately.
9418 if (supportsMutation) {
9419 unmountHostComponents(current$$1);
9420 } else if (supportsPersistence) {
9421 emptyPortalContainer(current$$1);
9422 }
9423 return;
9424 }
9425 }
9426}
9427
9428function commitNestedUnmounts(root) {
9429 // While we're inside a removed host node we don't want to call
9430 // removeChild on the inner nodes because they're removed by the top
9431 // call anyway. We also want to call componentWillUnmount on all
9432 // composites before this host node is removed from the tree. Therefore
9433 var node = root;
9434 while (true) {
9435 commitUnmount(node);
9436 // Visit children because they may contain more composite or host nodes.
9437 // Skip portals because commitUnmount() currently visits them recursively.
9438 if (node.child !== null && (
9439 // If we use mutation we drill down into portals using commitUnmount above.
9440 // If we don't use mutation we drill down into portals here instead.
9441 !supportsMutation || node.tag !== HostPortal)) {
9442 node.child.return = node;
9443 node = node.child;
9444 continue;
9445 }
9446 if (node === root) {
9447 return;
9448 }
9449 while (node.sibling === null) {
9450 if (node.return === null || node.return === root) {
9451 return;
9452 }
9453 node = node.return;
9454 }
9455 node.sibling.return = node.return;
9456 node = node.sibling;
9457 }
9458}
9459
9460function detachFiber(current$$1) {
9461 // Cut off the return pointers to disconnect it from the tree. Ideally, we
9462 // should clear the child pointer of the parent alternate to let this
9463 // get GC:ed but we don't know which for sure which parent is the current
9464 // one so we'll settle for GC:ing the subtree of this child. This child
9465 // itself will be GC:ed when the parent updates the next time.
9466 current$$1.return = null;
9467 current$$1.child = null;
9468 current$$1.memoizedState = null;
9469 current$$1.updateQueue = null;
9470 var alternate = current$$1.alternate;
9471 if (alternate !== null) {
9472 alternate.return = null;
9473 alternate.child = null;
9474 alternate.memoizedState = null;
9475 alternate.updateQueue = null;
9476 }
9477}
9478
9479function emptyPortalContainer(current$$1) {
9480 if (!supportsPersistence) {
9481 return;
9482 }
9483
9484 var portal = current$$1.stateNode;
9485 var containerInfo = portal.containerInfo;
9486
9487 var emptyChildSet = createContainerChildSet(containerInfo);
9488 replaceContainerChildren(containerInfo, emptyChildSet);
9489}
9490
9491function commitContainer(finishedWork) {
9492 if (!supportsPersistence) {
9493 return;
9494 }
9495
9496 switch (finishedWork.tag) {
9497 case ClassComponent:
9498 {
9499 return;
9500 }
9501 case HostComponent:
9502 {
9503 return;
9504 }
9505 case HostText:
9506 {
9507 return;
9508 }
9509 case HostRoot:
9510 case HostPortal:
9511 {
9512 var portalOrRoot = finishedWork.stateNode;
9513 var containerInfo = portalOrRoot.containerInfo,
9514 _pendingChildren = portalOrRoot.pendingChildren;
9515
9516 replaceContainerChildren(containerInfo, _pendingChildren);
9517 return;
9518 }
9519 default:
9520 {
9521 invariant(false, 'This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue.');
9522 }
9523 }
9524}
9525
9526function getHostParentFiber(fiber) {
9527 var parent = fiber.return;
9528 while (parent !== null) {
9529 if (isHostParent(parent)) {
9530 return parent;
9531 }
9532 parent = parent.return;
9533 }
9534 invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.');
9535}
9536
9537function isHostParent(fiber) {
9538 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
9539}
9540
9541function getHostSibling(fiber) {
9542 // We're going to search forward into the tree until we find a sibling host
9543 // node. Unfortunately, if multiple insertions are done in a row we have to
9544 // search past them. This leads to exponential search for the next sibling.
9545 var node = fiber;
9546 siblings: while (true) {
9547 // If we didn't find anything, let's try the next sibling.
9548 while (node.sibling === null) {
9549 if (node.return === null || isHostParent(node.return)) {
9550 // If we pop out of the root or hit the parent the fiber we are the
9551 // last sibling.
9552 return null;
9553 }
9554 node = node.return;
9555 }
9556 node.sibling.return = node.return;
9557 node = node.sibling;
9558 while (node.tag !== HostComponent && node.tag !== HostText) {
9559 // If it is not host node and, we might have a host node inside it.
9560 // Try to search down until we find one.
9561 if (node.effectTag & Placement) {
9562 // If we don't have a child, try the siblings instead.
9563 continue siblings;
9564 }
9565 // If we don't have a child, try the siblings instead.
9566 // We also skip portals because they are not part of this host tree.
9567 if (node.child === null || node.tag === HostPortal) {
9568 continue siblings;
9569 } else {
9570 node.child.return = node;
9571 node = node.child;
9572 }
9573 }
9574 // Check if this host node is stable or about to be placed.
9575 if (!(node.effectTag & Placement)) {
9576 // Found it!
9577 return node.stateNode;
9578 }
9579 }
9580}
9581
9582function commitPlacement(finishedWork) {
9583 if (!supportsMutation) {
9584 return;
9585 }
9586
9587 // Recursively insert all host nodes into the parent.
9588 var parentFiber = getHostParentFiber(finishedWork);
9589
9590 // Note: these two variables *must* always be updated together.
9591 var parent = void 0;
9592 var isContainer = void 0;
9593
9594 switch (parentFiber.tag) {
9595 case HostComponent:
9596 parent = parentFiber.stateNode;
9597 isContainer = false;
9598 break;
9599 case HostRoot:
9600 parent = parentFiber.stateNode.containerInfo;
9601 isContainer = true;
9602 break;
9603 case HostPortal:
9604 parent = parentFiber.stateNode.containerInfo;
9605 isContainer = true;
9606 break;
9607 default:
9608 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
9609 }
9610 if (parentFiber.effectTag & ContentReset) {
9611 // Reset the text content of the parent before doing any insertions
9612 parentFiber.effectTag &= ~ContentReset;
9613 }
9614
9615 var before = getHostSibling(finishedWork);
9616 // We only have the top Fiber that was inserted but we need recurse down its
9617 // children to find all the terminal nodes.
9618 var node = finishedWork;
9619 while (true) {
9620 if (node.tag === HostComponent || node.tag === HostText) {
9621 if (before) {
9622 if (isContainer) {
9623 insertInContainerBefore(parent, node.stateNode, before);
9624 } else {
9625 insertBefore(parent, node.stateNode, before);
9626 }
9627 } else {
9628 if (isContainer) {
9629 appendChildToContainer(parent, node.stateNode);
9630 } else {
9631 appendChild(parent, node.stateNode);
9632 }
9633 }
9634 } else if (node.tag === HostPortal) {
9635 // If the insertion itself is a portal, then we don't want to traverse
9636 // down its children. Instead, we'll get insertions from each child in
9637 // the portal directly.
9638 } else if (node.child !== null) {
9639 node.child.return = node;
9640 node = node.child;
9641 continue;
9642 }
9643 if (node === finishedWork) {
9644 return;
9645 }
9646 while (node.sibling === null) {
9647 if (node.return === null || node.return === finishedWork) {
9648 return;
9649 }
9650 node = node.return;
9651 }
9652 node.sibling.return = node.return;
9653 node = node.sibling;
9654 }
9655}
9656
9657function unmountHostComponents(current$$1) {
9658 // We only have the top Fiber that was deleted but we need recurse down its
9659 var node = current$$1;
9660
9661 // Each iteration, currentParent is populated with node's host parent if not
9662 // currentParentIsValid.
9663 var currentParentIsValid = false;
9664
9665 // Note: these two variables *must* always be updated together.
9666 var currentParent = void 0;
9667 var currentParentIsContainer = void 0;
9668
9669 while (true) {
9670 if (!currentParentIsValid) {
9671 var parent = node.return;
9672 findParent: while (true) {
9673 !(parent !== null) ? invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.') : void 0;
9674 switch (parent.tag) {
9675 case HostComponent:
9676 currentParent = parent.stateNode;
9677 currentParentIsContainer = false;
9678 break findParent;
9679 case HostRoot:
9680 currentParent = parent.stateNode.containerInfo;
9681 currentParentIsContainer = true;
9682 break findParent;
9683 case HostPortal:
9684 currentParent = parent.stateNode.containerInfo;
9685 currentParentIsContainer = true;
9686 break findParent;
9687 }
9688 parent = parent.return;
9689 }
9690 currentParentIsValid = true;
9691 }
9692
9693 if (node.tag === HostComponent || node.tag === HostText) {
9694 commitNestedUnmounts(node);
9695 // After all the children have unmounted, it is now safe to remove the
9696 // node from the tree.
9697 if (currentParentIsContainer) {
9698 removeChildFromContainer(currentParent, node.stateNode);
9699 } else {
9700 removeChild(currentParent, node.stateNode);
9701 }
9702 // Don't visit children because we already visited them.
9703 } else if (node.tag === HostPortal) {
9704 // When we go into a portal, it becomes the parent to remove from.
9705 // We will reassign it back when we pop the portal on the way up.
9706 currentParent = node.stateNode.containerInfo;
9707 currentParentIsContainer = true;
9708 // Visit children because portals might contain host components.
9709 if (node.child !== null) {
9710 node.child.return = node;
9711 node = node.child;
9712 continue;
9713 }
9714 } else {
9715 commitUnmount(node);
9716 // Visit children because we may find more host components below.
9717 if (node.child !== null) {
9718 node.child.return = node;
9719 node = node.child;
9720 continue;
9721 }
9722 }
9723 if (node === current$$1) {
9724 return;
9725 }
9726 while (node.sibling === null) {
9727 if (node.return === null || node.return === current$$1) {
9728 return;
9729 }
9730 node = node.return;
9731 if (node.tag === HostPortal) {
9732 // When we go out of the portal, we need to restore the parent.
9733 // Since we don't keep a stack of them, we will search for it.
9734 currentParentIsValid = false;
9735 }
9736 }
9737 node.sibling.return = node.return;
9738 node = node.sibling;
9739 }
9740}
9741
9742function commitDeletion(current$$1) {
9743 if (supportsMutation) {
9744 // Recursively delete all host nodes from the parent.
9745 // Detach refs and call componentWillUnmount() on the whole subtree.
9746 unmountHostComponents(current$$1);
9747 } else {
9748 // Detach refs and call componentWillUnmount() on the whole subtree.
9749 commitNestedUnmounts(current$$1);
9750 }
9751 detachFiber(current$$1);
9752}
9753
9754function commitWork(current$$1, finishedWork) {
9755 if (!supportsMutation) {
9756 switch (finishedWork.tag) {
9757 case FunctionComponent:
9758 case ForwardRef:
9759 case MemoComponent:
9760 case SimpleMemoComponent:
9761 {
9762 // Note: We currently never use MountMutation, but useLayout uses
9763 // UnmountMutation.
9764 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
9765 return;
9766 }
9767 }
9768
9769 commitContainer(finishedWork);
9770 return;
9771 }
9772
9773 switch (finishedWork.tag) {
9774 case FunctionComponent:
9775 case ForwardRef:
9776 case MemoComponent:
9777 case SimpleMemoComponent:
9778 {
9779 // Note: We currently never use MountMutation, but useLayout uses
9780 // UnmountMutation.
9781 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
9782 return;
9783 }
9784 case ClassComponent:
9785 {
9786 return;
9787 }
9788 case HostComponent:
9789 {
9790 var instance = finishedWork.stateNode;
9791 if (instance != null) {
9792 // Commit the work prepared earlier.
9793 var newProps = finishedWork.memoizedProps;
9794 // For hydration we reuse the update path but we treat the oldProps
9795 // as the newProps. The updatePayload will contain the real change in
9796 // this case.
9797 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
9798 var type = finishedWork.type;
9799 // TODO: Type the updateQueue to be specific to host components.
9800 var updatePayload = finishedWork.updateQueue;
9801 finishedWork.updateQueue = null;
9802 if (updatePayload !== null) {
9803 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
9804 }
9805 }
9806 return;
9807 }
9808 case HostText:
9809 {
9810 !(finishedWork.stateNode !== null) ? invariant(false, 'This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue.') : void 0;
9811 var textInstance = finishedWork.stateNode;
9812 var newText = finishedWork.memoizedProps;
9813 // For hydration we reuse the update path but we treat the oldProps
9814 // as the newProps. The updatePayload will contain the real change in
9815 // this case.
9816 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
9817 commitTextUpdate(textInstance, oldText, newText);
9818 return;
9819 }
9820 case HostRoot:
9821 {
9822 return;
9823 }
9824 case Profiler:
9825 {
9826 return;
9827 }
9828 case SuspenseComponent:
9829 {
9830 var newState = finishedWork.memoizedState;
9831
9832 var newDidTimeout = void 0;
9833 var primaryChildParent = finishedWork;
9834 if (newState === null) {
9835 newDidTimeout = false;
9836 } else {
9837 newDidTimeout = true;
9838 primaryChildParent = finishedWork.child;
9839 if (newState.timedOutAt === NoWork) {
9840 // If the children had not already timed out, record the time.
9841 // This is used to compute the elapsed time during subsequent
9842 // attempts to render the children.
9843 newState.timedOutAt = requestCurrentTime();
9844 }
9845 }
9846
9847 if (primaryChildParent !== null) {
9848 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
9849 }
9850
9851 // If this boundary just timed out, then it will have a set of thenables.
9852 // For each thenable, attach a listener so that when it resolves, React
9853 // attempts to re-render the boundary in the primary (pre-timeout) state.
9854 var thenables = finishedWork.updateQueue;
9855 if (thenables !== null) {
9856 finishedWork.updateQueue = null;
9857 var retryCache = finishedWork.stateNode;
9858 if (retryCache === null) {
9859 retryCache = finishedWork.stateNode = new PossiblyWeakSet();
9860 }
9861 thenables.forEach(function (thenable) {
9862 // Memoize using the boundary fiber to prevent redundant listeners.
9863 var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable);
9864 if (enableSchedulerTracing) {
9865 retry = unstable_wrap(retry);
9866 }
9867 if (!retryCache.has(thenable)) {
9868 retryCache.add(thenable);
9869 thenable.then(retry, retry);
9870 }
9871 });
9872 }
9873
9874 return;
9875 }
9876 case IncompleteClassComponent:
9877 {
9878 return;
9879 }
9880 default:
9881 {
9882 invariant(false, 'This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue.');
9883 }
9884 }
9885}
9886
9887function commitResetTextContent(current$$1) {
9888 if (!supportsMutation) {
9889 return;
9890 }
9891 resetTextContent(current$$1.stateNode);
9892}
9893
9894var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
9895
9896function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
9897 var update = createUpdate(expirationTime);
9898 // Unmount the root by rendering null.
9899 update.tag = CaptureUpdate;
9900 // Caution: React DevTools currently depends on this property
9901 // being called "element".
9902 update.payload = { element: null };
9903 var error = errorInfo.value;
9904 update.callback = function () {
9905 onUncaughtError(error);
9906 logError(fiber, errorInfo);
9907 };
9908 return update;
9909}
9910
9911function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
9912 var update = createUpdate(expirationTime);
9913 update.tag = CaptureUpdate;
9914 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
9915 if (typeof getDerivedStateFromError === 'function') {
9916 var error = errorInfo.value;
9917 update.payload = function () {
9918 return getDerivedStateFromError(error);
9919 };
9920 }
9921
9922 var inst = fiber.stateNode;
9923 if (inst !== null && typeof inst.componentDidCatch === 'function') {
9924 update.callback = function callback() {
9925 if (typeof getDerivedStateFromError !== 'function') {
9926 // To preserve the preexisting retry behavior of error boundaries,
9927 // we keep track of which ones already failed during this batch.
9928 // This gets reset before we yield back to the browser.
9929 // TODO: Warn in strict mode if getDerivedStateFromError is
9930 // not defined.
9931 markLegacyErrorBoundaryAsFailed(this);
9932 }
9933 var error = errorInfo.value;
9934 var stack = errorInfo.stack;
9935 logError(fiber, errorInfo);
9936 this.componentDidCatch(error, {
9937 componentStack: stack !== null ? stack : ''
9938 });
9939 {
9940 if (typeof getDerivedStateFromError !== 'function') {
9941 // If componentDidCatch is the only error boundary method defined,
9942 // then it needs to call setState to recover from errors.
9943 // If no state update is scheduled then the boundary will swallow the error.
9944 !(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;
9945 }
9946 }
9947 };
9948 }
9949 return update;
9950}
9951
9952function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
9953 // The source fiber did not complete.
9954 sourceFiber.effectTag |= Incomplete;
9955 // Its effect list is no longer valid.
9956 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
9957
9958 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
9959 // This is a thenable.
9960 var thenable = value;
9961
9962 // Find the earliest timeout threshold of all the placeholders in the
9963 // ancestor path. We could avoid this traversal by storing the thresholds on
9964 // the stack, but we choose not to because we only hit this path if we're
9965 // IO-bound (i.e. if something suspends). Whereas the stack is used even in
9966 // the non-IO- bound case.
9967 var _workInProgress = returnFiber;
9968 var earliestTimeoutMs = -1;
9969 var startTimeMs = -1;
9970 do {
9971 if (_workInProgress.tag === SuspenseComponent) {
9972 var current$$1 = _workInProgress.alternate;
9973 if (current$$1 !== null) {
9974 var currentState = current$$1.memoizedState;
9975 if (currentState !== null) {
9976 // Reached a boundary that already timed out. Do not search
9977 // any further.
9978 var timedOutAt = currentState.timedOutAt;
9979 startTimeMs = expirationTimeToMs(timedOutAt);
9980 // Do not search any further.
9981 break;
9982 }
9983 }
9984 var timeoutPropMs = _workInProgress.pendingProps.maxDuration;
9985 if (typeof timeoutPropMs === 'number') {
9986 if (timeoutPropMs <= 0) {
9987 earliestTimeoutMs = 0;
9988 } else if (earliestTimeoutMs === -1 || timeoutPropMs < earliestTimeoutMs) {
9989 earliestTimeoutMs = timeoutPropMs;
9990 }
9991 }
9992 }
9993 _workInProgress = _workInProgress.return;
9994 } while (_workInProgress !== null);
9995
9996 // Schedule the nearest Suspense to re-render the timed out view.
9997 _workInProgress = returnFiber;
9998 do {
9999 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress)) {
10000 // Found the nearest boundary.
10001
10002 // Stash the promise on the boundary fiber. If the boundary times out, we'll
10003 var thenables = _workInProgress.updateQueue;
10004 if (thenables === null) {
10005 var updateQueue = new Set();
10006 updateQueue.add(thenable);
10007 _workInProgress.updateQueue = updateQueue;
10008 } else {
10009 thenables.add(thenable);
10010 }
10011
10012 // If the boundary is outside of concurrent mode, we should *not*
10013 // suspend the commit. Pretend as if the suspended component rendered
10014 // null and keep rendering. In the commit phase, we'll schedule a
10015 // subsequent synchronous update to re-render the Suspense.
10016 //
10017 // Note: It doesn't matter whether the component that suspended was
10018 // inside a concurrent mode tree. If the Suspense is outside of it, we
10019 // should *not* suspend the commit.
10020 if ((_workInProgress.mode & ConcurrentMode) === NoEffect) {
10021 _workInProgress.effectTag |= DidCapture;
10022
10023 // We're going to commit this fiber even though it didn't complete.
10024 // But we shouldn't call any lifecycle methods or callbacks. Remove
10025 // all lifecycle effect tags.
10026 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
10027
10028 if (sourceFiber.tag === ClassComponent) {
10029 var currentSourceFiber = sourceFiber.alternate;
10030 if (currentSourceFiber === null) {
10031 // This is a new mount. Change the tag so it's not mistaken for a
10032 // completed class component. For example, we should not call
10033 // componentWillUnmount if it is deleted.
10034 sourceFiber.tag = IncompleteClassComponent;
10035 } else {
10036 // When we try rendering again, we should not reuse the current fiber,
10037 // since it's known to be in an inconsistent state. Use a force updte to
10038 // prevent a bail out.
10039 var update = createUpdate(Sync);
10040 update.tag = ForceUpdate;
10041 enqueueUpdate(sourceFiber, update);
10042 }
10043 }
10044
10045 // The source fiber did not complete. Mark it with Sync priority to
10046 // indicate that it still has pending work.
10047 sourceFiber.expirationTime = Sync;
10048
10049 // Exit without suspending.
10050 return;
10051 }
10052
10053 // Confirmed that the boundary is in a concurrent mode tree. Continue
10054 // with the normal suspend path.
10055
10056 // Attach a listener to the promise to "ping" the root and retry. But
10057 // only if one does not already exist for the current render expiration
10058 // time (which acts like a "thread ID" here).
10059 var pingCache = root.pingCache;
10060 var threadIDs = void 0;
10061 if (pingCache === null) {
10062 pingCache = root.pingCache = new PossiblyWeakMap();
10063 threadIDs = new Set();
10064 pingCache.set(thenable, threadIDs);
10065 } else {
10066 threadIDs = pingCache.get(thenable);
10067 if (threadIDs === undefined) {
10068 threadIDs = new Set();
10069 pingCache.set(thenable, threadIDs);
10070 }
10071 }
10072 if (!threadIDs.has(renderExpirationTime)) {
10073 // Memoize using the thread ID to prevent redundant listeners.
10074 threadIDs.add(renderExpirationTime);
10075 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
10076 if (enableSchedulerTracing) {
10077 ping = unstable_wrap(ping);
10078 }
10079 thenable.then(ping, ping);
10080 }
10081
10082 var absoluteTimeoutMs = void 0;
10083 if (earliestTimeoutMs === -1) {
10084 // If no explicit threshold is given, default to an arbitrarily large
10085 // value. The actual size doesn't matter because the threshold for the
10086 // whole tree will be clamped to the expiration time.
10087 absoluteTimeoutMs = maxSigned31BitInt;
10088 } else {
10089 if (startTimeMs === -1) {
10090 // This suspend happened outside of any already timed-out
10091 // placeholders. We don't know exactly when the update was
10092 // scheduled, but we can infer an approximate start time from the
10093 // expiration time. First, find the earliest uncommitted expiration
10094 // time in the tree, including work that is suspended. Then subtract
10095 // the offset used to compute an async update's expiration time.
10096 // This will cause high priority (interactive) work to expire
10097 // earlier than necessary, but we can account for this by adjusting
10098 // for the Just Noticeable Difference.
10099 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, renderExpirationTime);
10100 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
10101 startTimeMs = earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
10102 }
10103 absoluteTimeoutMs = startTimeMs + earliestTimeoutMs;
10104 }
10105
10106 // Mark the earliest timeout in the suspended fiber's ancestor path.
10107 // After completing the root, we'll take the largest of all the
10108 // suspended fiber's timeouts and use it to compute a timeout for the
10109 // whole tree.
10110 renderDidSuspend(root, absoluteTimeoutMs, renderExpirationTime);
10111
10112 _workInProgress.effectTag |= ShouldCapture;
10113 _workInProgress.expirationTime = renderExpirationTime;
10114 return;
10115 }
10116 // This boundary already captured during this render. Continue to the next
10117 // boundary.
10118 _workInProgress = _workInProgress.return;
10119 } while (_workInProgress !== null);
10120 // No boundary was found. Fallthrough to error mode.
10121 // TODO: Use invariant so the message is stripped in prod?
10122 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));
10123 }
10124
10125 // We didn't find a boundary that could handle this type of exception. Start
10126 // over and traverse parent path again, this time treating the exception
10127 // as an error.
10128 renderDidError();
10129 value = createCapturedValue(value, sourceFiber);
10130 var workInProgress = returnFiber;
10131 do {
10132 switch (workInProgress.tag) {
10133 case HostRoot:
10134 {
10135 var _errorInfo = value;
10136 workInProgress.effectTag |= ShouldCapture;
10137 workInProgress.expirationTime = renderExpirationTime;
10138 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
10139 enqueueCapturedUpdate(workInProgress, _update);
10140 return;
10141 }
10142 case ClassComponent:
10143 // Capture and retry
10144 var errorInfo = value;
10145 var ctor = workInProgress.type;
10146 var instance = workInProgress.stateNode;
10147 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
10148 workInProgress.effectTag |= ShouldCapture;
10149 workInProgress.expirationTime = renderExpirationTime;
10150 // Schedule the error boundary to re-render using updated state
10151 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
10152 enqueueCapturedUpdate(workInProgress, _update2);
10153 return;
10154 }
10155 break;
10156 default:
10157 break;
10158 }
10159 workInProgress = workInProgress.return;
10160 } while (workInProgress !== null);
10161}
10162
10163function unwindWork(workInProgress, renderExpirationTime) {
10164 switch (workInProgress.tag) {
10165 case ClassComponent:
10166 {
10167 var Component = workInProgress.type;
10168 if (isContextProvider(Component)) {
10169 popContext(workInProgress);
10170 }
10171 var effectTag = workInProgress.effectTag;
10172 if (effectTag & ShouldCapture) {
10173 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
10174 return workInProgress;
10175 }
10176 return null;
10177 }
10178 case HostRoot:
10179 {
10180 popHostContainer(workInProgress);
10181 popTopLevelContextObject(workInProgress);
10182 var _effectTag = workInProgress.effectTag;
10183 !((_effectTag & DidCapture) === NoEffect) ? invariant(false, 'The root failed to unmount after an error. This is likely a bug in React. Please file an issue.') : void 0;
10184 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
10185 return workInProgress;
10186 }
10187 case HostComponent:
10188 {
10189 popHostContext(workInProgress);
10190 return null;
10191 }
10192 case SuspenseComponent:
10193 {
10194 var _effectTag2 = workInProgress.effectTag;
10195 if (_effectTag2 & ShouldCapture) {
10196 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture;
10197 // Captured a suspense effect. Re-render the boundary.
10198 return workInProgress;
10199 }
10200 return null;
10201 }
10202 case HostPortal:
10203 popHostContainer(workInProgress);
10204 return null;
10205 case ContextProvider:
10206 popProvider(workInProgress);
10207 return null;
10208 default:
10209 return null;
10210 }
10211}
10212
10213function unwindInterruptedWork(interruptedWork) {
10214 switch (interruptedWork.tag) {
10215 case ClassComponent:
10216 {
10217 var childContextTypes = interruptedWork.type.childContextTypes;
10218 if (childContextTypes !== null && childContextTypes !== undefined) {
10219 popContext(interruptedWork);
10220 }
10221 break;
10222 }
10223 case HostRoot:
10224 {
10225 popHostContainer(interruptedWork);
10226 popTopLevelContextObject(interruptedWork);
10227 break;
10228 }
10229 case HostComponent:
10230 {
10231 popHostContext(interruptedWork);
10232 break;
10233 }
10234 case HostPortal:
10235 popHostContainer(interruptedWork);
10236 break;
10237 case ContextProvider:
10238 popProvider(interruptedWork);
10239 break;
10240 default:
10241 break;
10242 }
10243}
10244
10245var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
10246var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
10247
10248
10249var didWarnAboutStateTransition = void 0;
10250var didWarnSetStateChildContext = void 0;
10251var warnAboutUpdateOnUnmounted = void 0;
10252var warnAboutInvalidUpdates = void 0;
10253
10254if (enableSchedulerTracing) {
10255 // Provide explicit error message when production+profiling bundle of e.g. react-dom
10256 // is used with production (non-profiling) bundle of scheduler/tracing
10257 !(__interactionsRef != null && __interactionsRef.current != null) ? invariant(false, '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') : void 0;
10258}
10259
10260{
10261 didWarnAboutStateTransition = false;
10262 didWarnSetStateChildContext = false;
10263 var didWarnStateUpdateForUnmountedComponent = {};
10264
10265 warnAboutUpdateOnUnmounted = function (fiber, isClass) {
10266 // We show the whole stack but dedupe on the top component's name because
10267 // the problematic code almost always lies inside that component.
10268 var componentName = getComponentName(fiber.type) || 'ReactComponent';
10269 if (didWarnStateUpdateForUnmountedComponent[componentName]) {
10270 return;
10271 }
10272 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', isClass ? 'the componentWillUnmount method' : 'a useEffect cleanup function', getStackByFiberInDevAndProd(fiber));
10273 didWarnStateUpdateForUnmountedComponent[componentName] = true;
10274 };
10275
10276 warnAboutInvalidUpdates = function (instance) {
10277 switch (phase) {
10278 case 'getChildContext':
10279 if (didWarnSetStateChildContext) {
10280 return;
10281 }
10282 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
10283 didWarnSetStateChildContext = true;
10284 break;
10285 case 'render':
10286 if (didWarnAboutStateTransition) {
10287 return;
10288 }
10289 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.');
10290 didWarnAboutStateTransition = true;
10291 break;
10292 }
10293 };
10294}
10295
10296// Represents the expiration time that incoming updates should use. (If this
10297// is NoWork, use the default strategy: async updates in async mode, sync
10298// updates in sync mode.)
10299var expirationContext = NoWork;
10300
10301var isWorking = false;
10302
10303// The next work in progress fiber that we're currently working on.
10304var nextUnitOfWork = null;
10305var nextRoot = null;
10306// The time at which we're currently rendering work.
10307var nextRenderExpirationTime = NoWork;
10308var nextLatestAbsoluteTimeoutMs = -1;
10309var nextRenderDidError = false;
10310
10311// The next fiber with an effect that we're currently committing.
10312var nextEffect = null;
10313
10314var isCommitting$1 = false;
10315var rootWithPendingPassiveEffects = null;
10316var passiveEffectCallbackHandle = null;
10317var passiveEffectCallback = null;
10318
10319var legacyErrorBoundariesThatAlreadyFailed = null;
10320
10321// Used for performance tracking.
10322var interruptedBy = null;
10323
10324var stashedWorkInProgressProperties = void 0;
10325var replayUnitOfWork = void 0;
10326var mayReplayFailedUnitOfWork = void 0;
10327var isReplayingFailedUnitOfWork = void 0;
10328var originalReplayError = void 0;
10329var rethrowOriginalError = void 0;
10330if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10331 stashedWorkInProgressProperties = null;
10332 mayReplayFailedUnitOfWork = true;
10333 isReplayingFailedUnitOfWork = false;
10334 originalReplayError = null;
10335 replayUnitOfWork = function (failedUnitOfWork, thrownValue, isYieldy) {
10336 if (thrownValue !== null && typeof thrownValue === 'object' && typeof thrownValue.then === 'function') {
10337 // Don't replay promises. Treat everything else like an error.
10338 // TODO: Need to figure out a different strategy if/when we add
10339 // support for catching other types.
10340 return;
10341 }
10342
10343 // Restore the original state of the work-in-progress
10344 if (stashedWorkInProgressProperties === null) {
10345 // This should never happen. Don't throw because this code is DEV-only.
10346 warningWithoutStack$1(false, 'Could not replay rendering after an error. This is likely a bug in React. ' + 'Please file an issue.');
10347 return;
10348 }
10349 assignFiberPropertiesInDEV(failedUnitOfWork, stashedWorkInProgressProperties);
10350
10351 switch (failedUnitOfWork.tag) {
10352 case HostRoot:
10353 popHostContainer(failedUnitOfWork);
10354 popTopLevelContextObject(failedUnitOfWork);
10355 break;
10356 case HostComponent:
10357 popHostContext(failedUnitOfWork);
10358 break;
10359 case ClassComponent:
10360 {
10361 var Component = failedUnitOfWork.type;
10362 if (isContextProvider(Component)) {
10363 popContext(failedUnitOfWork);
10364 }
10365 break;
10366 }
10367 case HostPortal:
10368 popHostContainer(failedUnitOfWork);
10369 break;
10370 case ContextProvider:
10371 popProvider(failedUnitOfWork);
10372 break;
10373 }
10374 // Replay the begin phase.
10375 isReplayingFailedUnitOfWork = true;
10376 originalReplayError = thrownValue;
10377 invokeGuardedCallback(null, workLoop, null, isYieldy);
10378 isReplayingFailedUnitOfWork = false;
10379 originalReplayError = null;
10380 if (hasCaughtError()) {
10381 var replayError = clearCaughtError();
10382 if (replayError != null && thrownValue != null) {
10383 try {
10384 // Reading the expando property is intentionally
10385 // inside `try` because it might be a getter or Proxy.
10386 if (replayError._suppressLogging) {
10387 // Also suppress logging for the original error.
10388 thrownValue._suppressLogging = true;
10389 }
10390 } catch (inner) {
10391 // Ignore.
10392 }
10393 }
10394 } else {
10395 // If the begin phase did not fail the second time, set this pointer
10396 // back to the original value.
10397 nextUnitOfWork = failedUnitOfWork;
10398 }
10399 };
10400 rethrowOriginalError = function () {
10401 throw originalReplayError;
10402 };
10403}
10404
10405function resetStack() {
10406 if (nextUnitOfWork !== null) {
10407 var interruptedWork = nextUnitOfWork.return;
10408 while (interruptedWork !== null) {
10409 unwindInterruptedWork(interruptedWork);
10410 interruptedWork = interruptedWork.return;
10411 }
10412 }
10413
10414 {
10415 ReactStrictModeWarnings.discardPendingWarnings();
10416 checkThatStackIsEmpty();
10417 }
10418
10419 nextRoot = null;
10420 nextRenderExpirationTime = NoWork;
10421 nextLatestAbsoluteTimeoutMs = -1;
10422 nextRenderDidError = false;
10423 nextUnitOfWork = null;
10424}
10425
10426function commitAllHostEffects() {
10427 while (nextEffect !== null) {
10428 {
10429 setCurrentFiber(nextEffect);
10430 }
10431 recordEffect();
10432
10433 var effectTag = nextEffect.effectTag;
10434
10435 if (effectTag & ContentReset) {
10436 commitResetTextContent(nextEffect);
10437 }
10438
10439 if (effectTag & Ref) {
10440 var current$$1 = nextEffect.alternate;
10441 if (current$$1 !== null) {
10442 commitDetachRef(current$$1);
10443 }
10444 }
10445
10446 // The following switch statement is only concerned about placement,
10447 // updates, and deletions. To avoid needing to add a case for every
10448 // possible bitmap value, we remove the secondary effects from the
10449 // effect tag and switch on that value.
10450 var primaryEffectTag = effectTag & (Placement | Update | Deletion);
10451 switch (primaryEffectTag) {
10452 case Placement:
10453 {
10454 commitPlacement(nextEffect);
10455 // Clear the "placement" from effect tag so that we know that this is inserted, before
10456 // any life-cycles like componentDidMount gets called.
10457 // TODO: findDOMNode doesn't rely on this any more but isMounted
10458 // does and isMounted is deprecated anyway so we should be able
10459 // to kill this.
10460 nextEffect.effectTag &= ~Placement;
10461 break;
10462 }
10463 case PlacementAndUpdate:
10464 {
10465 // Placement
10466 commitPlacement(nextEffect);
10467 // Clear the "placement" from effect tag so that we know that this is inserted, before
10468 // any life-cycles like componentDidMount gets called.
10469 nextEffect.effectTag &= ~Placement;
10470
10471 // Update
10472 var _current = nextEffect.alternate;
10473 commitWork(_current, nextEffect);
10474 break;
10475 }
10476 case Update:
10477 {
10478 var _current2 = nextEffect.alternate;
10479 commitWork(_current2, nextEffect);
10480 break;
10481 }
10482 case Deletion:
10483 {
10484 commitDeletion(nextEffect);
10485 break;
10486 }
10487 }
10488 nextEffect = nextEffect.nextEffect;
10489 }
10490
10491 {
10492 resetCurrentFiber();
10493 }
10494}
10495
10496function commitBeforeMutationLifecycles() {
10497 while (nextEffect !== null) {
10498 {
10499 setCurrentFiber(nextEffect);
10500 }
10501
10502 var effectTag = nextEffect.effectTag;
10503 if (effectTag & Snapshot) {
10504 recordEffect();
10505 var current$$1 = nextEffect.alternate;
10506 commitBeforeMutationLifeCycles(current$$1, nextEffect);
10507 }
10508
10509 nextEffect = nextEffect.nextEffect;
10510 }
10511
10512 {
10513 resetCurrentFiber();
10514 }
10515}
10516
10517function commitAllLifeCycles(finishedRoot, committedExpirationTime) {
10518 {
10519 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
10520 ReactStrictModeWarnings.flushLegacyContextWarning();
10521
10522 if (warnAboutDeprecatedLifecycles) {
10523 ReactStrictModeWarnings.flushPendingDeprecationWarnings();
10524 }
10525 }
10526 while (nextEffect !== null) {
10527 {
10528 setCurrentFiber(nextEffect);
10529 }
10530 var effectTag = nextEffect.effectTag;
10531
10532 if (effectTag & (Update | Callback)) {
10533 recordEffect();
10534 var current$$1 = nextEffect.alternate;
10535 commitLifeCycles(finishedRoot, current$$1, nextEffect, committedExpirationTime);
10536 }
10537
10538 if (effectTag & Ref) {
10539 recordEffect();
10540 commitAttachRef(nextEffect);
10541 }
10542
10543 if (effectTag & Passive) {
10544 rootWithPendingPassiveEffects = finishedRoot;
10545 }
10546
10547 nextEffect = nextEffect.nextEffect;
10548 }
10549 {
10550 resetCurrentFiber();
10551 }
10552}
10553
10554function commitPassiveEffects(root, firstEffect) {
10555 rootWithPendingPassiveEffects = null;
10556 passiveEffectCallbackHandle = null;
10557 passiveEffectCallback = null;
10558
10559 // Set this to true to prevent re-entrancy
10560 var previousIsRendering = isRendering;
10561 isRendering = true;
10562
10563 var effect = firstEffect;
10564 do {
10565 {
10566 setCurrentFiber(effect);
10567 }
10568
10569 if (effect.effectTag & Passive) {
10570 var didError = false;
10571 var error = void 0;
10572 {
10573 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
10574 if (hasCaughtError()) {
10575 didError = true;
10576 error = clearCaughtError();
10577 }
10578 }
10579 if (didError) {
10580 captureCommitPhaseError(effect, error);
10581 }
10582 }
10583 effect = effect.nextEffect;
10584 } while (effect !== null);
10585 {
10586 resetCurrentFiber();
10587 }
10588
10589 isRendering = previousIsRendering;
10590
10591 // Check if work was scheduled by one of the effects
10592 var rootExpirationTime = root.expirationTime;
10593 if (rootExpirationTime !== NoWork) {
10594 requestWork(root, rootExpirationTime);
10595 }
10596}
10597
10598function isAlreadyFailedLegacyErrorBoundary(instance) {
10599 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
10600}
10601
10602function markLegacyErrorBoundaryAsFailed(instance) {
10603 if (legacyErrorBoundariesThatAlreadyFailed === null) {
10604 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
10605 } else {
10606 legacyErrorBoundariesThatAlreadyFailed.add(instance);
10607 }
10608}
10609
10610function flushPassiveEffects$1() {
10611 if (passiveEffectCallbackHandle !== null) {
10612 cancelPassiveEffects(passiveEffectCallbackHandle);
10613 }
10614 if (passiveEffectCallback !== null) {
10615 // We call the scheduled callback instead of commitPassiveEffects directly
10616 // to ensure tracing works correctly.
10617 passiveEffectCallback();
10618 }
10619}
10620
10621function commitRoot(root, finishedWork) {
10622 isWorking = true;
10623 isCommitting$1 = true;
10624 startCommitTimer();
10625
10626 !(root.current !== finishedWork) ? invariant(false, 'Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10627 var committedExpirationTime = root.pendingCommitExpirationTime;
10628 !(committedExpirationTime !== NoWork) ? invariant(false, 'Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10629 root.pendingCommitExpirationTime = NoWork;
10630
10631 // Update the pending priority levels to account for the work that we are
10632 // about to commit. This needs to happen before calling the lifecycles, since
10633 // they may schedule additional updates.
10634 var updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
10635 var childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
10636 var earliestRemainingTimeBeforeCommit = childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit ? childExpirationTimeBeforeCommit : updateExpirationTimeBeforeCommit;
10637 markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
10638
10639 var prevInteractions = null;
10640 if (enableSchedulerTracing) {
10641 // Restore any pending interactions at this point,
10642 // So that cascading work triggered during the render phase will be accounted for.
10643 prevInteractions = __interactionsRef.current;
10644 __interactionsRef.current = root.memoizedInteractions;
10645 }
10646
10647 // Reset this to null before calling lifecycles
10648 ReactCurrentOwner$1.current = null;
10649
10650 var firstEffect = void 0;
10651 if (finishedWork.effectTag > PerformedWork) {
10652 // A fiber's effect list consists only of its children, not itself. So if
10653 // the root has an effect, we need to add it to the end of the list. The
10654 // resulting list is the set that would belong to the root's parent, if
10655 // it had one; that is, all the effects in the tree including the root.
10656 if (finishedWork.lastEffect !== null) {
10657 finishedWork.lastEffect.nextEffect = finishedWork;
10658 firstEffect = finishedWork.firstEffect;
10659 } else {
10660 firstEffect = finishedWork;
10661 }
10662 } else {
10663 // There is no effect on the root.
10664 firstEffect = finishedWork.firstEffect;
10665 }
10666
10667 prepareForCommit(root.containerInfo);
10668
10669 // Invoke instances of getSnapshotBeforeUpdate before mutation.
10670 nextEffect = firstEffect;
10671 startCommitSnapshotEffectsTimer();
10672 while (nextEffect !== null) {
10673 var didError = false;
10674 var error = void 0;
10675 {
10676 invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
10677 if (hasCaughtError()) {
10678 didError = true;
10679 error = clearCaughtError();
10680 }
10681 }
10682 if (didError) {
10683 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10684 captureCommitPhaseError(nextEffect, error);
10685 // Clean-up
10686 if (nextEffect !== null) {
10687 nextEffect = nextEffect.nextEffect;
10688 }
10689 }
10690 }
10691 stopCommitSnapshotEffectsTimer();
10692
10693 if (enableProfilerTimer) {
10694 // Mark the current commit time to be shared by all Profilers in this batch.
10695 // This enables them to be grouped later.
10696 recordCommitTime();
10697 }
10698
10699 // Commit all the side-effects within a tree. We'll do this in two passes.
10700 // The first pass performs all the host insertions, updates, deletions and
10701 // ref unmounts.
10702 nextEffect = firstEffect;
10703 startCommitHostEffectsTimer();
10704 while (nextEffect !== null) {
10705 var _didError = false;
10706 var _error = void 0;
10707 {
10708 invokeGuardedCallback(null, commitAllHostEffects, null);
10709 if (hasCaughtError()) {
10710 _didError = true;
10711 _error = clearCaughtError();
10712 }
10713 }
10714 if (_didError) {
10715 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10716 captureCommitPhaseError(nextEffect, _error);
10717 // Clean-up
10718 if (nextEffect !== null) {
10719 nextEffect = nextEffect.nextEffect;
10720 }
10721 }
10722 }
10723 stopCommitHostEffectsTimer();
10724
10725 resetAfterCommit(root.containerInfo);
10726
10727 // The work-in-progress tree is now the current tree. This must come after
10728 // the first pass of the commit phase, so that the previous tree is still
10729 // current during componentWillUnmount, but before the second pass, so that
10730 // the finished work is current during componentDidMount/Update.
10731 root.current = finishedWork;
10732
10733 // In the second pass we'll perform all life-cycles and ref callbacks.
10734 // Life-cycles happen as a separate pass so that all placements, updates,
10735 // and deletions in the entire tree have already been invoked.
10736 // This pass also triggers any renderer-specific initial effects.
10737 nextEffect = firstEffect;
10738 startCommitLifeCyclesTimer();
10739 while (nextEffect !== null) {
10740 var _didError2 = false;
10741 var _error2 = void 0;
10742 {
10743 invokeGuardedCallback(null, commitAllLifeCycles, null, root, committedExpirationTime);
10744 if (hasCaughtError()) {
10745 _didError2 = true;
10746 _error2 = clearCaughtError();
10747 }
10748 }
10749 if (_didError2) {
10750 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10751 captureCommitPhaseError(nextEffect, _error2);
10752 if (nextEffect !== null) {
10753 nextEffect = nextEffect.nextEffect;
10754 }
10755 }
10756 }
10757
10758 if (firstEffect !== null && rootWithPendingPassiveEffects !== null) {
10759 // This commit included a passive effect. These do not need to fire until
10760 // after the next paint. Schedule an callback to fire them in an async
10761 // event. To ensure serial execution, the callback will be flushed early if
10762 // we enter rootWithPendingPassiveEffects commit phase before then.
10763 var callback = commitPassiveEffects.bind(null, root, firstEffect);
10764 if (enableSchedulerTracing) {
10765 // TODO: Avoid this extra callback by mutating the tracing ref directly,
10766 // like we do at the beginning of commitRoot. I've opted not to do that
10767 // here because that code is still in flux.
10768 callback = unstable_wrap(callback);
10769 }
10770 passiveEffectCallbackHandle = schedulePassiveEffects(callback);
10771 passiveEffectCallback = callback;
10772 }
10773
10774 isCommitting$1 = false;
10775 isWorking = false;
10776 stopCommitLifeCyclesTimer();
10777 stopCommitTimer();
10778 onCommitRoot(finishedWork.stateNode);
10779 if (true && ReactFiberInstrumentation_1.debugTool) {
10780 ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork);
10781 }
10782
10783 var updateExpirationTimeAfterCommit = finishedWork.expirationTime;
10784 var childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
10785 var earliestRemainingTimeAfterCommit = childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit ? childExpirationTimeAfterCommit : updateExpirationTimeAfterCommit;
10786 if (earliestRemainingTimeAfterCommit === NoWork) {
10787 // If there's no remaining work, we can clear the set of already failed
10788 // error boundaries.
10789 legacyErrorBoundariesThatAlreadyFailed = null;
10790 }
10791 onCommit(root, earliestRemainingTimeAfterCommit);
10792
10793 if (enableSchedulerTracing) {
10794 __interactionsRef.current = prevInteractions;
10795
10796 var subscriber = void 0;
10797
10798 try {
10799 subscriber = __subscriberRef.current;
10800 if (subscriber !== null && root.memoizedInteractions.size > 0) {
10801 var threadID = computeThreadID(committedExpirationTime, root.interactionThreadID);
10802 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
10803 }
10804 } catch (error) {
10805 // It's not safe for commitRoot() to throw.
10806 // Store the error for now and we'll re-throw in finishRendering().
10807 if (!hasUnhandledError) {
10808 hasUnhandledError = true;
10809 unhandledError = error;
10810 }
10811 } finally {
10812 // Clear completed interactions from the pending Map.
10813 // Unless the render was suspended or cascading work was scheduled,
10814 // In which case– leave pending interactions until the subsequent render.
10815 var pendingInteractionMap = root.pendingInteractionMap;
10816 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
10817 // Only decrement the pending interaction count if we're done.
10818 // If there's still work at the current priority,
10819 // That indicates that we are waiting for suspense data.
10820 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
10821 pendingInteractionMap.delete(scheduledExpirationTime);
10822
10823 scheduledInteractions.forEach(function (interaction) {
10824 interaction.__count--;
10825
10826 if (subscriber !== null && interaction.__count === 0) {
10827 try {
10828 subscriber.onInteractionScheduledWorkCompleted(interaction);
10829 } catch (error) {
10830 // It's not safe for commitRoot() to throw.
10831 // Store the error for now and we'll re-throw in finishRendering().
10832 if (!hasUnhandledError) {
10833 hasUnhandledError = true;
10834 unhandledError = error;
10835 }
10836 }
10837 }
10838 });
10839 }
10840 });
10841 }
10842 }
10843}
10844
10845function resetChildExpirationTime(workInProgress, renderTime) {
10846 if (renderTime !== Never && workInProgress.childExpirationTime === Never) {
10847 // The children of this component are hidden. Don't bubble their
10848 // expiration times.
10849 return;
10850 }
10851
10852 var newChildExpirationTime = NoWork;
10853
10854 // Bubble up the earliest expiration time.
10855 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
10856 // We're in profiling mode.
10857 // Let's use this same traversal to update the render durations.
10858 var actualDuration = workInProgress.actualDuration;
10859 var treeBaseDuration = workInProgress.selfBaseDuration;
10860
10861 // When a fiber is cloned, its actualDuration is reset to 0.
10862 // This value will only be updated if work is done on the fiber (i.e. it doesn't bailout).
10863 // When work is done, it should bubble to the parent's actualDuration.
10864 // If the fiber has not been cloned though, (meaning no work was done),
10865 // Then this value will reflect the amount of time spent working on a previous render.
10866 // In that case it should not bubble.
10867 // We determine whether it was cloned by comparing the child pointer.
10868 var shouldBubbleActualDurations = workInProgress.alternate === null || workInProgress.child !== workInProgress.alternate.child;
10869
10870 var child = workInProgress.child;
10871 while (child !== null) {
10872 var childUpdateExpirationTime = child.expirationTime;
10873 var childChildExpirationTime = child.childExpirationTime;
10874 if (childUpdateExpirationTime > newChildExpirationTime) {
10875 newChildExpirationTime = childUpdateExpirationTime;
10876 }
10877 if (childChildExpirationTime > newChildExpirationTime) {
10878 newChildExpirationTime = childChildExpirationTime;
10879 }
10880 if (shouldBubbleActualDurations) {
10881 actualDuration += child.actualDuration;
10882 }
10883 treeBaseDuration += child.treeBaseDuration;
10884 child = child.sibling;
10885 }
10886 workInProgress.actualDuration = actualDuration;
10887 workInProgress.treeBaseDuration = treeBaseDuration;
10888 } else {
10889 var _child = workInProgress.child;
10890 while (_child !== null) {
10891 var _childUpdateExpirationTime = _child.expirationTime;
10892 var _childChildExpirationTime = _child.childExpirationTime;
10893 if (_childUpdateExpirationTime > newChildExpirationTime) {
10894 newChildExpirationTime = _childUpdateExpirationTime;
10895 }
10896 if (_childChildExpirationTime > newChildExpirationTime) {
10897 newChildExpirationTime = _childChildExpirationTime;
10898 }
10899 _child = _child.sibling;
10900 }
10901 }
10902
10903 workInProgress.childExpirationTime = newChildExpirationTime;
10904}
10905
10906function completeUnitOfWork(workInProgress) {
10907 // Attempt to complete the current unit of work, then move to the
10908 // next sibling. If there are no more siblings, return to the
10909 // parent fiber.
10910 while (true) {
10911 // The current, flushed, state of this fiber is the alternate.
10912 // Ideally nothing should rely on this, but relying on it here
10913 // means that we don't need an additional field on the work in
10914 // progress.
10915 var current$$1 = workInProgress.alternate;
10916 {
10917 setCurrentFiber(workInProgress);
10918 }
10919
10920 var returnFiber = workInProgress.return;
10921 var siblingFiber = workInProgress.sibling;
10922
10923 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
10924 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10925 // Don't replay if it fails during completion phase.
10926 mayReplayFailedUnitOfWork = false;
10927 }
10928 // This fiber completed.
10929 // Remember we're completing this unit so we can find a boundary if it fails.
10930 nextUnitOfWork = workInProgress;
10931 if (enableProfilerTimer) {
10932 if (workInProgress.mode & ProfileMode) {
10933 startProfilerTimer(workInProgress);
10934 }
10935 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
10936 if (workInProgress.mode & ProfileMode) {
10937 // Update render duration assuming we didn't error.
10938 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
10939 }
10940 } else {
10941 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
10942 }
10943 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10944 // We're out of completion phase so replaying is fine now.
10945 mayReplayFailedUnitOfWork = true;
10946 }
10947 stopWorkTimer(workInProgress);
10948 resetChildExpirationTime(workInProgress, nextRenderExpirationTime);
10949 {
10950 resetCurrentFiber();
10951 }
10952
10953 if (nextUnitOfWork !== null) {
10954 // Completing this fiber spawned new work. Work on that next.
10955 return nextUnitOfWork;
10956 }
10957
10958 if (returnFiber !== null &&
10959 // Do not append effects to parents if a sibling failed to complete
10960 (returnFiber.effectTag & Incomplete) === NoEffect) {
10961 // Append all the effects of the subtree and this fiber onto the effect
10962 // list of the parent. The completion order of the children affects the
10963 // side-effect order.
10964 if (returnFiber.firstEffect === null) {
10965 returnFiber.firstEffect = workInProgress.firstEffect;
10966 }
10967 if (workInProgress.lastEffect !== null) {
10968 if (returnFiber.lastEffect !== null) {
10969 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
10970 }
10971 returnFiber.lastEffect = workInProgress.lastEffect;
10972 }
10973
10974 // If this fiber had side-effects, we append it AFTER the children's
10975 // side-effects. We can perform certain side-effects earlier if
10976 // needed, by doing multiple passes over the effect list. We don't want
10977 // to schedule our own side-effect on our own list because if end up
10978 // reusing children we'll schedule this effect onto itself since we're
10979 // at the end.
10980 var effectTag = workInProgress.effectTag;
10981 // Skip both NoWork and PerformedWork tags when creating the effect list.
10982 // PerformedWork effect is read by React DevTools but shouldn't be committed.
10983 if (effectTag > PerformedWork) {
10984 if (returnFiber.lastEffect !== null) {
10985 returnFiber.lastEffect.nextEffect = workInProgress;
10986 } else {
10987 returnFiber.firstEffect = workInProgress;
10988 }
10989 returnFiber.lastEffect = workInProgress;
10990 }
10991 }
10992
10993 if (true && ReactFiberInstrumentation_1.debugTool) {
10994 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
10995 }
10996
10997 if (siblingFiber !== null) {
10998 // If there is more work to do in this returnFiber, do that next.
10999 return siblingFiber;
11000 } else if (returnFiber !== null) {
11001 // If there's no more work in this returnFiber. Complete the returnFiber.
11002 workInProgress = returnFiber;
11003 continue;
11004 } else {
11005 // We've reached the root.
11006 return null;
11007 }
11008 } else {
11009 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11010 // Record the render duration for the fiber that errored.
11011 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11012
11013 // Include the time spent working on failed children before continuing.
11014 var actualDuration = workInProgress.actualDuration;
11015 var child = workInProgress.child;
11016 while (child !== null) {
11017 actualDuration += child.actualDuration;
11018 child = child.sibling;
11019 }
11020 workInProgress.actualDuration = actualDuration;
11021 }
11022
11023 // This fiber did not complete because something threw. Pop values off
11024 // the stack without entering the complete phase. If this is a boundary,
11025 // capture values if possible.
11026 var next = unwindWork(workInProgress, nextRenderExpirationTime);
11027 // Because this fiber did not complete, don't reset its expiration time.
11028 if (workInProgress.effectTag & DidCapture) {
11029 // Restarting an error boundary
11030 stopFailedWorkTimer(workInProgress);
11031 } else {
11032 stopWorkTimer(workInProgress);
11033 }
11034
11035 {
11036 resetCurrentFiber();
11037 }
11038
11039 if (next !== null) {
11040 stopWorkTimer(workInProgress);
11041 if (true && ReactFiberInstrumentation_1.debugTool) {
11042 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11043 }
11044
11045 // If completing this work spawned new work, do that next. We'll come
11046 // back here again.
11047 // Since we're restarting, remove anything that is not a host effect
11048 // from the effect tag.
11049 next.effectTag &= HostEffectMask;
11050 return next;
11051 }
11052
11053 if (returnFiber !== null) {
11054 // Mark the parent fiber as incomplete and clear its effect list.
11055 returnFiber.firstEffect = returnFiber.lastEffect = null;
11056 returnFiber.effectTag |= Incomplete;
11057 }
11058
11059 if (true && ReactFiberInstrumentation_1.debugTool) {
11060 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11061 }
11062
11063 if (siblingFiber !== null) {
11064 // If there is more work to do in this returnFiber, do that next.
11065 return siblingFiber;
11066 } else if (returnFiber !== null) {
11067 // If there's no more work in this returnFiber. Complete the returnFiber.
11068 workInProgress = returnFiber;
11069 continue;
11070 } else {
11071 return null;
11072 }
11073 }
11074 }
11075
11076 // Without this explicit null return Flow complains of invalid return type
11077 // TODO Remove the above while(true) loop
11078 // eslint-disable-next-line no-unreachable
11079 return null;
11080}
11081
11082function performUnitOfWork(workInProgress) {
11083 // The current, flushed, state of this fiber is the alternate.
11084 // Ideally nothing should rely on this, but relying on it here
11085 // means that we don't need an additional field on the work in
11086 // progress.
11087 var current$$1 = workInProgress.alternate;
11088
11089 // See if beginning this work spawns more work.
11090 startWorkTimer(workInProgress);
11091 {
11092 setCurrentFiber(workInProgress);
11093 }
11094
11095 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11096 stashedWorkInProgressProperties = assignFiberPropertiesInDEV(stashedWorkInProgressProperties, workInProgress);
11097 }
11098
11099 var next = void 0;
11100 if (enableProfilerTimer) {
11101 if (workInProgress.mode & ProfileMode) {
11102 startProfilerTimer(workInProgress);
11103 }
11104
11105 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11106 workInProgress.memoizedProps = workInProgress.pendingProps;
11107
11108 if (workInProgress.mode & ProfileMode) {
11109 // Record the render duration assuming we didn't bailout (or error).
11110 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
11111 }
11112 } else {
11113 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11114 workInProgress.memoizedProps = workInProgress.pendingProps;
11115 }
11116
11117 {
11118 resetCurrentFiber();
11119 if (isReplayingFailedUnitOfWork) {
11120 // Currently replaying a failed unit of work. This should be unreachable,
11121 // because the render phase is meant to be idempotent, and it should
11122 // have thrown again. Since it didn't, rethrow the original error, so
11123 // React's internal stack is not misaligned.
11124 rethrowOriginalError();
11125 }
11126 }
11127 if (true && ReactFiberInstrumentation_1.debugTool) {
11128 ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress);
11129 }
11130
11131 if (next === null) {
11132 // If this doesn't spawn new work, complete the current work.
11133 next = completeUnitOfWork(workInProgress);
11134 }
11135
11136 ReactCurrentOwner$1.current = null;
11137
11138 return next;
11139}
11140
11141function workLoop(isYieldy) {
11142 if (!isYieldy) {
11143 // Flush work without yielding
11144 while (nextUnitOfWork !== null) {
11145 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11146 }
11147 } else {
11148 // Flush asynchronous work until there's a higher priority event
11149 while (nextUnitOfWork !== null && !shouldYieldToRenderer()) {
11150 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11151 }
11152 }
11153}
11154
11155function renderRoot(root, isYieldy) {
11156 !!isWorking ? invariant(false, 'renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11157
11158 flushPassiveEffects$1();
11159
11160 isWorking = true;
11161 var previousDispatcher = ReactCurrentDispatcher.current;
11162 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
11163
11164 var expirationTime = root.nextExpirationTimeToWorkOn;
11165
11166 // Check if we're starting from a fresh stack, or if we're resuming from
11167 // previously yielded work.
11168 if (expirationTime !== nextRenderExpirationTime || root !== nextRoot || nextUnitOfWork === null) {
11169 // Reset the stack and start working from the root.
11170 resetStack();
11171 nextRoot = root;
11172 nextRenderExpirationTime = expirationTime;
11173 nextUnitOfWork = createWorkInProgress(nextRoot.current, null, nextRenderExpirationTime);
11174 root.pendingCommitExpirationTime = NoWork;
11175
11176 if (enableSchedulerTracing) {
11177 // Determine which interactions this batch of work currently includes,
11178 // So that we can accurately attribute time spent working on it,
11179 var interactions = new Set();
11180 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11181 if (scheduledExpirationTime >= expirationTime) {
11182 scheduledInteractions.forEach(function (interaction) {
11183 return interactions.add(interaction);
11184 });
11185 }
11186 });
11187
11188 // Store the current set of interactions on the FiberRoot for a few reasons:
11189 // We can re-use it in hot functions like renderRoot() without having to recalculate it.
11190 // We will also use it in commitWork() to pass to any Profiler onRender() hooks.
11191 // This also provides DevTools with a way to access it when the onCommitRoot() hook is called.
11192 root.memoizedInteractions = interactions;
11193
11194 if (interactions.size > 0) {
11195 var subscriber = __subscriberRef.current;
11196 if (subscriber !== null) {
11197 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11198 try {
11199 subscriber.onWorkStarted(interactions, threadID);
11200 } catch (error) {
11201 // Work thrown by an interaction tracing subscriber should be rethrown,
11202 // But only once it's safe (to avoid leaving the scheduler in an invalid state).
11203 // Store the error for now and we'll re-throw in finishRendering().
11204 if (!hasUnhandledError) {
11205 hasUnhandledError = true;
11206 unhandledError = error;
11207 }
11208 }
11209 }
11210 }
11211 }
11212 }
11213
11214 var prevInteractions = null;
11215 if (enableSchedulerTracing) {
11216 // We're about to start new traced work.
11217 // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
11218 prevInteractions = __interactionsRef.current;
11219 __interactionsRef.current = root.memoizedInteractions;
11220 }
11221
11222 var didFatal = false;
11223
11224 startWorkLoopTimer(nextUnitOfWork);
11225
11226 do {
11227 try {
11228 workLoop(isYieldy);
11229 } catch (thrownValue) {
11230 resetContextDependences();
11231 resetHooks();
11232
11233 // Reset in case completion throws.
11234 // This is only used in DEV and when replaying is on.
11235 var mayReplay = void 0;
11236 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11237 mayReplay = mayReplayFailedUnitOfWork;
11238 mayReplayFailedUnitOfWork = true;
11239 }
11240
11241 if (nextUnitOfWork === null) {
11242 // This is a fatal error.
11243 didFatal = true;
11244 onUncaughtError(thrownValue);
11245 } else {
11246 if (enableProfilerTimer && nextUnitOfWork.mode & ProfileMode) {
11247 // Record the time spent rendering before an error was thrown.
11248 // This avoids inaccurate Profiler durations in the case of a suspended render.
11249 stopProfilerTimerIfRunningAndRecordDelta(nextUnitOfWork, true);
11250 }
11251
11252 {
11253 // Reset global debug state
11254 // We assume this is defined in DEV
11255 resetCurrentlyProcessingQueue();
11256 }
11257
11258 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11259 if (mayReplay) {
11260 var failedUnitOfWork = nextUnitOfWork;
11261 replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
11262 }
11263 }
11264
11265 // TODO: we already know this isn't true in some cases.
11266 // At least this shows a nicer error message until we figure out the cause.
11267 // https://github.com/facebook/react/issues/12449#issuecomment-386727431
11268 !(nextUnitOfWork !== null) ? invariant(false, 'Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it.') : void 0;
11269
11270 var sourceFiber = nextUnitOfWork;
11271 var returnFiber = sourceFiber.return;
11272 if (returnFiber === null) {
11273 // This is the root. The root could capture its own errors. However,
11274 // we don't know if it errors before or after we pushed the host
11275 // context. This information is needed to avoid a stack mismatch.
11276 // Because we're not sure, treat this as a fatal error. We could track
11277 // which phase it fails in, but doesn't seem worth it. At least
11278 // for now.
11279 didFatal = true;
11280 onUncaughtError(thrownValue);
11281 } else {
11282 throwException(root, returnFiber, sourceFiber, thrownValue, nextRenderExpirationTime);
11283 nextUnitOfWork = completeUnitOfWork(sourceFiber);
11284 continue;
11285 }
11286 }
11287 }
11288 break;
11289 } while (true);
11290
11291 if (enableSchedulerTracing) {
11292 // Traced work is done for now; restore the previous interactions.
11293 __interactionsRef.current = prevInteractions;
11294 }
11295
11296 // We're done performing work. Time to clean up.
11297 isWorking = false;
11298 ReactCurrentDispatcher.current = previousDispatcher;
11299 resetContextDependences();
11300 resetHooks();
11301
11302 // Yield back to main thread.
11303 if (didFatal) {
11304 var _didCompleteRoot = false;
11305 stopWorkLoopTimer(interruptedBy, _didCompleteRoot);
11306 interruptedBy = null;
11307 // There was a fatal error.
11308 {
11309 resetStackAfterFatalErrorInDev();
11310 }
11311 // `nextRoot` points to the in-progress root. A non-null value indicates
11312 // that we're in the middle of an async render. Set it to null to indicate
11313 // there's no more work to be done in the current batch.
11314 nextRoot = null;
11315 onFatal(root);
11316 return;
11317 }
11318
11319 if (nextUnitOfWork !== null) {
11320 // There's still remaining async work in this tree, but we ran out of time
11321 // in the current frame. Yield back to the renderer. Unless we're
11322 // interrupted by a higher priority update, we'll continue later from where
11323 // we left off.
11324 var _didCompleteRoot2 = false;
11325 stopWorkLoopTimer(interruptedBy, _didCompleteRoot2);
11326 interruptedBy = null;
11327 onYield(root);
11328 return;
11329 }
11330
11331 // We completed the whole tree.
11332 var didCompleteRoot = true;
11333 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
11334 var rootWorkInProgress = root.current.alternate;
11335 !(rootWorkInProgress !== null) ? invariant(false, 'Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11336
11337 // `nextRoot` points to the in-progress root. A non-null value indicates
11338 // that we're in the middle of an async render. Set it to null to indicate
11339 // there's no more work to be done in the current batch.
11340 nextRoot = null;
11341 interruptedBy = null;
11342
11343 if (nextRenderDidError) {
11344 // There was an error
11345 if (hasLowerPriorityWork(root, expirationTime)) {
11346 // There's lower priority work. If so, it may have the effect of fixing
11347 // the exception that was just thrown. Exit without committing. This is
11348 // similar to a suspend, but without a timeout because we're not waiting
11349 // for a promise to resolve. React will restart at the lower
11350 // priority level.
11351 markSuspendedPriorityLevel(root, expirationTime);
11352 var suspendedExpirationTime = expirationTime;
11353 var rootExpirationTime = root.expirationTime;
11354 onSuspend(root, rootWorkInProgress, suspendedExpirationTime, rootExpirationTime, -1 // Indicates no timeout
11355 );
11356 return;
11357 } else if (
11358 // There's no lower priority work, but we're rendering asynchronously.
11359 // Synchronsouly attempt to render the same level one more time. This is
11360 // similar to a suspend, but without a timeout because we're not waiting
11361 // for a promise to resolve.
11362 !root.didError && isYieldy) {
11363 root.didError = true;
11364 var _suspendedExpirationTime = root.nextExpirationTimeToWorkOn = expirationTime;
11365 var _rootExpirationTime = root.expirationTime = Sync;
11366 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime, _rootExpirationTime, -1 // Indicates no timeout
11367 );
11368 return;
11369 }
11370 }
11371
11372 if (isYieldy && nextLatestAbsoluteTimeoutMs !== -1) {
11373 // The tree was suspended.
11374 var _suspendedExpirationTime2 = expirationTime;
11375 markSuspendedPriorityLevel(root, _suspendedExpirationTime2);
11376
11377 // Find the earliest uncommitted expiration time in the tree, including
11378 // work that is suspended. The timeout threshold cannot be longer than
11379 // the overall expiration.
11380 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, expirationTime);
11381 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
11382 if (earliestExpirationTimeMs < nextLatestAbsoluteTimeoutMs) {
11383 nextLatestAbsoluteTimeoutMs = earliestExpirationTimeMs;
11384 }
11385
11386 // Subtract the current time from the absolute timeout to get the number
11387 // of milliseconds until the timeout. In other words, convert an absolute
11388 // timestamp to a relative time. This is the value that is passed
11389 // to `setTimeout`.
11390 var currentTimeMs = expirationTimeToMs(requestCurrentTime());
11391 var msUntilTimeout = nextLatestAbsoluteTimeoutMs - currentTimeMs;
11392 msUntilTimeout = msUntilTimeout < 0 ? 0 : msUntilTimeout;
11393
11394 // TODO: Account for the Just Noticeable Difference
11395
11396 var _rootExpirationTime2 = root.expirationTime;
11397 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime2, _rootExpirationTime2, msUntilTimeout);
11398 return;
11399 }
11400
11401 // Ready to commit.
11402 onComplete(root, rootWorkInProgress, expirationTime);
11403}
11404
11405function captureCommitPhaseError(sourceFiber, value) {
11406 var expirationTime = Sync;
11407 var fiber = sourceFiber.return;
11408 while (fiber !== null) {
11409 switch (fiber.tag) {
11410 case ClassComponent:
11411 var ctor = fiber.type;
11412 var instance = fiber.stateNode;
11413 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
11414 var errorInfo = createCapturedValue(value, sourceFiber);
11415 var update = createClassErrorUpdate(fiber, errorInfo, expirationTime);
11416 enqueueUpdate(fiber, update);
11417 scheduleWork(fiber, expirationTime);
11418 return;
11419 }
11420 break;
11421 case HostRoot:
11422 {
11423 var _errorInfo = createCapturedValue(value, sourceFiber);
11424 var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime);
11425 enqueueUpdate(fiber, _update);
11426 scheduleWork(fiber, expirationTime);
11427 return;
11428 }
11429 }
11430 fiber = fiber.return;
11431 }
11432
11433 if (sourceFiber.tag === HostRoot) {
11434 // Error was thrown at the root. There is no parent, so the root
11435 // itself should capture it.
11436 var rootFiber = sourceFiber;
11437 var _errorInfo2 = createCapturedValue(value, rootFiber);
11438 var _update2 = createRootErrorUpdate(rootFiber, _errorInfo2, expirationTime);
11439 enqueueUpdate(rootFiber, _update2);
11440 scheduleWork(rootFiber, expirationTime);
11441 }
11442}
11443
11444function computeThreadID(expirationTime, interactionThreadID) {
11445 // Interaction threads are unique per root and expiration time.
11446 return expirationTime * 1000 + interactionThreadID;
11447}
11448
11449function computeExpirationForFiber(currentTime, fiber) {
11450 var expirationTime = void 0;
11451 if (expirationContext !== NoWork) {
11452 // An explicit expiration context was set;
11453 expirationTime = expirationContext;
11454 } else if (isWorking) {
11455 if (isCommitting$1) {
11456 // Updates that occur during the commit phase should have sync priority
11457 // by default.
11458 expirationTime = Sync;
11459 } else {
11460 // Updates during the render phase should expire at the same time as
11461 // the work that is being rendered.
11462 expirationTime = nextRenderExpirationTime;
11463 }
11464 } else {
11465 // No explicit expiration context was set, and we're not currently
11466 // performing work. Calculate a new expiration time.
11467 if (fiber.mode & ConcurrentMode) {
11468 if (isBatchingInteractiveUpdates) {
11469 // This is an interactive update
11470 expirationTime = computeInteractiveExpiration(currentTime);
11471 } else {
11472 // This is an async update
11473 expirationTime = computeAsyncExpiration(currentTime);
11474 }
11475 // If we're in the middle of rendering a tree, do not update at the same
11476 // expiration time that is already rendering.
11477 if (nextRoot !== null && expirationTime === nextRenderExpirationTime) {
11478 expirationTime -= 1;
11479 }
11480 } else {
11481 // This is a sync update
11482 expirationTime = Sync;
11483 }
11484 }
11485 return expirationTime;
11486}
11487
11488function renderDidSuspend(root, absoluteTimeoutMs, suspendedTime) {
11489 // Schedule the timeout.
11490 if (absoluteTimeoutMs >= 0 && nextLatestAbsoluteTimeoutMs < absoluteTimeoutMs) {
11491 nextLatestAbsoluteTimeoutMs = absoluteTimeoutMs;
11492 }
11493}
11494
11495function renderDidError() {
11496 nextRenderDidError = true;
11497}
11498
11499function pingSuspendedRoot(root, thenable, pingTime) {
11500 // A promise that previously suspended React from committing has resolved.
11501 // If React is still suspended, try again at the previous level (pingTime).
11502
11503 var pingCache = root.pingCache;
11504 if (pingCache !== null) {
11505 // The thenable resolved, so we no longer need to memoize, because it will
11506 // never be thrown again.
11507 pingCache.delete(thenable);
11508 }
11509
11510 if (nextRoot !== null && nextRenderExpirationTime === pingTime) {
11511 // Received a ping at the same priority level at which we're currently
11512 // rendering. Restart from the root.
11513 nextRoot = null;
11514 } else {
11515 // Confirm that the root is still suspended at this level. Otherwise exit.
11516 if (isPriorityLevelSuspended(root, pingTime)) {
11517 // Ping at the original level
11518 markPingedPriorityLevel(root, pingTime);
11519 var rootExpirationTime = root.expirationTime;
11520 if (rootExpirationTime !== NoWork) {
11521 requestWork(root, rootExpirationTime);
11522 }
11523 }
11524 }
11525}
11526
11527function retryTimedOutBoundary(boundaryFiber, thenable) {
11528 // The boundary fiber (a Suspense component) previously timed out and was
11529 // rendered in its fallback state. One of the promises that suspended it has
11530 // resolved, which means at least part of the tree was likely unblocked. Try
11531 var retryCache = boundaryFiber.stateNode;
11532 if (retryCache !== null) {
11533 // The thenable resolved, so we no longer need to memoize, because it will
11534 // never be thrown again.
11535 retryCache.delete(thenable);
11536 }
11537
11538 var currentTime = requestCurrentTime();
11539 var retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
11540 var root = scheduleWorkToRoot(boundaryFiber, retryTime);
11541 if (root !== null) {
11542 markPendingPriorityLevel(root, retryTime);
11543 var rootExpirationTime = root.expirationTime;
11544 if (rootExpirationTime !== NoWork) {
11545 requestWork(root, rootExpirationTime);
11546 }
11547 }
11548}
11549
11550function scheduleWorkToRoot(fiber, expirationTime) {
11551 recordScheduleUpdate();
11552
11553 {
11554 if (fiber.tag === ClassComponent) {
11555 var instance = fiber.stateNode;
11556 warnAboutInvalidUpdates(instance);
11557 }
11558 }
11559
11560 // Update the source fiber's expiration time
11561 if (fiber.expirationTime < expirationTime) {
11562 fiber.expirationTime = expirationTime;
11563 }
11564 var alternate = fiber.alternate;
11565 if (alternate !== null && alternate.expirationTime < expirationTime) {
11566 alternate.expirationTime = expirationTime;
11567 }
11568 // Walk the parent path to the root and update the child expiration time.
11569 var node = fiber.return;
11570 var root = null;
11571 if (node === null && fiber.tag === HostRoot) {
11572 root = fiber.stateNode;
11573 } else {
11574 while (node !== null) {
11575 alternate = node.alternate;
11576 if (node.childExpirationTime < expirationTime) {
11577 node.childExpirationTime = expirationTime;
11578 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
11579 alternate.childExpirationTime = expirationTime;
11580 }
11581 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
11582 alternate.childExpirationTime = expirationTime;
11583 }
11584 if (node.return === null && node.tag === HostRoot) {
11585 root = node.stateNode;
11586 break;
11587 }
11588 node = node.return;
11589 }
11590 }
11591
11592 if (enableSchedulerTracing) {
11593 if (root !== null) {
11594 var interactions = __interactionsRef.current;
11595 if (interactions.size > 0) {
11596 var pendingInteractionMap = root.pendingInteractionMap;
11597 var pendingInteractions = pendingInteractionMap.get(expirationTime);
11598 if (pendingInteractions != null) {
11599 interactions.forEach(function (interaction) {
11600 if (!pendingInteractions.has(interaction)) {
11601 // Update the pending async work count for previously unscheduled interaction.
11602 interaction.__count++;
11603 }
11604
11605 pendingInteractions.add(interaction);
11606 });
11607 } else {
11608 pendingInteractionMap.set(expirationTime, new Set(interactions));
11609
11610 // Update the pending async work count for the current interactions.
11611 interactions.forEach(function (interaction) {
11612 interaction.__count++;
11613 });
11614 }
11615
11616 var subscriber = __subscriberRef.current;
11617 if (subscriber !== null) {
11618 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11619 subscriber.onWorkScheduled(interactions, threadID);
11620 }
11621 }
11622 }
11623 }
11624 return root;
11625}
11626
11627function warnIfNotCurrentlyBatchingInDev(fiber) {
11628 {
11629 if (isRendering === false && isBatchingUpdates === false) {
11630 warningWithoutStack$1(false, 'An update to %s inside a test was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see in the browser." + ' Learn more at https://fb.me/react-wrap-tests-with-act', getComponentName(fiber.type));
11631 }
11632 }
11633}
11634
11635function scheduleWork(fiber, expirationTime) {
11636 var root = scheduleWorkToRoot(fiber, expirationTime);
11637 if (root === null) {
11638 {
11639 switch (fiber.tag) {
11640 case ClassComponent:
11641 warnAboutUpdateOnUnmounted(fiber, true);
11642 break;
11643 case FunctionComponent:
11644 case ForwardRef:
11645 case MemoComponent:
11646 case SimpleMemoComponent:
11647 warnAboutUpdateOnUnmounted(fiber, false);
11648 break;
11649 }
11650 }
11651 return;
11652 }
11653
11654 if (!isWorking && nextRenderExpirationTime !== NoWork && expirationTime > nextRenderExpirationTime) {
11655 // This is an interruption. (Used for performance tracking.)
11656 interruptedBy = fiber;
11657 resetStack();
11658 }
11659 markPendingPriorityLevel(root, expirationTime);
11660 if (
11661 // If we're in the render phase, we don't need to schedule this root
11662 // for an update, because we'll do it before we exit...
11663 !isWorking || isCommitting$1 ||
11664 // ...unless this is a different root than the one we're rendering.
11665 nextRoot !== root) {
11666 var rootExpirationTime = root.expirationTime;
11667 requestWork(root, rootExpirationTime);
11668 }
11669 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
11670 // Reset this back to zero so subsequent updates don't throw.
11671 nestedUpdateCount = 0;
11672 invariant(false, 'Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.');
11673 }
11674}
11675
11676function syncUpdates(fn, a, b, c, d) {
11677 var previousExpirationContext = expirationContext;
11678 expirationContext = Sync;
11679 try {
11680 return fn(a, b, c, d);
11681 } finally {
11682 expirationContext = previousExpirationContext;
11683 }
11684}
11685
11686// TODO: Everything below this is written as if it has been lifted to the
11687// renderers. I'll do this in a follow-up.
11688
11689// Linked-list of roots
11690var firstScheduledRoot = null;
11691var lastScheduledRoot = null;
11692
11693var callbackExpirationTime = NoWork;
11694var callbackID = void 0;
11695var isRendering = false;
11696var nextFlushedRoot = null;
11697var nextFlushedExpirationTime = NoWork;
11698var hasUnhandledError = false;
11699var unhandledError = null;
11700
11701var isBatchingUpdates = false;
11702var isUnbatchingUpdates = false;
11703var isBatchingInteractiveUpdates = false;
11704
11705var completedBatches = null;
11706
11707var originalStartTimeMs = now();
11708var currentRendererTime = msToExpirationTime(originalStartTimeMs);
11709var currentSchedulerTime = currentRendererTime;
11710
11711// Use these to prevent an infinite loop of nested updates
11712var NESTED_UPDATE_LIMIT = 50;
11713var nestedUpdateCount = 0;
11714var lastCommittedRootDuringThisBatch = null;
11715
11716function recomputeCurrentRendererTime() {
11717 var currentTimeMs = now() - originalStartTimeMs;
11718 currentRendererTime = msToExpirationTime(currentTimeMs);
11719}
11720
11721function scheduleCallbackWithExpirationTime(root, expirationTime) {
11722 if (callbackExpirationTime !== NoWork) {
11723 // A callback is already scheduled. Check its expiration time (timeout).
11724 if (expirationTime < callbackExpirationTime) {
11725 // Existing callback has sufficient timeout. Exit.
11726 return;
11727 } else {
11728 if (callbackID !== null) {
11729 // Existing callback has insufficient timeout. Cancel and schedule a
11730 // new one.
11731 cancelDeferredCallback$$1(callbackID);
11732 }
11733 }
11734 // The request callback timer is already running. Don't start a new one.
11735 } else {
11736 startRequestCallbackTimer();
11737 }
11738
11739 callbackExpirationTime = expirationTime;
11740 var currentMs = now() - originalStartTimeMs;
11741 var expirationTimeMs = expirationTimeToMs(expirationTime);
11742 var timeout = expirationTimeMs - currentMs;
11743 callbackID = scheduleDeferredCallback$$1(performAsyncWork, { timeout: timeout });
11744}
11745
11746// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and
11747// onYield is called upon exiting. We use these in lieu of returning a tuple.
11748// I've also chosen not to inline them into renderRoot because these will
11749// eventually be lifted into the renderer.
11750function onFatal(root) {
11751 root.finishedWork = null;
11752}
11753
11754function onComplete(root, finishedWork, expirationTime) {
11755 root.pendingCommitExpirationTime = expirationTime;
11756 root.finishedWork = finishedWork;
11757}
11758
11759function onSuspend(root, finishedWork, suspendedExpirationTime, rootExpirationTime, msUntilTimeout) {
11760 root.expirationTime = rootExpirationTime;
11761 if (msUntilTimeout === 0 && !shouldYieldToRenderer()) {
11762 // Don't wait an additional tick. Commit the tree immediately.
11763 root.pendingCommitExpirationTime = suspendedExpirationTime;
11764 root.finishedWork = finishedWork;
11765 } else if (msUntilTimeout > 0) {
11766 // Wait `msUntilTimeout` milliseconds before committing.
11767 root.timeoutHandle = scheduleTimeout(onTimeout.bind(null, root, finishedWork, suspendedExpirationTime), msUntilTimeout);
11768 }
11769}
11770
11771function onYield(root) {
11772 root.finishedWork = null;
11773}
11774
11775function onTimeout(root, finishedWork, suspendedExpirationTime) {
11776 // The root timed out. Commit it.
11777 root.pendingCommitExpirationTime = suspendedExpirationTime;
11778 root.finishedWork = finishedWork;
11779 // Read the current time before entering the commit phase. We can be
11780 // certain this won't cause tearing related to batching of event updates
11781 // because we're at the top of a timer event.
11782 recomputeCurrentRendererTime();
11783 currentSchedulerTime = currentRendererTime;
11784 flushRoot(root, suspendedExpirationTime);
11785}
11786
11787function onCommit(root, expirationTime) {
11788 root.expirationTime = expirationTime;
11789 root.finishedWork = null;
11790}
11791
11792function requestCurrentTime() {
11793 // requestCurrentTime is called by the scheduler to compute an expiration
11794 // time.
11795 //
11796 // Expiration times are computed by adding to the current time (the start
11797 // time). However, if two updates are scheduled within the same event, we
11798 // should treat their start times as simultaneous, even if the actual clock
11799 // time has advanced between the first and second call.
11800
11801 // In other words, because expiration times determine how updates are batched,
11802 // we want all updates of like priority that occur within the same event to
11803 // receive the same expiration time. Otherwise we get tearing.
11804 //
11805 // We keep track of two separate times: the current "renderer" time and the
11806 // current "scheduler" time. The renderer time can be updated whenever; it
11807 // only exists to minimize the calls performance.now.
11808 //
11809 // But the scheduler time can only be updated if there's no pending work, or
11810 // if we know for certain that we're not in the middle of an event.
11811
11812 if (isRendering) {
11813 // We're already rendering. Return the most recently read time.
11814 return currentSchedulerTime;
11815 }
11816 // Check if there's pending work.
11817 findHighestPriorityRoot();
11818 if (nextFlushedExpirationTime === NoWork || nextFlushedExpirationTime === Never) {
11819 // If there's no pending work, or if the pending work is offscreen, we can
11820 // read the current time without risk of tearing.
11821 recomputeCurrentRendererTime();
11822 currentSchedulerTime = currentRendererTime;
11823 return currentSchedulerTime;
11824 }
11825 // There's already pending work. We might be in the middle of a browser
11826 // event. If we were to read the current time, it could cause multiple updates
11827 // within the same event to receive different expiration times, leading to
11828 // tearing. Return the last read time. During the next idle callback, the
11829 // time will be updated.
11830 return currentSchedulerTime;
11831}
11832
11833// requestWork is called by the scheduler whenever a root receives an update.
11834// It's up to the renderer to call renderRoot at some point in the future.
11835function requestWork(root, expirationTime) {
11836 addRootToSchedule(root, expirationTime);
11837 if (isRendering) {
11838 // Prevent reentrancy. Remaining work will be scheduled at the end of
11839 // the currently rendering batch.
11840 return;
11841 }
11842
11843 if (isBatchingUpdates) {
11844 // Flush work at the end of the batch.
11845 if (isUnbatchingUpdates) {
11846 // ...unless we're inside unbatchedUpdates, in which case we should
11847 // flush it now.
11848 nextFlushedRoot = root;
11849 nextFlushedExpirationTime = Sync;
11850 performWorkOnRoot(root, Sync, false);
11851 }
11852 return;
11853 }
11854
11855 // TODO: Get rid of Sync and use current time?
11856 if (expirationTime === Sync) {
11857 performSyncWork();
11858 } else {
11859 scheduleCallbackWithExpirationTime(root, expirationTime);
11860 }
11861}
11862
11863function addRootToSchedule(root, expirationTime) {
11864 // Add the root to the schedule.
11865 // Check if this root is already part of the schedule.
11866 if (root.nextScheduledRoot === null) {
11867 // This root is not already scheduled. Add it.
11868 root.expirationTime = expirationTime;
11869 if (lastScheduledRoot === null) {
11870 firstScheduledRoot = lastScheduledRoot = root;
11871 root.nextScheduledRoot = root;
11872 } else {
11873 lastScheduledRoot.nextScheduledRoot = root;
11874 lastScheduledRoot = root;
11875 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
11876 }
11877 } else {
11878 // This root is already scheduled, but its priority may have increased.
11879 var remainingExpirationTime = root.expirationTime;
11880 if (expirationTime > remainingExpirationTime) {
11881 // Update the priority.
11882 root.expirationTime = expirationTime;
11883 }
11884 }
11885}
11886
11887function findHighestPriorityRoot() {
11888 var highestPriorityWork = NoWork;
11889 var highestPriorityRoot = null;
11890 if (lastScheduledRoot !== null) {
11891 var previousScheduledRoot = lastScheduledRoot;
11892 var root = firstScheduledRoot;
11893 while (root !== null) {
11894 var remainingExpirationTime = root.expirationTime;
11895 if (remainingExpirationTime === NoWork) {
11896 // This root no longer has work. Remove it from the scheduler.
11897
11898 // TODO: This check is redudant, but Flow is confused by the branch
11899 // below where we set lastScheduledRoot to null, even though we break
11900 // from the loop right after.
11901 !(previousScheduledRoot !== null && lastScheduledRoot !== null) ? invariant(false, 'Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11902 if (root === root.nextScheduledRoot) {
11903 // This is the only root in the list.
11904 root.nextScheduledRoot = null;
11905 firstScheduledRoot = lastScheduledRoot = null;
11906 break;
11907 } else if (root === firstScheduledRoot) {
11908 // This is the first root in the list.
11909 var next = root.nextScheduledRoot;
11910 firstScheduledRoot = next;
11911 lastScheduledRoot.nextScheduledRoot = next;
11912 root.nextScheduledRoot = null;
11913 } else if (root === lastScheduledRoot) {
11914 // This is the last root in the list.
11915 lastScheduledRoot = previousScheduledRoot;
11916 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
11917 root.nextScheduledRoot = null;
11918 break;
11919 } else {
11920 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
11921 root.nextScheduledRoot = null;
11922 }
11923 root = previousScheduledRoot.nextScheduledRoot;
11924 } else {
11925 if (remainingExpirationTime > highestPriorityWork) {
11926 // Update the priority, if it's higher
11927 highestPriorityWork = remainingExpirationTime;
11928 highestPriorityRoot = root;
11929 }
11930 if (root === lastScheduledRoot) {
11931 break;
11932 }
11933 if (highestPriorityWork === Sync) {
11934 // Sync is highest priority by definition so
11935 // we can stop searching.
11936 break;
11937 }
11938 previousScheduledRoot = root;
11939 root = root.nextScheduledRoot;
11940 }
11941 }
11942 }
11943
11944 nextFlushedRoot = highestPriorityRoot;
11945 nextFlushedExpirationTime = highestPriorityWork;
11946}
11947
11948// TODO: This wrapper exists because many of the older tests (the ones that use
11949// flushDeferredPri) rely on the number of times `shouldYield` is called. We
11950// should get rid of it.
11951var didYield = false;
11952function shouldYieldToRenderer() {
11953 if (didYield) {
11954 return true;
11955 }
11956 if (shouldYield$$1()) {
11957 didYield = true;
11958 return true;
11959 }
11960 return false;
11961}
11962
11963function performAsyncWork() {
11964 try {
11965 if (!shouldYieldToRenderer()) {
11966 // The callback timed out. That means at least one update has expired.
11967 // Iterate through the root schedule. If they contain expired work, set
11968 // the next render expiration time to the current time. This has the effect
11969 // of flushing all expired work in a single batch, instead of flushing each
11970 // level one at a time.
11971 if (firstScheduledRoot !== null) {
11972 recomputeCurrentRendererTime();
11973 var root = firstScheduledRoot;
11974 do {
11975 didExpireAtExpirationTime(root, currentRendererTime);
11976 // The root schedule is circular, so this is never null.
11977 root = root.nextScheduledRoot;
11978 } while (root !== firstScheduledRoot);
11979 }
11980 }
11981 performWork(NoWork, true);
11982 } finally {
11983 didYield = false;
11984 }
11985}
11986
11987function performSyncWork() {
11988 performWork(Sync, false);
11989}
11990
11991function performWork(minExpirationTime, isYieldy) {
11992 // Keep working on roots until there's no more work, or until there's a higher
11993 // priority event.
11994 findHighestPriorityRoot();
11995
11996 if (isYieldy) {
11997 recomputeCurrentRendererTime();
11998 currentSchedulerTime = currentRendererTime;
11999
12000 if (enableUserTimingAPI) {
12001 var didExpire = nextFlushedExpirationTime > currentRendererTime;
12002 var timeout = expirationTimeToMs(nextFlushedExpirationTime);
12003 stopRequestCallbackTimer(didExpire, timeout);
12004 }
12005
12006 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime && !(didYield && currentRendererTime > nextFlushedExpirationTime)) {
12007 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, currentRendererTime > nextFlushedExpirationTime);
12008 findHighestPriorityRoot();
12009 recomputeCurrentRendererTime();
12010 currentSchedulerTime = currentRendererTime;
12011 }
12012 } else {
12013 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime) {
12014 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
12015 findHighestPriorityRoot();
12016 }
12017 }
12018
12019 // We're done flushing work. Either we ran out of time in this callback,
12020 // or there's no more work left with sufficient priority.
12021
12022 // If we're inside a callback, set this to false since we just completed it.
12023 if (isYieldy) {
12024 callbackExpirationTime = NoWork;
12025 callbackID = null;
12026 }
12027 // If there's work left over, schedule a new callback.
12028 if (nextFlushedExpirationTime !== NoWork) {
12029 scheduleCallbackWithExpirationTime(nextFlushedRoot, nextFlushedExpirationTime);
12030 }
12031
12032 // Clean-up.
12033 finishRendering();
12034}
12035
12036function flushRoot(root, expirationTime) {
12037 !!isRendering ? invariant(false, 'work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method.') : void 0;
12038 // Perform work on root as if the given expiration time is the current time.
12039 // This has the effect of synchronously flushing all work up to and
12040 // including the given time.
12041 nextFlushedRoot = root;
12042 nextFlushedExpirationTime = expirationTime;
12043 performWorkOnRoot(root, expirationTime, false);
12044 // Flush any sync work that was scheduled by lifecycles
12045 performSyncWork();
12046}
12047
12048function finishRendering() {
12049 nestedUpdateCount = 0;
12050 lastCommittedRootDuringThisBatch = null;
12051
12052 if (completedBatches !== null) {
12053 var batches = completedBatches;
12054 completedBatches = null;
12055 for (var i = 0; i < batches.length; i++) {
12056 var batch = batches[i];
12057 try {
12058 batch._onComplete();
12059 } catch (error) {
12060 if (!hasUnhandledError) {
12061 hasUnhandledError = true;
12062 unhandledError = error;
12063 }
12064 }
12065 }
12066 }
12067
12068 if (hasUnhandledError) {
12069 var error = unhandledError;
12070 unhandledError = null;
12071 hasUnhandledError = false;
12072 throw error;
12073 }
12074}
12075
12076function performWorkOnRoot(root, expirationTime, isYieldy) {
12077 !!isRendering ? invariant(false, 'performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
12078
12079 isRendering = true;
12080
12081 // Check if this is async work or sync/expired work.
12082 if (!isYieldy) {
12083 // Flush work without yielding.
12084 // TODO: Non-yieldy work does not necessarily imply expired work. A renderer
12085 // may want to perform some work without yielding, but also without
12086 // requiring the root to complete (by triggering placeholders).
12087
12088 var finishedWork = root.finishedWork;
12089 if (finishedWork !== null) {
12090 // This root is already complete. We can commit it.
12091 completeRoot(root, finishedWork, expirationTime);
12092 } else {
12093 root.finishedWork = null;
12094 // If this root previously suspended, clear its existing timeout, since
12095 // we're about to try rendering again.
12096 var timeoutHandle = root.timeoutHandle;
12097 if (timeoutHandle !== noTimeout) {
12098 root.timeoutHandle = noTimeout;
12099 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12100 cancelTimeout(timeoutHandle);
12101 }
12102 renderRoot(root, isYieldy);
12103 finishedWork = root.finishedWork;
12104 if (finishedWork !== null) {
12105 // We've completed the root. Commit it.
12106 completeRoot(root, finishedWork, expirationTime);
12107 }
12108 }
12109 } else {
12110 // Flush async work.
12111 var _finishedWork = root.finishedWork;
12112 if (_finishedWork !== null) {
12113 // This root is already complete. We can commit it.
12114 completeRoot(root, _finishedWork, expirationTime);
12115 } else {
12116 root.finishedWork = null;
12117 // If this root previously suspended, clear its existing timeout, since
12118 // we're about to try rendering again.
12119 var _timeoutHandle = root.timeoutHandle;
12120 if (_timeoutHandle !== noTimeout) {
12121 root.timeoutHandle = noTimeout;
12122 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12123 cancelTimeout(_timeoutHandle);
12124 }
12125 renderRoot(root, isYieldy);
12126 _finishedWork = root.finishedWork;
12127 if (_finishedWork !== null) {
12128 // We've completed the root. Check the if we should yield one more time
12129 // before committing.
12130 if (!shouldYieldToRenderer()) {
12131 // Still time left. Commit the root.
12132 completeRoot(root, _finishedWork, expirationTime);
12133 } else {
12134 // There's no time left. Mark this root as complete. We'll come
12135 // back and commit it later.
12136 root.finishedWork = _finishedWork;
12137 }
12138 }
12139 }
12140 }
12141
12142 isRendering = false;
12143}
12144
12145function completeRoot(root, finishedWork, expirationTime) {
12146 // Check if there's a batch that matches this expiration time.
12147 var firstBatch = root.firstBatch;
12148 if (firstBatch !== null && firstBatch._expirationTime >= expirationTime) {
12149 if (completedBatches === null) {
12150 completedBatches = [firstBatch];
12151 } else {
12152 completedBatches.push(firstBatch);
12153 }
12154 if (firstBatch._defer) {
12155 // This root is blocked from committing by a batch. Unschedule it until
12156 // we receive another update.
12157 root.finishedWork = finishedWork;
12158 root.expirationTime = NoWork;
12159 return;
12160 }
12161 }
12162
12163 // Commit the root.
12164 root.finishedWork = null;
12165
12166 // Check if this is a nested update (a sync update scheduled during the
12167 // commit phase).
12168 if (root === lastCommittedRootDuringThisBatch) {
12169 // If the next root is the same as the previous root, this is a nested
12170 // update. To prevent an infinite loop, increment the nested update count.
12171 nestedUpdateCount++;
12172 } else {
12173 // Reset whenever we switch roots.
12174 lastCommittedRootDuringThisBatch = root;
12175 nestedUpdateCount = 0;
12176 }
12177 commitRoot(root, finishedWork);
12178}
12179
12180function onUncaughtError(error) {
12181 !(nextFlushedRoot !== null) ? invariant(false, 'Should be working on a root. This error is likely caused by a bug in React. Please file an issue.') : void 0;
12182 // Unschedule this root so we don't work on it again until there's
12183 // another update.
12184 nextFlushedRoot.expirationTime = NoWork;
12185 if (!hasUnhandledError) {
12186 hasUnhandledError = true;
12187 unhandledError = error;
12188 }
12189}
12190
12191// TODO: Batching should be implemented at the renderer level, not inside
12192// the reconciler.
12193function batchedUpdates(fn, a) {
12194 var previousIsBatchingUpdates = isBatchingUpdates;
12195 isBatchingUpdates = true;
12196 try {
12197 return fn(a);
12198 } finally {
12199 isBatchingUpdates = previousIsBatchingUpdates;
12200 if (!isBatchingUpdates && !isRendering) {
12201 performSyncWork();
12202 }
12203 }
12204}
12205
12206// TODO: Batching should be implemented at the renderer level, not within
12207// the reconciler.
12208function flushSync(fn, a) {
12209 !!isRendering ? invariant(false, 'flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.') : void 0;
12210 var previousIsBatchingUpdates = isBatchingUpdates;
12211 isBatchingUpdates = true;
12212 try {
12213 return syncUpdates(fn, a);
12214 } finally {
12215 isBatchingUpdates = previousIsBatchingUpdates;
12216 performSyncWork();
12217 }
12218}
12219
12220// 0 is PROD, 1 is DEV.
12221// Might add PROFILE later.
12222
12223
12224var didWarnAboutNestedUpdates = void 0;
12225{
12226 didWarnAboutNestedUpdates = false;
12227
12228}
12229
12230function getContextForSubtree(parentComponent) {
12231 if (!parentComponent) {
12232 return emptyContextObject;
12233 }
12234
12235 var fiber = get(parentComponent);
12236 var parentContext = findCurrentUnmaskedContext(fiber);
12237
12238 if (fiber.tag === ClassComponent) {
12239 var Component = fiber.type;
12240 if (isContextProvider(Component)) {
12241 return processChildContext(fiber, Component, parentContext);
12242 }
12243 }
12244
12245 return parentContext;
12246}
12247
12248function scheduleRootUpdate(current$$1, element, expirationTime, callback) {
12249 {
12250 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
12251 didWarnAboutNestedUpdates = true;
12252 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');
12253 }
12254 }
12255
12256 var update = createUpdate(expirationTime);
12257 // Caution: React DevTools currently depends on this property
12258 // being called "element".
12259 update.payload = { element: element };
12260
12261 callback = callback === undefined ? null : callback;
12262 if (callback !== null) {
12263 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
12264 update.callback = callback;
12265 }
12266
12267 flushPassiveEffects$1();
12268 enqueueUpdate(current$$1, update);
12269 scheduleWork(current$$1, expirationTime);
12270
12271 return expirationTime;
12272}
12273
12274function updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback) {
12275 // TODO: If this is a nested container, this won't be the root.
12276 var current$$1 = container.current;
12277
12278 {
12279 if (ReactFiberInstrumentation_1.debugTool) {
12280 if (current$$1.alternate === null) {
12281 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
12282 } else if (element === null) {
12283 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
12284 } else {
12285 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
12286 }
12287 }
12288 }
12289
12290 var context = getContextForSubtree(parentComponent);
12291 if (container.context === null) {
12292 container.context = context;
12293 } else {
12294 container.pendingContext = context;
12295 }
12296
12297 return scheduleRootUpdate(current$$1, element, expirationTime, callback);
12298}
12299
12300function createContainer(containerInfo, isConcurrent, hydrate) {
12301 return createFiberRoot(containerInfo, isConcurrent, hydrate);
12302}
12303
12304function updateContainer(element, container, parentComponent, callback) {
12305 var current$$1 = container.current;
12306 var currentTime = requestCurrentTime();
12307 var expirationTime = computeExpirationForFiber(currentTime, current$$1);
12308 return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback);
12309}
12310
12311function getPublicRootInstance(container) {
12312 var containerFiber = container.current;
12313 if (!containerFiber.child) {
12314 return null;
12315 }
12316 switch (containerFiber.child.tag) {
12317 case HostComponent:
12318 return getPublicInstance(containerFiber.child.stateNode);
12319 default:
12320 return containerFiber.child.stateNode;
12321 }
12322}
12323
12324
12325
12326var overrideProps = null;
12327
12328{
12329 var copyWithSetImpl = function (obj, path, idx, value) {
12330 if (idx >= path.length) {
12331 return value;
12332 }
12333 var key = path[idx];
12334 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
12335 // $FlowFixMe number or string is fine here
12336 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
12337 return updated;
12338 };
12339
12340 var copyWithSet = function (obj, path, value) {
12341 return copyWithSetImpl(obj, path, 0, value);
12342 };
12343
12344 // Support DevTools props for function components, forwardRef, memo, host components, etc.
12345 overrideProps = function (fiber, path, value) {
12346 flushPassiveEffects$1();
12347 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
12348 if (fiber.alternate) {
12349 fiber.alternate.pendingProps = fiber.pendingProps;
12350 }
12351 scheduleWork(fiber, Sync);
12352 };
12353}
12354
12355function injectIntoDevTools(devToolsConfig) {
12356 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
12357 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
12358
12359
12360 return injectInternals(_assign({}, devToolsConfig, {
12361 overrideProps: overrideProps,
12362 currentDispatcherRef: ReactCurrentDispatcher,
12363 findHostInstanceByFiber: function (fiber) {
12364 var hostFiber = findCurrentHostFiber(fiber);
12365 if (hostFiber === null) {
12366 return null;
12367 }
12368 return hostFiber.stateNode;
12369 },
12370 findFiberByHostInstance: function (instance) {
12371 if (!findFiberByHostInstance) {
12372 // Might not be implemented by the renderer.
12373 return null;
12374 }
12375 return findFiberByHostInstance(instance);
12376 }
12377 }));
12378}
12379
12380// This file intentionally does *not* have the Flow annotation.
12381// Don't add it. See `./inline-typed.js` for an explanation.
12382
12383// TODO: this is special because it gets imported during build.
12384
12385var ReactVersion = '16.8.1';
12386
12387var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
12388
12389function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12390
12391function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
12392
12393// for .act's return value
12394
12395
12396var defaultTestOptions = {
12397 createNodeMock: function () {
12398 return null;
12399 }
12400};
12401
12402function toJSON(inst) {
12403 if (inst.isHidden) {
12404 // Omit timed out children from output entirely. This seems like the least
12405 // surprising behavior. We could perhaps add a separate API that includes
12406 // them, if it turns out people need it.
12407 return null;
12408 }
12409 switch (inst.tag) {
12410 case 'TEXT':
12411 return inst.text;
12412 case 'INSTANCE':
12413 {
12414 /* eslint-disable no-unused-vars */
12415 // We don't include the `children` prop in JSON.
12416 // Instead, we will include the actual rendered children.
12417 var _inst$props = inst.props,
12418 _children = _inst$props.children,
12419 _props = _objectWithoutProperties(_inst$props, ['children']);
12420 /* eslint-enable */
12421
12422
12423 var renderedChildren = null;
12424 if (inst.children && inst.children.length) {
12425 for (var i = 0; i < inst.children.length; i++) {
12426 var renderedChild = toJSON(inst.children[i]);
12427 if (renderedChild !== null) {
12428 if (renderedChildren === null) {
12429 renderedChildren = [renderedChild];
12430 } else {
12431 renderedChildren.push(renderedChild);
12432 }
12433 }
12434 }
12435 }
12436 var json = {
12437 type: inst.type,
12438 props: _props,
12439 children: renderedChildren
12440 };
12441 Object.defineProperty(json, '$$typeof', {
12442 value: Symbol.for('react.test.json')
12443 });
12444 return json;
12445 }
12446 default:
12447 throw new Error('Unexpected node type in toJSON: ' + inst.tag);
12448 }
12449}
12450
12451function childrenToTree(node) {
12452 if (!node) {
12453 return null;
12454 }
12455 var children = nodeAndSiblingsArray(node);
12456 if (children.length === 0) {
12457 return null;
12458 } else if (children.length === 1) {
12459 return toTree(children[0]);
12460 }
12461 return flatten(children.map(toTree));
12462}
12463
12464function nodeAndSiblingsArray(nodeWithSibling) {
12465 var array = [];
12466 var node = nodeWithSibling;
12467 while (node != null) {
12468 array.push(node);
12469 node = node.sibling;
12470 }
12471 return array;
12472}
12473
12474function flatten(arr) {
12475 var result = [];
12476 var stack = [{ i: 0, array: arr }];
12477 while (stack.length) {
12478 var n = stack.pop();
12479 while (n.i < n.array.length) {
12480 var el = n.array[n.i];
12481 n.i += 1;
12482 if (Array.isArray(el)) {
12483 stack.push(n);
12484 stack.push({ i: 0, array: el });
12485 break;
12486 }
12487 result.push(el);
12488 }
12489 }
12490 return result;
12491}
12492
12493function toTree(node) {
12494 if (node == null) {
12495 return null;
12496 }
12497 switch (node.tag) {
12498 case HostRoot:
12499 return childrenToTree(node.child);
12500 case HostPortal:
12501 return childrenToTree(node.child);
12502 case ClassComponent:
12503 return {
12504 nodeType: 'component',
12505 type: node.type,
12506 props: _assign({}, node.memoizedProps),
12507 instance: node.stateNode,
12508 rendered: childrenToTree(node.child)
12509 };
12510 case FunctionComponent:
12511 case SimpleMemoComponent:
12512 return {
12513 nodeType: 'component',
12514 type: node.type,
12515 props: _assign({}, node.memoizedProps),
12516 instance: null,
12517 rendered: childrenToTree(node.child)
12518 };
12519 case HostComponent:
12520 {
12521 return {
12522 nodeType: 'host',
12523 type: node.type,
12524 props: _assign({}, node.memoizedProps),
12525 instance: null, // TODO: use createNodeMock here somehow?
12526 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
12527 };
12528 }
12529 case HostText:
12530 return node.stateNode.text;
12531 case Fragment:
12532 case ContextProvider:
12533 case ContextConsumer:
12534 case Mode:
12535 case Profiler:
12536 case ForwardRef:
12537 case MemoComponent:
12538 case IncompleteClassComponent:
12539 return childrenToTree(node.child);
12540 default:
12541 invariant(false, 'toTree() does not yet know how to handle nodes with tag=%s', node.tag);
12542 }
12543}
12544
12545var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent,
12546// Normally skipped, but used when there's more than one root child.
12547HostRoot]);
12548
12549function getChildren(parent) {
12550 var children = [];
12551 var startingNode = parent;
12552 var node = startingNode;
12553 if (node.child === null) {
12554 return children;
12555 }
12556 node.child.return = node;
12557 node = node.child;
12558 outer: while (true) {
12559 var descend = false;
12560 if (validWrapperTypes.has(node.tag)) {
12561 children.push(wrapFiber(node));
12562 } else if (node.tag === HostText) {
12563 children.push('' + node.memoizedProps);
12564 } else {
12565 descend = true;
12566 }
12567 if (descend && node.child !== null) {
12568 node.child.return = node;
12569 node = node.child;
12570 continue;
12571 }
12572 while (node.sibling === null) {
12573 if (node.return === startingNode) {
12574 break outer;
12575 }
12576 node = node.return;
12577 }
12578 node.sibling.return = node.return;
12579 node = node.sibling;
12580 }
12581 return children;
12582}
12583
12584var ReactTestInstance = function () {
12585 ReactTestInstance.prototype._currentFiber = function _currentFiber() {
12586 // Throws if this component has been unmounted.
12587 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
12588 !(fiber !== null) ? invariant(false, 'Can\'t read from currently-mounting component. This error is likely caused by a bug in React. Please file an issue.') : void 0;
12589 return fiber;
12590 };
12591
12592 function ReactTestInstance(fiber) {
12593 _classCallCheck(this, ReactTestInstance);
12594
12595 !validWrapperTypes.has(fiber.tag) ? invariant(false, 'Unexpected object passed to ReactTestInstance constructor (tag: %s). This is probably a bug in React.', fiber.tag) : void 0;
12596 this._fiber = fiber;
12597 }
12598
12599 // Custom search functions
12600 ReactTestInstance.prototype.find = function find(predicate) {
12601 return expectOne(this.findAll(predicate, { deep: false }), 'matching custom predicate: ' + predicate.toString());
12602 };
12603
12604 ReactTestInstance.prototype.findByType = function findByType(type) {
12605 return expectOne(this.findAllByType(type, { deep: false }), 'with node type: "' + (type.displayName || type.name) + '"');
12606 };
12607
12608 ReactTestInstance.prototype.findByProps = function findByProps(props) {
12609 return expectOne(this.findAllByProps(props, { deep: false }), 'with props: ' + JSON.stringify(props));
12610 };
12611
12612 ReactTestInstance.prototype.findAll = function findAll(predicate) {
12613 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12614
12615 return _findAll(this, predicate, options);
12616 };
12617
12618 ReactTestInstance.prototype.findAllByType = function findAllByType(type) {
12619 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12620
12621 return _findAll(this, function (node) {
12622 return node.type === type;
12623 }, options);
12624 };
12625
12626 ReactTestInstance.prototype.findAllByProps = function findAllByProps(props) {
12627 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12628
12629 return _findAll(this, function (node) {
12630 return node.props && propsMatch(node.props, props);
12631 }, options);
12632 };
12633
12634 _createClass(ReactTestInstance, [{
12635 key: 'instance',
12636 get: function () {
12637 if (this._fiber.tag === HostComponent) {
12638 return getPublicInstance(this._fiber.stateNode);
12639 } else {
12640 return this._fiber.stateNode;
12641 }
12642 }
12643 }, {
12644 key: 'type',
12645 get: function () {
12646 return this._fiber.type;
12647 }
12648 }, {
12649 key: 'props',
12650 get: function () {
12651 return this._currentFiber().memoizedProps;
12652 }
12653 }, {
12654 key: 'parent',
12655 get: function () {
12656 var parent = this._fiber.return;
12657 while (parent !== null) {
12658 if (validWrapperTypes.has(parent.tag)) {
12659 if (parent.tag === HostRoot) {
12660 // Special case: we only "materialize" instances for roots
12661 // if they have more than a single child. So we'll check that now.
12662 if (getChildren(parent).length < 2) {
12663 return null;
12664 }
12665 }
12666 return wrapFiber(parent);
12667 }
12668 parent = parent.return;
12669 }
12670 return null;
12671 }
12672 }, {
12673 key: 'children',
12674 get: function () {
12675 return getChildren(this._currentFiber());
12676 }
12677 }]);
12678
12679 return ReactTestInstance;
12680}();
12681
12682function _findAll(root, predicate, options) {
12683 var deep = options ? options.deep : true;
12684 var results = [];
12685
12686 if (predicate(root)) {
12687 results.push(root);
12688 if (!deep) {
12689 return results;
12690 }
12691 }
12692
12693 root.children.forEach(function (child) {
12694 if (typeof child === 'string') {
12695 return;
12696 }
12697 results.push.apply(results, _findAll(child, predicate, options));
12698 });
12699
12700 return results;
12701}
12702
12703function expectOne(all, message) {
12704 if (all.length === 1) {
12705 return all[0];
12706 }
12707
12708 var prefix = all.length === 0 ? 'No instances found ' : 'Expected 1 but found ' + all.length + ' instances ';
12709
12710 throw new Error(prefix + message);
12711}
12712
12713function propsMatch(props, filter) {
12714 for (var key in filter) {
12715 if (props[key] !== filter[key]) {
12716 return false;
12717 }
12718 }
12719 return true;
12720}
12721
12722var ReactTestRendererFiber = {
12723 create: function (element, options) {
12724 var createNodeMock = defaultTestOptions.createNodeMock;
12725 var isConcurrent = false;
12726 if (typeof options === 'object' && options !== null) {
12727 if (typeof options.createNodeMock === 'function') {
12728 createNodeMock = options.createNodeMock;
12729 }
12730 if (options.unstable_isConcurrent === true) {
12731 isConcurrent = true;
12732 }
12733 }
12734 var container = {
12735 children: [],
12736 createNodeMock: createNodeMock,
12737 tag: 'CONTAINER'
12738 };
12739 var root = createContainer(container, isConcurrent, false);
12740 !(root != null) ? invariant(false, 'something went wrong') : void 0;
12741 updateContainer(element, root, null, null);
12742
12743 var entry = {
12744 root: undefined, // makes flow happy
12745 // we define a 'getter' for 'root' below using 'Object.defineProperty'
12746 toJSON: function () {
12747 if (root == null || root.current == null || container == null) {
12748 return null;
12749 }
12750 if (container.children.length === 0) {
12751 return null;
12752 }
12753 if (container.children.length === 1) {
12754 return toJSON(container.children[0]);
12755 }
12756 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
12757 // Omit timed out children from output entirely, including the fact that we
12758 // temporarily wrap fallback and timed out children in an array.
12759 return toJSON(container.children[1]);
12760 }
12761 var renderedChildren = null;
12762 if (container.children && container.children.length) {
12763 for (var i = 0; i < container.children.length; i++) {
12764 var renderedChild = toJSON(container.children[i]);
12765 if (renderedChild !== null) {
12766 if (renderedChildren === null) {
12767 renderedChildren = [renderedChild];
12768 } else {
12769 renderedChildren.push(renderedChild);
12770 }
12771 }
12772 }
12773 }
12774 return renderedChildren;
12775 },
12776 toTree: function () {
12777 if (root == null || root.current == null) {
12778 return null;
12779 }
12780 return toTree(root.current);
12781 },
12782 update: function (newElement) {
12783 if (root == null || root.current == null) {
12784 return;
12785 }
12786 updateContainer(newElement, root, null, null);
12787 },
12788 unmount: function () {
12789 if (root == null || root.current == null) {
12790 return;
12791 }
12792 updateContainer(null, root, null, null);
12793 container = null;
12794 root = null;
12795 },
12796 getInstance: function () {
12797 if (root == null || root.current == null) {
12798 return null;
12799 }
12800 return getPublicRootInstance(root);
12801 },
12802
12803
12804 unstable_flushAll: flushAll,
12805 unstable_flushSync: function (fn) {
12806 clearYields();
12807 return flushSync(fn);
12808 },
12809
12810 unstable_flushNumberOfYields: flushNumberOfYields,
12811 unstable_clearYields: clearYields
12812 };
12813
12814 Object.defineProperty(entry, 'root', {
12815 configurable: true,
12816 enumerable: true,
12817 get: function () {
12818 if (root === null) {
12819 throw new Error("Can't access .root on unmounted test renderer");
12820 }
12821 var children = getChildren(root.current);
12822 if (children.length === 0) {
12823 throw new Error("Can't access .root on unmounted test renderer");
12824 } else if (children.length === 1) {
12825 // Normally, we skip the root and just give you the child.
12826 return children[0];
12827 } else {
12828 // However, we give you the root if there's more than one root child.
12829 // We could make this the behavior for all cases but it would be a breaking change.
12830 return wrapFiber(root.current);
12831 }
12832 }
12833 });
12834
12835 return entry;
12836 },
12837
12838
12839 unstable_yield: yieldValue,
12840 unstable_clearYields: clearYields,
12841
12842 /* eslint-disable camelcase */
12843 unstable_batchedUpdates: batchedUpdates,
12844 /* eslint-enable camelcase */
12845
12846 unstable_setNowImplementation: setNowImplementation,
12847
12848 act: function (callback) {
12849 // note: keep these warning messages in sync with
12850 // createNoop.js and ReactTestUtils.js
12851 var result = batchedUpdates(callback);
12852 {
12853 if (result !== undefined) {
12854 var addendum = void 0;
12855 if (result !== null && typeof result.then === 'function') {
12856 addendum = "\n\nIt looks like you wrote TestRenderer.act(async () => ...) or returned a Promise from it's callback. " + 'Putting asynchronous logic inside TestRenderer.act(...) is not supported.\n';
12857 } else {
12858 addendum = ' You returned: ' + result;
12859 }
12860 warningWithoutStack$1(false, 'The callback passed to TestRenderer.act(...) function must not return anything.%s', addendum);
12861 }
12862 }
12863 flushPassiveEffects();
12864 // we want the user to not expect a return,
12865 // but we want to warn if they use it like they can await on it.
12866 return {
12867 then: function () {
12868 {
12869 warningWithoutStack$1(false, 'Do not await the result of calling TestRenderer.act(...), it is not a Promise.');
12870 }
12871 }
12872 };
12873 }
12874};
12875
12876// root used to flush effects during .act() calls
12877var actRoot = createContainer({
12878 children: [],
12879 createNodeMock: defaultTestOptions.createNodeMock,
12880 tag: 'CONTAINER'
12881}, true, false);
12882
12883function flushPassiveEffects() {
12884 // Trick to flush passive effects without exposing an internal API:
12885 // Create a throwaway root and schedule a dummy update on it.
12886 updateContainer(null, actRoot, null, null);
12887}
12888
12889var fiberToWrapper = new WeakMap();
12890function wrapFiber(fiber) {
12891 var wrapper = fiberToWrapper.get(fiber);
12892 if (wrapper === undefined && fiber.alternate !== null) {
12893 wrapper = fiberToWrapper.get(fiber.alternate);
12894 }
12895 if (wrapper === undefined) {
12896 wrapper = new ReactTestInstance(fiber);
12897 fiberToWrapper.set(fiber, wrapper);
12898 }
12899 return wrapper;
12900}
12901
12902// Enable ReactTestRenderer to be used to test DevTools integration.
12903injectIntoDevTools({
12904 findFiberByHostInstance: function () {
12905 throw new Error('TestRenderer does not support findFiberByHostInstance()');
12906 },
12907 bundleType: 1,
12908 version: ReactVersion,
12909 rendererPackageName: 'react-test-renderer'
12910});
12911
12912
12913
12914var ReactTestRenderer = Object.freeze({
12915 default: ReactTestRendererFiber
12916});
12917
12918var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
12919
12920// TODO: decide on the top-level export form.
12921// This is hacky but makes it work with both Rollup and Jest.
12922var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
12923
12924return reactTestRenderer;
12925
12926})));