UNPKG

503 kBJavaScriptView Raw
1/** @license React v16.8.5
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;
271var DehydratedSuspenseComponent = 18;
272
273// Don't change these two values. They're used by React Dev Tools.
274var NoEffect = /* */0;
275var PerformedWork = /* */1;
276
277// You can change the rest (and add more).
278var Placement = /* */2;
279var Update = /* */4;
280var PlacementAndUpdate = /* */6;
281var Deletion = /* */8;
282var ContentReset = /* */16;
283var Callback = /* */32;
284var DidCapture = /* */64;
285var Ref = /* */128;
286var Snapshot = /* */256;
287var Passive = /* */512;
288
289// Passive & Update & Callback & Ref & Snapshot
290var LifecycleEffectMask = /* */932;
291
292// Union of all host effects
293var HostEffectMask = /* */1023;
294
295var Incomplete = /* */1024;
296var ShouldCapture = /* */2048;
297
298var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
299
300var MOUNTING = 1;
301var MOUNTED = 2;
302var UNMOUNTED = 3;
303
304function isFiberMountedImpl(fiber) {
305 var node = fiber;
306 if (!fiber.alternate) {
307 // If there is no alternate, this might be a new tree that isn't inserted
308 // yet. If it is, then it will have a pending insertion effect on it.
309 if ((node.effectTag & Placement) !== NoEffect) {
310 return MOUNTING;
311 }
312 while (node.return) {
313 node = node.return;
314 if ((node.effectTag & Placement) !== NoEffect) {
315 return MOUNTING;
316 }
317 }
318 } else {
319 while (node.return) {
320 node = node.return;
321 }
322 }
323 if (node.tag === HostRoot) {
324 // TODO: Check if this was a nested HostRoot when used with
325 // renderContainerIntoSubtree.
326 return MOUNTED;
327 }
328 // If we didn't hit the root, that means that we're in an disconnected tree
329 // that has been unmounted.
330 return UNMOUNTED;
331}
332
333function isFiberMounted(fiber) {
334 return isFiberMountedImpl(fiber) === MOUNTED;
335}
336
337function isMounted(component) {
338 {
339 var owner = ReactCurrentOwner.current;
340 if (owner !== null && owner.tag === ClassComponent) {
341 var ownerFiber = owner;
342 var instance = ownerFiber.stateNode;
343 !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;
344 instance._warnedAboutRefsInRender = true;
345 }
346 }
347
348 var fiber = get(component);
349 if (!fiber) {
350 return false;
351 }
352 return isFiberMountedImpl(fiber) === MOUNTED;
353}
354
355function assertIsMounted(fiber) {
356 !(isFiberMountedImpl(fiber) === MOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
357}
358
359function findCurrentFiberUsingSlowPath(fiber) {
360 var alternate = fiber.alternate;
361 if (!alternate) {
362 // If there is no alternate, then we only need to check if it is mounted.
363 var state = isFiberMountedImpl(fiber);
364 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
365 if (state === MOUNTING) {
366 return null;
367 }
368 return fiber;
369 }
370 // If we have two possible branches, we'll walk backwards up to the root
371 // to see what path the root points to. On the way we may hit one of the
372 // special cases and we'll deal with them.
373 var a = fiber;
374 var b = alternate;
375 while (true) {
376 var parentA = a.return;
377 var parentB = parentA ? parentA.alternate : null;
378 if (!parentA || !parentB) {
379 // We're at the root.
380 break;
381 }
382
383 // If both copies of the parent fiber point to the same child, we can
384 // assume that the child is current. This happens when we bailout on low
385 // priority: the bailed out fiber's child reuses the current child.
386 if (parentA.child === parentB.child) {
387 var child = parentA.child;
388 while (child) {
389 if (child === a) {
390 // We've determined that A is the current branch.
391 assertIsMounted(parentA);
392 return fiber;
393 }
394 if (child === b) {
395 // We've determined that B is the current branch.
396 assertIsMounted(parentA);
397 return alternate;
398 }
399 child = child.sibling;
400 }
401 // We should never have an alternate for any mounting node. So the only
402 // way this could possibly happen is if this was unmounted, if at all.
403 invariant(false, 'Unable to find node on an unmounted component.');
404 }
405
406 if (a.return !== b.return) {
407 // The return pointer of A and the return pointer of B point to different
408 // fibers. We assume that return pointers never criss-cross, so A must
409 // belong to the child set of A.return, and B must belong to the child
410 // set of B.return.
411 a = parentA;
412 b = parentB;
413 } else {
414 // The return pointers point to the same fiber. We'll have to use the
415 // default, slow path: scan the child sets of each parent alternate to see
416 // which child belongs to which set.
417 //
418 // Search parent A's child set
419 var didFindChild = false;
420 var _child = parentA.child;
421 while (_child) {
422 if (_child === a) {
423 didFindChild = true;
424 a = parentA;
425 b = parentB;
426 break;
427 }
428 if (_child === b) {
429 didFindChild = true;
430 b = parentA;
431 a = parentB;
432 break;
433 }
434 _child = _child.sibling;
435 }
436 if (!didFindChild) {
437 // Search parent B's child set
438 _child = parentB.child;
439 while (_child) {
440 if (_child === a) {
441 didFindChild = true;
442 a = parentB;
443 b = parentA;
444 break;
445 }
446 if (_child === b) {
447 didFindChild = true;
448 b = parentB;
449 a = parentA;
450 break;
451 }
452 _child = _child.sibling;
453 }
454 !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;
455 }
456 }
457
458 !(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;
459 }
460 // If the root is not a host container, we're in a disconnected tree. I.e.
461 // unmounted.
462 !(a.tag === HostRoot) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
463 if (a.stateNode.current === a) {
464 // We've determined that A is the current branch.
465 return fiber;
466 }
467 // Otherwise B has to be current branch.
468 return alternate;
469}
470
471function findCurrentHostFiber(parent) {
472 var currentParent = findCurrentFiberUsingSlowPath(parent);
473 if (!currentParent) {
474 return null;
475 }
476
477 // Next we'll drill down this component to find the first HostComponent/Text.
478 var node = currentParent;
479 while (true) {
480 if (node.tag === HostComponent || node.tag === HostText) {
481 return node;
482 } else if (node.child) {
483 node.child.return = node;
484 node = node.child;
485 continue;
486 }
487 if (node === currentParent) {
488 return null;
489 }
490 while (!node.sibling) {
491 if (!node.return || node.return === currentParent) {
492 return null;
493 }
494 node = node.return;
495 }
496 node.sibling.return = node.return;
497 node = node.sibling;
498 }
499 // Flow needs the return null here, but ESLint complains about it.
500 // eslint-disable-next-line no-unreachable
501 return null;
502}
503
504/**
505 * Similar to invariant but only logs a warning if the condition is not met.
506 * This can be used to log issues in development environments in critical
507 * paths. Removing the logging code for production environments will keep the
508 * same logic and follow the same code paths.
509 */
510
511var warning = warningWithoutStack$1;
512
513{
514 warning = function (condition, format) {
515 if (condition) {
516 return;
517 }
518 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
519 var stack = ReactDebugCurrentFrame.getStackAddendum();
520 // eslint-disable-next-line react-internal/warning-and-invariant-args
521
522 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
523 args[_key - 2] = arguments[_key];
524 }
525
526 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
527 };
528}
529
530var warning$1 = warning;
531
532// Current virtual time
533var nowImplementation = function () {
534 return 0;
535};
536var scheduledCallback = null;
537var yieldedValues = [];
538
539var didStop = false;
540var expectedNumberOfYields = -1;
541
542function scheduleDeferredCallback$1(callback, options) {
543 scheduledCallback = callback;
544 var fakeCallbackId = 0;
545 return fakeCallbackId;
546}
547
548function cancelDeferredCallback$1(timeoutID) {
549 scheduledCallback = null;
550}
551
552function setNowImplementation(implementation) {
553 nowImplementation = implementation;
554}
555
556function shouldYield$1() {
557 if (expectedNumberOfYields !== -1 && yieldedValues.length >= expectedNumberOfYields) {
558 // We yielded at least as many values as expected. Stop rendering.
559 didStop = true;
560 return true;
561 }
562 // Keep rendering.
563 return false;
564}
565
566function flushAll() {
567 yieldedValues = [];
568 while (scheduledCallback !== null) {
569 var cb = scheduledCallback;
570 scheduledCallback = null;
571 cb();
572 }
573 var values = yieldedValues;
574 yieldedValues = [];
575 return values;
576}
577
578function flushNumberOfYields(count) {
579 expectedNumberOfYields = count;
580 didStop = false;
581 yieldedValues = [];
582 try {
583 while (scheduledCallback !== null && !didStop) {
584 var cb = scheduledCallback;
585 scheduledCallback = null;
586 cb();
587 }
588 return yieldedValues;
589 } finally {
590 expectedNumberOfYields = -1;
591 didStop = false;
592 yieldedValues = [];
593 }
594}
595
596function yieldValue(value) {
597 yieldedValues.push(value);
598}
599
600function clearYields() {
601 var values = yieldedValues;
602 yieldedValues = [];
603 return values;
604}
605
606// Renderers that don't support persistence
607// can re-export everything from this module.
608
609function shim() {
610 invariant(false, 'The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.');
611}
612
613// Persistence (when unsupported)
614var supportsPersistence = false;
615var cloneInstance = shim;
616var createContainerChildSet = shim;
617var appendChildToContainerChildSet = shim;
618var finalizeContainerChildren = shim;
619var replaceContainerChildren = shim;
620var cloneHiddenInstance = shim;
621var cloneUnhiddenInstance = shim;
622var createHiddenTextInstance = shim;
623
624// Renderers that don't support hydration
625// can re-export everything from this module.
626
627function shim$1() {
628 invariant(false, 'The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.');
629}
630
631// Hydration (when unsupported)
632
633var supportsHydration = false;
634var canHydrateInstance = shim$1;
635var canHydrateTextInstance = shim$1;
636var canHydrateSuspenseInstance = shim$1;
637var getNextHydratableSibling = shim$1;
638var getFirstHydratableChild = shim$1;
639var hydrateInstance = shim$1;
640var hydrateTextInstance = shim$1;
641var getNextHydratableInstanceAfterSuspenseInstance = shim$1;
642var clearSuspenseBoundary = shim$1;
643var clearSuspenseBoundaryFromContainer = shim$1;
644var didNotMatchHydratedContainerTextInstance = shim$1;
645var didNotMatchHydratedTextInstance = shim$1;
646var didNotHydrateContainerInstance = shim$1;
647var didNotHydrateInstance = shim$1;
648var didNotFindHydratableContainerInstance = shim$1;
649var didNotFindHydratableContainerTextInstance = shim$1;
650var didNotFindHydratableContainerSuspenseInstance = shim$1;
651var didNotFindHydratableInstance = shim$1;
652var didNotFindHydratableTextInstance = shim$1;
653var didNotFindHydratableSuspenseInstance = shim$1;
654
655var NO_CONTEXT = {};
656var UPDATE_SIGNAL = {};
657{
658 Object.freeze(NO_CONTEXT);
659 Object.freeze(UPDATE_SIGNAL);
660}
661
662function getPublicInstance(inst) {
663 switch (inst.tag) {
664 case 'INSTANCE':
665 var _createNodeMock = inst.rootContainerInstance.createNodeMock;
666 return _createNodeMock({
667 type: inst.type,
668 props: inst.props
669 });
670 default:
671 return inst;
672 }
673}
674
675function appendChild(parentInstance, child) {
676 {
677 !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;
678 }
679 var index = parentInstance.children.indexOf(child);
680 if (index !== -1) {
681 parentInstance.children.splice(index, 1);
682 }
683 parentInstance.children.push(child);
684}
685
686function insertBefore(parentInstance, child, beforeChild) {
687 var index = parentInstance.children.indexOf(child);
688 if (index !== -1) {
689 parentInstance.children.splice(index, 1);
690 }
691 var beforeIndex = parentInstance.children.indexOf(beforeChild);
692 parentInstance.children.splice(beforeIndex, 0, child);
693}
694
695function removeChild(parentInstance, child) {
696 var index = parentInstance.children.indexOf(child);
697 parentInstance.children.splice(index, 1);
698}
699
700function getRootHostContext(rootContainerInstance) {
701 return NO_CONTEXT;
702}
703
704function getChildHostContext(parentHostContext, type, rootContainerInstance) {
705 return NO_CONTEXT;
706}
707
708function prepareForCommit(containerInfo) {
709 // noop
710}
711
712function resetAfterCommit(containerInfo) {
713 // noop
714}
715
716function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
717 return {
718 type: type,
719 props: props,
720 isHidden: false,
721 children: [],
722 rootContainerInstance: rootContainerInstance,
723 tag: 'INSTANCE'
724 };
725}
726
727function appendInitialChild(parentInstance, child) {
728 var index = parentInstance.children.indexOf(child);
729 if (index !== -1) {
730 parentInstance.children.splice(index, 1);
731 }
732 parentInstance.children.push(child);
733}
734
735function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
736 return false;
737}
738
739function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
740 return UPDATE_SIGNAL;
741}
742
743function shouldSetTextContent(type, props) {
744 return false;
745}
746
747function shouldDeprioritizeSubtree(type, props) {
748 return false;
749}
750
751function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
752 return {
753 text: text,
754 isHidden: false,
755 tag: 'TEXT'
756 };
757}
758
759var isPrimaryRenderer = false;
760// This approach enables `now` to be mocked by tests,
761// Even after the reconciler has initialized and read host config values.
762var now = function () {
763 return nowImplementation();
764};
765var scheduleDeferredCallback$$1 = scheduleDeferredCallback$1;
766var cancelDeferredCallback$$1 = cancelDeferredCallback$1;
767var shouldYield$$1 = shouldYield$1;
768
769var scheduleTimeout = setTimeout;
770var cancelTimeout = clearTimeout;
771var noTimeout = -1;
772var schedulePassiveEffects = scheduleDeferredCallback$$1;
773var cancelPassiveEffects = cancelDeferredCallback$$1;
774
775// -------------------
776// Mutation
777// -------------------
778
779var supportsMutation = true;
780
781function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
782 instance.type = type;
783 instance.props = newProps;
784}
785
786
787
788function commitTextUpdate(textInstance, oldText, newText) {
789 textInstance.text = newText;
790}
791
792function resetTextContent(testElement) {
793 // noop
794}
795
796var appendChildToContainer = appendChild;
797var insertInContainerBefore = insertBefore;
798var removeChildFromContainer = removeChild;
799
800function hideInstance(instance) {
801 instance.isHidden = true;
802}
803
804function hideTextInstance(textInstance) {
805 textInstance.isHidden = true;
806}
807
808function unhideInstance(instance, props) {
809 instance.isHidden = false;
810}
811
812function unhideTextInstance(textInstance, text) {
813 textInstance.isHidden = false;
814}
815
816/**
817 * Copyright (c) 2013-present, Facebook, Inc.
818 *
819 * This source code is licensed under the MIT license found in the
820 * LICENSE file in the root directory of this source tree.
821 */
822
823
824
825var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
826
827var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
828
829/**
830 * Copyright (c) 2013-present, Facebook, Inc.
831 *
832 * This source code is licensed under the MIT license found in the
833 * LICENSE file in the root directory of this source tree.
834 */
835
836
837
838var printWarning = function() {};
839
840{
841 var ReactPropTypesSecret = ReactPropTypesSecret_1;
842 var loggedTypeFailures = {};
843
844 printWarning = function(text) {
845 var message = 'Warning: ' + text;
846 if (typeof console !== 'undefined') {
847 console.error(message);
848 }
849 try {
850 // --- Welcome to debugging React ---
851 // This error was thrown as a convenience so that you can use this stack
852 // to find the callsite that caused this warning to fire.
853 throw new Error(message);
854 } catch (x) {}
855 };
856}
857
858/**
859 * Assert that the values match with the type specs.
860 * Error messages are memorized and will only be shown once.
861 *
862 * @param {object} typeSpecs Map of name to a ReactPropType
863 * @param {object} values Runtime values that need to be type-checked
864 * @param {string} location e.g. "prop", "context", "child context"
865 * @param {string} componentName Name of the component for error messages.
866 * @param {?Function} getStack Returns the component stack.
867 * @private
868 */
869function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
870 {
871 for (var typeSpecName in typeSpecs) {
872 if (typeSpecs.hasOwnProperty(typeSpecName)) {
873 var error;
874 // Prop type validation may throw. In case they do, we don't want to
875 // fail the render phase where it didn't fail before. So we log it.
876 // After these have been cleaned up, we'll let them throw.
877 try {
878 // This is intentionally an invariant that gets caught. It's the same
879 // behavior as without this statement except with a better message.
880 if (typeof typeSpecs[typeSpecName] !== 'function') {
881 var err = Error(
882 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
883 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
884 );
885 err.name = 'Invariant Violation';
886 throw err;
887 }
888 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
889 } catch (ex) {
890 error = ex;
891 }
892 if (error && !(error instanceof Error)) {
893 printWarning(
894 (componentName || 'React class') + ': type specification of ' +
895 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
896 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
897 'You may have forgotten to pass an argument to the type checker ' +
898 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
899 'shape all require an argument).'
900 );
901
902 }
903 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
904 // Only monitor this failure once because there tends to be a lot of the
905 // same error.
906 loggedTypeFailures[error.message] = true;
907
908 var stack = getStack ? getStack() : '';
909
910 printWarning(
911 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
912 );
913 }
914 }
915 }
916 }
917}
918
919var checkPropTypes_1 = checkPropTypes;
920
921var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
922
923var describeComponentFrame = function (name, source, ownerName) {
924 var sourceInfo = '';
925 if (source) {
926 var path = source.fileName;
927 var fileName = path.replace(BEFORE_SLASH_RE, '');
928 {
929 // In DEV, include code for a common special case:
930 // prefer "folder/index.js" instead of just "index.js".
931 if (/^index\./.test(fileName)) {
932 var match = path.match(BEFORE_SLASH_RE);
933 if (match) {
934 var pathBeforeSlash = match[1];
935 if (pathBeforeSlash) {
936 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
937 fileName = folderName + '/' + fileName;
938 }
939 }
940 }
941 }
942 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
943 } else if (ownerName) {
944 sourceInfo = ' (created by ' + ownerName + ')';
945 }
946 return '\n in ' + (name || 'Unknown') + sourceInfo;
947};
948
949var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
950
951function describeFiber(fiber) {
952 switch (fiber.tag) {
953 case HostRoot:
954 case HostPortal:
955 case HostText:
956 case Fragment:
957 case ContextProvider:
958 case ContextConsumer:
959 return '';
960 default:
961 var owner = fiber._debugOwner;
962 var source = fiber._debugSource;
963 var name = getComponentName(fiber.type);
964 var ownerName = null;
965 if (owner) {
966 ownerName = getComponentName(owner.type);
967 }
968 return describeComponentFrame(name, source, ownerName);
969 }
970}
971
972function getStackByFiberInDevAndProd(workInProgress) {
973 var info = '';
974 var node = workInProgress;
975 do {
976 info += describeFiber(node);
977 node = node.return;
978 } while (node);
979 return info;
980}
981
982var current = null;
983var phase = null;
984
985function getCurrentFiberOwnerNameInDevOrNull() {
986 {
987 if (current === null) {
988 return null;
989 }
990 var owner = current._debugOwner;
991 if (owner !== null && typeof owner !== 'undefined') {
992 return getComponentName(owner.type);
993 }
994 }
995 return null;
996}
997
998function getCurrentFiberStackInDev() {
999 {
1000 if (current === null) {
1001 return '';
1002 }
1003 // Safe because if current fiber exists, we are reconciling,
1004 // and it is guaranteed to be the work-in-progress version.
1005 return getStackByFiberInDevAndProd(current);
1006 }
1007 return '';
1008}
1009
1010function resetCurrentFiber() {
1011 {
1012 ReactDebugCurrentFrame.getCurrentStack = null;
1013 current = null;
1014 phase = null;
1015 }
1016}
1017
1018function setCurrentFiber(fiber) {
1019 {
1020 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1021 current = fiber;
1022 phase = null;
1023 }
1024}
1025
1026function setCurrentPhase(lifeCyclePhase) {
1027 {
1028 phase = lifeCyclePhase;
1029 }
1030}
1031
1032var debugRenderPhaseSideEffects = false;
1033var debugRenderPhaseSideEffectsForStrictMode = false;
1034var enableUserTimingAPI = true;
1035var warnAboutDeprecatedLifecycles = false;
1036var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
1037var enableProfilerTimer = false;
1038var enableSchedulerTracing = false;
1039var enableSuspenseServerRenderer = false;
1040
1041
1042
1043
1044
1045// Only used in www builds.
1046
1047// Prefix measurements so that it's possible to filter them.
1048// Longer prefixes are hard to read in DevTools.
1049var reactEmoji = '\u269B';
1050var warningEmoji = '\u26D4';
1051var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
1052
1053// Keep track of current fiber so that we know the path to unwind on pause.
1054// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1055var currentFiber = null;
1056// If we're in the middle of user code, which fiber and method is it?
1057// Reusing `currentFiber` would be confusing for this because user code fiber
1058// can change during commit phase too, but we don't need to unwind it (since
1059// lifecycles in the commit phase don't resemble a tree).
1060var currentPhase = null;
1061var currentPhaseFiber = null;
1062// Did lifecycle hook schedule an update? This is often a performance problem,
1063// so we will keep track of it, and include it in the report.
1064// Track commits caused by cascading updates.
1065var isCommitting = false;
1066var hasScheduledUpdateInCurrentCommit = false;
1067var hasScheduledUpdateInCurrentPhase = false;
1068var commitCountInCurrentWorkLoop = 0;
1069var effectCountInCurrentCommit = 0;
1070var isWaitingForCallback = false;
1071// During commits, we only show a measurement once per method name
1072// to avoid stretch the commit phase with measurement overhead.
1073var labelsInCurrentCommit = new Set();
1074
1075var formatMarkName = function (markName) {
1076 return reactEmoji + ' ' + markName;
1077};
1078
1079var formatLabel = function (label, warning) {
1080 var prefix = warning ? warningEmoji + ' ' : reactEmoji + ' ';
1081 var suffix = warning ? ' Warning: ' + warning : '';
1082 return '' + prefix + label + suffix;
1083};
1084
1085var beginMark = function (markName) {
1086 performance.mark(formatMarkName(markName));
1087};
1088
1089var clearMark = function (markName) {
1090 performance.clearMarks(formatMarkName(markName));
1091};
1092
1093var endMark = function (label, markName, warning) {
1094 var formattedMarkName = formatMarkName(markName);
1095 var formattedLabel = formatLabel(label, warning);
1096 try {
1097 performance.measure(formattedLabel, formattedMarkName);
1098 } catch (err) {}
1099 // If previous mark was missing for some reason, this will throw.
1100 // This could only happen if React crashed in an unexpected place earlier.
1101 // Don't pile on with more errors.
1102
1103 // Clear marks immediately to avoid growing buffer.
1104 performance.clearMarks(formattedMarkName);
1105 performance.clearMeasures(formattedLabel);
1106};
1107
1108var getFiberMarkName = function (label, debugID) {
1109 return label + ' (#' + debugID + ')';
1110};
1111
1112var getFiberLabel = function (componentName, isMounted, phase) {
1113 if (phase === null) {
1114 // These are composite component total time measurements.
1115 return componentName + ' [' + (isMounted ? 'update' : 'mount') + ']';
1116 } else {
1117 // Composite component methods.
1118 return componentName + '.' + phase;
1119 }
1120};
1121
1122var beginFiberMark = function (fiber, phase) {
1123 var componentName = getComponentName(fiber.type) || 'Unknown';
1124 var debugID = fiber._debugID;
1125 var isMounted = fiber.alternate !== null;
1126 var label = getFiberLabel(componentName, isMounted, phase);
1127
1128 if (isCommitting && labelsInCurrentCommit.has(label)) {
1129 // During the commit phase, we don't show duplicate labels because
1130 // there is a fixed overhead for every measurement, and we don't
1131 // want to stretch the commit phase beyond necessary.
1132 return false;
1133 }
1134 labelsInCurrentCommit.add(label);
1135
1136 var markName = getFiberMarkName(label, debugID);
1137 beginMark(markName);
1138 return true;
1139};
1140
1141var clearFiberMark = function (fiber, phase) {
1142 var componentName = getComponentName(fiber.type) || 'Unknown';
1143 var debugID = fiber._debugID;
1144 var isMounted = fiber.alternate !== null;
1145 var label = getFiberLabel(componentName, isMounted, phase);
1146 var markName = getFiberMarkName(label, debugID);
1147 clearMark(markName);
1148};
1149
1150var endFiberMark = function (fiber, phase, warning) {
1151 var componentName = getComponentName(fiber.type) || 'Unknown';
1152 var debugID = fiber._debugID;
1153 var isMounted = fiber.alternate !== null;
1154 var label = getFiberLabel(componentName, isMounted, phase);
1155 var markName = getFiberMarkName(label, debugID);
1156 endMark(label, markName, warning);
1157};
1158
1159var shouldIgnoreFiber = function (fiber) {
1160 // Host components should be skipped in the timeline.
1161 // We could check typeof fiber.type, but does this work with RN?
1162 switch (fiber.tag) {
1163 case HostRoot:
1164 case HostComponent:
1165 case HostText:
1166 case HostPortal:
1167 case Fragment:
1168 case ContextProvider:
1169 case ContextConsumer:
1170 case Mode:
1171 return true;
1172 default:
1173 return false;
1174 }
1175};
1176
1177var clearPendingPhaseMeasurement = function () {
1178 if (currentPhase !== null && currentPhaseFiber !== null) {
1179 clearFiberMark(currentPhaseFiber, currentPhase);
1180 }
1181 currentPhaseFiber = null;
1182 currentPhase = null;
1183 hasScheduledUpdateInCurrentPhase = false;
1184};
1185
1186var pauseTimers = function () {
1187 // Stops all currently active measurements so that they can be resumed
1188 // if we continue in a later deferred loop from the same unit of work.
1189 var fiber = currentFiber;
1190 while (fiber) {
1191 if (fiber._debugIsCurrentlyTiming) {
1192 endFiberMark(fiber, null, null);
1193 }
1194 fiber = fiber.return;
1195 }
1196};
1197
1198var resumeTimersRecursively = function (fiber) {
1199 if (fiber.return !== null) {
1200 resumeTimersRecursively(fiber.return);
1201 }
1202 if (fiber._debugIsCurrentlyTiming) {
1203 beginFiberMark(fiber, null);
1204 }
1205};
1206
1207var resumeTimers = function () {
1208 // Resumes all measurements that were active during the last deferred loop.
1209 if (currentFiber !== null) {
1210 resumeTimersRecursively(currentFiber);
1211 }
1212};
1213
1214function recordEffect() {
1215 if (enableUserTimingAPI) {
1216 effectCountInCurrentCommit++;
1217 }
1218}
1219
1220function recordScheduleUpdate() {
1221 if (enableUserTimingAPI) {
1222 if (isCommitting) {
1223 hasScheduledUpdateInCurrentCommit = true;
1224 }
1225 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1226 hasScheduledUpdateInCurrentPhase = true;
1227 }
1228 }
1229}
1230
1231function startRequestCallbackTimer() {
1232 if (enableUserTimingAPI) {
1233 if (supportsUserTiming && !isWaitingForCallback) {
1234 isWaitingForCallback = true;
1235 beginMark('(Waiting for async callback...)');
1236 }
1237 }
1238}
1239
1240function stopRequestCallbackTimer(didExpire, expirationTime) {
1241 if (enableUserTimingAPI) {
1242 if (supportsUserTiming) {
1243 isWaitingForCallback = false;
1244 var warning = didExpire ? 'React was blocked by main thread' : null;
1245 endMark('(Waiting for async callback... will force flush in ' + expirationTime + ' ms)', '(Waiting for async callback...)', warning);
1246 }
1247 }
1248}
1249
1250function startWorkTimer(fiber) {
1251 if (enableUserTimingAPI) {
1252 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1253 return;
1254 }
1255 // If we pause, this is the fiber to unwind from.
1256 currentFiber = fiber;
1257 if (!beginFiberMark(fiber, null)) {
1258 return;
1259 }
1260 fiber._debugIsCurrentlyTiming = true;
1261 }
1262}
1263
1264function cancelWorkTimer(fiber) {
1265 if (enableUserTimingAPI) {
1266 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1267 return;
1268 }
1269 // Remember we shouldn't complete measurement for this fiber.
1270 // Otherwise flamechart will be deep even for small updates.
1271 fiber._debugIsCurrentlyTiming = false;
1272 clearFiberMark(fiber, null);
1273 }
1274}
1275
1276function stopWorkTimer(fiber) {
1277 if (enableUserTimingAPI) {
1278 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1279 return;
1280 }
1281 // If we pause, its parent is the fiber to unwind from.
1282 currentFiber = fiber.return;
1283 if (!fiber._debugIsCurrentlyTiming) {
1284 return;
1285 }
1286 fiber._debugIsCurrentlyTiming = false;
1287 endFiberMark(fiber, null, null);
1288 }
1289}
1290
1291function stopFailedWorkTimer(fiber) {
1292 if (enableUserTimingAPI) {
1293 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1294 return;
1295 }
1296 // If we pause, its parent is the fiber to unwind from.
1297 currentFiber = fiber.return;
1298 if (!fiber._debugIsCurrentlyTiming) {
1299 return;
1300 }
1301 fiber._debugIsCurrentlyTiming = false;
1302 var warning = fiber.tag === SuspenseComponent || fiber.tag === DehydratedSuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1303 endFiberMark(fiber, null, warning);
1304 }
1305}
1306
1307function startPhaseTimer(fiber, phase) {
1308 if (enableUserTimingAPI) {
1309 if (!supportsUserTiming) {
1310 return;
1311 }
1312 clearPendingPhaseMeasurement();
1313 if (!beginFiberMark(fiber, phase)) {
1314 return;
1315 }
1316 currentPhaseFiber = fiber;
1317 currentPhase = phase;
1318 }
1319}
1320
1321function stopPhaseTimer() {
1322 if (enableUserTimingAPI) {
1323 if (!supportsUserTiming) {
1324 return;
1325 }
1326 if (currentPhase !== null && currentPhaseFiber !== null) {
1327 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1328 endFiberMark(currentPhaseFiber, currentPhase, warning);
1329 }
1330 currentPhase = null;
1331 currentPhaseFiber = null;
1332 }
1333}
1334
1335function startWorkLoopTimer(nextUnitOfWork) {
1336 if (enableUserTimingAPI) {
1337 currentFiber = nextUnitOfWork;
1338 if (!supportsUserTiming) {
1339 return;
1340 }
1341 commitCountInCurrentWorkLoop = 0;
1342 // This is top level call.
1343 // Any other measurements are performed within.
1344 beginMark('(React Tree Reconciliation)');
1345 // Resume any measurements that were in progress during the last loop.
1346 resumeTimers();
1347 }
1348}
1349
1350function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1351 if (enableUserTimingAPI) {
1352 if (!supportsUserTiming) {
1353 return;
1354 }
1355 var warning = null;
1356 if (interruptedBy !== null) {
1357 if (interruptedBy.tag === HostRoot) {
1358 warning = 'A top-level update interrupted the previous render';
1359 } else {
1360 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1361 warning = 'An update to ' + componentName + ' interrupted the previous render';
1362 }
1363 } else if (commitCountInCurrentWorkLoop > 1) {
1364 warning = 'There were cascading updates';
1365 }
1366 commitCountInCurrentWorkLoop = 0;
1367 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)';
1368 // Pause any measurements until the next loop.
1369 pauseTimers();
1370 endMark(label, '(React Tree Reconciliation)', warning);
1371 }
1372}
1373
1374function startCommitTimer() {
1375 if (enableUserTimingAPI) {
1376 if (!supportsUserTiming) {
1377 return;
1378 }
1379 isCommitting = true;
1380 hasScheduledUpdateInCurrentCommit = false;
1381 labelsInCurrentCommit.clear();
1382 beginMark('(Committing Changes)');
1383 }
1384}
1385
1386function stopCommitTimer() {
1387 if (enableUserTimingAPI) {
1388 if (!supportsUserTiming) {
1389 return;
1390 }
1391
1392 var warning = null;
1393 if (hasScheduledUpdateInCurrentCommit) {
1394 warning = 'Lifecycle hook scheduled a cascading update';
1395 } else if (commitCountInCurrentWorkLoop > 0) {
1396 warning = 'Caused by a cascading update in earlier commit';
1397 }
1398 hasScheduledUpdateInCurrentCommit = false;
1399 commitCountInCurrentWorkLoop++;
1400 isCommitting = false;
1401 labelsInCurrentCommit.clear();
1402
1403 endMark('(Committing Changes)', '(Committing Changes)', warning);
1404 }
1405}
1406
1407function startCommitSnapshotEffectsTimer() {
1408 if (enableUserTimingAPI) {
1409 if (!supportsUserTiming) {
1410 return;
1411 }
1412 effectCountInCurrentCommit = 0;
1413 beginMark('(Committing Snapshot Effects)');
1414 }
1415}
1416
1417function stopCommitSnapshotEffectsTimer() {
1418 if (enableUserTimingAPI) {
1419 if (!supportsUserTiming) {
1420 return;
1421 }
1422 var count = effectCountInCurrentCommit;
1423 effectCountInCurrentCommit = 0;
1424 endMark('(Committing Snapshot Effects: ' + count + ' Total)', '(Committing Snapshot Effects)', null);
1425 }
1426}
1427
1428function startCommitHostEffectsTimer() {
1429 if (enableUserTimingAPI) {
1430 if (!supportsUserTiming) {
1431 return;
1432 }
1433 effectCountInCurrentCommit = 0;
1434 beginMark('(Committing Host Effects)');
1435 }
1436}
1437
1438function stopCommitHostEffectsTimer() {
1439 if (enableUserTimingAPI) {
1440 if (!supportsUserTiming) {
1441 return;
1442 }
1443 var count = effectCountInCurrentCommit;
1444 effectCountInCurrentCommit = 0;
1445 endMark('(Committing Host Effects: ' + count + ' Total)', '(Committing Host Effects)', null);
1446 }
1447}
1448
1449function startCommitLifeCyclesTimer() {
1450 if (enableUserTimingAPI) {
1451 if (!supportsUserTiming) {
1452 return;
1453 }
1454 effectCountInCurrentCommit = 0;
1455 beginMark('(Calling Lifecycle Methods)');
1456 }
1457}
1458
1459function stopCommitLifeCyclesTimer() {
1460 if (enableUserTimingAPI) {
1461 if (!supportsUserTiming) {
1462 return;
1463 }
1464 var count = effectCountInCurrentCommit;
1465 effectCountInCurrentCommit = 0;
1466 endMark('(Calling Lifecycle Methods: ' + count + ' Total)', '(Calling Lifecycle Methods)', null);
1467 }
1468}
1469
1470var valueStack = [];
1471
1472var fiberStack = void 0;
1473
1474{
1475 fiberStack = [];
1476}
1477
1478var index = -1;
1479
1480function createCursor(defaultValue) {
1481 return {
1482 current: defaultValue
1483 };
1484}
1485
1486function pop(cursor, fiber) {
1487 if (index < 0) {
1488 {
1489 warningWithoutStack$1(false, 'Unexpected pop.');
1490 }
1491 return;
1492 }
1493
1494 {
1495 if (fiber !== fiberStack[index]) {
1496 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1497 }
1498 }
1499
1500 cursor.current = valueStack[index];
1501
1502 valueStack[index] = null;
1503
1504 {
1505 fiberStack[index] = null;
1506 }
1507
1508 index--;
1509}
1510
1511function push(cursor, value, fiber) {
1512 index++;
1513
1514 valueStack[index] = cursor.current;
1515
1516 {
1517 fiberStack[index] = fiber;
1518 }
1519
1520 cursor.current = value;
1521}
1522
1523function checkThatStackIsEmpty() {
1524 {
1525 if (index !== -1) {
1526 warningWithoutStack$1(false, 'Expected an empty stack. Something was not reset properly.');
1527 }
1528 }
1529}
1530
1531function resetStackAfterFatalErrorInDev() {
1532 {
1533 index = -1;
1534 valueStack.length = 0;
1535 fiberStack.length = 0;
1536 }
1537}
1538
1539var warnedAboutMissingGetChildContext = void 0;
1540
1541{
1542 warnedAboutMissingGetChildContext = {};
1543}
1544
1545var emptyContextObject = {};
1546{
1547 Object.freeze(emptyContextObject);
1548}
1549
1550// A cursor to the current merged context object on the stack.
1551var contextStackCursor = createCursor(emptyContextObject);
1552// A cursor to a boolean indicating whether the context has changed.
1553var didPerformWorkStackCursor = createCursor(false);
1554// Keep track of the previous context object that was on the stack.
1555// We use this to get access to the parent context after we have already
1556// pushed the next context provider, and now need to merge their contexts.
1557var previousContext = emptyContextObject;
1558
1559function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1560 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1561 // If the fiber is a context provider itself, when we read its context
1562 // we may have already pushed its own child context on the stack. A context
1563 // provider should not "see" its own child context. Therefore we read the
1564 // previous (parent) context instead for a context provider.
1565 return previousContext;
1566 }
1567 return contextStackCursor.current;
1568}
1569
1570function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1571 var instance = workInProgress.stateNode;
1572 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1573 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1574}
1575
1576function getMaskedContext(workInProgress, unmaskedContext) {
1577 var type = workInProgress.type;
1578 var contextTypes = type.contextTypes;
1579 if (!contextTypes) {
1580 return emptyContextObject;
1581 }
1582
1583 // Avoid recreating masked context unless unmasked context has changed.
1584 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1585 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1586 var instance = workInProgress.stateNode;
1587 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1588 return instance.__reactInternalMemoizedMaskedChildContext;
1589 }
1590
1591 var context = {};
1592 for (var key in contextTypes) {
1593 context[key] = unmaskedContext[key];
1594 }
1595
1596 {
1597 var name = getComponentName(type) || 'Unknown';
1598 checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1599 }
1600
1601 // Cache unmasked context so we can avoid recreating masked context unless necessary.
1602 // Context is created before the class component is instantiated so check for instance.
1603 if (instance) {
1604 cacheContext(workInProgress, unmaskedContext, context);
1605 }
1606
1607 return context;
1608}
1609
1610function hasContextChanged() {
1611 return didPerformWorkStackCursor.current;
1612}
1613
1614function isContextProvider(type) {
1615 var childContextTypes = type.childContextTypes;
1616 return childContextTypes !== null && childContextTypes !== undefined;
1617}
1618
1619function popContext(fiber) {
1620 pop(didPerformWorkStackCursor, fiber);
1621 pop(contextStackCursor, fiber);
1622}
1623
1624function popTopLevelContextObject(fiber) {
1625 pop(didPerformWorkStackCursor, fiber);
1626 pop(contextStackCursor, fiber);
1627}
1628
1629function pushTopLevelContextObject(fiber, context, didChange) {
1630 !(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;
1631
1632 push(contextStackCursor, context, fiber);
1633 push(didPerformWorkStackCursor, didChange, fiber);
1634}
1635
1636function processChildContext(fiber, type, parentContext) {
1637 var instance = fiber.stateNode;
1638 var childContextTypes = type.childContextTypes;
1639
1640 // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1641 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1642 if (typeof instance.getChildContext !== 'function') {
1643 {
1644 var componentName = getComponentName(type) || 'Unknown';
1645
1646 if (!warnedAboutMissingGetChildContext[componentName]) {
1647 warnedAboutMissingGetChildContext[componentName] = true;
1648 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);
1649 }
1650 }
1651 return parentContext;
1652 }
1653
1654 var childContext = void 0;
1655 {
1656 setCurrentPhase('getChildContext');
1657 }
1658 startPhaseTimer(fiber, 'getChildContext');
1659 childContext = instance.getChildContext();
1660 stopPhaseTimer();
1661 {
1662 setCurrentPhase(null);
1663 }
1664 for (var contextKey in childContext) {
1665 !(contextKey in childContextTypes) ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(type) || 'Unknown', contextKey) : void 0;
1666 }
1667 {
1668 var name = getComponentName(type) || 'Unknown';
1669 checkPropTypes_1(childContextTypes, childContext, 'child context', name,
1670 // In practice, there is one case in which we won't get a stack. It's when
1671 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1672 // context from the parent component instance. The stack will be missing
1673 // because it's outside of the reconciliation, and so the pointer has not
1674 // been set. This is rare and doesn't matter. We'll also remove that API.
1675 getCurrentFiberStackInDev);
1676 }
1677
1678 return _assign({}, parentContext, childContext);
1679}
1680
1681function pushContextProvider(workInProgress) {
1682 var instance = workInProgress.stateNode;
1683 // We push the context as early as possible to ensure stack integrity.
1684 // If the instance does not exist yet, we will push null at first,
1685 // and replace it on the stack later when invalidating the context.
1686 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject;
1687
1688 // Remember the parent context so we can merge with it later.
1689 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1690 previousContext = contextStackCursor.current;
1691 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1692 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1693
1694 return true;
1695}
1696
1697function invalidateContextProvider(workInProgress, type, didChange) {
1698 var instance = workInProgress.stateNode;
1699 !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;
1700
1701 if (didChange) {
1702 // Merge parent and own context.
1703 // Skip this if we're not updating due to sCU.
1704 // This avoids unnecessarily recomputing memoized values.
1705 var mergedContext = processChildContext(workInProgress, type, previousContext);
1706 instance.__reactInternalMemoizedMergedChildContext = mergedContext;
1707
1708 // Replace the old (or empty) context with the new one.
1709 // It is important to unwind the context in the reverse order.
1710 pop(didPerformWorkStackCursor, workInProgress);
1711 pop(contextStackCursor, workInProgress);
1712 // Now push the new context and mark that it has changed.
1713 push(contextStackCursor, mergedContext, workInProgress);
1714 push(didPerformWorkStackCursor, didChange, workInProgress);
1715 } else {
1716 pop(didPerformWorkStackCursor, workInProgress);
1717 push(didPerformWorkStackCursor, didChange, workInProgress);
1718 }
1719}
1720
1721function findCurrentUnmaskedContext(fiber) {
1722 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1723 // makes sense elsewhere
1724 !(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;
1725
1726 var node = fiber;
1727 do {
1728 switch (node.tag) {
1729 case HostRoot:
1730 return node.stateNode.context;
1731 case ClassComponent:
1732 {
1733 var Component = node.type;
1734 if (isContextProvider(Component)) {
1735 return node.stateNode.__reactInternalMemoizedMergedChildContext;
1736 }
1737 break;
1738 }
1739 }
1740 node = node.return;
1741 } while (node !== null);
1742 invariant(false, 'Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.');
1743}
1744
1745var onCommitFiberRoot = null;
1746var onCommitFiberUnmount = null;
1747var hasLoggedError = false;
1748
1749function catchErrors(fn) {
1750 return function (arg) {
1751 try {
1752 return fn(arg);
1753 } catch (err) {
1754 if (true && !hasLoggedError) {
1755 hasLoggedError = true;
1756 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
1757 }
1758 }
1759 };
1760}
1761
1762var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
1763
1764function injectInternals(internals) {
1765 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
1766 // No DevTools
1767 return false;
1768 }
1769 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
1770 if (hook.isDisabled) {
1771 // This isn't a real property on the hook, but it can be set to opt out
1772 // of DevTools integration and associated warnings and logs.
1773 // https://github.com/facebook/react/issues/3877
1774 return true;
1775 }
1776 if (!hook.supportsFiber) {
1777 {
1778 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');
1779 }
1780 // DevTools exists, even though it doesn't support Fiber.
1781 return true;
1782 }
1783 try {
1784 var rendererID = hook.inject(internals);
1785 // We have successfully injected, so now it is safe to set up hooks.
1786 onCommitFiberRoot = catchErrors(function (root) {
1787 return hook.onCommitFiberRoot(rendererID, root);
1788 });
1789 onCommitFiberUnmount = catchErrors(function (fiber) {
1790 return hook.onCommitFiberUnmount(rendererID, fiber);
1791 });
1792 } catch (err) {
1793 // Catch all errors because it is unsafe to throw during initialization.
1794 {
1795 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
1796 }
1797 }
1798 // DevTools exists
1799 return true;
1800}
1801
1802function onCommitRoot(root) {
1803 if (typeof onCommitFiberRoot === 'function') {
1804 onCommitFiberRoot(root);
1805 }
1806}
1807
1808function onCommitUnmount(fiber) {
1809 if (typeof onCommitFiberUnmount === 'function') {
1810 onCommitFiberUnmount(fiber);
1811 }
1812}
1813
1814// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
1815// Math.pow(2, 30) - 1
1816// 0b111111111111111111111111111111
1817var maxSigned31BitInt = 1073741823;
1818
1819var NoWork = 0;
1820var Never = 1;
1821var Sync = maxSigned31BitInt;
1822
1823var UNIT_SIZE = 10;
1824var MAGIC_NUMBER_OFFSET = maxSigned31BitInt - 1;
1825
1826// 1 unit of expiration time represents 10ms.
1827function msToExpirationTime(ms) {
1828 // Always add an offset so that we don't clash with the magic number for NoWork.
1829 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
1830}
1831
1832function expirationTimeToMs(expirationTime) {
1833 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
1834}
1835
1836function ceiling(num, precision) {
1837 return ((num / precision | 0) + 1) * precision;
1838}
1839
1840function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
1841 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
1842}
1843
1844var LOW_PRIORITY_EXPIRATION = 5000;
1845var LOW_PRIORITY_BATCH_SIZE = 250;
1846
1847function computeAsyncExpiration(currentTime) {
1848 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
1849}
1850
1851// We intentionally set a higher expiration time for interactive updates in
1852// dev than in production.
1853//
1854// If the main thread is being blocked so long that you hit the expiration,
1855// it's a problem that could be solved with better scheduling.
1856//
1857// People will be more likely to notice this and fix it with the long
1858// expiration time in development.
1859//
1860// In production we opt for better UX at the risk of masking scheduling
1861// problems, by expiring fast.
1862var HIGH_PRIORITY_EXPIRATION = 500;
1863var HIGH_PRIORITY_BATCH_SIZE = 100;
1864
1865function computeInteractiveExpiration(currentTime) {
1866 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
1867}
1868
1869var NoContext = 0;
1870var ConcurrentMode = 1;
1871var StrictMode = 2;
1872var ProfileMode = 4;
1873
1874var hasBadMapPolyfill = void 0;
1875
1876{
1877 hasBadMapPolyfill = false;
1878 try {
1879 var nonExtensibleObject = Object.preventExtensions({});
1880 var testMap = new Map([[nonExtensibleObject, null]]);
1881 var testSet = new Set([nonExtensibleObject]);
1882 // This is necessary for Rollup to not consider these unused.
1883 // https://github.com/rollup/rollup/issues/1771
1884 // TODO: we can remove these if Rollup fixes the bug.
1885 testMap.set(0, 0);
1886 testSet.add(0);
1887 } catch (e) {
1888 // TODO: Consider warning about bad polyfills
1889 hasBadMapPolyfill = true;
1890 }
1891}
1892
1893// A Fiber is work on a Component that needs to be done or was done. There can
1894// be more than one per component.
1895
1896
1897var debugCounter = void 0;
1898
1899{
1900 debugCounter = 1;
1901}
1902
1903function FiberNode(tag, pendingProps, key, mode) {
1904 // Instance
1905 this.tag = tag;
1906 this.key = key;
1907 this.elementType = null;
1908 this.type = null;
1909 this.stateNode = null;
1910
1911 // Fiber
1912 this.return = null;
1913 this.child = null;
1914 this.sibling = null;
1915 this.index = 0;
1916
1917 this.ref = null;
1918
1919 this.pendingProps = pendingProps;
1920 this.memoizedProps = null;
1921 this.updateQueue = null;
1922 this.memoizedState = null;
1923 this.contextDependencies = null;
1924
1925 this.mode = mode;
1926
1927 // Effects
1928 this.effectTag = NoEffect;
1929 this.nextEffect = null;
1930
1931 this.firstEffect = null;
1932 this.lastEffect = null;
1933
1934 this.expirationTime = NoWork;
1935 this.childExpirationTime = NoWork;
1936
1937 this.alternate = null;
1938
1939 if (enableProfilerTimer) {
1940 // Note: The following is done to avoid a v8 performance cliff.
1941 //
1942 // Initializing the fields below to smis and later updating them with
1943 // double values will cause Fibers to end up having separate shapes.
1944 // This behavior/bug has something to do with Object.preventExtension().
1945 // Fortunately this only impacts DEV builds.
1946 // Unfortunately it makes React unusably slow for some applications.
1947 // To work around this, initialize the fields below with doubles.
1948 //
1949 // Learn more about this here:
1950 // https://github.com/facebook/react/issues/14365
1951 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
1952 this.actualDuration = Number.NaN;
1953 this.actualStartTime = Number.NaN;
1954 this.selfBaseDuration = Number.NaN;
1955 this.treeBaseDuration = Number.NaN;
1956
1957 // It's okay to replace the initial doubles with smis after initialization.
1958 // This won't trigger the performance cliff mentioned above,
1959 // and it simplifies other profiler code (including DevTools).
1960 this.actualDuration = 0;
1961 this.actualStartTime = -1;
1962 this.selfBaseDuration = 0;
1963 this.treeBaseDuration = 0;
1964 }
1965
1966 {
1967 this._debugID = debugCounter++;
1968 this._debugSource = null;
1969 this._debugOwner = null;
1970 this._debugIsCurrentlyTiming = false;
1971 this._debugHookTypes = null;
1972 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
1973 Object.preventExtensions(this);
1974 }
1975 }
1976}
1977
1978// This is a constructor function, rather than a POJO constructor, still
1979// please ensure we do the following:
1980// 1) Nobody should add any instance methods on this. Instance methods can be
1981// more difficult to predict when they get optimized and they are almost
1982// never inlined properly in static compilers.
1983// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
1984// always know when it is a fiber.
1985// 3) We might want to experiment with using numeric keys since they are easier
1986// to optimize in a non-JIT environment.
1987// 4) We can easily go from a constructor to a createFiber object literal if that
1988// is faster.
1989// 5) It should be easy to port this to a C struct and keep a C implementation
1990// compatible.
1991var createFiber = function (tag, pendingProps, key, mode) {
1992 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
1993 return new FiberNode(tag, pendingProps, key, mode);
1994};
1995
1996function shouldConstruct(Component) {
1997 var prototype = Component.prototype;
1998 return !!(prototype && prototype.isReactComponent);
1999}
2000
2001function isSimpleFunctionComponent(type) {
2002 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
2003}
2004
2005function resolveLazyComponentTag(Component) {
2006 if (typeof Component === 'function') {
2007 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
2008 } else if (Component !== undefined && Component !== null) {
2009 var $$typeof = Component.$$typeof;
2010 if ($$typeof === REACT_FORWARD_REF_TYPE) {
2011 return ForwardRef;
2012 }
2013 if ($$typeof === REACT_MEMO_TYPE) {
2014 return MemoComponent;
2015 }
2016 }
2017 return IndeterminateComponent;
2018}
2019
2020// This is used to create an alternate fiber to do work on.
2021function createWorkInProgress(current, pendingProps, expirationTime) {
2022 var workInProgress = current.alternate;
2023 if (workInProgress === null) {
2024 // We use a double buffering pooling technique because we know that we'll
2025 // only ever need at most two versions of a tree. We pool the "other" unused
2026 // node that we're free to reuse. This is lazily created to avoid allocating
2027 // extra objects for things that are never updated. It also allow us to
2028 // reclaim the extra memory if needed.
2029 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
2030 workInProgress.elementType = current.elementType;
2031 workInProgress.type = current.type;
2032 workInProgress.stateNode = current.stateNode;
2033
2034 {
2035 // DEV-only fields
2036 workInProgress._debugID = current._debugID;
2037 workInProgress._debugSource = current._debugSource;
2038 workInProgress._debugOwner = current._debugOwner;
2039 workInProgress._debugHookTypes = current._debugHookTypes;
2040 }
2041
2042 workInProgress.alternate = current;
2043 current.alternate = workInProgress;
2044 } else {
2045 workInProgress.pendingProps = pendingProps;
2046
2047 // We already have an alternate.
2048 // Reset the effect tag.
2049 workInProgress.effectTag = NoEffect;
2050
2051 // The effect list is no longer valid.
2052 workInProgress.nextEffect = null;
2053 workInProgress.firstEffect = null;
2054 workInProgress.lastEffect = null;
2055
2056 if (enableProfilerTimer) {
2057 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
2058 // This prevents time from endlessly accumulating in new commits.
2059 // This has the downside of resetting values for different priority renders,
2060 // But works for yielding (the common case) and should support resuming.
2061 workInProgress.actualDuration = 0;
2062 workInProgress.actualStartTime = -1;
2063 }
2064 }
2065
2066 workInProgress.childExpirationTime = current.childExpirationTime;
2067 workInProgress.expirationTime = current.expirationTime;
2068
2069 workInProgress.child = current.child;
2070 workInProgress.memoizedProps = current.memoizedProps;
2071 workInProgress.memoizedState = current.memoizedState;
2072 workInProgress.updateQueue = current.updateQueue;
2073 workInProgress.contextDependencies = current.contextDependencies;
2074
2075 // These will be overridden during the parent's reconciliation
2076 workInProgress.sibling = current.sibling;
2077 workInProgress.index = current.index;
2078 workInProgress.ref = current.ref;
2079
2080 if (enableProfilerTimer) {
2081 workInProgress.selfBaseDuration = current.selfBaseDuration;
2082 workInProgress.treeBaseDuration = current.treeBaseDuration;
2083 }
2084
2085 return workInProgress;
2086}
2087
2088function createHostRootFiber(isConcurrent) {
2089 var mode = isConcurrent ? ConcurrentMode | StrictMode : NoContext;
2090
2091 if (enableProfilerTimer && isDevToolsPresent) {
2092 // Always collect profile timings when DevTools are present.
2093 // This enables DevTools to start capturing timing at any point–
2094 // Without some nodes in the tree having empty base times.
2095 mode |= ProfileMode;
2096 }
2097
2098 return createFiber(HostRoot, null, null, mode);
2099}
2100
2101function createFiberFromTypeAndProps(type, // React$ElementType
2102key, pendingProps, owner, mode, expirationTime) {
2103 var fiber = void 0;
2104
2105 var fiberTag = IndeterminateComponent;
2106 // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
2107 var resolvedType = type;
2108 if (typeof type === 'function') {
2109 if (shouldConstruct(type)) {
2110 fiberTag = ClassComponent;
2111 }
2112 } else if (typeof type === 'string') {
2113 fiberTag = HostComponent;
2114 } else {
2115 getTag: switch (type) {
2116 case REACT_FRAGMENT_TYPE:
2117 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
2118 case REACT_CONCURRENT_MODE_TYPE:
2119 return createFiberFromMode(pendingProps, mode | ConcurrentMode | StrictMode, expirationTime, key);
2120 case REACT_STRICT_MODE_TYPE:
2121 return createFiberFromMode(pendingProps, mode | StrictMode, expirationTime, key);
2122 case REACT_PROFILER_TYPE:
2123 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
2124 case REACT_SUSPENSE_TYPE:
2125 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
2126 default:
2127 {
2128 if (typeof type === 'object' && type !== null) {
2129 switch (type.$$typeof) {
2130 case REACT_PROVIDER_TYPE:
2131 fiberTag = ContextProvider;
2132 break getTag;
2133 case REACT_CONTEXT_TYPE:
2134 // This is a consumer
2135 fiberTag = ContextConsumer;
2136 break getTag;
2137 case REACT_FORWARD_REF_TYPE:
2138 fiberTag = ForwardRef;
2139 break getTag;
2140 case REACT_MEMO_TYPE:
2141 fiberTag = MemoComponent;
2142 break getTag;
2143 case REACT_LAZY_TYPE:
2144 fiberTag = LazyComponent;
2145 resolvedType = null;
2146 break getTag;
2147 }
2148 }
2149 var info = '';
2150 {
2151 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2152 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.';
2153 }
2154 var ownerName = owner ? getComponentName(owner.type) : null;
2155 if (ownerName) {
2156 info += '\n\nCheck the render method of `' + ownerName + '`.';
2157 }
2158 }
2159 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);
2160 }
2161 }
2162 }
2163
2164 fiber = createFiber(fiberTag, pendingProps, key, mode);
2165 fiber.elementType = type;
2166 fiber.type = resolvedType;
2167 fiber.expirationTime = expirationTime;
2168
2169 return fiber;
2170}
2171
2172function createFiberFromElement(element, mode, expirationTime) {
2173 var owner = null;
2174 {
2175 owner = element._owner;
2176 }
2177 var type = element.type;
2178 var key = element.key;
2179 var pendingProps = element.props;
2180 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
2181 {
2182 fiber._debugSource = element._source;
2183 fiber._debugOwner = element._owner;
2184 }
2185 return fiber;
2186}
2187
2188function createFiberFromFragment(elements, mode, expirationTime, key) {
2189 var fiber = createFiber(Fragment, elements, key, mode);
2190 fiber.expirationTime = expirationTime;
2191 return fiber;
2192}
2193
2194function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
2195 {
2196 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
2197 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
2198 }
2199 }
2200
2201 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode);
2202 // TODO: The Profiler fiber shouldn't have a type. It has a tag.
2203 fiber.elementType = REACT_PROFILER_TYPE;
2204 fiber.type = REACT_PROFILER_TYPE;
2205 fiber.expirationTime = expirationTime;
2206
2207 return fiber;
2208}
2209
2210function createFiberFromMode(pendingProps, mode, expirationTime, key) {
2211 var fiber = createFiber(Mode, pendingProps, key, mode);
2212
2213 // TODO: The Mode fiber shouldn't have a type. It has a tag.
2214 var type = (mode & ConcurrentMode) === NoContext ? REACT_STRICT_MODE_TYPE : REACT_CONCURRENT_MODE_TYPE;
2215 fiber.elementType = type;
2216 fiber.type = type;
2217
2218 fiber.expirationTime = expirationTime;
2219 return fiber;
2220}
2221
2222function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
2223 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode);
2224
2225 // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
2226 var type = REACT_SUSPENSE_TYPE;
2227 fiber.elementType = type;
2228 fiber.type = type;
2229
2230 fiber.expirationTime = expirationTime;
2231 return fiber;
2232}
2233
2234function createFiberFromText(content, mode, expirationTime) {
2235 var fiber = createFiber(HostText, content, null, mode);
2236 fiber.expirationTime = expirationTime;
2237 return fiber;
2238}
2239
2240function createFiberFromHostInstanceForDeletion() {
2241 var fiber = createFiber(HostComponent, null, null, NoContext);
2242 // TODO: These should not need a type.
2243 fiber.elementType = 'DELETED';
2244 fiber.type = 'DELETED';
2245 return fiber;
2246}
2247
2248function createFiberFromPortal(portal, mode, expirationTime) {
2249 var pendingProps = portal.children !== null ? portal.children : [];
2250 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
2251 fiber.expirationTime = expirationTime;
2252 fiber.stateNode = {
2253 containerInfo: portal.containerInfo,
2254 pendingChildren: null, // Used by persistent updates
2255 implementation: portal.implementation
2256 };
2257 return fiber;
2258}
2259
2260// Used for stashing WIP properties to replay failed work in DEV.
2261function assignFiberPropertiesInDEV(target, source) {
2262 if (target === null) {
2263 // This Fiber's initial properties will always be overwritten.
2264 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
2265 target = createFiber(IndeterminateComponent, null, null, NoContext);
2266 }
2267
2268 // This is intentionally written as a list of all properties.
2269 // We tried to use Object.assign() instead but this is called in
2270 // the hottest path, and Object.assign() was too slow:
2271 // https://github.com/facebook/react/issues/12502
2272 // This code is DEV-only so size is not a concern.
2273
2274 target.tag = source.tag;
2275 target.key = source.key;
2276 target.elementType = source.elementType;
2277 target.type = source.type;
2278 target.stateNode = source.stateNode;
2279 target.return = source.return;
2280 target.child = source.child;
2281 target.sibling = source.sibling;
2282 target.index = source.index;
2283 target.ref = source.ref;
2284 target.pendingProps = source.pendingProps;
2285 target.memoizedProps = source.memoizedProps;
2286 target.updateQueue = source.updateQueue;
2287 target.memoizedState = source.memoizedState;
2288 target.contextDependencies = source.contextDependencies;
2289 target.mode = source.mode;
2290 target.effectTag = source.effectTag;
2291 target.nextEffect = source.nextEffect;
2292 target.firstEffect = source.firstEffect;
2293 target.lastEffect = source.lastEffect;
2294 target.expirationTime = source.expirationTime;
2295 target.childExpirationTime = source.childExpirationTime;
2296 target.alternate = source.alternate;
2297 if (enableProfilerTimer) {
2298 target.actualDuration = source.actualDuration;
2299 target.actualStartTime = source.actualStartTime;
2300 target.selfBaseDuration = source.selfBaseDuration;
2301 target.treeBaseDuration = source.treeBaseDuration;
2302 }
2303 target._debugID = source._debugID;
2304 target._debugSource = source._debugSource;
2305 target._debugOwner = source._debugOwner;
2306 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
2307 target._debugHookTypes = source._debugHookTypes;
2308 return target;
2309}
2310
2311var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2312
2313var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing;
2314var __interactionsRef = _ReactInternals$Sched.__interactionsRef;
2315var __subscriberRef = _ReactInternals$Sched.__subscriberRef;
2316var unstable_clear = _ReactInternals$Sched.unstable_clear;
2317var unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent;
2318var unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID;
2319var unstable_subscribe = _ReactInternals$Sched.unstable_subscribe;
2320var unstable_trace = _ReactInternals$Sched.unstable_trace;
2321var unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe;
2322var unstable_wrap = _ReactInternals$Sched.unstable_wrap;
2323
2324// TODO: This should be lifted into the renderer.
2325
2326
2327// The following attributes are only used by interaction tracing builds.
2328// They enable interactions to be associated with their async work,
2329// And expose interaction metadata to the React DevTools Profiler plugin.
2330// Note that these attributes are only defined when the enableSchedulerTracing flag is enabled.
2331
2332
2333// Exported FiberRoot type includes all properties,
2334// To avoid requiring potentially error-prone :any casts throughout the project.
2335// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracing is true).
2336// The types are defined separately within this file to ensure they stay in sync.
2337// (We don't have to use an inline :any cast when enableSchedulerTracing is disabled.)
2338
2339
2340function createFiberRoot(containerInfo, isConcurrent, hydrate) {
2341 // Cyclic construction. This cheats the type system right now because
2342 // stateNode is any.
2343 var uninitializedFiber = createHostRootFiber(isConcurrent);
2344
2345 var root = void 0;
2346 if (enableSchedulerTracing) {
2347 root = {
2348 current: uninitializedFiber,
2349 containerInfo: containerInfo,
2350 pendingChildren: null,
2351
2352 earliestPendingTime: NoWork,
2353 latestPendingTime: NoWork,
2354 earliestSuspendedTime: NoWork,
2355 latestSuspendedTime: NoWork,
2356 latestPingedTime: NoWork,
2357
2358 pingCache: null,
2359
2360 didError: false,
2361
2362 pendingCommitExpirationTime: NoWork,
2363 finishedWork: null,
2364 timeoutHandle: noTimeout,
2365 context: null,
2366 pendingContext: null,
2367 hydrate: hydrate,
2368 nextExpirationTimeToWorkOn: NoWork,
2369 expirationTime: NoWork,
2370 firstBatch: null,
2371 nextScheduledRoot: null,
2372
2373 interactionThreadID: unstable_getThreadID(),
2374 memoizedInteractions: new Set(),
2375 pendingInteractionMap: new Map()
2376 };
2377 } else {
2378 root = {
2379 current: uninitializedFiber,
2380 containerInfo: containerInfo,
2381 pendingChildren: null,
2382
2383 pingCache: null,
2384
2385 earliestPendingTime: NoWork,
2386 latestPendingTime: NoWork,
2387 earliestSuspendedTime: NoWork,
2388 latestSuspendedTime: NoWork,
2389 latestPingedTime: NoWork,
2390
2391 didError: false,
2392
2393 pendingCommitExpirationTime: NoWork,
2394 finishedWork: null,
2395 timeoutHandle: noTimeout,
2396 context: null,
2397 pendingContext: null,
2398 hydrate: hydrate,
2399 nextExpirationTimeToWorkOn: NoWork,
2400 expirationTime: NoWork,
2401 firstBatch: null,
2402 nextScheduledRoot: null
2403 };
2404 }
2405
2406 uninitializedFiber.stateNode = root;
2407
2408 // The reason for the way the Flow types are structured in this file,
2409 // Is to avoid needing :any casts everywhere interaction tracing fields are used.
2410 // Unfortunately that requires an :any cast for non-interaction tracing capable builds.
2411 // $FlowFixMe Remove this :any cast and replace it with something better.
2412 return root;
2413}
2414
2415var ReactInternals$2 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2416
2417var _ReactInternals$Sched$1 = ReactInternals$2.Scheduler;
2418var unstable_cancelCallback = _ReactInternals$Sched$1.unstable_cancelCallback;
2419var unstable_now = _ReactInternals$Sched$1.unstable_now;
2420var unstable_scheduleCallback = _ReactInternals$Sched$1.unstable_scheduleCallback;
2421var unstable_shouldYield = _ReactInternals$Sched$1.unstable_shouldYield;
2422var unstable_getFirstCallbackNode = _ReactInternals$Sched$1.unstable_getFirstCallbackNode;
2423var unstable_runWithPriority = _ReactInternals$Sched$1.unstable_runWithPriority;
2424var unstable_next = _ReactInternals$Sched$1.unstable_next;
2425var unstable_continueExecution = _ReactInternals$Sched$1.unstable_continueExecution;
2426var unstable_pauseExecution = _ReactInternals$Sched$1.unstable_pauseExecution;
2427var unstable_getCurrentPriorityLevel = _ReactInternals$Sched$1.unstable_getCurrentPriorityLevel;
2428var unstable_ImmediatePriority = _ReactInternals$Sched$1.unstable_ImmediatePriority;
2429var unstable_UserBlockingPriority = _ReactInternals$Sched$1.unstable_UserBlockingPriority;
2430var unstable_NormalPriority = _ReactInternals$Sched$1.unstable_NormalPriority;
2431var unstable_LowPriority = _ReactInternals$Sched$1.unstable_LowPriority;
2432var unstable_IdlePriority = _ReactInternals$Sched$1.unstable_IdlePriority;
2433
2434var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
2435 var funcArgs = Array.prototype.slice.call(arguments, 3);
2436 try {
2437 func.apply(context, funcArgs);
2438 } catch (error) {
2439 this.onError(error);
2440 }
2441};
2442
2443{
2444 // In DEV mode, we swap out invokeGuardedCallback for a special version
2445 // that plays more nicely with the browser's DevTools. The idea is to preserve
2446 // "Pause on exceptions" behavior. Because React wraps all user-provided
2447 // functions in invokeGuardedCallback, and the production version of
2448 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
2449 // like caught exceptions, and the DevTools won't pause unless the developer
2450 // takes the extra step of enabling pause on caught exceptions. This is
2451 // unintuitive, though, because even though React has caught the error, from
2452 // the developer's perspective, the error is uncaught.
2453 //
2454 // To preserve the expected "Pause on exceptions" behavior, we don't use a
2455 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
2456 // DOM node, and call the user-provided callback from inside an event handler
2457 // for that fake event. If the callback throws, the error is "captured" using
2458 // a global event handler. But because the error happens in a different
2459 // event loop context, it does not interrupt the normal program flow.
2460 // Effectively, this gives us try-catch behavior without actually using
2461 // try-catch. Neat!
2462
2463 // Check that the browser supports the APIs we need to implement our special
2464 // DEV version of invokeGuardedCallback
2465 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
2466 var fakeNode = document.createElement('react');
2467
2468 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
2469 // If document doesn't exist we know for sure we will crash in this method
2470 // when we call document.createEvent(). However this can cause confusing
2471 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
2472 // So we preemptively throw with a better message instead.
2473 !(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;
2474 var evt = document.createEvent('Event');
2475
2476 // Keeps track of whether the user-provided callback threw an error. We
2477 // set this to true at the beginning, then set it to false right after
2478 // calling the function. If the function errors, `didError` will never be
2479 // set to false. This strategy works even if the browser is flaky and
2480 // fails to call our global error handler, because it doesn't rely on
2481 // the error event at all.
2482 var didError = true;
2483
2484 // Keeps track of the value of window.event so that we can reset it
2485 // during the callback to let user code access window.event in the
2486 // browsers that support it.
2487 var windowEvent = window.event;
2488
2489 // Keeps track of the descriptor of window.event to restore it after event
2490 // dispatching: https://github.com/facebook/react/issues/13688
2491 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
2492
2493 // Create an event handler for our fake event. We will synchronously
2494 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
2495 // call the user-provided callback.
2496 var funcArgs = Array.prototype.slice.call(arguments, 3);
2497 function callCallback() {
2498 // We immediately remove the callback from event listeners so that
2499 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
2500 // nested call would trigger the fake event handlers of any call higher
2501 // in the stack.
2502 fakeNode.removeEventListener(evtType, callCallback, false);
2503
2504 // We check for window.hasOwnProperty('event') to prevent the
2505 // window.event assignment in both IE <= 10 as they throw an error
2506 // "Member not found" in strict mode, and in Firefox which does not
2507 // support window.event.
2508 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
2509 window.event = windowEvent;
2510 }
2511
2512 func.apply(context, funcArgs);
2513 didError = false;
2514 }
2515
2516 // Create a global error event handler. We use this to capture the value
2517 // that was thrown. It's possible that this error handler will fire more
2518 // than once; for example, if non-React code also calls `dispatchEvent`
2519 // and a handler for that event throws. We should be resilient to most of
2520 // those cases. Even if our error event handler fires more than once, the
2521 // last error event is always used. If the callback actually does error,
2522 // we know that the last error event is the correct one, because it's not
2523 // possible for anything else to have happened in between our callback
2524 // erroring and the code that follows the `dispatchEvent` call below. If
2525 // the callback doesn't error, but the error event was fired, we know to
2526 // ignore it because `didError` will be false, as described above.
2527 var error = void 0;
2528 // Use this to track whether the error event is ever called.
2529 var didSetError = false;
2530 var isCrossOriginError = false;
2531
2532 function handleWindowError(event) {
2533 error = event.error;
2534 didSetError = true;
2535 if (error === null && event.colno === 0 && event.lineno === 0) {
2536 isCrossOriginError = true;
2537 }
2538 if (event.defaultPrevented) {
2539 // Some other error handler has prevented default.
2540 // Browsers silence the error report if this happens.
2541 // We'll remember this to later decide whether to log it or not.
2542 if (error != null && typeof error === 'object') {
2543 try {
2544 error._suppressLogging = true;
2545 } catch (inner) {
2546 // Ignore.
2547 }
2548 }
2549 }
2550 }
2551
2552 // Create a fake event type.
2553 var evtType = 'react-' + (name ? name : 'invokeguardedcallback');
2554
2555 // Attach our event handlers
2556 window.addEventListener('error', handleWindowError);
2557 fakeNode.addEventListener(evtType, callCallback, false);
2558
2559 // Synchronously dispatch our fake event. If the user-provided function
2560 // errors, it will trigger our global error handler.
2561 evt.initEvent(evtType, false, false);
2562 fakeNode.dispatchEvent(evt);
2563
2564 if (windowEventDescriptor) {
2565 Object.defineProperty(window, 'event', windowEventDescriptor);
2566 }
2567
2568 if (didError) {
2569 if (!didSetError) {
2570 // The callback errored, but the error event never fired.
2571 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.');
2572 } else if (isCrossOriginError) {
2573 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.');
2574 }
2575 this.onError(error);
2576 }
2577
2578 // Remove our event listeners
2579 window.removeEventListener('error', handleWindowError);
2580 };
2581
2582 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
2583 }
2584}
2585
2586var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
2587
2588// Used by Fiber to simulate a try-catch.
2589var hasError = false;
2590var caughtError = null;
2591
2592var reporter = {
2593 onError: function (error) {
2594 hasError = true;
2595 caughtError = error;
2596 }
2597};
2598
2599/**
2600 * Call a function while guarding against errors that happens within it.
2601 * Returns an error if it throws, otherwise null.
2602 *
2603 * In production, this is implemented using a try-catch. The reason we don't
2604 * use a try-catch directly is so that we can swap out a different
2605 * implementation in DEV mode.
2606 *
2607 * @param {String} name of the guard to use for logging or debugging
2608 * @param {Function} func The function to invoke
2609 * @param {*} context The context to use when calling the function
2610 * @param {...*} args Arguments for function
2611 */
2612function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
2613 hasError = false;
2614 caughtError = null;
2615 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
2616}
2617
2618/**
2619 * Same as invokeGuardedCallback, but instead of returning an error, it stores
2620 * it in a global so it can be rethrown by `rethrowCaughtError` later.
2621 * TODO: See if caughtError and rethrowError can be unified.
2622 *
2623 * @param {String} name of the guard to use for logging or debugging
2624 * @param {Function} func The function to invoke
2625 * @param {*} context The context to use when calling the function
2626 * @param {...*} args Arguments for function
2627 */
2628
2629
2630/**
2631 * During execution of guarded functions we will capture the first error which
2632 * we will rethrow to be handled by the top level error handler.
2633 */
2634
2635
2636function hasCaughtError() {
2637 return hasError;
2638}
2639
2640function clearCaughtError() {
2641 if (hasError) {
2642 var error = caughtError;
2643 hasError = false;
2644 caughtError = null;
2645 return error;
2646 } else {
2647 invariant(false, 'clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.');
2648 }
2649}
2650
2651/**
2652 * Forked from fbjs/warning:
2653 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2654 *
2655 * Only change is we use console.warn instead of console.error,
2656 * and do nothing when 'console' is not supported.
2657 * This really simplifies the code.
2658 * ---
2659 * Similar to invariant but only logs a warning if the condition is not met.
2660 * This can be used to log issues in development environments in critical
2661 * paths. Removing the logging code for production environments will keep the
2662 * same logic and follow the same code paths.
2663 */
2664
2665var lowPriorityWarning = function () {};
2666
2667{
2668 var printWarning$1 = function (format) {
2669 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2670 args[_key - 1] = arguments[_key];
2671 }
2672
2673 var argIndex = 0;
2674 var message = 'Warning: ' + format.replace(/%s/g, function () {
2675 return args[argIndex++];
2676 });
2677 if (typeof console !== 'undefined') {
2678 console.warn(message);
2679 }
2680 try {
2681 // --- Welcome to debugging React ---
2682 // This error was thrown as a convenience so that you can use this stack
2683 // to find the callsite that caused this warning to fire.
2684 throw new Error(message);
2685 } catch (x) {}
2686 };
2687
2688 lowPriorityWarning = function (condition, format) {
2689 if (format === undefined) {
2690 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
2691 }
2692 if (!condition) {
2693 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2694 args[_key2 - 2] = arguments[_key2];
2695 }
2696
2697 printWarning$1.apply(undefined, [format].concat(args));
2698 }
2699 };
2700}
2701
2702var lowPriorityWarning$1 = lowPriorityWarning;
2703
2704var ReactStrictModeWarnings = {
2705 discardPendingWarnings: function () {},
2706 flushPendingDeprecationWarnings: function () {},
2707 flushPendingUnsafeLifecycleWarnings: function () {},
2708 recordDeprecationWarnings: function (fiber, instance) {},
2709 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2710 recordLegacyContextWarning: function (fiber, instance) {},
2711 flushLegacyContextWarning: function () {}
2712};
2713
2714{
2715 var LIFECYCLE_SUGGESTIONS = {
2716 UNSAFE_componentWillMount: 'componentDidMount',
2717 UNSAFE_componentWillReceiveProps: 'static getDerivedStateFromProps',
2718 UNSAFE_componentWillUpdate: 'componentDidUpdate'
2719 };
2720
2721 var pendingComponentWillMountWarnings = [];
2722 var pendingComponentWillReceivePropsWarnings = [];
2723 var pendingComponentWillUpdateWarnings = [];
2724 var pendingUnsafeLifecycleWarnings = new Map();
2725 var pendingLegacyContextWarning = new Map();
2726
2727 // Tracks components we have already warned about.
2728 var didWarnAboutDeprecatedLifecycles = new Set();
2729 var didWarnAboutUnsafeLifecycles = new Set();
2730 var didWarnAboutLegacyContext = new Set();
2731
2732 var setToSortedString = function (set) {
2733 var array = [];
2734 set.forEach(function (value) {
2735 array.push(value);
2736 });
2737 return array.sort().join(', ');
2738 };
2739
2740 ReactStrictModeWarnings.discardPendingWarnings = function () {
2741 pendingComponentWillMountWarnings = [];
2742 pendingComponentWillReceivePropsWarnings = [];
2743 pendingComponentWillUpdateWarnings = [];
2744 pendingUnsafeLifecycleWarnings = new Map();
2745 pendingLegacyContextWarning = new Map();
2746 };
2747
2748 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2749 pendingUnsafeLifecycleWarnings.forEach(function (lifecycleWarningsMap, strictRoot) {
2750 var lifecyclesWarningMessages = [];
2751
2752 Object.keys(lifecycleWarningsMap).forEach(function (lifecycle) {
2753 var lifecycleWarnings = lifecycleWarningsMap[lifecycle];
2754 if (lifecycleWarnings.length > 0) {
2755 var componentNames = new Set();
2756 lifecycleWarnings.forEach(function (fiber) {
2757 componentNames.add(getComponentName(fiber.type) || 'Component');
2758 didWarnAboutUnsafeLifecycles.add(fiber.type);
2759 });
2760
2761 var formatted = lifecycle.replace('UNSAFE_', '');
2762 var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle];
2763 var sortedComponentNames = setToSortedString(componentNames);
2764
2765 lifecyclesWarningMessages.push(formatted + ': Please update the following components to use ' + (suggestion + ' instead: ' + sortedComponentNames));
2766 }
2767 });
2768
2769 if (lifecyclesWarningMessages.length > 0) {
2770 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2771
2772 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'));
2773 }
2774 });
2775
2776 pendingUnsafeLifecycleWarnings = new Map();
2777 };
2778
2779 var findStrictRoot = function (fiber) {
2780 var maybeStrictRoot = null;
2781
2782 var node = fiber;
2783 while (node !== null) {
2784 if (node.mode & StrictMode) {
2785 maybeStrictRoot = node;
2786 }
2787 node = node.return;
2788 }
2789
2790 return maybeStrictRoot;
2791 };
2792
2793 ReactStrictModeWarnings.flushPendingDeprecationWarnings = function () {
2794 if (pendingComponentWillMountWarnings.length > 0) {
2795 var uniqueNames = new Set();
2796 pendingComponentWillMountWarnings.forEach(function (fiber) {
2797 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2798 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2799 });
2800
2801 var sortedNames = setToSortedString(uniqueNames);
2802
2803 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);
2804
2805 pendingComponentWillMountWarnings = [];
2806 }
2807
2808 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2809 var _uniqueNames = new Set();
2810 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2811 _uniqueNames.add(getComponentName(fiber.type) || 'Component');
2812 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2813 });
2814
2815 var _sortedNames = setToSortedString(_uniqueNames);
2816
2817 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);
2818
2819 pendingComponentWillReceivePropsWarnings = [];
2820 }
2821
2822 if (pendingComponentWillUpdateWarnings.length > 0) {
2823 var _uniqueNames2 = new Set();
2824 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2825 _uniqueNames2.add(getComponentName(fiber.type) || 'Component');
2826 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2827 });
2828
2829 var _sortedNames2 = setToSortedString(_uniqueNames2);
2830
2831 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);
2832
2833 pendingComponentWillUpdateWarnings = [];
2834 }
2835 };
2836
2837 ReactStrictModeWarnings.recordDeprecationWarnings = function (fiber, instance) {
2838 // Dedup strategy: Warn once per component.
2839 if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) {
2840 return;
2841 }
2842
2843 // Don't warn about react-lifecycles-compat polyfilled components.
2844 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
2845 pendingComponentWillMountWarnings.push(fiber);
2846 }
2847 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2848 pendingComponentWillReceivePropsWarnings.push(fiber);
2849 }
2850 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2851 pendingComponentWillUpdateWarnings.push(fiber);
2852 }
2853 };
2854
2855 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2856 var strictRoot = findStrictRoot(fiber);
2857 if (strictRoot === null) {
2858 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.');
2859 return;
2860 }
2861
2862 // Dedup strategy: Warn once per component.
2863 // This is difficult to track any other way since component names
2864 // are often vague and are likely to collide between 3rd party libraries.
2865 // An expand property is probably okay to use here since it's DEV-only,
2866 // and will only be set in the event of serious warnings.
2867 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2868 return;
2869 }
2870
2871 var warningsForRoot = void 0;
2872 if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) {
2873 warningsForRoot = {
2874 UNSAFE_componentWillMount: [],
2875 UNSAFE_componentWillReceiveProps: [],
2876 UNSAFE_componentWillUpdate: []
2877 };
2878
2879 pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot);
2880 } else {
2881 warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot);
2882 }
2883
2884 var unsafeLifecycles = [];
2885 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillMount === 'function') {
2886 unsafeLifecycles.push('UNSAFE_componentWillMount');
2887 }
2888 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2889 unsafeLifecycles.push('UNSAFE_componentWillReceiveProps');
2890 }
2891 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillUpdate === 'function') {
2892 unsafeLifecycles.push('UNSAFE_componentWillUpdate');
2893 }
2894
2895 if (unsafeLifecycles.length > 0) {
2896 unsafeLifecycles.forEach(function (lifecycle) {
2897 warningsForRoot[lifecycle].push(fiber);
2898 });
2899 }
2900 };
2901
2902 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2903 var strictRoot = findStrictRoot(fiber);
2904 if (strictRoot === null) {
2905 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.');
2906 return;
2907 }
2908
2909 // Dedup strategy: Warn once per component.
2910 if (didWarnAboutLegacyContext.has(fiber.type)) {
2911 return;
2912 }
2913
2914 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2915
2916 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2917 if (warningsForRoot === undefined) {
2918 warningsForRoot = [];
2919 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2920 }
2921 warningsForRoot.push(fiber);
2922 }
2923 };
2924
2925 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2926 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2927 var uniqueNames = new Set();
2928 fiberArray.forEach(function (fiber) {
2929 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2930 didWarnAboutLegacyContext.add(fiber.type);
2931 });
2932
2933 var sortedNames = setToSortedString(uniqueNames);
2934 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2935
2936 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);
2937 });
2938 };
2939}
2940
2941// This lets us hook into Fiber to debug what it's doing.
2942// See https://github.com/facebook/react/pull/8033.
2943// This is not part of the public API, not even for React DevTools.
2944// You may only inject a debugTool if you work on React Fiber itself.
2945var ReactFiberInstrumentation = {
2946 debugTool: null
2947};
2948
2949var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
2950
2951// TODO: Offscreen updates should never suspend. However, a promise that
2952// suspended inside an offscreen subtree should be able to ping at the priority
2953// of the outer render.
2954
2955function markPendingPriorityLevel(root, expirationTime) {
2956 // If there's a gap between completing a failed root and retrying it,
2957 // additional updates may be scheduled. Clear `didError`, in case the update
2958 // is sufficient to fix the error.
2959 root.didError = false;
2960
2961 // Update the latest and earliest pending times
2962 var earliestPendingTime = root.earliestPendingTime;
2963 if (earliestPendingTime === NoWork) {
2964 // No other pending updates.
2965 root.earliestPendingTime = root.latestPendingTime = expirationTime;
2966 } else {
2967 if (earliestPendingTime < expirationTime) {
2968 // This is the earliest pending update.
2969 root.earliestPendingTime = expirationTime;
2970 } else {
2971 var latestPendingTime = root.latestPendingTime;
2972 if (latestPendingTime > expirationTime) {
2973 // This is the latest pending update
2974 root.latestPendingTime = expirationTime;
2975 }
2976 }
2977 }
2978 findNextExpirationTimeToWorkOn(expirationTime, root);
2979}
2980
2981function markCommittedPriorityLevels(root, earliestRemainingTime) {
2982 root.didError = false;
2983
2984 if (earliestRemainingTime === NoWork) {
2985 // Fast path. There's no remaining work. Clear everything.
2986 root.earliestPendingTime = NoWork;
2987 root.latestPendingTime = NoWork;
2988 root.earliestSuspendedTime = NoWork;
2989 root.latestSuspendedTime = NoWork;
2990 root.latestPingedTime = NoWork;
2991 findNextExpirationTimeToWorkOn(NoWork, root);
2992 return;
2993 }
2994
2995 if (earliestRemainingTime < root.latestPingedTime) {
2996 root.latestPingedTime = NoWork;
2997 }
2998
2999 // Let's see if the previous latest known pending level was just flushed.
3000 var latestPendingTime = root.latestPendingTime;
3001 if (latestPendingTime !== NoWork) {
3002 if (latestPendingTime > earliestRemainingTime) {
3003 // We've flushed all the known pending levels.
3004 root.earliestPendingTime = root.latestPendingTime = NoWork;
3005 } else {
3006 var earliestPendingTime = root.earliestPendingTime;
3007 if (earliestPendingTime > earliestRemainingTime) {
3008 // We've flushed the earliest known pending level. Set this to the
3009 // latest pending time.
3010 root.earliestPendingTime = root.latestPendingTime;
3011 }
3012 }
3013 }
3014
3015 // Now let's handle the earliest remaining level in the whole tree. We need to
3016 // decide whether to treat it as a pending level or as suspended. Check
3017 // it falls within the range of known suspended levels.
3018
3019 var earliestSuspendedTime = root.earliestSuspendedTime;
3020 if (earliestSuspendedTime === NoWork) {
3021 // There's no suspended work. Treat the earliest remaining level as a
3022 // pending level.
3023 markPendingPriorityLevel(root, earliestRemainingTime);
3024 findNextExpirationTimeToWorkOn(NoWork, root);
3025 return;
3026 }
3027
3028 var latestSuspendedTime = root.latestSuspendedTime;
3029 if (earliestRemainingTime < latestSuspendedTime) {
3030 // The earliest remaining level is later than all the suspended work. That
3031 // means we've flushed all the suspended work.
3032 root.earliestSuspendedTime = NoWork;
3033 root.latestSuspendedTime = NoWork;
3034 root.latestPingedTime = NoWork;
3035
3036 // There's no suspended work. Treat the earliest remaining level as a
3037 // pending level.
3038 markPendingPriorityLevel(root, earliestRemainingTime);
3039 findNextExpirationTimeToWorkOn(NoWork, root);
3040 return;
3041 }
3042
3043 if (earliestRemainingTime > earliestSuspendedTime) {
3044 // The earliest remaining time is earlier than all the suspended work.
3045 // Treat it as a pending update.
3046 markPendingPriorityLevel(root, earliestRemainingTime);
3047 findNextExpirationTimeToWorkOn(NoWork, root);
3048 return;
3049 }
3050
3051 // The earliest remaining time falls within the range of known suspended
3052 // levels. We should treat this as suspended work.
3053 findNextExpirationTimeToWorkOn(NoWork, root);
3054}
3055
3056function hasLowerPriorityWork(root, erroredExpirationTime) {
3057 var latestPendingTime = root.latestPendingTime;
3058 var latestSuspendedTime = root.latestSuspendedTime;
3059 var latestPingedTime = root.latestPingedTime;
3060 return latestPendingTime !== NoWork && latestPendingTime < erroredExpirationTime || latestSuspendedTime !== NoWork && latestSuspendedTime < erroredExpirationTime || latestPingedTime !== NoWork && latestPingedTime < erroredExpirationTime;
3061}
3062
3063function isPriorityLevelSuspended(root, expirationTime) {
3064 var earliestSuspendedTime = root.earliestSuspendedTime;
3065 var latestSuspendedTime = root.latestSuspendedTime;
3066 return earliestSuspendedTime !== NoWork && expirationTime <= earliestSuspendedTime && expirationTime >= latestSuspendedTime;
3067}
3068
3069function markSuspendedPriorityLevel(root, suspendedTime) {
3070 root.didError = false;
3071 clearPing(root, suspendedTime);
3072
3073 // First, check the known pending levels and update them if needed.
3074 var earliestPendingTime = root.earliestPendingTime;
3075 var latestPendingTime = root.latestPendingTime;
3076 if (earliestPendingTime === suspendedTime) {
3077 if (latestPendingTime === suspendedTime) {
3078 // Both known pending levels were suspended. Clear them.
3079 root.earliestPendingTime = root.latestPendingTime = NoWork;
3080 } else {
3081 // The earliest pending level was suspended. Clear by setting it to the
3082 // latest pending level.
3083 root.earliestPendingTime = latestPendingTime;
3084 }
3085 } else if (latestPendingTime === suspendedTime) {
3086 // The latest pending level was suspended. Clear by setting it to the
3087 // latest pending level.
3088 root.latestPendingTime = earliestPendingTime;
3089 }
3090
3091 // Finally, update the known suspended levels.
3092 var earliestSuspendedTime = root.earliestSuspendedTime;
3093 var latestSuspendedTime = root.latestSuspendedTime;
3094 if (earliestSuspendedTime === NoWork) {
3095 // No other suspended levels.
3096 root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime;
3097 } else {
3098 if (earliestSuspendedTime < suspendedTime) {
3099 // This is the earliest suspended level.
3100 root.earliestSuspendedTime = suspendedTime;
3101 } else if (latestSuspendedTime > suspendedTime) {
3102 // This is the latest suspended level
3103 root.latestSuspendedTime = suspendedTime;
3104 }
3105 }
3106
3107 findNextExpirationTimeToWorkOn(suspendedTime, root);
3108}
3109
3110function markPingedPriorityLevel(root, pingedTime) {
3111 root.didError = false;
3112
3113 // TODO: When we add back resuming, we need to ensure the progressed work
3114 // is thrown out and not reused during the restarted render. One way to
3115 // invalidate the progressed work is to restart at expirationTime + 1.
3116 var latestPingedTime = root.latestPingedTime;
3117 if (latestPingedTime === NoWork || latestPingedTime > pingedTime) {
3118 root.latestPingedTime = pingedTime;
3119 }
3120 findNextExpirationTimeToWorkOn(pingedTime, root);
3121}
3122
3123function clearPing(root, completedTime) {
3124 var latestPingedTime = root.latestPingedTime;
3125 if (latestPingedTime >= completedTime) {
3126 root.latestPingedTime = NoWork;
3127 }
3128}
3129
3130function findEarliestOutstandingPriorityLevel(root, renderExpirationTime) {
3131 var earliestExpirationTime = renderExpirationTime;
3132
3133 var earliestPendingTime = root.earliestPendingTime;
3134 var earliestSuspendedTime = root.earliestSuspendedTime;
3135 if (earliestPendingTime > earliestExpirationTime) {
3136 earliestExpirationTime = earliestPendingTime;
3137 }
3138 if (earliestSuspendedTime > earliestExpirationTime) {
3139 earliestExpirationTime = earliestSuspendedTime;
3140 }
3141 return earliestExpirationTime;
3142}
3143
3144function didExpireAtExpirationTime(root, currentTime) {
3145 var expirationTime = root.expirationTime;
3146 if (expirationTime !== NoWork && currentTime <= expirationTime) {
3147 // The root has expired. Flush all work up to the current time.
3148 root.nextExpirationTimeToWorkOn = currentTime;
3149 }
3150}
3151
3152function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
3153 var earliestSuspendedTime = root.earliestSuspendedTime;
3154 var latestSuspendedTime = root.latestSuspendedTime;
3155 var earliestPendingTime = root.earliestPendingTime;
3156 var latestPingedTime = root.latestPingedTime;
3157
3158 // Work on the earliest pending time. Failing that, work on the latest
3159 // pinged time.
3160 var nextExpirationTimeToWorkOn = earliestPendingTime !== NoWork ? earliestPendingTime : latestPingedTime;
3161
3162 // If there is no pending or pinged work, check if there's suspended work
3163 // that's lower priority than what we just completed.
3164 if (nextExpirationTimeToWorkOn === NoWork && (completedExpirationTime === NoWork || latestSuspendedTime < completedExpirationTime)) {
3165 // The lowest priority suspended work is the work most likely to be
3166 // committed next. Let's start rendering it again, so that if it times out,
3167 // it's ready to commit.
3168 nextExpirationTimeToWorkOn = latestSuspendedTime;
3169 }
3170
3171 var expirationTime = nextExpirationTimeToWorkOn;
3172 if (expirationTime !== NoWork && earliestSuspendedTime > expirationTime) {
3173 // Expire using the earliest known expiration time.
3174 expirationTime = earliestSuspendedTime;
3175 }
3176
3177 root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn;
3178 root.expirationTime = expirationTime;
3179}
3180
3181/**
3182 * inlined Object.is polyfill to avoid requiring consumers ship their own
3183 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3184 */
3185function is(x, y) {
3186 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
3187 ;
3188}
3189
3190var hasOwnProperty = Object.prototype.hasOwnProperty;
3191
3192/**
3193 * Performs equality by iterating through keys on an object and returning false
3194 * when any key has values which are not strictly equal between the arguments.
3195 * Returns true when the values of all keys are strictly equal.
3196 */
3197function shallowEqual(objA, objB) {
3198 if (is(objA, objB)) {
3199 return true;
3200 }
3201
3202 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
3203 return false;
3204 }
3205
3206 var keysA = Object.keys(objA);
3207 var keysB = Object.keys(objB);
3208
3209 if (keysA.length !== keysB.length) {
3210 return false;
3211 }
3212
3213 // Test for A's keys different from B.
3214 for (var i = 0; i < keysA.length; i++) {
3215 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
3216 return false;
3217 }
3218 }
3219
3220 return true;
3221}
3222
3223function resolveDefaultProps(Component, baseProps) {
3224 if (Component && Component.defaultProps) {
3225 // Resolve default props. Taken from ReactElement
3226 var props = _assign({}, baseProps);
3227 var defaultProps = Component.defaultProps;
3228 for (var propName in defaultProps) {
3229 if (props[propName] === undefined) {
3230 props[propName] = defaultProps[propName];
3231 }
3232 }
3233 return props;
3234 }
3235 return baseProps;
3236}
3237
3238function readLazyComponentType(lazyComponent) {
3239 var status = lazyComponent._status;
3240 var result = lazyComponent._result;
3241 switch (status) {
3242 case Resolved:
3243 {
3244 var Component = result;
3245 return Component;
3246 }
3247 case Rejected:
3248 {
3249 var error = result;
3250 throw error;
3251 }
3252 case Pending:
3253 {
3254 var thenable = result;
3255 throw thenable;
3256 }
3257 default:
3258 {
3259 lazyComponent._status = Pending;
3260 var ctor = lazyComponent._ctor;
3261 var _thenable = ctor();
3262 _thenable.then(function (moduleObject) {
3263 if (lazyComponent._status === Pending) {
3264 var defaultExport = moduleObject.default;
3265 {
3266 if (defaultExport === undefined) {
3267 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);
3268 }
3269 }
3270 lazyComponent._status = Resolved;
3271 lazyComponent._result = defaultExport;
3272 }
3273 }, function (error) {
3274 if (lazyComponent._status === Pending) {
3275 lazyComponent._status = Rejected;
3276 lazyComponent._result = error;
3277 }
3278 });
3279 // Handle synchronous thenables.
3280 switch (lazyComponent._status) {
3281 case Resolved:
3282 return lazyComponent._result;
3283 case Rejected:
3284 throw lazyComponent._result;
3285 }
3286 lazyComponent._result = _thenable;
3287 throw _thenable;
3288 }
3289 }
3290}
3291
3292var fakeInternalInstance = {};
3293var isArray$1 = Array.isArray;
3294
3295// React.Component uses a shared frozen object by default.
3296// We'll use it to determine whether we need to initialize legacy refs.
3297var emptyRefsObject = new React.Component().refs;
3298
3299var didWarnAboutStateAssignmentForComponent = void 0;
3300var didWarnAboutUninitializedState = void 0;
3301var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0;
3302var didWarnAboutLegacyLifecyclesAndDerivedState = void 0;
3303var didWarnAboutUndefinedDerivedState = void 0;
3304var warnOnUndefinedDerivedState = void 0;
3305var warnOnInvalidCallback = void 0;
3306var didWarnAboutDirectlyAssigningPropsToState = void 0;
3307var didWarnAboutContextTypeAndContextTypes = void 0;
3308var didWarnAboutInvalidateContextType = void 0;
3309
3310{
3311 didWarnAboutStateAssignmentForComponent = new Set();
3312 didWarnAboutUninitializedState = new Set();
3313 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3314 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3315 didWarnAboutDirectlyAssigningPropsToState = new Set();
3316 didWarnAboutUndefinedDerivedState = new Set();
3317 didWarnAboutContextTypeAndContextTypes = new Set();
3318 didWarnAboutInvalidateContextType = new Set();
3319
3320 var didWarnOnInvalidCallback = new Set();
3321
3322 warnOnInvalidCallback = function (callback, callerName) {
3323 if (callback === null || typeof callback === 'function') {
3324 return;
3325 }
3326 var key = callerName + '_' + callback;
3327 if (!didWarnOnInvalidCallback.has(key)) {
3328 didWarnOnInvalidCallback.add(key);
3329 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
3330 }
3331 };
3332
3333 warnOnUndefinedDerivedState = function (type, partialState) {
3334 if (partialState === undefined) {
3335 var componentName = getComponentName(type) || 'Component';
3336 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
3337 didWarnAboutUndefinedDerivedState.add(componentName);
3338 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
3339 }
3340 }
3341 };
3342
3343 // This is so gross but it's at least non-critical and can be removed if
3344 // it causes problems. This is meant to give a nicer error message for
3345 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
3346 // ...)) which otherwise throws a "_processChildContext is not a function"
3347 // exception.
3348 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
3349 enumerable: false,
3350 value: function () {
3351 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).');
3352 }
3353 });
3354 Object.freeze(fakeInternalInstance);
3355}
3356
3357function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
3358 var prevState = workInProgress.memoizedState;
3359
3360 {
3361 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3362 // Invoke the function an extra time to help detect side-effects.
3363 getDerivedStateFromProps(nextProps, prevState);
3364 }
3365 }
3366
3367 var partialState = getDerivedStateFromProps(nextProps, prevState);
3368
3369 {
3370 warnOnUndefinedDerivedState(ctor, partialState);
3371 }
3372 // Merge the partial state and the previous state.
3373 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
3374 workInProgress.memoizedState = memoizedState;
3375
3376 // Once the update queue is empty, persist the derived state onto the
3377 // base state.
3378 var updateQueue = workInProgress.updateQueue;
3379 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
3380 updateQueue.baseState = memoizedState;
3381 }
3382}
3383
3384var classComponentUpdater = {
3385 isMounted: isMounted,
3386 enqueueSetState: function (inst, payload, callback) {
3387 var fiber = get(inst);
3388 var currentTime = requestCurrentTime();
3389 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3390
3391 var update = createUpdate(expirationTime);
3392 update.payload = payload;
3393 if (callback !== undefined && callback !== null) {
3394 {
3395 warnOnInvalidCallback(callback, 'setState');
3396 }
3397 update.callback = callback;
3398 }
3399
3400 flushPassiveEffects$1();
3401 enqueueUpdate(fiber, update);
3402 scheduleWork(fiber, expirationTime);
3403 },
3404 enqueueReplaceState: function (inst, payload, callback) {
3405 var fiber = get(inst);
3406 var currentTime = requestCurrentTime();
3407 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3408
3409 var update = createUpdate(expirationTime);
3410 update.tag = ReplaceState;
3411 update.payload = payload;
3412
3413 if (callback !== undefined && callback !== null) {
3414 {
3415 warnOnInvalidCallback(callback, 'replaceState');
3416 }
3417 update.callback = callback;
3418 }
3419
3420 flushPassiveEffects$1();
3421 enqueueUpdate(fiber, update);
3422 scheduleWork(fiber, expirationTime);
3423 },
3424 enqueueForceUpdate: function (inst, callback) {
3425 var fiber = get(inst);
3426 var currentTime = requestCurrentTime();
3427 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3428
3429 var update = createUpdate(expirationTime);
3430 update.tag = ForceUpdate;
3431
3432 if (callback !== undefined && callback !== null) {
3433 {
3434 warnOnInvalidCallback(callback, 'forceUpdate');
3435 }
3436 update.callback = callback;
3437 }
3438
3439 flushPassiveEffects$1();
3440 enqueueUpdate(fiber, update);
3441 scheduleWork(fiber, expirationTime);
3442 }
3443};
3444
3445function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
3446 var instance = workInProgress.stateNode;
3447 if (typeof instance.shouldComponentUpdate === 'function') {
3448 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
3449 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
3450 stopPhaseTimer();
3451
3452 {
3453 !(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;
3454 }
3455
3456 return shouldUpdate;
3457 }
3458
3459 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
3460 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
3461 }
3462
3463 return true;
3464}
3465
3466function checkClassInstance(workInProgress, ctor, newProps) {
3467 var instance = workInProgress.stateNode;
3468 {
3469 var name = getComponentName(ctor) || 'Component';
3470 var renderPresent = instance.render;
3471
3472 if (!renderPresent) {
3473 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
3474 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
3475 } else {
3476 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
3477 }
3478 }
3479
3480 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
3481 !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;
3482 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
3483 !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;
3484 var noInstancePropTypes = !instance.propTypes;
3485 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
3486 var noInstanceContextType = !instance.contextType;
3487 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
3488 var noInstanceContextTypes = !instance.contextTypes;
3489 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
3490
3491 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
3492 didWarnAboutContextTypeAndContextTypes.add(ctor);
3493 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
3494 }
3495
3496 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
3497 !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;
3498 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
3499 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');
3500 }
3501 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
3502 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
3503 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
3504 !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;
3505 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
3506 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
3507 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
3508 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
3509 var hasMutatedProps = instance.props !== newProps;
3510 !(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;
3511 var noInstanceDefaultProps = !instance.defaultProps;
3512 !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;
3513
3514 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
3515 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
3516 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
3517 }
3518
3519 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
3520 !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;
3521 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
3522 !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;
3523 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
3524 !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;
3525 var _state = instance.state;
3526 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
3527 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
3528 }
3529 if (typeof instance.getChildContext === 'function') {
3530 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
3531 }
3532 }
3533}
3534
3535function adoptClassInstance(workInProgress, instance) {
3536 instance.updater = classComponentUpdater;
3537 workInProgress.stateNode = instance;
3538 // The instance needs access to the fiber so that it can schedule updates
3539 set(instance, workInProgress);
3540 {
3541 instance._reactInternalInstance = fakeInternalInstance;
3542 }
3543}
3544
3545function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
3546 var isLegacyContextConsumer = false;
3547 var unmaskedContext = emptyContextObject;
3548 var context = null;
3549 var contextType = ctor.contextType;
3550 if (typeof contextType === 'object' && contextType !== null) {
3551 {
3552 if (contextType.$$typeof !== REACT_CONTEXT_TYPE && !didWarnAboutInvalidateContextType.has(ctor)) {
3553 didWarnAboutInvalidateContextType.add(ctor);
3554 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');
3555 }
3556 }
3557
3558 context = readContext(contextType);
3559 } else {
3560 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3561 var contextTypes = ctor.contextTypes;
3562 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
3563 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
3564 }
3565
3566 // Instantiate twice to help detect side-effects.
3567 {
3568 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3569 new ctor(props, context); // eslint-disable-line no-new
3570 }
3571 }
3572
3573 var instance = new ctor(props, context);
3574 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
3575 adoptClassInstance(workInProgress, instance);
3576
3577 {
3578 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
3579 var componentName = getComponentName(ctor) || 'Component';
3580 if (!didWarnAboutUninitializedState.has(componentName)) {
3581 didWarnAboutUninitializedState.add(componentName);
3582 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);
3583 }
3584 }
3585
3586 // If new component APIs are defined, "unsafe" lifecycles won't be called.
3587 // Warn about these lifecycles if they are present.
3588 // Don't warn about react-lifecycles-compat polyfilled methods though.
3589 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
3590 var foundWillMountName = null;
3591 var foundWillReceivePropsName = null;
3592 var foundWillUpdateName = null;
3593 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
3594 foundWillMountName = 'componentWillMount';
3595 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
3596 foundWillMountName = 'UNSAFE_componentWillMount';
3597 }
3598 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
3599 foundWillReceivePropsName = 'componentWillReceiveProps';
3600 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3601 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
3602 }
3603 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
3604 foundWillUpdateName = 'componentWillUpdate';
3605 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3606 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
3607 }
3608 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
3609 var _componentName = getComponentName(ctor) || 'Component';
3610 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
3611 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
3612 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
3613 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 : '');
3614 }
3615 }
3616 }
3617 }
3618
3619 // Cache unmasked context so we can avoid recreating masked context unless necessary.
3620 // ReactFiberContext usually updates this cache but can't for newly-created instances.
3621 if (isLegacyContextConsumer) {
3622 cacheContext(workInProgress, unmaskedContext, context);
3623 }
3624
3625 return instance;
3626}
3627
3628function callComponentWillMount(workInProgress, instance) {
3629 startPhaseTimer(workInProgress, 'componentWillMount');
3630 var oldState = instance.state;
3631
3632 if (typeof instance.componentWillMount === 'function') {
3633 instance.componentWillMount();
3634 }
3635 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3636 instance.UNSAFE_componentWillMount();
3637 }
3638
3639 stopPhaseTimer();
3640
3641 if (oldState !== instance.state) {
3642 {
3643 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');
3644 }
3645 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3646 }
3647}
3648
3649function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
3650 var oldState = instance.state;
3651 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
3652 if (typeof instance.componentWillReceiveProps === 'function') {
3653 instance.componentWillReceiveProps(newProps, nextContext);
3654 }
3655 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3656 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
3657 }
3658 stopPhaseTimer();
3659
3660 if (instance.state !== oldState) {
3661 {
3662 var componentName = getComponentName(workInProgress.type) || 'Component';
3663 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
3664 didWarnAboutStateAssignmentForComponent.add(componentName);
3665 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
3666 }
3667 }
3668 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3669 }
3670}
3671
3672// Invokes the mount life-cycles on a previously never rendered instance.
3673function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3674 {
3675 checkClassInstance(workInProgress, ctor, newProps);
3676 }
3677
3678 var instance = workInProgress.stateNode;
3679 instance.props = newProps;
3680 instance.state = workInProgress.memoizedState;
3681 instance.refs = emptyRefsObject;
3682
3683 var contextType = ctor.contextType;
3684 if (typeof contextType === 'object' && contextType !== null) {
3685 instance.context = readContext(contextType);
3686 } else {
3687 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3688 instance.context = getMaskedContext(workInProgress, unmaskedContext);
3689 }
3690
3691 {
3692 if (instance.state === newProps) {
3693 var componentName = getComponentName(ctor) || 'Component';
3694 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
3695 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
3696 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);
3697 }
3698 }
3699
3700 if (workInProgress.mode & StrictMode) {
3701 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
3702
3703 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
3704 }
3705
3706 if (warnAboutDeprecatedLifecycles) {
3707 ReactStrictModeWarnings.recordDeprecationWarnings(workInProgress, instance);
3708 }
3709 }
3710
3711 var updateQueue = workInProgress.updateQueue;
3712 if (updateQueue !== null) {
3713 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3714 instance.state = workInProgress.memoizedState;
3715 }
3716
3717 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3718 if (typeof getDerivedStateFromProps === 'function') {
3719 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3720 instance.state = workInProgress.memoizedState;
3721 }
3722
3723 // In order to support react-lifecycles-compat polyfilled components,
3724 // Unsafe lifecycles should not be invoked for components using the new APIs.
3725 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3726 callComponentWillMount(workInProgress, instance);
3727 // If we had additional state updates during this life-cycle, let's
3728 // process them now.
3729 updateQueue = workInProgress.updateQueue;
3730 if (updateQueue !== null) {
3731 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3732 instance.state = workInProgress.memoizedState;
3733 }
3734 }
3735
3736 if (typeof instance.componentDidMount === 'function') {
3737 workInProgress.effectTag |= Update;
3738 }
3739}
3740
3741function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3742 var instance = workInProgress.stateNode;
3743
3744 var oldProps = workInProgress.memoizedProps;
3745 instance.props = oldProps;
3746
3747 var oldContext = instance.context;
3748 var contextType = ctor.contextType;
3749 var nextContext = void 0;
3750 if (typeof contextType === 'object' && contextType !== null) {
3751 nextContext = readContext(contextType);
3752 } else {
3753 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3754 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
3755 }
3756
3757 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3758 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3759
3760 // Note: During these life-cycles, instance.props/instance.state are what
3761 // ever the previously attempted to render - not the "current". However,
3762 // during componentDidUpdate we pass the "current" props.
3763
3764 // In order to support react-lifecycles-compat polyfilled components,
3765 // Unsafe lifecycles should not be invoked for components using the new APIs.
3766 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3767 if (oldProps !== newProps || oldContext !== nextContext) {
3768 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3769 }
3770 }
3771
3772 resetHasForceUpdateBeforeProcessing();
3773
3774 var oldState = workInProgress.memoizedState;
3775 var newState = instance.state = oldState;
3776 var updateQueue = workInProgress.updateQueue;
3777 if (updateQueue !== null) {
3778 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3779 newState = workInProgress.memoizedState;
3780 }
3781 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3782 // If an update was already in progress, we should schedule an Update
3783 // effect even though we're bailing out, so that cWU/cDU are called.
3784 if (typeof instance.componentDidMount === 'function') {
3785 workInProgress.effectTag |= Update;
3786 }
3787 return false;
3788 }
3789
3790 if (typeof getDerivedStateFromProps === 'function') {
3791 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3792 newState = workInProgress.memoizedState;
3793 }
3794
3795 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3796
3797 if (shouldUpdate) {
3798 // In order to support react-lifecycles-compat polyfilled components,
3799 // Unsafe lifecycles should not be invoked for components using the new APIs.
3800 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3801 startPhaseTimer(workInProgress, 'componentWillMount');
3802 if (typeof instance.componentWillMount === 'function') {
3803 instance.componentWillMount();
3804 }
3805 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3806 instance.UNSAFE_componentWillMount();
3807 }
3808 stopPhaseTimer();
3809 }
3810 if (typeof instance.componentDidMount === 'function') {
3811 workInProgress.effectTag |= Update;
3812 }
3813 } else {
3814 // If an update was already in progress, we should schedule an Update
3815 // effect even though we're bailing out, so that cWU/cDU are called.
3816 if (typeof instance.componentDidMount === 'function') {
3817 workInProgress.effectTag |= Update;
3818 }
3819
3820 // If shouldComponentUpdate returned false, we should still update the
3821 // memoized state to indicate that this work can be reused.
3822 workInProgress.memoizedProps = newProps;
3823 workInProgress.memoizedState = newState;
3824 }
3825
3826 // Update the existing instance's state, props, and context pointers even
3827 // if shouldComponentUpdate returns false.
3828 instance.props = newProps;
3829 instance.state = newState;
3830 instance.context = nextContext;
3831
3832 return shouldUpdate;
3833}
3834
3835// Invokes the update life-cycles and returns false if it shouldn't rerender.
3836function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
3837 var instance = workInProgress.stateNode;
3838
3839 var oldProps = workInProgress.memoizedProps;
3840 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
3841
3842 var oldContext = instance.context;
3843 var contextType = ctor.contextType;
3844 var nextContext = void 0;
3845 if (typeof contextType === 'object' && contextType !== null) {
3846 nextContext = readContext(contextType);
3847 } else {
3848 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3849 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
3850 }
3851
3852 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3853 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3854
3855 // Note: During these life-cycles, instance.props/instance.state are what
3856 // ever the previously attempted to render - not the "current". However,
3857 // during componentDidUpdate we pass the "current" props.
3858
3859 // In order to support react-lifecycles-compat polyfilled components,
3860 // Unsafe lifecycles should not be invoked for components using the new APIs.
3861 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3862 if (oldProps !== newProps || oldContext !== nextContext) {
3863 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3864 }
3865 }
3866
3867 resetHasForceUpdateBeforeProcessing();
3868
3869 var oldState = workInProgress.memoizedState;
3870 var newState = instance.state = oldState;
3871 var updateQueue = workInProgress.updateQueue;
3872 if (updateQueue !== null) {
3873 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3874 newState = workInProgress.memoizedState;
3875 }
3876
3877 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3878 // If an update was already in progress, we should schedule an Update
3879 // effect even though we're bailing out, so that cWU/cDU are called.
3880 if (typeof instance.componentDidUpdate === 'function') {
3881 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3882 workInProgress.effectTag |= Update;
3883 }
3884 }
3885 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3886 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3887 workInProgress.effectTag |= Snapshot;
3888 }
3889 }
3890 return false;
3891 }
3892
3893 if (typeof getDerivedStateFromProps === 'function') {
3894 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3895 newState = workInProgress.memoizedState;
3896 }
3897
3898 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3899
3900 if (shouldUpdate) {
3901 // In order to support react-lifecycles-compat polyfilled components,
3902 // Unsafe lifecycles should not be invoked for components using the new APIs.
3903 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
3904 startPhaseTimer(workInProgress, 'componentWillUpdate');
3905 if (typeof instance.componentWillUpdate === 'function') {
3906 instance.componentWillUpdate(newProps, newState, nextContext);
3907 }
3908 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3909 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
3910 }
3911 stopPhaseTimer();
3912 }
3913 if (typeof instance.componentDidUpdate === 'function') {
3914 workInProgress.effectTag |= Update;
3915 }
3916 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3917 workInProgress.effectTag |= Snapshot;
3918 }
3919 } else {
3920 // If an update was already in progress, we should schedule an Update
3921 // effect even though we're bailing out, so that cWU/cDU are called.
3922 if (typeof instance.componentDidUpdate === 'function') {
3923 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3924 workInProgress.effectTag |= Update;
3925 }
3926 }
3927 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3928 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3929 workInProgress.effectTag |= Snapshot;
3930 }
3931 }
3932
3933 // If shouldComponentUpdate returned false, we should still update the
3934 // memoized props/state to indicate that this work can be reused.
3935 workInProgress.memoizedProps = newProps;
3936 workInProgress.memoizedState = newState;
3937 }
3938
3939 // Update the existing instance's state, props, and context pointers even
3940 // if shouldComponentUpdate returns false.
3941 instance.props = newProps;
3942 instance.state = newState;
3943 instance.context = nextContext;
3944
3945 return shouldUpdate;
3946}
3947
3948var didWarnAboutMaps = void 0;
3949var didWarnAboutGenerators = void 0;
3950var didWarnAboutStringRefInStrictMode = void 0;
3951var ownerHasKeyUseWarning = void 0;
3952var ownerHasFunctionTypeWarning = void 0;
3953var warnForMissingKey = function (child) {};
3954
3955{
3956 didWarnAboutMaps = false;
3957 didWarnAboutGenerators = false;
3958 didWarnAboutStringRefInStrictMode = {};
3959
3960 /**
3961 * Warn if there's no key explicitly set on dynamic arrays of children or
3962 * object keys are not valid. This allows us to keep track of children between
3963 * updates.
3964 */
3965 ownerHasKeyUseWarning = {};
3966 ownerHasFunctionTypeWarning = {};
3967
3968 warnForMissingKey = function (child) {
3969 if (child === null || typeof child !== 'object') {
3970 return;
3971 }
3972 if (!child._store || child._store.validated || child.key != null) {
3973 return;
3974 }
3975 !(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;
3976 child._store.validated = true;
3977
3978 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
3979 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
3980 return;
3981 }
3982 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
3983
3984 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
3985 };
3986}
3987
3988var isArray = Array.isArray;
3989
3990function coerceRef(returnFiber, current$$1, element) {
3991 var mixedRef = element.ref;
3992 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
3993 {
3994 if (returnFiber.mode & StrictMode) {
3995 var componentName = getComponentName(returnFiber.type) || 'Component';
3996 if (!didWarnAboutStringRefInStrictMode[componentName]) {
3997 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));
3998 didWarnAboutStringRefInStrictMode[componentName] = true;
3999 }
4000 }
4001 }
4002
4003 if (element._owner) {
4004 var owner = element._owner;
4005 var inst = void 0;
4006 if (owner) {
4007 var ownerFiber = owner;
4008 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Function components cannot have refs. Did you mean to use React.forwardRef()?') : void 0;
4009 inst = ownerFiber.stateNode;
4010 }
4011 !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;
4012 var stringRef = '' + mixedRef;
4013 // Check if previous string ref matches new string ref
4014 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
4015 return current$$1.ref;
4016 }
4017 var ref = function (value) {
4018 var refs = inst.refs;
4019 if (refs === emptyRefsObject) {
4020 // This is a lazy pooled frozen object, so we need to initialize.
4021 refs = inst.refs = {};
4022 }
4023 if (value === null) {
4024 delete refs[stringRef];
4025 } else {
4026 refs[stringRef] = value;
4027 }
4028 };
4029 ref._stringRef = stringRef;
4030 return ref;
4031 } else {
4032 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.') : void 0;
4033 !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;
4034 }
4035 }
4036 return mixedRef;
4037}
4038
4039function throwOnInvalidObjectType(returnFiber, newChild) {
4040 if (returnFiber.type !== 'textarea') {
4041 var addendum = '';
4042 {
4043 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
4044 }
4045 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);
4046 }
4047}
4048
4049function warnOnFunctionType() {
4050 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();
4051
4052 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
4053 return;
4054 }
4055 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
4056
4057 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.');
4058}
4059
4060// This wrapper function exists because I expect to clone the code in each path
4061// to be able to optimize each path individually by branching early. This needs
4062// a compiler or we can do it manually. Helpers that don't need this branching
4063// live outside of this function.
4064function ChildReconciler(shouldTrackSideEffects) {
4065 function deleteChild(returnFiber, childToDelete) {
4066 if (!shouldTrackSideEffects) {
4067 // Noop.
4068 return;
4069 }
4070 // Deletions are added in reversed order so we add it to the front.
4071 // At this point, the return fiber's effect list is empty except for
4072 // deletions, so we can just append the deletion to the list. The remaining
4073 // effects aren't added until the complete phase. Once we implement
4074 // resuming, this may not be true.
4075 var last = returnFiber.lastEffect;
4076 if (last !== null) {
4077 last.nextEffect = childToDelete;
4078 returnFiber.lastEffect = childToDelete;
4079 } else {
4080 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
4081 }
4082 childToDelete.nextEffect = null;
4083 childToDelete.effectTag = Deletion;
4084 }
4085
4086 function deleteRemainingChildren(returnFiber, currentFirstChild) {
4087 if (!shouldTrackSideEffects) {
4088 // Noop.
4089 return null;
4090 }
4091
4092 // TODO: For the shouldClone case, this could be micro-optimized a bit by
4093 // assuming that after the first child we've already added everything.
4094 var childToDelete = currentFirstChild;
4095 while (childToDelete !== null) {
4096 deleteChild(returnFiber, childToDelete);
4097 childToDelete = childToDelete.sibling;
4098 }
4099 return null;
4100 }
4101
4102 function mapRemainingChildren(returnFiber, currentFirstChild) {
4103 // Add the remaining children to a temporary map so that we can find them by
4104 // keys quickly. Implicit (null) keys get added to this set with their index
4105 var existingChildren = new Map();
4106
4107 var existingChild = currentFirstChild;
4108 while (existingChild !== null) {
4109 if (existingChild.key !== null) {
4110 existingChildren.set(existingChild.key, existingChild);
4111 } else {
4112 existingChildren.set(existingChild.index, existingChild);
4113 }
4114 existingChild = existingChild.sibling;
4115 }
4116 return existingChildren;
4117 }
4118
4119 function useFiber(fiber, pendingProps, expirationTime) {
4120 // We currently set sibling to null and index to 0 here because it is easy
4121 // to forget to do before returning it. E.g. for the single child case.
4122 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4123 clone.index = 0;
4124 clone.sibling = null;
4125 return clone;
4126 }
4127
4128 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4129 newFiber.index = newIndex;
4130 if (!shouldTrackSideEffects) {
4131 // Noop.
4132 return lastPlacedIndex;
4133 }
4134 var current$$1 = newFiber.alternate;
4135 if (current$$1 !== null) {
4136 var oldIndex = current$$1.index;
4137 if (oldIndex < lastPlacedIndex) {
4138 // This is a move.
4139 newFiber.effectTag = Placement;
4140 return lastPlacedIndex;
4141 } else {
4142 // This item can stay in place.
4143 return oldIndex;
4144 }
4145 } else {
4146 // This is an insertion.
4147 newFiber.effectTag = Placement;
4148 return lastPlacedIndex;
4149 }
4150 }
4151
4152 function placeSingleChild(newFiber) {
4153 // This is simpler for the single child case. We only need to do a
4154 // placement for inserting new children.
4155 if (shouldTrackSideEffects && newFiber.alternate === null) {
4156 newFiber.effectTag = Placement;
4157 }
4158 return newFiber;
4159 }
4160
4161 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4162 if (current$$1 === null || current$$1.tag !== HostText) {
4163 // Insert
4164 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4165 created.return = returnFiber;
4166 return created;
4167 } else {
4168 // Update
4169 var existing = useFiber(current$$1, textContent, expirationTime);
4170 existing.return = returnFiber;
4171 return existing;
4172 }
4173 }
4174
4175 function updateElement(returnFiber, current$$1, element, expirationTime) {
4176 if (current$$1 !== null && current$$1.elementType === element.type) {
4177 // Move based on index
4178 var existing = useFiber(current$$1, element.props, expirationTime);
4179 existing.ref = coerceRef(returnFiber, current$$1, element);
4180 existing.return = returnFiber;
4181 {
4182 existing._debugSource = element._source;
4183 existing._debugOwner = element._owner;
4184 }
4185 return existing;
4186 } else {
4187 // Insert
4188 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
4189 created.ref = coerceRef(returnFiber, current$$1, element);
4190 created.return = returnFiber;
4191 return created;
4192 }
4193 }
4194
4195 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
4196 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
4197 // Insert
4198 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4199 created.return = returnFiber;
4200 return created;
4201 } else {
4202 // Update
4203 var existing = useFiber(current$$1, portal.children || [], expirationTime);
4204 existing.return = returnFiber;
4205 return existing;
4206 }
4207 }
4208
4209 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
4210 if (current$$1 === null || current$$1.tag !== Fragment) {
4211 // Insert
4212 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
4213 created.return = returnFiber;
4214 return created;
4215 } else {
4216 // Update
4217 var existing = useFiber(current$$1, fragment, expirationTime);
4218 existing.return = returnFiber;
4219 return existing;
4220 }
4221 }
4222
4223 function createChild(returnFiber, newChild, expirationTime) {
4224 if (typeof newChild === 'string' || typeof newChild === 'number') {
4225 // Text nodes don't have keys. If the previous node is implicitly keyed
4226 // we can continue to replace it without aborting even if it is not a text
4227 // node.
4228 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
4229 created.return = returnFiber;
4230 return created;
4231 }
4232
4233 if (typeof newChild === 'object' && newChild !== null) {
4234 switch (newChild.$$typeof) {
4235 case REACT_ELEMENT_TYPE:
4236 {
4237 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
4238 _created.ref = coerceRef(returnFiber, null, newChild);
4239 _created.return = returnFiber;
4240 return _created;
4241 }
4242 case REACT_PORTAL_TYPE:
4243 {
4244 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
4245 _created2.return = returnFiber;
4246 return _created2;
4247 }
4248 }
4249
4250 if (isArray(newChild) || getIteratorFn(newChild)) {
4251 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
4252 _created3.return = returnFiber;
4253 return _created3;
4254 }
4255
4256 throwOnInvalidObjectType(returnFiber, newChild);
4257 }
4258
4259 {
4260 if (typeof newChild === 'function') {
4261 warnOnFunctionType();
4262 }
4263 }
4264
4265 return null;
4266 }
4267
4268 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
4269 // Update the fiber if the keys match, otherwise return null.
4270
4271 var key = oldFiber !== null ? oldFiber.key : null;
4272
4273 if (typeof newChild === 'string' || typeof newChild === 'number') {
4274 // Text nodes don't have keys. If the previous node is implicitly keyed
4275 // we can continue to replace it without aborting even if it is not a text
4276 // node.
4277 if (key !== null) {
4278 return null;
4279 }
4280 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
4281 }
4282
4283 if (typeof newChild === 'object' && newChild !== null) {
4284 switch (newChild.$$typeof) {
4285 case REACT_ELEMENT_TYPE:
4286 {
4287 if (newChild.key === key) {
4288 if (newChild.type === REACT_FRAGMENT_TYPE) {
4289 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
4290 }
4291 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
4292 } else {
4293 return null;
4294 }
4295 }
4296 case REACT_PORTAL_TYPE:
4297 {
4298 if (newChild.key === key) {
4299 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
4300 } else {
4301 return null;
4302 }
4303 }
4304 }
4305
4306 if (isArray(newChild) || getIteratorFn(newChild)) {
4307 if (key !== null) {
4308 return null;
4309 }
4310
4311 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
4312 }
4313
4314 throwOnInvalidObjectType(returnFiber, newChild);
4315 }
4316
4317 {
4318 if (typeof newChild === 'function') {
4319 warnOnFunctionType();
4320 }
4321 }
4322
4323 return null;
4324 }
4325
4326 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
4327 if (typeof newChild === 'string' || typeof newChild === 'number') {
4328 // Text nodes don't have keys, so we neither have to check the old nor
4329 // new node for the key. If both are text nodes, they match.
4330 var matchedFiber = existingChildren.get(newIdx) || null;
4331 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
4332 }
4333
4334 if (typeof newChild === 'object' && newChild !== null) {
4335 switch (newChild.$$typeof) {
4336 case REACT_ELEMENT_TYPE:
4337 {
4338 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4339 if (newChild.type === REACT_FRAGMENT_TYPE) {
4340 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
4341 }
4342 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
4343 }
4344 case REACT_PORTAL_TYPE:
4345 {
4346 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4347 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
4348 }
4349 }
4350
4351 if (isArray(newChild) || getIteratorFn(newChild)) {
4352 var _matchedFiber3 = existingChildren.get(newIdx) || null;
4353 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
4354 }
4355
4356 throwOnInvalidObjectType(returnFiber, newChild);
4357 }
4358
4359 {
4360 if (typeof newChild === 'function') {
4361 warnOnFunctionType();
4362 }
4363 }
4364
4365 return null;
4366 }
4367
4368 /**
4369 * Warns if there is a duplicate or missing key
4370 */
4371 function warnOnInvalidKey(child, knownKeys) {
4372 {
4373 if (typeof child !== 'object' || child === null) {
4374 return knownKeys;
4375 }
4376 switch (child.$$typeof) {
4377 case REACT_ELEMENT_TYPE:
4378 case REACT_PORTAL_TYPE:
4379 warnForMissingKey(child);
4380 var key = child.key;
4381 if (typeof key !== 'string') {
4382 break;
4383 }
4384 if (knownKeys === null) {
4385 knownKeys = new Set();
4386 knownKeys.add(key);
4387 break;
4388 }
4389 if (!knownKeys.has(key)) {
4390 knownKeys.add(key);
4391 break;
4392 }
4393 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);
4394 break;
4395 default:
4396 break;
4397 }
4398 }
4399 return knownKeys;
4400 }
4401
4402 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
4403 // This algorithm can't optimize by searching from both ends since we
4404 // don't have backpointers on fibers. I'm trying to see how far we can get
4405 // with that model. If it ends up not being worth the tradeoffs, we can
4406 // add it later.
4407
4408 // Even with a two ended optimization, we'd want to optimize for the case
4409 // where there are few changes and brute force the comparison instead of
4410 // going for the Map. It'd like to explore hitting that path first in
4411 // forward-only mode and only go for the Map once we notice that we need
4412 // lots of look ahead. This doesn't handle reversal as well as two ended
4413 // search but that's unusual. Besides, for the two ended optimization to
4414 // work on Iterables, we'd need to copy the whole set.
4415
4416 // In this first iteration, we'll just live with hitting the bad case
4417 // (adding everything to a Map) in for every insert/move.
4418
4419 // If you change this code, also update reconcileChildrenIterator() which
4420 // uses the same algorithm.
4421
4422 {
4423 // First, validate keys.
4424 var knownKeys = null;
4425 for (var i = 0; i < newChildren.length; i++) {
4426 var child = newChildren[i];
4427 knownKeys = warnOnInvalidKey(child, knownKeys);
4428 }
4429 }
4430
4431 var resultingFirstChild = null;
4432 var previousNewFiber = null;
4433
4434 var oldFiber = currentFirstChild;
4435 var lastPlacedIndex = 0;
4436 var newIdx = 0;
4437 var nextOldFiber = null;
4438 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
4439 if (oldFiber.index > newIdx) {
4440 nextOldFiber = oldFiber;
4441 oldFiber = null;
4442 } else {
4443 nextOldFiber = oldFiber.sibling;
4444 }
4445 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
4446 if (newFiber === null) {
4447 // TODO: This breaks on empty slots like null children. That's
4448 // unfortunate because it triggers the slow path all the time. We need
4449 // a better way to communicate whether this was a miss or null,
4450 // boolean, undefined, etc.
4451 if (oldFiber === null) {
4452 oldFiber = nextOldFiber;
4453 }
4454 break;
4455 }
4456 if (shouldTrackSideEffects) {
4457 if (oldFiber && newFiber.alternate === null) {
4458 // We matched the slot, but we didn't reuse the existing fiber, so we
4459 // need to delete the existing child.
4460 deleteChild(returnFiber, oldFiber);
4461 }
4462 }
4463 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4464 if (previousNewFiber === null) {
4465 // TODO: Move out of the loop. This only happens for the first run.
4466 resultingFirstChild = newFiber;
4467 } else {
4468 // TODO: Defer siblings if we're not at the right index for this slot.
4469 // I.e. if we had null values before, then we want to defer this
4470 // for each null value. However, we also don't want to call updateSlot
4471 // with the previous one.
4472 previousNewFiber.sibling = newFiber;
4473 }
4474 previousNewFiber = newFiber;
4475 oldFiber = nextOldFiber;
4476 }
4477
4478 if (newIdx === newChildren.length) {
4479 // We've reached the end of the new children. We can delete the rest.
4480 deleteRemainingChildren(returnFiber, oldFiber);
4481 return resultingFirstChild;
4482 }
4483
4484 if (oldFiber === null) {
4485 // If we don't have any more existing children we can choose a fast path
4486 // since the rest will all be insertions.
4487 for (; newIdx < newChildren.length; newIdx++) {
4488 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
4489 if (!_newFiber) {
4490 continue;
4491 }
4492 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
4493 if (previousNewFiber === null) {
4494 // TODO: Move out of the loop. This only happens for the first run.
4495 resultingFirstChild = _newFiber;
4496 } else {
4497 previousNewFiber.sibling = _newFiber;
4498 }
4499 previousNewFiber = _newFiber;
4500 }
4501 return resultingFirstChild;
4502 }
4503
4504 // Add all children to a key map for quick lookups.
4505 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4506
4507 // Keep scanning and use the map to restore deleted items as moves.
4508 for (; newIdx < newChildren.length; newIdx++) {
4509 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
4510 if (_newFiber2) {
4511 if (shouldTrackSideEffects) {
4512 if (_newFiber2.alternate !== null) {
4513 // The new fiber is a work in progress, but if there exists a
4514 // current, that means that we reused the fiber. We need to delete
4515 // it from the child list so that we don't add it to the deletion
4516 // list.
4517 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
4518 }
4519 }
4520 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
4521 if (previousNewFiber === null) {
4522 resultingFirstChild = _newFiber2;
4523 } else {
4524 previousNewFiber.sibling = _newFiber2;
4525 }
4526 previousNewFiber = _newFiber2;
4527 }
4528 }
4529
4530 if (shouldTrackSideEffects) {
4531 // Any existing children that weren't consumed above were deleted. We need
4532 // to add them to the deletion list.
4533 existingChildren.forEach(function (child) {
4534 return deleteChild(returnFiber, child);
4535 });
4536 }
4537
4538 return resultingFirstChild;
4539 }
4540
4541 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
4542 // This is the same implementation as reconcileChildrenArray(),
4543 // but using the iterator instead.
4544
4545 var iteratorFn = getIteratorFn(newChildrenIterable);
4546 !(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;
4547
4548 {
4549 // We don't support rendering Generators because it's a mutation.
4550 // See https://github.com/facebook/react/issues/12995
4551 if (typeof Symbol === 'function' &&
4552 // $FlowFixMe Flow doesn't know about toStringTag
4553 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
4554 !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;
4555 didWarnAboutGenerators = true;
4556 }
4557
4558 // Warn about using Maps as children
4559 if (newChildrenIterable.entries === iteratorFn) {
4560 !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;
4561 didWarnAboutMaps = true;
4562 }
4563
4564 // First, validate keys.
4565 // We'll get a different iterator later for the main pass.
4566 var _newChildren = iteratorFn.call(newChildrenIterable);
4567 if (_newChildren) {
4568 var knownKeys = null;
4569 var _step = _newChildren.next();
4570 for (; !_step.done; _step = _newChildren.next()) {
4571 var child = _step.value;
4572 knownKeys = warnOnInvalidKey(child, knownKeys);
4573 }
4574 }
4575 }
4576
4577 var newChildren = iteratorFn.call(newChildrenIterable);
4578 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
4579
4580 var resultingFirstChild = null;
4581 var previousNewFiber = null;
4582
4583 var oldFiber = currentFirstChild;
4584 var lastPlacedIndex = 0;
4585 var newIdx = 0;
4586 var nextOldFiber = null;
4587
4588 var step = newChildren.next();
4589 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
4590 if (oldFiber.index > newIdx) {
4591 nextOldFiber = oldFiber;
4592 oldFiber = null;
4593 } else {
4594 nextOldFiber = oldFiber.sibling;
4595 }
4596 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
4597 if (newFiber === null) {
4598 // TODO: This breaks on empty slots like null children. That's
4599 // unfortunate because it triggers the slow path all the time. We need
4600 // a better way to communicate whether this was a miss or null,
4601 // boolean, undefined, etc.
4602 if (!oldFiber) {
4603 oldFiber = nextOldFiber;
4604 }
4605 break;
4606 }
4607 if (shouldTrackSideEffects) {
4608 if (oldFiber && newFiber.alternate === null) {
4609 // We matched the slot, but we didn't reuse the existing fiber, so we
4610 // need to delete the existing child.
4611 deleteChild(returnFiber, oldFiber);
4612 }
4613 }
4614 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4615 if (previousNewFiber === null) {
4616 // TODO: Move out of the loop. This only happens for the first run.
4617 resultingFirstChild = newFiber;
4618 } else {
4619 // TODO: Defer siblings if we're not at the right index for this slot.
4620 // I.e. if we had null values before, then we want to defer this
4621 // for each null value. However, we also don't want to call updateSlot
4622 // with the previous one.
4623 previousNewFiber.sibling = newFiber;
4624 }
4625 previousNewFiber = newFiber;
4626 oldFiber = nextOldFiber;
4627 }
4628
4629 if (step.done) {
4630 // We've reached the end of the new children. We can delete the rest.
4631 deleteRemainingChildren(returnFiber, oldFiber);
4632 return resultingFirstChild;
4633 }
4634
4635 if (oldFiber === null) {
4636 // If we don't have any more existing children we can choose a fast path
4637 // since the rest will all be insertions.
4638 for (; !step.done; newIdx++, step = newChildren.next()) {
4639 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
4640 if (_newFiber3 === null) {
4641 continue;
4642 }
4643 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
4644 if (previousNewFiber === null) {
4645 // TODO: Move out of the loop. This only happens for the first run.
4646 resultingFirstChild = _newFiber3;
4647 } else {
4648 previousNewFiber.sibling = _newFiber3;
4649 }
4650 previousNewFiber = _newFiber3;
4651 }
4652 return resultingFirstChild;
4653 }
4654
4655 // Add all children to a key map for quick lookups.
4656 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4657
4658 // Keep scanning and use the map to restore deleted items as moves.
4659 for (; !step.done; newIdx++, step = newChildren.next()) {
4660 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
4661 if (_newFiber4 !== null) {
4662 if (shouldTrackSideEffects) {
4663 if (_newFiber4.alternate !== null) {
4664 // The new fiber is a work in progress, but if there exists a
4665 // current, that means that we reused the fiber. We need to delete
4666 // it from the child list so that we don't add it to the deletion
4667 // list.
4668 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
4669 }
4670 }
4671 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
4672 if (previousNewFiber === null) {
4673 resultingFirstChild = _newFiber4;
4674 } else {
4675 previousNewFiber.sibling = _newFiber4;
4676 }
4677 previousNewFiber = _newFiber4;
4678 }
4679 }
4680
4681 if (shouldTrackSideEffects) {
4682 // Any existing children that weren't consumed above were deleted. We need
4683 // to add them to the deletion list.
4684 existingChildren.forEach(function (child) {
4685 return deleteChild(returnFiber, child);
4686 });
4687 }
4688
4689 return resultingFirstChild;
4690 }
4691
4692 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
4693 // There's no need to check for keys on text nodes since we don't have a
4694 // way to define them.
4695 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
4696 // We already have an existing node so let's just update it and delete
4697 // the rest.
4698 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
4699 var existing = useFiber(currentFirstChild, textContent, expirationTime);
4700 existing.return = returnFiber;
4701 return existing;
4702 }
4703 // The existing first child is not a text node so we need to create one
4704 // and delete the existing ones.
4705 deleteRemainingChildren(returnFiber, currentFirstChild);
4706 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4707 created.return = returnFiber;
4708 return created;
4709 }
4710
4711 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
4712 var key = element.key;
4713 var child = currentFirstChild;
4714 while (child !== null) {
4715 // TODO: If key === null and child.key === null, then this only applies to
4716 // the first item in the list.
4717 if (child.key === key) {
4718 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type) {
4719 deleteRemainingChildren(returnFiber, child.sibling);
4720 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
4721 existing.ref = coerceRef(returnFiber, child, element);
4722 existing.return = returnFiber;
4723 {
4724 existing._debugSource = element._source;
4725 existing._debugOwner = element._owner;
4726 }
4727 return existing;
4728 } else {
4729 deleteRemainingChildren(returnFiber, child);
4730 break;
4731 }
4732 } else {
4733 deleteChild(returnFiber, child);
4734 }
4735 child = child.sibling;
4736 }
4737
4738 if (element.type === REACT_FRAGMENT_TYPE) {
4739 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
4740 created.return = returnFiber;
4741 return created;
4742 } else {
4743 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
4744 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
4745 _created4.return = returnFiber;
4746 return _created4;
4747 }
4748 }
4749
4750 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
4751 var key = portal.key;
4752 var child = currentFirstChild;
4753 while (child !== null) {
4754 // TODO: If key === null and child.key === null, then this only applies to
4755 // the first item in the list.
4756 if (child.key === key) {
4757 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
4758 deleteRemainingChildren(returnFiber, child.sibling);
4759 var existing = useFiber(child, portal.children || [], expirationTime);
4760 existing.return = returnFiber;
4761 return existing;
4762 } else {
4763 deleteRemainingChildren(returnFiber, child);
4764 break;
4765 }
4766 } else {
4767 deleteChild(returnFiber, child);
4768 }
4769 child = child.sibling;
4770 }
4771
4772 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4773 created.return = returnFiber;
4774 return created;
4775 }
4776
4777 // This API will tag the children with the side-effect of the reconciliation
4778 // itself. They will be added to the side-effect list as we pass through the
4779 // children and the parent.
4780 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
4781 // This function is not recursive.
4782 // If the top level item is an array, we treat it as a set of children,
4783 // not as a fragment. Nested arrays on the other hand will be treated as
4784 // fragment nodes. Recursion happens at the normal flow.
4785
4786 // Handle top level unkeyed fragments as if they were arrays.
4787 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
4788 // We treat the ambiguous cases above the same.
4789 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
4790 if (isUnkeyedTopLevelFragment) {
4791 newChild = newChild.props.children;
4792 }
4793
4794 // Handle object types
4795 var isObject = typeof newChild === 'object' && newChild !== null;
4796
4797 if (isObject) {
4798 switch (newChild.$$typeof) {
4799 case REACT_ELEMENT_TYPE:
4800 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
4801 case REACT_PORTAL_TYPE:
4802 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
4803 }
4804 }
4805
4806 if (typeof newChild === 'string' || typeof newChild === 'number') {
4807 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
4808 }
4809
4810 if (isArray(newChild)) {
4811 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
4812 }
4813
4814 if (getIteratorFn(newChild)) {
4815 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
4816 }
4817
4818 if (isObject) {
4819 throwOnInvalidObjectType(returnFiber, newChild);
4820 }
4821
4822 {
4823 if (typeof newChild === 'function') {
4824 warnOnFunctionType();
4825 }
4826 }
4827 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
4828 // If the new child is undefined, and the return fiber is a composite
4829 // component, throw an error. If Fiber return types are disabled,
4830 // we already threw above.
4831 switch (returnFiber.tag) {
4832 case ClassComponent:
4833 {
4834 {
4835 var instance = returnFiber.stateNode;
4836 if (instance.render._isMockFunction) {
4837 // We allow auto-mocks to proceed as if they're returning null.
4838 break;
4839 }
4840 }
4841 }
4842 // Intentionally fall through to the next case, which handles both
4843 // functions and classes
4844 // eslint-disable-next-lined no-fallthrough
4845 case FunctionComponent:
4846 {
4847 var Component = returnFiber.type;
4848 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');
4849 }
4850 }
4851 }
4852
4853 // Remaining cases are all treated as empty.
4854 return deleteRemainingChildren(returnFiber, currentFirstChild);
4855 }
4856
4857 return reconcileChildFibers;
4858}
4859
4860var reconcileChildFibers = ChildReconciler(true);
4861var mountChildFibers = ChildReconciler(false);
4862
4863function cloneChildFibers(current$$1, workInProgress) {
4864 !(current$$1 === null || workInProgress.child === current$$1.child) ? invariant(false, 'Resuming work not yet implemented.') : void 0;
4865
4866 if (workInProgress.child === null) {
4867 return;
4868 }
4869
4870 var currentChild = workInProgress.child;
4871 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4872 workInProgress.child = newChild;
4873
4874 newChild.return = workInProgress;
4875 while (currentChild.sibling !== null) {
4876 currentChild = currentChild.sibling;
4877 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4878 newChild.return = workInProgress;
4879 }
4880 newChild.sibling = null;
4881}
4882
4883var NO_CONTEXT$1 = {};
4884
4885var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
4886var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
4887var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
4888
4889function requiredContext(c) {
4890 !(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;
4891 return c;
4892}
4893
4894function getRootHostContainer() {
4895 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4896 return rootInstance;
4897}
4898
4899function pushHostContainer(fiber, nextRootInstance) {
4900 // Push current root instance onto the stack;
4901 // This allows us to reset root when portals are popped.
4902 push(rootInstanceStackCursor, nextRootInstance, fiber);
4903 // Track the context and the Fiber that provided it.
4904 // This enables us to pop only Fibers that provide unique contexts.
4905 push(contextFiberStackCursor, fiber, fiber);
4906
4907 // Finally, we need to push the host context to the stack.
4908 // However, we can't just call getRootHostContext() and push it because
4909 // we'd have a different number of entries on the stack depending on
4910 // whether getRootHostContext() throws somewhere in renderer code or not.
4911 // So we push an empty value first. This lets us safely unwind on errors.
4912 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
4913 var nextRootContext = getRootHostContext(nextRootInstance);
4914 // Now that we know this function doesn't throw, replace it.
4915 pop(contextStackCursor$1, fiber);
4916 push(contextStackCursor$1, nextRootContext, fiber);
4917}
4918
4919function popHostContainer(fiber) {
4920 pop(contextStackCursor$1, fiber);
4921 pop(contextFiberStackCursor, fiber);
4922 pop(rootInstanceStackCursor, fiber);
4923}
4924
4925function getHostContext() {
4926 var context = requiredContext(contextStackCursor$1.current);
4927 return context;
4928}
4929
4930function pushHostContext(fiber) {
4931 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4932 var context = requiredContext(contextStackCursor$1.current);
4933 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
4934
4935 // Don't push this Fiber's context unless it's unique.
4936 if (context === nextContext) {
4937 return;
4938 }
4939
4940 // Track the context and the Fiber that provided it.
4941 // This enables us to pop only Fibers that provide unique contexts.
4942 push(contextFiberStackCursor, fiber, fiber);
4943 push(contextStackCursor$1, nextContext, fiber);
4944}
4945
4946function popHostContext(fiber) {
4947 // Do not pop unless this Fiber provided the current context.
4948 // pushHostContext() only pushes Fibers that provide unique contexts.
4949 if (contextFiberStackCursor.current !== fiber) {
4950 return;
4951 }
4952
4953 pop(contextStackCursor$1, fiber);
4954 pop(contextFiberStackCursor, fiber);
4955}
4956
4957var NoEffect$1 = /* */0;
4958var UnmountSnapshot = /* */2;
4959var UnmountMutation = /* */4;
4960var MountMutation = /* */8;
4961var UnmountLayout = /* */16;
4962var MountLayout = /* */32;
4963var MountPassive = /* */64;
4964var UnmountPassive = /* */128;
4965
4966var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
4967
4968
4969var didWarnAboutMismatchedHooksForComponent = void 0;
4970{
4971 didWarnAboutMismatchedHooksForComponent = new Set();
4972}
4973
4974// These are set right before calling the component.
4975var renderExpirationTime = NoWork;
4976// The work-in-progress fiber. I've named it differently to distinguish it from
4977// the work-in-progress hook.
4978var currentlyRenderingFiber$1 = null;
4979
4980// Hooks are stored as a linked list on the fiber's memoizedState field. The
4981// current hook list is the list that belongs to the current fiber. The
4982// work-in-progress hook list is a new list that will be added to the
4983// work-in-progress fiber.
4984var currentHook = null;
4985var nextCurrentHook = null;
4986var firstWorkInProgressHook = null;
4987var workInProgressHook = null;
4988var nextWorkInProgressHook = null;
4989
4990var remainingExpirationTime = NoWork;
4991var componentUpdateQueue = null;
4992var sideEffectTag = 0;
4993
4994// Updates scheduled during render will trigger an immediate re-render at the
4995// end of the current pass. We can't store these updates on the normal queue,
4996// because if the work is aborted, they should be discarded. Because this is
4997// a relatively rare case, we also don't want to add an additional field to
4998// either the hook or queue object types. So we store them in a lazily create
4999// map of queue -> render-phase updates, which are discarded once the component
5000// completes without re-rendering.
5001
5002// Whether an update was scheduled during the currently executing render pass.
5003var didScheduleRenderPhaseUpdate = false;
5004// Lazily created map of render-phase updates
5005var renderPhaseUpdates = null;
5006// Counter to prevent infinite loops.
5007var numberOfReRenders = 0;
5008var RE_RENDER_LIMIT = 25;
5009
5010// In DEV, this is the name of the currently executing primitive hook
5011var currentHookNameInDev = null;
5012
5013// In DEV, this list ensures that hooks are called in the same order between renders.
5014// The list stores the order of hooks used during the initial render (mount).
5015// Subsequent renders (updates) reference this list.
5016var hookTypesDev = null;
5017var hookTypesUpdateIndexDev = -1;
5018
5019function mountHookTypesDev() {
5020 {
5021 var hookName = currentHookNameInDev;
5022
5023 if (hookTypesDev === null) {
5024 hookTypesDev = [hookName];
5025 } else {
5026 hookTypesDev.push(hookName);
5027 }
5028 }
5029}
5030
5031function updateHookTypesDev() {
5032 {
5033 var hookName = currentHookNameInDev;
5034
5035 if (hookTypesDev !== null) {
5036 hookTypesUpdateIndexDev++;
5037 if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
5038 warnOnHookMismatchInDev(hookName);
5039 }
5040 }
5041 }
5042}
5043
5044function warnOnHookMismatchInDev(currentHookName) {
5045 {
5046 var componentName = getComponentName(currentlyRenderingFiber$1.type);
5047 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
5048 didWarnAboutMismatchedHooksForComponent.add(componentName);
5049
5050 if (hookTypesDev !== null) {
5051 var table = '';
5052
5053 var secondColumnStart = 30;
5054
5055 for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
5056 var oldHookName = hookTypesDev[i];
5057 var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
5058
5059 var row = i + 1 + '. ' + oldHookName;
5060
5061 // Extra space so second column lines up
5062 // lol @ IE not supporting String#repeat
5063 while (row.length < secondColumnStart) {
5064 row += ' ';
5065 }
5066
5067 row += newHookName + '\n';
5068
5069 table += row;
5070 }
5071
5072 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);
5073 }
5074 }
5075 }
5076}
5077
5078function throwInvalidHookError() {
5079 invariant(false, 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.');
5080}
5081
5082function areHookInputsEqual(nextDeps, prevDeps) {
5083 if (prevDeps === null) {
5084 {
5085 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);
5086 }
5087 return false;
5088 }
5089
5090 {
5091 // Don't bother comparing lengths in prod because these arrays should be
5092 // passed inline.
5093 if (nextDeps.length !== prevDeps.length) {
5094 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(', ') + ']');
5095 }
5096 }
5097 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
5098 if (is(nextDeps[i], prevDeps[i])) {
5099 continue;
5100 }
5101 return false;
5102 }
5103 return true;
5104}
5105
5106function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
5107 renderExpirationTime = nextRenderExpirationTime;
5108 currentlyRenderingFiber$1 = workInProgress;
5109 nextCurrentHook = current !== null ? current.memoizedState : null;
5110
5111 {
5112 hookTypesDev = current !== null ? current._debugHookTypes : null;
5113 hookTypesUpdateIndexDev = -1;
5114 }
5115
5116 // The following should have already been reset
5117 // currentHook = null;
5118 // workInProgressHook = null;
5119
5120 // remainingExpirationTime = NoWork;
5121 // componentUpdateQueue = null;
5122
5123 // didScheduleRenderPhaseUpdate = false;
5124 // renderPhaseUpdates = null;
5125 // numberOfReRenders = 0;
5126 // sideEffectTag = 0;
5127
5128 // TODO Warn if no hooks are used at all during mount, then some are used during update.
5129 // Currently we will identify the update render as a mount because nextCurrentHook === null.
5130 // This is tricky because it's valid for certain types of components (e.g. React.lazy)
5131
5132 // Using nextCurrentHook to differentiate between mount/update only works if at least one stateful hook is used.
5133 // Non-stateful hooks (e.g. context) don't get added to memoizedState,
5134 // so nextCurrentHook would be null during updates and mounts.
5135 {
5136 if (nextCurrentHook !== null) {
5137 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
5138 } else if (hookTypesDev !== null) {
5139 // This dispatcher handles an edge case where a component is updating,
5140 // but no stateful hooks have been used.
5141 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
5142 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
5143 // This dispatcher does that.
5144 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
5145 } else {
5146 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
5147 }
5148 }
5149
5150 var children = Component(props, refOrContext);
5151
5152 if (didScheduleRenderPhaseUpdate) {
5153 do {
5154 didScheduleRenderPhaseUpdate = false;
5155 numberOfReRenders += 1;
5156
5157 // Start over from the beginning of the list
5158 nextCurrentHook = current !== null ? current.memoizedState : null;
5159 nextWorkInProgressHook = firstWorkInProgressHook;
5160
5161 currentHook = null;
5162 workInProgressHook = null;
5163 componentUpdateQueue = null;
5164
5165 {
5166 // Also validate hook order for cascading updates.
5167 hookTypesUpdateIndexDev = -1;
5168 }
5169
5170 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
5171
5172 children = Component(props, refOrContext);
5173 } while (didScheduleRenderPhaseUpdate);
5174
5175 renderPhaseUpdates = null;
5176 numberOfReRenders = 0;
5177 }
5178
5179 // We can assume the previous dispatcher is always this one, since we set it
5180 // at the beginning of the render phase and there's no re-entrancy.
5181 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5182
5183 var renderedWork = currentlyRenderingFiber$1;
5184
5185 renderedWork.memoizedState = firstWorkInProgressHook;
5186 renderedWork.expirationTime = remainingExpirationTime;
5187 renderedWork.updateQueue = componentUpdateQueue;
5188 renderedWork.effectTag |= sideEffectTag;
5189
5190 {
5191 renderedWork._debugHookTypes = hookTypesDev;
5192 }
5193
5194 // This check uses currentHook so that it works the same in DEV and prod bundles.
5195 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
5196 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
5197
5198 renderExpirationTime = NoWork;
5199 currentlyRenderingFiber$1 = null;
5200
5201 currentHook = null;
5202 nextCurrentHook = null;
5203 firstWorkInProgressHook = null;
5204 workInProgressHook = null;
5205 nextWorkInProgressHook = null;
5206
5207 {
5208 currentHookNameInDev = null;
5209 hookTypesDev = null;
5210 hookTypesUpdateIndexDev = -1;
5211 }
5212
5213 remainingExpirationTime = NoWork;
5214 componentUpdateQueue = null;
5215 sideEffectTag = 0;
5216
5217 // These were reset above
5218 // didScheduleRenderPhaseUpdate = false;
5219 // renderPhaseUpdates = null;
5220 // numberOfReRenders = 0;
5221
5222 !!didRenderTooFewHooks ? invariant(false, 'Rendered fewer hooks than expected. This may be caused by an accidental early return statement.') : void 0;
5223
5224 return children;
5225}
5226
5227function bailoutHooks(current, workInProgress, expirationTime) {
5228 workInProgress.updateQueue = current.updateQueue;
5229 workInProgress.effectTag &= ~(Passive | Update);
5230 if (current.expirationTime <= expirationTime) {
5231 current.expirationTime = NoWork;
5232 }
5233}
5234
5235function resetHooks() {
5236 // We can assume the previous dispatcher is always this one, since we set it
5237 // at the beginning of the render phase and there's no re-entrancy.
5238 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5239
5240 // This is used to reset the state of this module when a component throws.
5241 // It's also called inside mountIndeterminateComponent if we determine the
5242 // component is a module-style component.
5243 renderExpirationTime = NoWork;
5244 currentlyRenderingFiber$1 = null;
5245
5246 currentHook = null;
5247 nextCurrentHook = null;
5248 firstWorkInProgressHook = null;
5249 workInProgressHook = null;
5250 nextWorkInProgressHook = null;
5251
5252 {
5253 hookTypesDev = null;
5254 hookTypesUpdateIndexDev = -1;
5255
5256 currentHookNameInDev = null;
5257 }
5258
5259 remainingExpirationTime = NoWork;
5260 componentUpdateQueue = null;
5261 sideEffectTag = 0;
5262
5263 didScheduleRenderPhaseUpdate = false;
5264 renderPhaseUpdates = null;
5265 numberOfReRenders = 0;
5266}
5267
5268function mountWorkInProgressHook() {
5269 var hook = {
5270 memoizedState: null,
5271
5272 baseState: null,
5273 queue: null,
5274 baseUpdate: null,
5275
5276 next: null
5277 };
5278
5279 if (workInProgressHook === null) {
5280 // This is the first hook in the list
5281 firstWorkInProgressHook = workInProgressHook = hook;
5282 } else {
5283 // Append to the end of the list
5284 workInProgressHook = workInProgressHook.next = hook;
5285 }
5286 return workInProgressHook;
5287}
5288
5289function updateWorkInProgressHook() {
5290 // This function is used both for updates and for re-renders triggered by a
5291 // render phase update. It assumes there is either a current hook we can
5292 // clone, or a work-in-progress hook from a previous render pass that we can
5293 // use as a base. When we reach the end of the base list, we must switch to
5294 // the dispatcher used for mounts.
5295 if (nextWorkInProgressHook !== null) {
5296 // There's already a work-in-progress. Reuse it.
5297 workInProgressHook = nextWorkInProgressHook;
5298 nextWorkInProgressHook = workInProgressHook.next;
5299
5300 currentHook = nextCurrentHook;
5301 nextCurrentHook = currentHook !== null ? currentHook.next : null;
5302 } else {
5303 // Clone from the current hook.
5304 !(nextCurrentHook !== null) ? invariant(false, 'Rendered more hooks than during the previous render.') : void 0;
5305 currentHook = nextCurrentHook;
5306
5307 var newHook = {
5308 memoizedState: currentHook.memoizedState,
5309
5310 baseState: currentHook.baseState,
5311 queue: currentHook.queue,
5312 baseUpdate: currentHook.baseUpdate,
5313
5314 next: null
5315 };
5316
5317 if (workInProgressHook === null) {
5318 // This is the first hook in the list.
5319 workInProgressHook = firstWorkInProgressHook = newHook;
5320 } else {
5321 // Append to the end of the list.
5322 workInProgressHook = workInProgressHook.next = newHook;
5323 }
5324 nextCurrentHook = currentHook.next;
5325 }
5326 return workInProgressHook;
5327}
5328
5329function createFunctionComponentUpdateQueue() {
5330 return {
5331 lastEffect: null
5332 };
5333}
5334
5335function basicStateReducer(state, action) {
5336 return typeof action === 'function' ? action(state) : action;
5337}
5338
5339function mountReducer(reducer, initialArg, init) {
5340 var hook = mountWorkInProgressHook();
5341 var initialState = void 0;
5342 if (init !== undefined) {
5343 initialState = init(initialArg);
5344 } else {
5345 initialState = initialArg;
5346 }
5347 hook.memoizedState = hook.baseState = initialState;
5348 var queue = hook.queue = {
5349 last: null,
5350 dispatch: null,
5351 eagerReducer: reducer,
5352 eagerState: initialState
5353 };
5354 var dispatch = queue.dispatch = dispatchAction.bind(null,
5355 // Flow doesn't know this is non-null, but we do.
5356 currentlyRenderingFiber$1, queue);
5357 return [hook.memoizedState, dispatch];
5358}
5359
5360function updateReducer(reducer, initialArg, init) {
5361 var hook = updateWorkInProgressHook();
5362 var queue = hook.queue;
5363 !(queue !== null) ? invariant(false, 'Should have a queue. This is likely a bug in React. Please file an issue.') : void 0;
5364
5365 if (numberOfReRenders > 0) {
5366 // This is a re-render. Apply the new render phase updates to the previous
5367 var _dispatch = queue.dispatch;
5368 if (renderPhaseUpdates !== null) {
5369 // Render phase updates are stored in a map of queue -> linked list
5370 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5371 if (firstRenderPhaseUpdate !== undefined) {
5372 renderPhaseUpdates.delete(queue);
5373 var newState = hook.memoizedState;
5374 var update = firstRenderPhaseUpdate;
5375 do {
5376 // Process this render phase update. We don't have to check the
5377 // priority because it will always be the same as the current
5378 // render's.
5379 var _action = update.action;
5380 newState = reducer(newState, _action);
5381 update = update.next;
5382 } while (update !== null);
5383
5384 // Mark that the fiber performed work, but only if the new state is
5385 // different from the current state.
5386 if (!is(newState, hook.memoizedState)) {
5387 markWorkInProgressReceivedUpdate();
5388 }
5389
5390 hook.memoizedState = newState;
5391 // Don't persist the state accumlated from the render phase updates to
5392 // the base state unless the queue is empty.
5393 // TODO: Not sure if this is the desired semantics, but it's what we
5394 // do for gDSFP. I can't remember why.
5395 if (hook.baseUpdate === queue.last) {
5396 hook.baseState = newState;
5397 }
5398
5399 queue.eagerReducer = reducer;
5400 queue.eagerState = newState;
5401
5402 return [newState, _dispatch];
5403 }
5404 }
5405 return [hook.memoizedState, _dispatch];
5406 }
5407
5408 // The last update in the entire queue
5409 var last = queue.last;
5410 // The last update that is part of the base state.
5411 var baseUpdate = hook.baseUpdate;
5412 var baseState = hook.baseState;
5413
5414 // Find the first unprocessed update.
5415 var first = void 0;
5416 if (baseUpdate !== null) {
5417 if (last !== null) {
5418 // For the first update, the queue is a circular linked list where
5419 // `queue.last.next = queue.first`. Once the first update commits, and
5420 // the `baseUpdate` is no longer empty, we can unravel the list.
5421 last.next = null;
5422 }
5423 first = baseUpdate.next;
5424 } else {
5425 first = last !== null ? last.next : null;
5426 }
5427 if (first !== null) {
5428 var _newState = baseState;
5429 var newBaseState = null;
5430 var newBaseUpdate = null;
5431 var prevUpdate = baseUpdate;
5432 var _update = first;
5433 var didSkip = false;
5434 do {
5435 var updateExpirationTime = _update.expirationTime;
5436 if (updateExpirationTime < renderExpirationTime) {
5437 // Priority is insufficient. Skip this update. If this is the first
5438 // skipped update, the previous update/state is the new base
5439 // update/state.
5440 if (!didSkip) {
5441 didSkip = true;
5442 newBaseUpdate = prevUpdate;
5443 newBaseState = _newState;
5444 }
5445 // Update the remaining priority in the queue.
5446 if (updateExpirationTime > remainingExpirationTime) {
5447 remainingExpirationTime = updateExpirationTime;
5448 }
5449 } else {
5450 // Process this update.
5451 if (_update.eagerReducer === reducer) {
5452 // If this update was processed eagerly, and its reducer matches the
5453 // current reducer, we can use the eagerly computed state.
5454 _newState = _update.eagerState;
5455 } else {
5456 var _action2 = _update.action;
5457 _newState = reducer(_newState, _action2);
5458 }
5459 }
5460 prevUpdate = _update;
5461 _update = _update.next;
5462 } while (_update !== null && _update !== first);
5463
5464 if (!didSkip) {
5465 newBaseUpdate = prevUpdate;
5466 newBaseState = _newState;
5467 }
5468
5469 // Mark that the fiber performed work, but only if the new state is
5470 // different from the current state.
5471 if (!is(_newState, hook.memoizedState)) {
5472 markWorkInProgressReceivedUpdate();
5473 }
5474
5475 hook.memoizedState = _newState;
5476 hook.baseUpdate = newBaseUpdate;
5477 hook.baseState = newBaseState;
5478
5479 queue.eagerReducer = reducer;
5480 queue.eagerState = _newState;
5481 }
5482
5483 var dispatch = queue.dispatch;
5484 return [hook.memoizedState, dispatch];
5485}
5486
5487function mountState(initialState) {
5488 var hook = mountWorkInProgressHook();
5489 if (typeof initialState === 'function') {
5490 initialState = initialState();
5491 }
5492 hook.memoizedState = hook.baseState = initialState;
5493 var queue = hook.queue = {
5494 last: null,
5495 dispatch: null,
5496 eagerReducer: basicStateReducer,
5497 eagerState: initialState
5498 };
5499 var dispatch = queue.dispatch = dispatchAction.bind(null,
5500 // Flow doesn't know this is non-null, but we do.
5501 currentlyRenderingFiber$1, queue);
5502 return [hook.memoizedState, dispatch];
5503}
5504
5505function updateState(initialState) {
5506 return updateReducer(basicStateReducer, initialState);
5507}
5508
5509function pushEffect(tag, create, destroy, deps) {
5510 var effect = {
5511 tag: tag,
5512 create: create,
5513 destroy: destroy,
5514 deps: deps,
5515 // Circular
5516 next: null
5517 };
5518 if (componentUpdateQueue === null) {
5519 componentUpdateQueue = createFunctionComponentUpdateQueue();
5520 componentUpdateQueue.lastEffect = effect.next = effect;
5521 } else {
5522 var _lastEffect = componentUpdateQueue.lastEffect;
5523 if (_lastEffect === null) {
5524 componentUpdateQueue.lastEffect = effect.next = effect;
5525 } else {
5526 var firstEffect = _lastEffect.next;
5527 _lastEffect.next = effect;
5528 effect.next = firstEffect;
5529 componentUpdateQueue.lastEffect = effect;
5530 }
5531 }
5532 return effect;
5533}
5534
5535function mountRef(initialValue) {
5536 var hook = mountWorkInProgressHook();
5537 var ref = { current: initialValue };
5538 {
5539 Object.seal(ref);
5540 }
5541 hook.memoizedState = ref;
5542 return ref;
5543}
5544
5545function updateRef(initialValue) {
5546 var hook = updateWorkInProgressHook();
5547 return hook.memoizedState;
5548}
5549
5550function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5551 var hook = mountWorkInProgressHook();
5552 var nextDeps = deps === undefined ? null : deps;
5553 sideEffectTag |= fiberEffectTag;
5554 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
5555}
5556
5557function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5558 var hook = updateWorkInProgressHook();
5559 var nextDeps = deps === undefined ? null : deps;
5560 var destroy = undefined;
5561
5562 if (currentHook !== null) {
5563 var prevEffect = currentHook.memoizedState;
5564 destroy = prevEffect.destroy;
5565 if (nextDeps !== null) {
5566 var prevDeps = prevEffect.deps;
5567 if (areHookInputsEqual(nextDeps, prevDeps)) {
5568 pushEffect(NoEffect$1, create, destroy, nextDeps);
5569 return;
5570 }
5571 }
5572 }
5573
5574 sideEffectTag |= fiberEffectTag;
5575 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
5576}
5577
5578function mountEffect(create, deps) {
5579 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5580}
5581
5582function updateEffect(create, deps) {
5583 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5584}
5585
5586function mountLayoutEffect(create, deps) {
5587 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5588}
5589
5590function updateLayoutEffect(create, deps) {
5591 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5592}
5593
5594function imperativeHandleEffect(create, ref) {
5595 if (typeof ref === 'function') {
5596 var refCallback = ref;
5597 var _inst = create();
5598 refCallback(_inst);
5599 return function () {
5600 refCallback(null);
5601 };
5602 } else if (ref !== null && ref !== undefined) {
5603 var refObject = ref;
5604 {
5605 !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;
5606 }
5607 var _inst2 = create();
5608 refObject.current = _inst2;
5609 return function () {
5610 refObject.current = null;
5611 };
5612 }
5613}
5614
5615function mountImperativeHandle(ref, create, deps) {
5616 {
5617 !(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;
5618 }
5619
5620 // TODO: If deps are provided, should we skip comparing the ref itself?
5621 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
5622
5623 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5624}
5625
5626function updateImperativeHandle(ref, create, deps) {
5627 {
5628 !(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;
5629 }
5630
5631 // TODO: If deps are provided, should we skip comparing the ref itself?
5632 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
5633
5634 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5635}
5636
5637function mountDebugValue(value, formatterFn) {
5638 // This hook is normally a no-op.
5639 // The react-debug-hooks package injects its own implementation
5640 // so that e.g. DevTools can display custom hook values.
5641}
5642
5643var updateDebugValue = mountDebugValue;
5644
5645function mountCallback(callback, deps) {
5646 var hook = mountWorkInProgressHook();
5647 var nextDeps = deps === undefined ? null : deps;
5648 hook.memoizedState = [callback, nextDeps];
5649 return callback;
5650}
5651
5652function updateCallback(callback, deps) {
5653 var hook = updateWorkInProgressHook();
5654 var nextDeps = deps === undefined ? null : deps;
5655 var prevState = hook.memoizedState;
5656 if (prevState !== null) {
5657 if (nextDeps !== null) {
5658 var prevDeps = prevState[1];
5659 if (areHookInputsEqual(nextDeps, prevDeps)) {
5660 return prevState[0];
5661 }
5662 }
5663 }
5664 hook.memoizedState = [callback, nextDeps];
5665 return callback;
5666}
5667
5668function mountMemo(nextCreate, deps) {
5669 var hook = mountWorkInProgressHook();
5670 var nextDeps = deps === undefined ? null : deps;
5671 var nextValue = nextCreate();
5672 hook.memoizedState = [nextValue, nextDeps];
5673 return nextValue;
5674}
5675
5676function updateMemo(nextCreate, deps) {
5677 var hook = updateWorkInProgressHook();
5678 var nextDeps = deps === undefined ? null : deps;
5679 var prevState = hook.memoizedState;
5680 if (prevState !== null) {
5681 // Assume these are defined. If they're not, areHookInputsEqual will warn.
5682 if (nextDeps !== null) {
5683 var prevDeps = prevState[1];
5684 if (areHookInputsEqual(nextDeps, prevDeps)) {
5685 return prevState[0];
5686 }
5687 }
5688 }
5689 var nextValue = nextCreate();
5690 hook.memoizedState = [nextValue, nextDeps];
5691 return nextValue;
5692}
5693
5694// in a test-like environment, we want to warn if dispatchAction()
5695// is called outside of a batchedUpdates/TestUtils.act(...) call.
5696var shouldWarnForUnbatchedSetState = false;
5697
5698{
5699 // jest isn't a 'global', it's just exposed to tests via a wrapped function
5700 // further, this isn't a test file, so flow doesn't recognize the symbol. So...
5701 // $FlowExpectedError - because requirements don't give a damn about your type sigs.
5702 if ('undefined' !== typeof jest) {
5703 shouldWarnForUnbatchedSetState = true;
5704 }
5705}
5706
5707function dispatchAction(fiber, queue, action) {
5708 !(numberOfReRenders < RE_RENDER_LIMIT) ? invariant(false, 'Too many re-renders. React limits the number of renders to prevent an infinite loop.') : void 0;
5709
5710 {
5711 !(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;
5712 }
5713
5714 var alternate = fiber.alternate;
5715 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
5716 // This is a render phase update. Stash it in a lazily-created map of
5717 // queue -> linked list of updates. After this render pass, we'll restart
5718 // and apply the stashed updates on top of the work-in-progress hook.
5719 didScheduleRenderPhaseUpdate = true;
5720 var update = {
5721 expirationTime: renderExpirationTime,
5722 action: action,
5723 eagerReducer: null,
5724 eagerState: null,
5725 next: null
5726 };
5727 if (renderPhaseUpdates === null) {
5728 renderPhaseUpdates = new Map();
5729 }
5730 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5731 if (firstRenderPhaseUpdate === undefined) {
5732 renderPhaseUpdates.set(queue, update);
5733 } else {
5734 // Append the update to the end of the list.
5735 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
5736 while (lastRenderPhaseUpdate.next !== null) {
5737 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
5738 }
5739 lastRenderPhaseUpdate.next = update;
5740 }
5741 } else {
5742 flushPassiveEffects$1();
5743
5744 var currentTime = requestCurrentTime();
5745 var _expirationTime = computeExpirationForFiber(currentTime, fiber);
5746
5747 var _update2 = {
5748 expirationTime: _expirationTime,
5749 action: action,
5750 eagerReducer: null,
5751 eagerState: null,
5752 next: null
5753 };
5754
5755 // Append the update to the end of the list.
5756 var _last = queue.last;
5757 if (_last === null) {
5758 // This is the first update. Create a circular list.
5759 _update2.next = _update2;
5760 } else {
5761 var first = _last.next;
5762 if (first !== null) {
5763 // Still circular.
5764 _update2.next = first;
5765 }
5766 _last.next = _update2;
5767 }
5768 queue.last = _update2;
5769
5770 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
5771 // The queue is currently empty, which means we can eagerly compute the
5772 // next state before entering the render phase. If the new state is the
5773 // same as the current state, we may be able to bail out entirely.
5774 var _eagerReducer = queue.eagerReducer;
5775 if (_eagerReducer !== null) {
5776 var prevDispatcher = void 0;
5777 {
5778 prevDispatcher = ReactCurrentDispatcher$1.current;
5779 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5780 }
5781 try {
5782 var currentState = queue.eagerState;
5783 var _eagerState = _eagerReducer(currentState, action);
5784 // Stash the eagerly computed state, and the reducer used to compute
5785 // it, on the update object. If the reducer hasn't changed by the
5786 // time we enter the render phase, then the eager state can be used
5787 // without calling the reducer again.
5788 _update2.eagerReducer = _eagerReducer;
5789 _update2.eagerState = _eagerState;
5790 if (is(_eagerState, currentState)) {
5791 // Fast path. We can bail out without scheduling React to re-render.
5792 // It's still possible that we'll need to rebase this update later,
5793 // if the component re-renders for a different reason and by that
5794 // time the reducer has changed.
5795 return;
5796 }
5797 } catch (error) {
5798 // Suppress the error. It will throw again in the render phase.
5799 } finally {
5800 {
5801 ReactCurrentDispatcher$1.current = prevDispatcher;
5802 }
5803 }
5804 }
5805 }
5806 {
5807 if (shouldWarnForUnbatchedSetState === true) {
5808 warnIfNotCurrentlyBatchingInDev(fiber);
5809 }
5810 }
5811 scheduleWork(fiber, _expirationTime);
5812 }
5813}
5814
5815var ContextOnlyDispatcher = {
5816 readContext: readContext,
5817
5818 useCallback: throwInvalidHookError,
5819 useContext: throwInvalidHookError,
5820 useEffect: throwInvalidHookError,
5821 useImperativeHandle: throwInvalidHookError,
5822 useLayoutEffect: throwInvalidHookError,
5823 useMemo: throwInvalidHookError,
5824 useReducer: throwInvalidHookError,
5825 useRef: throwInvalidHookError,
5826 useState: throwInvalidHookError,
5827 useDebugValue: throwInvalidHookError
5828};
5829
5830var HooksDispatcherOnMountInDEV = null;
5831var HooksDispatcherOnMountWithHookTypesInDEV = null;
5832var HooksDispatcherOnUpdateInDEV = null;
5833var InvalidNestedHooksDispatcherOnMountInDEV = null;
5834var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
5835
5836{
5837 var warnInvalidContextAccess = function () {
5838 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().');
5839 };
5840
5841 var warnInvalidHookAccess = function () {
5842 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');
5843 };
5844
5845 HooksDispatcherOnMountInDEV = {
5846 readContext: function (context, observedBits) {
5847 return readContext(context, observedBits);
5848 },
5849 useCallback: function (callback, deps) {
5850 currentHookNameInDev = 'useCallback';
5851 mountHookTypesDev();
5852 return mountCallback(callback, deps);
5853 },
5854 useContext: function (context, observedBits) {
5855 currentHookNameInDev = 'useContext';
5856 mountHookTypesDev();
5857 return readContext(context, observedBits);
5858 },
5859 useEffect: function (create, deps) {
5860 currentHookNameInDev = 'useEffect';
5861 mountHookTypesDev();
5862 return mountEffect(create, deps);
5863 },
5864 useImperativeHandle: function (ref, create, deps) {
5865 currentHookNameInDev = 'useImperativeHandle';
5866 mountHookTypesDev();
5867 return mountImperativeHandle(ref, create, deps);
5868 },
5869 useLayoutEffect: function (create, deps) {
5870 currentHookNameInDev = 'useLayoutEffect';
5871 mountHookTypesDev();
5872 return mountLayoutEffect(create, deps);
5873 },
5874 useMemo: function (create, deps) {
5875 currentHookNameInDev = 'useMemo';
5876 mountHookTypesDev();
5877 var prevDispatcher = ReactCurrentDispatcher$1.current;
5878 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5879 try {
5880 return mountMemo(create, deps);
5881 } finally {
5882 ReactCurrentDispatcher$1.current = prevDispatcher;
5883 }
5884 },
5885 useReducer: function (reducer, initialArg, init) {
5886 currentHookNameInDev = 'useReducer';
5887 mountHookTypesDev();
5888 var prevDispatcher = ReactCurrentDispatcher$1.current;
5889 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5890 try {
5891 return mountReducer(reducer, initialArg, init);
5892 } finally {
5893 ReactCurrentDispatcher$1.current = prevDispatcher;
5894 }
5895 },
5896 useRef: function (initialValue) {
5897 currentHookNameInDev = 'useRef';
5898 mountHookTypesDev();
5899 return mountRef(initialValue);
5900 },
5901 useState: function (initialState) {
5902 currentHookNameInDev = 'useState';
5903 mountHookTypesDev();
5904 var prevDispatcher = ReactCurrentDispatcher$1.current;
5905 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5906 try {
5907 return mountState(initialState);
5908 } finally {
5909 ReactCurrentDispatcher$1.current = prevDispatcher;
5910 }
5911 },
5912 useDebugValue: function (value, formatterFn) {
5913 currentHookNameInDev = 'useDebugValue';
5914 mountHookTypesDev();
5915 return mountDebugValue(value, formatterFn);
5916 }
5917 };
5918
5919 HooksDispatcherOnMountWithHookTypesInDEV = {
5920 readContext: function (context, observedBits) {
5921 return readContext(context, observedBits);
5922 },
5923 useCallback: function (callback, deps) {
5924 currentHookNameInDev = 'useCallback';
5925 updateHookTypesDev();
5926 return mountCallback(callback, deps);
5927 },
5928 useContext: function (context, observedBits) {
5929 currentHookNameInDev = 'useContext';
5930 updateHookTypesDev();
5931 return readContext(context, observedBits);
5932 },
5933 useEffect: function (create, deps) {
5934 currentHookNameInDev = 'useEffect';
5935 updateHookTypesDev();
5936 return mountEffect(create, deps);
5937 },
5938 useImperativeHandle: function (ref, create, deps) {
5939 currentHookNameInDev = 'useImperativeHandle';
5940 updateHookTypesDev();
5941 return mountImperativeHandle(ref, create, deps);
5942 },
5943 useLayoutEffect: function (create, deps) {
5944 currentHookNameInDev = 'useLayoutEffect';
5945 updateHookTypesDev();
5946 return mountLayoutEffect(create, deps);
5947 },
5948 useMemo: function (create, deps) {
5949 currentHookNameInDev = 'useMemo';
5950 updateHookTypesDev();
5951 var prevDispatcher = ReactCurrentDispatcher$1.current;
5952 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5953 try {
5954 return mountMemo(create, deps);
5955 } finally {
5956 ReactCurrentDispatcher$1.current = prevDispatcher;
5957 }
5958 },
5959 useReducer: function (reducer, initialArg, init) {
5960 currentHookNameInDev = 'useReducer';
5961 updateHookTypesDev();
5962 var prevDispatcher = ReactCurrentDispatcher$1.current;
5963 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5964 try {
5965 return mountReducer(reducer, initialArg, init);
5966 } finally {
5967 ReactCurrentDispatcher$1.current = prevDispatcher;
5968 }
5969 },
5970 useRef: function (initialValue) {
5971 currentHookNameInDev = 'useRef';
5972 updateHookTypesDev();
5973 return mountRef(initialValue);
5974 },
5975 useState: function (initialState) {
5976 currentHookNameInDev = 'useState';
5977 updateHookTypesDev();
5978 var prevDispatcher = ReactCurrentDispatcher$1.current;
5979 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5980 try {
5981 return mountState(initialState);
5982 } finally {
5983 ReactCurrentDispatcher$1.current = prevDispatcher;
5984 }
5985 },
5986 useDebugValue: function (value, formatterFn) {
5987 currentHookNameInDev = 'useDebugValue';
5988 updateHookTypesDev();
5989 return mountDebugValue(value, formatterFn);
5990 }
5991 };
5992
5993 HooksDispatcherOnUpdateInDEV = {
5994 readContext: function (context, observedBits) {
5995 return readContext(context, observedBits);
5996 },
5997 useCallback: function (callback, deps) {
5998 currentHookNameInDev = 'useCallback';
5999 updateHookTypesDev();
6000 return updateCallback(callback, deps);
6001 },
6002 useContext: function (context, observedBits) {
6003 currentHookNameInDev = 'useContext';
6004 updateHookTypesDev();
6005 return readContext(context, observedBits);
6006 },
6007 useEffect: function (create, deps) {
6008 currentHookNameInDev = 'useEffect';
6009 updateHookTypesDev();
6010 return updateEffect(create, deps);
6011 },
6012 useImperativeHandle: function (ref, create, deps) {
6013 currentHookNameInDev = 'useImperativeHandle';
6014 updateHookTypesDev();
6015 return updateImperativeHandle(ref, create, deps);
6016 },
6017 useLayoutEffect: function (create, deps) {
6018 currentHookNameInDev = 'useLayoutEffect';
6019 updateHookTypesDev();
6020 return updateLayoutEffect(create, deps);
6021 },
6022 useMemo: function (create, deps) {
6023 currentHookNameInDev = 'useMemo';
6024 updateHookTypesDev();
6025 var prevDispatcher = ReactCurrentDispatcher$1.current;
6026 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6027 try {
6028 return updateMemo(create, deps);
6029 } finally {
6030 ReactCurrentDispatcher$1.current = prevDispatcher;
6031 }
6032 },
6033 useReducer: function (reducer, initialArg, init) {
6034 currentHookNameInDev = 'useReducer';
6035 updateHookTypesDev();
6036 var prevDispatcher = ReactCurrentDispatcher$1.current;
6037 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6038 try {
6039 return updateReducer(reducer, initialArg, init);
6040 } finally {
6041 ReactCurrentDispatcher$1.current = prevDispatcher;
6042 }
6043 },
6044 useRef: function (initialValue) {
6045 currentHookNameInDev = 'useRef';
6046 updateHookTypesDev();
6047 return updateRef(initialValue);
6048 },
6049 useState: function (initialState) {
6050 currentHookNameInDev = 'useState';
6051 updateHookTypesDev();
6052 var prevDispatcher = ReactCurrentDispatcher$1.current;
6053 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6054 try {
6055 return updateState(initialState);
6056 } finally {
6057 ReactCurrentDispatcher$1.current = prevDispatcher;
6058 }
6059 },
6060 useDebugValue: function (value, formatterFn) {
6061 currentHookNameInDev = 'useDebugValue';
6062 updateHookTypesDev();
6063 return updateDebugValue(value, formatterFn);
6064 }
6065 };
6066
6067 InvalidNestedHooksDispatcherOnMountInDEV = {
6068 readContext: function (context, observedBits) {
6069 warnInvalidContextAccess();
6070 return readContext(context, observedBits);
6071 },
6072 useCallback: function (callback, deps) {
6073 currentHookNameInDev = 'useCallback';
6074 warnInvalidHookAccess();
6075 mountHookTypesDev();
6076 return mountCallback(callback, deps);
6077 },
6078 useContext: function (context, observedBits) {
6079 currentHookNameInDev = 'useContext';
6080 warnInvalidHookAccess();
6081 mountHookTypesDev();
6082 return readContext(context, observedBits);
6083 },
6084 useEffect: function (create, deps) {
6085 currentHookNameInDev = 'useEffect';
6086 warnInvalidHookAccess();
6087 mountHookTypesDev();
6088 return mountEffect(create, deps);
6089 },
6090 useImperativeHandle: function (ref, create, deps) {
6091 currentHookNameInDev = 'useImperativeHandle';
6092 warnInvalidHookAccess();
6093 mountHookTypesDev();
6094 return mountImperativeHandle(ref, create, deps);
6095 },
6096 useLayoutEffect: function (create, deps) {
6097 currentHookNameInDev = 'useLayoutEffect';
6098 warnInvalidHookAccess();
6099 mountHookTypesDev();
6100 return mountLayoutEffect(create, deps);
6101 },
6102 useMemo: function (create, deps) {
6103 currentHookNameInDev = 'useMemo';
6104 warnInvalidHookAccess();
6105 mountHookTypesDev();
6106 var prevDispatcher = ReactCurrentDispatcher$1.current;
6107 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
6108 try {
6109 return mountMemo(create, deps);
6110 } finally {
6111 ReactCurrentDispatcher$1.current = prevDispatcher;
6112 }
6113 },
6114 useReducer: function (reducer, initialArg, init) {
6115 currentHookNameInDev = 'useReducer';
6116 warnInvalidHookAccess();
6117 mountHookTypesDev();
6118 var prevDispatcher = ReactCurrentDispatcher$1.current;
6119 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
6120 try {
6121 return mountReducer(reducer, initialArg, init);
6122 } finally {
6123 ReactCurrentDispatcher$1.current = prevDispatcher;
6124 }
6125 },
6126 useRef: function (initialValue) {
6127 currentHookNameInDev = 'useRef';
6128 warnInvalidHookAccess();
6129 mountHookTypesDev();
6130 return mountRef(initialValue);
6131 },
6132 useState: function (initialState) {
6133 currentHookNameInDev = 'useState';
6134 warnInvalidHookAccess();
6135 mountHookTypesDev();
6136 var prevDispatcher = ReactCurrentDispatcher$1.current;
6137 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
6138 try {
6139 return mountState(initialState);
6140 } finally {
6141 ReactCurrentDispatcher$1.current = prevDispatcher;
6142 }
6143 },
6144 useDebugValue: function (value, formatterFn) {
6145 currentHookNameInDev = 'useDebugValue';
6146 warnInvalidHookAccess();
6147 mountHookTypesDev();
6148 return mountDebugValue(value, formatterFn);
6149 }
6150 };
6151
6152 InvalidNestedHooksDispatcherOnUpdateInDEV = {
6153 readContext: function (context, observedBits) {
6154 warnInvalidContextAccess();
6155 return readContext(context, observedBits);
6156 },
6157 useCallback: function (callback, deps) {
6158 currentHookNameInDev = 'useCallback';
6159 warnInvalidHookAccess();
6160 updateHookTypesDev();
6161 return updateCallback(callback, deps);
6162 },
6163 useContext: function (context, observedBits) {
6164 currentHookNameInDev = 'useContext';
6165 warnInvalidHookAccess();
6166 updateHookTypesDev();
6167 return readContext(context, observedBits);
6168 },
6169 useEffect: function (create, deps) {
6170 currentHookNameInDev = 'useEffect';
6171 warnInvalidHookAccess();
6172 updateHookTypesDev();
6173 return updateEffect(create, deps);
6174 },
6175 useImperativeHandle: function (ref, create, deps) {
6176 currentHookNameInDev = 'useImperativeHandle';
6177 warnInvalidHookAccess();
6178 updateHookTypesDev();
6179 return updateImperativeHandle(ref, create, deps);
6180 },
6181 useLayoutEffect: function (create, deps) {
6182 currentHookNameInDev = 'useLayoutEffect';
6183 warnInvalidHookAccess();
6184 updateHookTypesDev();
6185 return updateLayoutEffect(create, deps);
6186 },
6187 useMemo: function (create, deps) {
6188 currentHookNameInDev = 'useMemo';
6189 warnInvalidHookAccess();
6190 updateHookTypesDev();
6191 var prevDispatcher = ReactCurrentDispatcher$1.current;
6192 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6193 try {
6194 return updateMemo(create, deps);
6195 } finally {
6196 ReactCurrentDispatcher$1.current = prevDispatcher;
6197 }
6198 },
6199 useReducer: function (reducer, initialArg, init) {
6200 currentHookNameInDev = 'useReducer';
6201 warnInvalidHookAccess();
6202 updateHookTypesDev();
6203 var prevDispatcher = ReactCurrentDispatcher$1.current;
6204 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6205 try {
6206 return updateReducer(reducer, initialArg, init);
6207 } finally {
6208 ReactCurrentDispatcher$1.current = prevDispatcher;
6209 }
6210 },
6211 useRef: function (initialValue) {
6212 currentHookNameInDev = 'useRef';
6213 warnInvalidHookAccess();
6214 updateHookTypesDev();
6215 return updateRef(initialValue);
6216 },
6217 useState: function (initialState) {
6218 currentHookNameInDev = 'useState';
6219 warnInvalidHookAccess();
6220 updateHookTypesDev();
6221 var prevDispatcher = ReactCurrentDispatcher$1.current;
6222 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6223 try {
6224 return updateState(initialState);
6225 } finally {
6226 ReactCurrentDispatcher$1.current = prevDispatcher;
6227 }
6228 },
6229 useDebugValue: function (value, formatterFn) {
6230 currentHookNameInDev = 'useDebugValue';
6231 warnInvalidHookAccess();
6232 updateHookTypesDev();
6233 return updateDebugValue(value, formatterFn);
6234 }
6235 };
6236}
6237
6238var commitTime = 0;
6239var profilerStartTime = -1;
6240
6241function getCommitTime() {
6242 return commitTime;
6243}
6244
6245function recordCommitTime() {
6246 if (!enableProfilerTimer) {
6247 return;
6248 }
6249 commitTime = now();
6250}
6251
6252function startProfilerTimer(fiber) {
6253 if (!enableProfilerTimer) {
6254 return;
6255 }
6256
6257 profilerStartTime = now();
6258
6259 if (fiber.actualStartTime < 0) {
6260 fiber.actualStartTime = now();
6261 }
6262}
6263
6264function stopProfilerTimerIfRunning(fiber) {
6265 if (!enableProfilerTimer) {
6266 return;
6267 }
6268 profilerStartTime = -1;
6269}
6270
6271function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
6272 if (!enableProfilerTimer) {
6273 return;
6274 }
6275
6276 if (profilerStartTime >= 0) {
6277 var elapsedTime = now() - profilerStartTime;
6278 fiber.actualDuration += elapsedTime;
6279 if (overrideBaseTime) {
6280 fiber.selfBaseDuration = elapsedTime;
6281 }
6282 profilerStartTime = -1;
6283 }
6284}
6285
6286// The deepest Fiber on the stack involved in a hydration context.
6287// This may have been an insertion or a hydration.
6288var hydrationParentFiber = null;
6289var nextHydratableInstance = null;
6290var isHydrating = false;
6291
6292function enterHydrationState(fiber) {
6293 if (!supportsHydration) {
6294 return false;
6295 }
6296
6297 var parentInstance = fiber.stateNode.containerInfo;
6298 nextHydratableInstance = getFirstHydratableChild(parentInstance);
6299 hydrationParentFiber = fiber;
6300 isHydrating = true;
6301 return true;
6302}
6303
6304function reenterHydrationStateFromDehydratedSuspenseInstance(fiber) {
6305 if (!supportsHydration) {
6306 return false;
6307 }
6308
6309 var suspenseInstance = fiber.stateNode;
6310 nextHydratableInstance = getNextHydratableSibling(suspenseInstance);
6311 popToNextHostParent(fiber);
6312 isHydrating = true;
6313 return true;
6314}
6315
6316function deleteHydratableInstance(returnFiber, instance) {
6317 {
6318 switch (returnFiber.tag) {
6319 case HostRoot:
6320 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
6321 break;
6322 case HostComponent:
6323 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
6324 break;
6325 }
6326 }
6327
6328 var childToDelete = createFiberFromHostInstanceForDeletion();
6329 childToDelete.stateNode = instance;
6330 childToDelete.return = returnFiber;
6331 childToDelete.effectTag = Deletion;
6332
6333 // This might seem like it belongs on progressedFirstDeletion. However,
6334 // these children are not part of the reconciliation list of children.
6335 // Even if we abort and rereconcile the children, that will try to hydrate
6336 // again and the nodes are still in the host tree so these will be
6337 // recreated.
6338 if (returnFiber.lastEffect !== null) {
6339 returnFiber.lastEffect.nextEffect = childToDelete;
6340 returnFiber.lastEffect = childToDelete;
6341 } else {
6342 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
6343 }
6344}
6345
6346function insertNonHydratedInstance(returnFiber, fiber) {
6347 fiber.effectTag |= Placement;
6348 {
6349 switch (returnFiber.tag) {
6350 case HostRoot:
6351 {
6352 var parentContainer = returnFiber.stateNode.containerInfo;
6353 switch (fiber.tag) {
6354 case HostComponent:
6355 var type = fiber.type;
6356 var props = fiber.pendingProps;
6357 didNotFindHydratableContainerInstance(parentContainer, type, props);
6358 break;
6359 case HostText:
6360 var text = fiber.pendingProps;
6361 didNotFindHydratableContainerTextInstance(parentContainer, text);
6362 break;
6363 case SuspenseComponent:
6364 didNotFindHydratableContainerSuspenseInstance(parentContainer);
6365 break;
6366 }
6367 break;
6368 }
6369 case HostComponent:
6370 {
6371 var parentType = returnFiber.type;
6372 var parentProps = returnFiber.memoizedProps;
6373 var parentInstance = returnFiber.stateNode;
6374 switch (fiber.tag) {
6375 case HostComponent:
6376 var _type = fiber.type;
6377 var _props = fiber.pendingProps;
6378 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
6379 break;
6380 case HostText:
6381 var _text = fiber.pendingProps;
6382 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
6383 break;
6384 case SuspenseComponent:
6385 didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance);
6386 break;
6387 }
6388 break;
6389 }
6390 default:
6391 return;
6392 }
6393 }
6394}
6395
6396function tryHydrate(fiber, nextInstance) {
6397 switch (fiber.tag) {
6398 case HostComponent:
6399 {
6400 var type = fiber.type;
6401 var props = fiber.pendingProps;
6402 var instance = canHydrateInstance(nextInstance, type, props);
6403 if (instance !== null) {
6404 fiber.stateNode = instance;
6405 return true;
6406 }
6407 return false;
6408 }
6409 case HostText:
6410 {
6411 var text = fiber.pendingProps;
6412 var textInstance = canHydrateTextInstance(nextInstance, text);
6413 if (textInstance !== null) {
6414 fiber.stateNode = textInstance;
6415 return true;
6416 }
6417 return false;
6418 }
6419 case SuspenseComponent:
6420 {
6421 if (enableSuspenseServerRenderer) {
6422 var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
6423 if (suspenseInstance !== null) {
6424 // Downgrade the tag to a dehydrated component until we've hydrated it.
6425 fiber.tag = DehydratedSuspenseComponent;
6426 fiber.stateNode = suspenseInstance;
6427 return true;
6428 }
6429 }
6430 return false;
6431 }
6432 default:
6433 return false;
6434 }
6435}
6436
6437function tryToClaimNextHydratableInstance(fiber) {
6438 if (!isHydrating) {
6439 return;
6440 }
6441 var nextInstance = nextHydratableInstance;
6442 if (!nextInstance) {
6443 // Nothing to hydrate. Make it an insertion.
6444 insertNonHydratedInstance(hydrationParentFiber, fiber);
6445 isHydrating = false;
6446 hydrationParentFiber = fiber;
6447 return;
6448 }
6449 var firstAttemptedInstance = nextInstance;
6450 if (!tryHydrate(fiber, nextInstance)) {
6451 // If we can't hydrate this instance let's try the next one.
6452 // We use this as a heuristic. It's based on intuition and not data so it
6453 // might be flawed or unnecessary.
6454 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
6455 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
6456 // Nothing to hydrate. Make it an insertion.
6457 insertNonHydratedInstance(hydrationParentFiber, fiber);
6458 isHydrating = false;
6459 hydrationParentFiber = fiber;
6460 return;
6461 }
6462 // We matched the next one, we'll now assume that the first one was
6463 // superfluous and we'll delete it. Since we can't eagerly delete it
6464 // we'll have to schedule a deletion. To do that, this node needs a dummy
6465 // fiber associated with it.
6466 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
6467 }
6468 hydrationParentFiber = fiber;
6469 nextHydratableInstance = getFirstHydratableChild(nextInstance);
6470}
6471
6472function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
6473 if (!supportsHydration) {
6474 invariant(false, 'Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6475 }
6476
6477 var instance = fiber.stateNode;
6478 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber);
6479 // TODO: Type this specific to this type of component.
6480 fiber.updateQueue = updatePayload;
6481 // If the update payload indicates that there is a change or if there
6482 // is a new ref we mark this as an update.
6483 if (updatePayload !== null) {
6484 return true;
6485 }
6486 return false;
6487}
6488
6489function prepareToHydrateHostTextInstance(fiber) {
6490 if (!supportsHydration) {
6491 invariant(false, 'Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6492 }
6493
6494 var textInstance = fiber.stateNode;
6495 var textContent = fiber.memoizedProps;
6496 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
6497 {
6498 if (shouldUpdate) {
6499 // We assume that prepareToHydrateHostTextInstance is called in a context where the
6500 // hydration parent is the parent host component of this host text.
6501 var returnFiber = hydrationParentFiber;
6502 if (returnFiber !== null) {
6503 switch (returnFiber.tag) {
6504 case HostRoot:
6505 {
6506 var parentContainer = returnFiber.stateNode.containerInfo;
6507 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
6508 break;
6509 }
6510 case HostComponent:
6511 {
6512 var parentType = returnFiber.type;
6513 var parentProps = returnFiber.memoizedProps;
6514 var parentInstance = returnFiber.stateNode;
6515 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
6516 break;
6517 }
6518 }
6519 }
6520 }
6521 }
6522 return shouldUpdate;
6523}
6524
6525function skipPastDehydratedSuspenseInstance(fiber) {
6526 if (!supportsHydration) {
6527 invariant(false, 'Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6528 }
6529 var suspenseInstance = fiber.stateNode;
6530 !suspenseInstance ? invariant(false, 'Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.') : void 0;
6531 nextHydratableInstance = getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
6532}
6533
6534function popToNextHostParent(fiber) {
6535 var parent = fiber.return;
6536 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== DehydratedSuspenseComponent) {
6537 parent = parent.return;
6538 }
6539 hydrationParentFiber = parent;
6540}
6541
6542function popHydrationState(fiber) {
6543 if (!supportsHydration) {
6544 return false;
6545 }
6546 if (fiber !== hydrationParentFiber) {
6547 // We're deeper than the current hydration context, inside an inserted
6548 // tree.
6549 return false;
6550 }
6551 if (!isHydrating) {
6552 // If we're not currently hydrating but we're in a hydration context, then
6553 // we were an insertion and now need to pop up reenter hydration of our
6554 // siblings.
6555 popToNextHostParent(fiber);
6556 isHydrating = true;
6557 return false;
6558 }
6559
6560 var type = fiber.type;
6561
6562 // If we have any remaining hydratable nodes, we need to delete them now.
6563 // We only do this deeper than head and body since they tend to have random
6564 // other nodes in them. We also ignore components with pure text content in
6565 // side of them.
6566 // TODO: Better heuristic.
6567 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
6568 var nextInstance = nextHydratableInstance;
6569 while (nextInstance) {
6570 deleteHydratableInstance(fiber, nextInstance);
6571 nextInstance = getNextHydratableSibling(nextInstance);
6572 }
6573 }
6574
6575 popToNextHostParent(fiber);
6576 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
6577 return true;
6578}
6579
6580function resetHydrationState() {
6581 if (!supportsHydration) {
6582 return;
6583 }
6584
6585 hydrationParentFiber = null;
6586 nextHydratableInstance = null;
6587 isHydrating = false;
6588}
6589
6590var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
6591
6592var didReceiveUpdate = false;
6593
6594var didWarnAboutBadClass = void 0;
6595var didWarnAboutContextTypeOnFunctionComponent = void 0;
6596var didWarnAboutGetDerivedStateOnFunctionComponent = void 0;
6597var didWarnAboutFunctionRefs = void 0;
6598var didWarnAboutReassigningProps = void 0;
6599
6600{
6601 didWarnAboutBadClass = {};
6602 didWarnAboutContextTypeOnFunctionComponent = {};
6603 didWarnAboutGetDerivedStateOnFunctionComponent = {};
6604 didWarnAboutFunctionRefs = {};
6605 didWarnAboutReassigningProps = false;
6606}
6607
6608function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6609 if (current$$1 === null) {
6610 // If this is a fresh new component that hasn't been rendered yet, we
6611 // won't update its child set by applying minimal side-effects. Instead,
6612 // we will add them all to the child before it gets rendered. That means
6613 // we can optimize this reconciliation pass by not tracking side-effects.
6614 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6615 } else {
6616 // If the current child is the same as the work in progress, it means that
6617 // we haven't yet started any work on these children. Therefore, we use
6618 // the clone algorithm to create a copy of all the current children.
6619
6620 // If we had any progressed work already, that is invalid at this point so
6621 // let's throw it out.
6622 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
6623 }
6624}
6625
6626function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6627 // This function is fork of reconcileChildren. It's used in cases where we
6628 // want to reconcile without matching against the existing set. This has the
6629 // effect of all current children being unmounted; even if the type and key
6630 // are the same, the old child is unmounted and a new child is created.
6631 //
6632 // To do this, we're going to go through the reconcile algorithm twice. In
6633 // the first pass, we schedule a deletion for all the current children by
6634 // passing null.
6635 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
6636 // In the second pass, we mount the new children. The trick here is that we
6637 // pass null in place of where we usually pass the current child set. This has
6638 // the effect of remounting all children regardless of whether their their
6639 // identity matches.
6640 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6641}
6642
6643function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6644 // TODO: current can be non-null here even if the component
6645 // hasn't yet mounted. This happens after the first render suspends.
6646 // We'll need to figure out if this is fine or can cause issues.
6647
6648 {
6649 if (workInProgress.type !== workInProgress.elementType) {
6650 // Lazy component props can't be validated in createElement
6651 // because they're only guaranteed to be resolved here.
6652 var innerPropTypes = Component.propTypes;
6653 if (innerPropTypes) {
6654 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6655 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6656 }
6657 }
6658 }
6659
6660 var render = Component.render;
6661 var ref = workInProgress.ref;
6662
6663 // The rest is a fork of updateFunctionComponent
6664 var nextChildren = void 0;
6665 prepareToReadContext(workInProgress, renderExpirationTime);
6666 {
6667 ReactCurrentOwner$2.current = workInProgress;
6668 setCurrentPhase('render');
6669 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6670 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6671 // Only double-render components with Hooks
6672 if (workInProgress.memoizedState !== null) {
6673 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6674 }
6675 }
6676 setCurrentPhase(null);
6677 }
6678
6679 if (current$$1 !== null && !didReceiveUpdate) {
6680 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6681 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6682 }
6683
6684 // React DevTools reads this flag.
6685 workInProgress.effectTag |= PerformedWork;
6686 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6687 return workInProgress.child;
6688}
6689
6690function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6691 if (current$$1 === null) {
6692 var type = Component.type;
6693 if (isSimpleFunctionComponent(type) && Component.compare === null &&
6694 // SimpleMemoComponent codepath doesn't resolve outer props either.
6695 Component.defaultProps === undefined) {
6696 // If this is a plain function component without default props,
6697 // and with only the default shallow comparison, we upgrade it
6698 // to a SimpleMemoComponent to allow fast path updates.
6699 workInProgress.tag = SimpleMemoComponent;
6700 workInProgress.type = type;
6701 {
6702 validateFunctionComponentInDev(workInProgress, type);
6703 }
6704 return updateSimpleMemoComponent(current$$1, workInProgress, type, nextProps, updateExpirationTime, renderExpirationTime);
6705 }
6706 {
6707 var innerPropTypes = type.propTypes;
6708 if (innerPropTypes) {
6709 // Inner memo component props aren't currently validated in createElement.
6710 // We could move it there, but we'd still need this for lazy code path.
6711 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6712 'prop', getComponentName(type), getCurrentFiberStackInDev);
6713 }
6714 }
6715 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
6716 child.ref = workInProgress.ref;
6717 child.return = workInProgress;
6718 workInProgress.child = child;
6719 return child;
6720 }
6721 {
6722 var _type = Component.type;
6723 var _innerPropTypes = _type.propTypes;
6724 if (_innerPropTypes) {
6725 // Inner memo component props aren't currently validated in createElement.
6726 // We could move it there, but we'd still need this for lazy code path.
6727 checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
6728 'prop', getComponentName(_type), getCurrentFiberStackInDev);
6729 }
6730 }
6731 var currentChild = current$$1.child; // This is always exactly one child
6732 if (updateExpirationTime < renderExpirationTime) {
6733 // This will be the props with resolved defaultProps,
6734 // unlike current.memoizedProps which will be the unresolved ones.
6735 var prevProps = currentChild.memoizedProps;
6736 // Default to shallow comparison
6737 var compare = Component.compare;
6738 compare = compare !== null ? compare : shallowEqual;
6739 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6740 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6741 }
6742 }
6743 // React DevTools reads this flag.
6744 workInProgress.effectTag |= PerformedWork;
6745 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
6746 newChild.ref = workInProgress.ref;
6747 newChild.return = workInProgress;
6748 workInProgress.child = newChild;
6749 return newChild;
6750}
6751
6752function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6753 // TODO: current can be non-null here even if the component
6754 // hasn't yet mounted. This happens when the inner render suspends.
6755 // We'll need to figure out if this is fine or can cause issues.
6756
6757 {
6758 if (workInProgress.type !== workInProgress.elementType) {
6759 // Lazy component props can't be validated in createElement
6760 // because they're only guaranteed to be resolved here.
6761 var outerMemoType = workInProgress.elementType;
6762 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
6763 // We warn when you define propTypes on lazy()
6764 // so let's just skip over it to find memo() outer wrapper.
6765 // Inner props for memo are validated later.
6766 outerMemoType = refineResolvedLazyComponent(outerMemoType);
6767 }
6768 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
6769 if (outerPropTypes) {
6770 checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
6771 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
6772 }
6773 // Inner propTypes will be validated in the function component path.
6774 }
6775 }
6776 if (current$$1 !== null) {
6777 var prevProps = current$$1.memoizedProps;
6778 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6779 didReceiveUpdate = false;
6780 if (updateExpirationTime < renderExpirationTime) {
6781 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6782 }
6783 }
6784 }
6785 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6786}
6787
6788function updateFragment(current$$1, workInProgress, renderExpirationTime) {
6789 var nextChildren = workInProgress.pendingProps;
6790 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6791 return workInProgress.child;
6792}
6793
6794function updateMode(current$$1, workInProgress, renderExpirationTime) {
6795 var nextChildren = workInProgress.pendingProps.children;
6796 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6797 return workInProgress.child;
6798}
6799
6800function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
6801 if (enableProfilerTimer) {
6802 workInProgress.effectTag |= Update;
6803 }
6804 var nextProps = workInProgress.pendingProps;
6805 var nextChildren = nextProps.children;
6806 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6807 return workInProgress.child;
6808}
6809
6810function markRef(current$$1, workInProgress) {
6811 var ref = workInProgress.ref;
6812 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
6813 // Schedule a Ref effect
6814 workInProgress.effectTag |= Ref;
6815 }
6816}
6817
6818function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6819 {
6820 if (workInProgress.type !== workInProgress.elementType) {
6821 // Lazy component props can't be validated in createElement
6822 // because they're only guaranteed to be resolved here.
6823 var innerPropTypes = Component.propTypes;
6824 if (innerPropTypes) {
6825 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6826 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6827 }
6828 }
6829 }
6830
6831 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
6832 var context = getMaskedContext(workInProgress, unmaskedContext);
6833
6834 var nextChildren = void 0;
6835 prepareToReadContext(workInProgress, renderExpirationTime);
6836 {
6837 ReactCurrentOwner$2.current = workInProgress;
6838 setCurrentPhase('render');
6839 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6840 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6841 // Only double-render components with Hooks
6842 if (workInProgress.memoizedState !== null) {
6843 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6844 }
6845 }
6846 setCurrentPhase(null);
6847 }
6848
6849 if (current$$1 !== null && !didReceiveUpdate) {
6850 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6851 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6852 }
6853
6854 // React DevTools reads this flag.
6855 workInProgress.effectTag |= PerformedWork;
6856 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6857 return workInProgress.child;
6858}
6859
6860function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6861 {
6862 if (workInProgress.type !== workInProgress.elementType) {
6863 // Lazy component props can't be validated in createElement
6864 // because they're only guaranteed to be resolved here.
6865 var innerPropTypes = Component.propTypes;
6866 if (innerPropTypes) {
6867 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6868 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6869 }
6870 }
6871 }
6872
6873 // Push context providers early to prevent context stack mismatches.
6874 // During mounting we don't know the child context yet as the instance doesn't exist.
6875 // We will invalidate the child context in finishClassComponent() right after rendering.
6876 var hasContext = void 0;
6877 if (isContextProvider(Component)) {
6878 hasContext = true;
6879 pushContextProvider(workInProgress);
6880 } else {
6881 hasContext = false;
6882 }
6883 prepareToReadContext(workInProgress, renderExpirationTime);
6884
6885 var instance = workInProgress.stateNode;
6886 var shouldUpdate = void 0;
6887 if (instance === null) {
6888 if (current$$1 !== null) {
6889 // An class component without an instance only mounts if it suspended
6890 // inside a non- concurrent tree, in an inconsistent state. We want to
6891 // tree it like a new mount, even though an empty version of it already
6892 // committed. Disconnect the alternate pointers.
6893 current$$1.alternate = null;
6894 workInProgress.alternate = null;
6895 // Since this is conceptually a new fiber, schedule a Placement effect
6896 workInProgress.effectTag |= Placement;
6897 }
6898 // In the initial pass we might need to construct the instance.
6899 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6900 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6901 shouldUpdate = true;
6902 } else if (current$$1 === null) {
6903 // In a resume, we'll already have an instance we can reuse.
6904 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6905 } else {
6906 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6907 }
6908 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
6909 {
6910 var inst = workInProgress.stateNode;
6911 if (inst.props !== nextProps) {
6912 !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;
6913 didWarnAboutReassigningProps = true;
6914 }
6915 }
6916 return nextUnitOfWork;
6917}
6918
6919function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
6920 // Refs should update even if shouldComponentUpdate returns false
6921 markRef(current$$1, workInProgress);
6922
6923 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
6924
6925 if (!shouldUpdate && !didCaptureError) {
6926 // Context providers should defer to sCU for rendering
6927 if (hasContext) {
6928 invalidateContextProvider(workInProgress, Component, false);
6929 }
6930
6931 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6932 }
6933
6934 var instance = workInProgress.stateNode;
6935
6936 // Rerender
6937 ReactCurrentOwner$2.current = workInProgress;
6938 var nextChildren = void 0;
6939 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
6940 // If we captured an error, but getDerivedStateFrom catch is not defined,
6941 // unmount all the children. componentDidCatch will schedule an update to
6942 // re-render a fallback. This is temporary until we migrate everyone to
6943 // the new API.
6944 // TODO: Warn in a future release.
6945 nextChildren = null;
6946
6947 if (enableProfilerTimer) {
6948 stopProfilerTimerIfRunning(workInProgress);
6949 }
6950 } else {
6951 {
6952 setCurrentPhase('render');
6953 nextChildren = instance.render();
6954 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6955 instance.render();
6956 }
6957 setCurrentPhase(null);
6958 }
6959 }
6960
6961 // React DevTools reads this flag.
6962 workInProgress.effectTag |= PerformedWork;
6963 if (current$$1 !== null && didCaptureError) {
6964 // If we're recovering from an error, reconcile without reusing any of
6965 // the existing children. Conceptually, the normal children and the children
6966 // that are shown on error are two different sets, so we shouldn't reuse
6967 // normal children even if their identities match.
6968 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
6969 } else {
6970 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6971 }
6972
6973 // Memoize state using the values we just used to render.
6974 // TODO: Restructure so we never read values from the instance.
6975 workInProgress.memoizedState = instance.state;
6976
6977 // The context might have changed so we need to recalculate it.
6978 if (hasContext) {
6979 invalidateContextProvider(workInProgress, Component, true);
6980 }
6981
6982 return workInProgress.child;
6983}
6984
6985function pushHostRootContext(workInProgress) {
6986 var root = workInProgress.stateNode;
6987 if (root.pendingContext) {
6988 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
6989 } else if (root.context) {
6990 // Should always be set
6991 pushTopLevelContextObject(workInProgress, root.context, false);
6992 }
6993 pushHostContainer(workInProgress, root.containerInfo);
6994}
6995
6996function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
6997 pushHostRootContext(workInProgress);
6998 var updateQueue = workInProgress.updateQueue;
6999 !(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;
7000 var nextProps = workInProgress.pendingProps;
7001 var prevState = workInProgress.memoizedState;
7002 var prevChildren = prevState !== null ? prevState.element : null;
7003 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
7004 var nextState = workInProgress.memoizedState;
7005 // Caution: React DevTools currently depends on this property
7006 // being called "element".
7007 var nextChildren = nextState.element;
7008 if (nextChildren === prevChildren) {
7009 // If the state is the same as before, that's a bailout because we had
7010 // no work that expires at this time.
7011 resetHydrationState();
7012 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7013 }
7014 var root = workInProgress.stateNode;
7015 if ((current$$1 === null || current$$1.child === null) && root.hydrate && enterHydrationState(workInProgress)) {
7016 // If we don't have any current children this might be the first pass.
7017 // We always try to hydrate. If this isn't a hydration pass there won't
7018 // be any children to hydrate which is effectively the same thing as
7019 // not hydrating.
7020
7021 // This is a bit of a hack. We track the host root as a placement to
7022 // know that we're currently in a mounting state. That way isMounted
7023 // works as expected. We must reset this before committing.
7024 // TODO: Delete this when we delete isMounted and findDOMNode.
7025 workInProgress.effectTag |= Placement;
7026
7027 // Ensure that children mount into this root without tracking
7028 // side-effects. This ensures that we don't store Placement effects on
7029 // nodes that will be hydrated.
7030 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7031 } else {
7032 // Otherwise reset hydration state in case we aborted and resumed another
7033 // root.
7034 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7035 resetHydrationState();
7036 }
7037 return workInProgress.child;
7038}
7039
7040function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
7041 pushHostContext(workInProgress);
7042
7043 if (current$$1 === null) {
7044 tryToClaimNextHydratableInstance(workInProgress);
7045 }
7046
7047 var type = workInProgress.type;
7048 var nextProps = workInProgress.pendingProps;
7049 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
7050
7051 var nextChildren = nextProps.children;
7052 var isDirectTextChild = shouldSetTextContent(type, nextProps);
7053
7054 if (isDirectTextChild) {
7055 // We special case a direct text child of a host node. This is a common
7056 // case. We won't handle it as a reified child. We will instead handle
7057 // this in the host environment that also have access to this prop. That
7058 // avoids allocating another HostText fiber and traversing it.
7059 nextChildren = null;
7060 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
7061 // If we're switching from a direct text child to a normal child, or to
7062 // empty, we need to schedule the text content to be reset.
7063 workInProgress.effectTag |= ContentReset;
7064 }
7065
7066 markRef(current$$1, workInProgress);
7067
7068 // Check the host config to see if the children are offscreen/hidden.
7069 if (renderExpirationTime !== Never && workInProgress.mode & ConcurrentMode && shouldDeprioritizeSubtree(type, nextProps)) {
7070 // Schedule this fiber to re-render at offscreen priority. Then bailout.
7071 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
7072 return null;
7073 }
7074
7075 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7076 return workInProgress.child;
7077}
7078
7079function updateHostText(current$$1, workInProgress) {
7080 if (current$$1 === null) {
7081 tryToClaimNextHydratableInstance(workInProgress);
7082 }
7083 // Nothing to do here. This is terminal. We'll do the completion step
7084 // immediately after.
7085 return null;
7086}
7087
7088function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
7089 if (_current !== null) {
7090 // An lazy component only mounts if it suspended inside a non-
7091 // concurrent tree, in an inconsistent state. We want to treat it like
7092 // a new mount, even though an empty version of it already committed.
7093 // Disconnect the alternate pointers.
7094 _current.alternate = null;
7095 workInProgress.alternate = null;
7096 // Since this is conceptually a new fiber, schedule a Placement effect
7097 workInProgress.effectTag |= Placement;
7098 }
7099
7100 var props = workInProgress.pendingProps;
7101 // We can't start a User Timing measurement with correct label yet.
7102 // Cancel and resume right after we know the tag.
7103 cancelWorkTimer(workInProgress);
7104 var Component = readLazyComponentType(elementType);
7105 // Store the unwrapped component in the type.
7106 workInProgress.type = Component;
7107 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
7108 startWorkTimer(workInProgress);
7109 var resolvedProps = resolveDefaultProps(Component, props);
7110 var child = void 0;
7111 switch (resolvedTag) {
7112 case FunctionComponent:
7113 {
7114 {
7115 validateFunctionComponentInDev(workInProgress, Component);
7116 }
7117 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7118 break;
7119 }
7120 case ClassComponent:
7121 {
7122 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7123 break;
7124 }
7125 case ForwardRef:
7126 {
7127 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7128 break;
7129 }
7130 case MemoComponent:
7131 {
7132 {
7133 if (workInProgress.type !== workInProgress.elementType) {
7134 var outerPropTypes = Component.propTypes;
7135 if (outerPropTypes) {
7136 checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
7137 'prop', getComponentName(Component), getCurrentFiberStackInDev);
7138 }
7139 }
7140 }
7141 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
7142 updateExpirationTime, renderExpirationTime);
7143 break;
7144 }
7145 default:
7146 {
7147 var hint = '';
7148 {
7149 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
7150 hint = ' Did you wrap a component in React.lazy() more than once?';
7151 }
7152 }
7153 // This message intentionally doesn't mention ForwardRef or MemoComponent
7154 // because the fact that it's a separate type of work is an
7155 // implementation detail.
7156 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);
7157 }
7158 }
7159 return child;
7160}
7161
7162function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
7163 if (_current !== null) {
7164 // An incomplete component only mounts if it suspended inside a non-
7165 // concurrent tree, in an inconsistent state. We want to treat it like
7166 // a new mount, even though an empty version of it already committed.
7167 // Disconnect the alternate pointers.
7168 _current.alternate = null;
7169 workInProgress.alternate = null;
7170 // Since this is conceptually a new fiber, schedule a Placement effect
7171 workInProgress.effectTag |= Placement;
7172 }
7173
7174 // Promote the fiber to a class and try rendering again.
7175 workInProgress.tag = ClassComponent;
7176
7177 // The rest of this function is a fork of `updateClassComponent`
7178
7179 // Push context providers early to prevent context stack mismatches.
7180 // During mounting we don't know the child context yet as the instance doesn't exist.
7181 // We will invalidate the child context in finishClassComponent() right after rendering.
7182 var hasContext = void 0;
7183 if (isContextProvider(Component)) {
7184 hasContext = true;
7185 pushContextProvider(workInProgress);
7186 } else {
7187 hasContext = false;
7188 }
7189 prepareToReadContext(workInProgress, renderExpirationTime);
7190
7191 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7192 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7193
7194 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7195}
7196
7197function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
7198 if (_current !== null) {
7199 // An indeterminate component only mounts if it suspended inside a non-
7200 // concurrent tree, in an inconsistent state. We want to treat it like
7201 // a new mount, even though an empty version of it already committed.
7202 // Disconnect the alternate pointers.
7203 _current.alternate = null;
7204 workInProgress.alternate = null;
7205 // Since this is conceptually a new fiber, schedule a Placement effect
7206 workInProgress.effectTag |= Placement;
7207 }
7208
7209 var props = workInProgress.pendingProps;
7210 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
7211 var context = getMaskedContext(workInProgress, unmaskedContext);
7212
7213 prepareToReadContext(workInProgress, renderExpirationTime);
7214
7215 var value = void 0;
7216
7217 {
7218 if (Component.prototype && typeof Component.prototype.render === 'function') {
7219 var componentName = getComponentName(Component) || 'Unknown';
7220
7221 if (!didWarnAboutBadClass[componentName]) {
7222 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);
7223 didWarnAboutBadClass[componentName] = true;
7224 }
7225 }
7226
7227 if (workInProgress.mode & StrictMode) {
7228 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
7229 }
7230
7231 ReactCurrentOwner$2.current = workInProgress;
7232 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7233 }
7234 // React DevTools reads this flag.
7235 workInProgress.effectTag |= PerformedWork;
7236
7237 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
7238 // Proceed under the assumption that this is a class instance
7239 workInProgress.tag = ClassComponent;
7240
7241 // Throw out any hooks that were used.
7242 resetHooks();
7243
7244 // Push context providers early to prevent context stack mismatches.
7245 // During mounting we don't know the child context yet as the instance doesn't exist.
7246 // We will invalidate the child context in finishClassComponent() right after rendering.
7247 var hasContext = false;
7248 if (isContextProvider(Component)) {
7249 hasContext = true;
7250 pushContextProvider(workInProgress);
7251 } else {
7252 hasContext = false;
7253 }
7254
7255 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
7256
7257 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
7258 if (typeof getDerivedStateFromProps === 'function') {
7259 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
7260 }
7261
7262 adoptClassInstance(workInProgress, value);
7263 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
7264 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7265 } else {
7266 // Proceed under the assumption that this is a function component
7267 workInProgress.tag = FunctionComponent;
7268 {
7269 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
7270 // Only double-render components with Hooks
7271 if (workInProgress.memoizedState !== null) {
7272 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7273 }
7274 }
7275 }
7276 reconcileChildren(null, workInProgress, value, renderExpirationTime);
7277 {
7278 validateFunctionComponentInDev(workInProgress, Component);
7279 }
7280 return workInProgress.child;
7281 }
7282}
7283
7284function validateFunctionComponentInDev(workInProgress, Component) {
7285 if (Component) {
7286 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
7287 }
7288 if (workInProgress.ref !== null) {
7289 var info = '';
7290 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
7291 if (ownerName) {
7292 info += '\n\nCheck the render method of `' + ownerName + '`.';
7293 }
7294
7295 var warningKey = ownerName || workInProgress._debugID || '';
7296 var debugSource = workInProgress._debugSource;
7297 if (debugSource) {
7298 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
7299 }
7300 if (!didWarnAboutFunctionRefs[warningKey]) {
7301 didWarnAboutFunctionRefs[warningKey] = true;
7302 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);
7303 }
7304 }
7305
7306 if (typeof Component.getDerivedStateFromProps === 'function') {
7307 var componentName = getComponentName(Component) || 'Unknown';
7308
7309 if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) {
7310 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', componentName);
7311 didWarnAboutGetDerivedStateOnFunctionComponent[componentName] = true;
7312 }
7313 }
7314
7315 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
7316 var _componentName = getComponentName(Component) || 'Unknown';
7317
7318 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName]) {
7319 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName);
7320 didWarnAboutContextTypeOnFunctionComponent[_componentName] = true;
7321 }
7322 }
7323}
7324
7325function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7326 var mode = workInProgress.mode;
7327 var nextProps = workInProgress.pendingProps;
7328
7329 // We should attempt to render the primary children unless this boundary
7330 // already suspended during this render (`alreadyCaptured` is true).
7331 var nextState = workInProgress.memoizedState;
7332
7333 var nextDidTimeout = void 0;
7334 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7335 // This is the first attempt.
7336 nextState = null;
7337 nextDidTimeout = false;
7338 } else {
7339 // Something in this boundary's subtree already suspended. Switch to
7340 // rendering the fallback children.
7341 nextState = {
7342 timedOutAt: nextState !== null ? nextState.timedOutAt : NoWork
7343 };
7344 nextDidTimeout = true;
7345 workInProgress.effectTag &= ~DidCapture;
7346 }
7347
7348 // This next part is a bit confusing. If the children timeout, we switch to
7349 // showing the fallback children in place of the "primary" children.
7350 // However, we don't want to delete the primary children because then their
7351 // state will be lost (both the React state and the host state, e.g.
7352 // uncontrolled form inputs). Instead we keep them mounted and hide them.
7353 // Both the fallback children AND the primary children are rendered at the
7354 // same time. Once the primary children are un-suspended, we can delete
7355 // the fallback children — don't need to preserve their state.
7356 //
7357 // The two sets of children are siblings in the host environment, but
7358 // semantically, for purposes of reconciliation, they are two separate sets.
7359 // So we store them using two fragment fibers.
7360 //
7361 // However, we want to avoid allocating extra fibers for every placeholder.
7362 // They're only necessary when the children time out, because that's the
7363 // only time when both sets are mounted.
7364 //
7365 // So, the extra fragment fibers are only used if the children time out.
7366 // Otherwise, we render the primary children directly. This requires some
7367 // custom reconciliation logic to preserve the state of the primary
7368 // children. It's essentially a very basic form of re-parenting.
7369
7370 // `child` points to the child fiber. In the normal case, this is the first
7371 // fiber of the primary children set. In the timed-out case, it's a
7372 // a fragment fiber containing the primary children.
7373 var child = void 0;
7374 // `next` points to the next fiber React should render. In the normal case,
7375 // it's the same as `child`: the first fiber of the primary children set.
7376 // In the timed-out case, it's a fragment fiber containing the *fallback*
7377 // children -- we skip over the primary children entirely.
7378 var next = void 0;
7379 if (current$$1 === null) {
7380 if (enableSuspenseServerRenderer) {
7381 // If we're currently hydrating, try to hydrate this boundary.
7382 // But only if this has a fallback.
7383 if (nextProps.fallback !== undefined) {
7384 tryToClaimNextHydratableInstance(workInProgress);
7385 // This could've changed the tag if this was a dehydrated suspense component.
7386 if (workInProgress.tag === DehydratedSuspenseComponent) {
7387 return updateDehydratedSuspenseComponent(null, workInProgress, renderExpirationTime);
7388 }
7389 }
7390 }
7391
7392 // This is the initial mount. This branch is pretty simple because there's
7393 // no previous state that needs to be preserved.
7394 if (nextDidTimeout) {
7395 // Mount separate fragments for primary and fallback children.
7396 var nextFallbackChildren = nextProps.fallback;
7397 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
7398
7399 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7400 // Outside of concurrent mode, we commit the effects from the
7401 var progressedState = workInProgress.memoizedState;
7402 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
7403 primaryChildFragment.child = progressedPrimaryChild;
7404 }
7405
7406 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
7407 primaryChildFragment.sibling = fallbackChildFragment;
7408 child = primaryChildFragment;
7409 // Skip the primary children, and continue working on the
7410 // fallback children.
7411 next = fallbackChildFragment;
7412 child.return = next.return = workInProgress;
7413 } else {
7414 // Mount the primary children without an intermediate fragment fiber.
7415 var nextPrimaryChildren = nextProps.children;
7416 child = next = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
7417 }
7418 } else {
7419 // This is an update. This branch is more complicated because we need to
7420 // ensure the state of the primary children is preserved.
7421 var prevState = current$$1.memoizedState;
7422 var prevDidTimeout = prevState !== null;
7423 if (prevDidTimeout) {
7424 // The current tree already timed out. That means each child set is
7425 var currentPrimaryChildFragment = current$$1.child;
7426 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
7427 if (nextDidTimeout) {
7428 // Still timed out. Reuse the current primary children by cloning
7429 // its fragment. We're going to skip over these entirely.
7430 var _nextFallbackChildren = nextProps.fallback;
7431 var _primaryChildFragment = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
7432
7433 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7434 // Outside of concurrent mode, we commit the effects from the
7435 var _progressedState = workInProgress.memoizedState;
7436 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
7437 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
7438 _primaryChildFragment.child = _progressedPrimaryChild;
7439 }
7440 }
7441
7442 // Because primaryChildFragment is a new fiber that we're inserting as the
7443 // parent of a new tree, we need to set its treeBaseDuration.
7444 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7445 // treeBaseDuration is the sum of all the child tree base durations.
7446 var treeBaseDuration = 0;
7447 var hiddenChild = _primaryChildFragment.child;
7448 while (hiddenChild !== null) {
7449 treeBaseDuration += hiddenChild.treeBaseDuration;
7450 hiddenChild = hiddenChild.sibling;
7451 }
7452 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
7453 }
7454
7455 // Clone the fallback child fragment, too. These we'll continue
7456 // working on.
7457 var _fallbackChildFragment = _primaryChildFragment.sibling = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren, currentFallbackChildFragment.expirationTime);
7458 child = _primaryChildFragment;
7459 _primaryChildFragment.childExpirationTime = NoWork;
7460 // Skip the primary children, and continue working on the
7461 // fallback children.
7462 next = _fallbackChildFragment;
7463 child.return = next.return = workInProgress;
7464 } else {
7465 // No longer suspended. Switch back to showing the primary children,
7466 // and remove the intermediate fragment fiber.
7467 var _nextPrimaryChildren = nextProps.children;
7468 var currentPrimaryChild = currentPrimaryChildFragment.child;
7469 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime);
7470
7471 // If this render doesn't suspend, we need to delete the fallback
7472 // children. Wait until the complete phase, after we've confirmed the
7473 // fallback is no longer needed.
7474 // TODO: Would it be better to store the fallback fragment on
7475 // the stateNode?
7476
7477 // Continue rendering the children, like we normally do.
7478 child = next = primaryChild;
7479 }
7480 } else {
7481 // The current tree has not already timed out. That means the primary
7482 // children are not wrapped in a fragment fiber.
7483 var _currentPrimaryChild = current$$1.child;
7484 if (nextDidTimeout) {
7485 // Timed out. Wrap the children in a fragment fiber to keep them
7486 // separate from the fallback children.
7487 var _nextFallbackChildren2 = nextProps.fallback;
7488 var _primaryChildFragment2 = createFiberFromFragment(
7489 // It shouldn't matter what the pending props are because we aren't
7490 // going to render this fragment.
7491 null, mode, NoWork, null);
7492 _primaryChildFragment2.child = _currentPrimaryChild;
7493
7494 // Even though we're creating a new fiber, there are no new children,
7495 // because we're reusing an already mounted tree. So we don't need to
7496 // schedule a placement.
7497 // primaryChildFragment.effectTag |= Placement;
7498
7499 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7500 // Outside of concurrent mode, we commit the effects from the
7501 var _progressedState2 = workInProgress.memoizedState;
7502 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
7503 _primaryChildFragment2.child = _progressedPrimaryChild2;
7504 }
7505
7506 // Because primaryChildFragment is a new fiber that we're inserting as the
7507 // parent of a new tree, we need to set its treeBaseDuration.
7508 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7509 // treeBaseDuration is the sum of all the child tree base durations.
7510 var _treeBaseDuration = 0;
7511 var _hiddenChild = _primaryChildFragment2.child;
7512 while (_hiddenChild !== null) {
7513 _treeBaseDuration += _hiddenChild.treeBaseDuration;
7514 _hiddenChild = _hiddenChild.sibling;
7515 }
7516 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
7517 }
7518
7519 // Create a fragment from the fallback children, too.
7520 var _fallbackChildFragment2 = _primaryChildFragment2.sibling = createFiberFromFragment(_nextFallbackChildren2, mode, renderExpirationTime, null);
7521 _fallbackChildFragment2.effectTag |= Placement;
7522 child = _primaryChildFragment2;
7523 _primaryChildFragment2.childExpirationTime = NoWork;
7524 // Skip the primary children, and continue working on the
7525 // fallback children.
7526 next = _fallbackChildFragment2;
7527 child.return = next.return = workInProgress;
7528 } else {
7529 // Still haven't timed out. Continue rendering the children, like we
7530 // normally do.
7531 var _nextPrimaryChildren2 = nextProps.children;
7532 next = child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
7533 }
7534 }
7535 workInProgress.stateNode = current$$1.stateNode;
7536 }
7537
7538 workInProgress.memoizedState = nextState;
7539 workInProgress.child = child;
7540 return next;
7541}
7542
7543function updateDehydratedSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7544 if (current$$1 === null) {
7545 // During the first pass, we'll bail out and not drill into the children.
7546 // Instead, we'll leave the content in place and try to hydrate it later.
7547 workInProgress.expirationTime = Never;
7548 return null;
7549 }
7550 // We use childExpirationTime to indicate that a child might depend on context, so if
7551 // any context has changed, we need to treat is as if the input might have changed.
7552 var hasContextChanged$$1 = current$$1.childExpirationTime >= renderExpirationTime;
7553 if (didReceiveUpdate || hasContextChanged$$1) {
7554 // This boundary has changed since the first render. This means that we are now unable to
7555 // hydrate it. We might still be able to hydrate it using an earlier expiration time but
7556 // during this render we can't. Instead, we're going to delete the whole subtree and
7557 // instead inject a new real Suspense boundary to take its place, which may render content
7558 // or fallback. The real Suspense boundary will suspend for a while so we have some time
7559 // to ensure it can produce real content, but all state and pending events will be lost.
7560
7561 // Detach from the current dehydrated boundary.
7562 current$$1.alternate = null;
7563 workInProgress.alternate = null;
7564
7565 // Insert a deletion in the effect list.
7566 var returnFiber = workInProgress.return;
7567 !(returnFiber !== null) ? invariant(false, 'Suspense boundaries are never on the root. This is probably a bug in React.') : void 0;
7568 var last = returnFiber.lastEffect;
7569 if (last !== null) {
7570 last.nextEffect = current$$1;
7571 returnFiber.lastEffect = current$$1;
7572 } else {
7573 returnFiber.firstEffect = returnFiber.lastEffect = current$$1;
7574 }
7575 current$$1.nextEffect = null;
7576 current$$1.effectTag = Deletion;
7577
7578 // Upgrade this work in progress to a real Suspense component.
7579 workInProgress.tag = SuspenseComponent;
7580 workInProgress.stateNode = null;
7581 workInProgress.memoizedState = null;
7582 // This is now an insertion.
7583 workInProgress.effectTag |= Placement;
7584 // Retry as a real Suspense component.
7585 return updateSuspenseComponent(null, workInProgress, renderExpirationTime);
7586 }
7587 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7588 // This is the first attempt.
7589 reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress);
7590 var nextProps = workInProgress.pendingProps;
7591 var nextChildren = nextProps.children;
7592 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7593 return workInProgress.child;
7594 } else {
7595 // Something suspended. Leave the existing children in place.
7596 // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far?
7597 workInProgress.child = null;
7598 return null;
7599 }
7600}
7601
7602function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
7603 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7604 var nextChildren = workInProgress.pendingProps;
7605 if (current$$1 === null) {
7606 // Portals are special because we don't append the children during mount
7607 // but at commit. Therefore we need to track insertions which the normal
7608 // flow doesn't do during mount. This doesn't happen at the root because
7609 // the root always starts with a "current" with a null child.
7610 // TODO: Consider unifying this with how the root works.
7611 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7612 } else {
7613 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7614 }
7615 return workInProgress.child;
7616}
7617
7618function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
7619 var providerType = workInProgress.type;
7620 var context = providerType._context;
7621
7622 var newProps = workInProgress.pendingProps;
7623 var oldProps = workInProgress.memoizedProps;
7624
7625 var newValue = newProps.value;
7626
7627 {
7628 var providerPropTypes = workInProgress.type.propTypes;
7629
7630 if (providerPropTypes) {
7631 checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
7632 }
7633 }
7634
7635 pushProvider(workInProgress, newValue);
7636
7637 if (oldProps !== null) {
7638 var oldValue = oldProps.value;
7639 var changedBits = calculateChangedBits(context, newValue, oldValue);
7640 if (changedBits === 0) {
7641 // No change. Bailout early if children are the same.
7642 if (oldProps.children === newProps.children && !hasContextChanged()) {
7643 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7644 }
7645 } else {
7646 // The context value changed. Search for matching consumers and schedule
7647 // them to update.
7648 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
7649 }
7650 }
7651
7652 var newChildren = newProps.children;
7653 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7654 return workInProgress.child;
7655}
7656
7657var hasWarnedAboutUsingContextAsConsumer = false;
7658
7659function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
7660 var context = workInProgress.type;
7661 // The logic below for Context differs depending on PROD or DEV mode. In
7662 // DEV mode, we create a separate object for Context.Consumer that acts
7663 // like a proxy to Context. This proxy object adds unnecessary code in PROD
7664 // so we use the old behaviour (Context.Consumer references Context) to
7665 // reduce size and overhead. The separate object references context via
7666 // a property called "_context", which also gives us the ability to check
7667 // in DEV mode if this property exists or not and warn if it does not.
7668 {
7669 if (context._context === undefined) {
7670 // This may be because it's a Context (rather than a Consumer).
7671 // Or it may be because it's older React where they're the same thing.
7672 // We only want to warn if we're sure it's a new React.
7673 if (context !== context.Consumer) {
7674 if (!hasWarnedAboutUsingContextAsConsumer) {
7675 hasWarnedAboutUsingContextAsConsumer = true;
7676 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?');
7677 }
7678 }
7679 } else {
7680 context = context._context;
7681 }
7682 }
7683 var newProps = workInProgress.pendingProps;
7684 var render = newProps.children;
7685
7686 {
7687 !(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;
7688 }
7689
7690 prepareToReadContext(workInProgress, renderExpirationTime);
7691 var newValue = readContext(context, newProps.unstable_observedBits);
7692 var newChildren = void 0;
7693 {
7694 ReactCurrentOwner$2.current = workInProgress;
7695 setCurrentPhase('render');
7696 newChildren = render(newValue);
7697 setCurrentPhase(null);
7698 }
7699
7700 // React DevTools reads this flag.
7701 workInProgress.effectTag |= PerformedWork;
7702 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7703 return workInProgress.child;
7704}
7705
7706function markWorkInProgressReceivedUpdate() {
7707 didReceiveUpdate = true;
7708}
7709
7710function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
7711 cancelWorkTimer(workInProgress);
7712
7713 if (current$$1 !== null) {
7714 // Reuse previous context list
7715 workInProgress.contextDependencies = current$$1.contextDependencies;
7716 }
7717
7718 if (enableProfilerTimer) {
7719 // Don't update "base" render times for bailouts.
7720 stopProfilerTimerIfRunning(workInProgress);
7721 }
7722
7723 // Check if the children have any pending work.
7724 var childExpirationTime = workInProgress.childExpirationTime;
7725 if (childExpirationTime < renderExpirationTime) {
7726 // The children don't have any work either. We can skip them.
7727 // TODO: Once we add back resuming, we should check if the children are
7728 // a work-in-progress set. If so, we need to transfer their effects.
7729 return null;
7730 } else {
7731 // This fiber doesn't have work, but its subtree does. Clone the child
7732 // fibers and continue.
7733 cloneChildFibers(current$$1, workInProgress);
7734 return workInProgress.child;
7735 }
7736}
7737
7738function beginWork(current$$1, workInProgress, renderExpirationTime) {
7739 var updateExpirationTime = workInProgress.expirationTime;
7740
7741 if (current$$1 !== null) {
7742 var oldProps = current$$1.memoizedProps;
7743 var newProps = workInProgress.pendingProps;
7744
7745 if (oldProps !== newProps || hasContextChanged()) {
7746 // If props or context changed, mark the fiber as having performed work.
7747 // This may be unset if the props are determined to be equal later (memo).
7748 didReceiveUpdate = true;
7749 } else if (updateExpirationTime < renderExpirationTime) {
7750 didReceiveUpdate = false;
7751 // This fiber does not have any pending work. Bailout without entering
7752 // the begin phase. There's still some bookkeeping we that needs to be done
7753 // in this optimized path, mostly pushing stuff onto the stack.
7754 switch (workInProgress.tag) {
7755 case HostRoot:
7756 pushHostRootContext(workInProgress);
7757 resetHydrationState();
7758 break;
7759 case HostComponent:
7760 pushHostContext(workInProgress);
7761 break;
7762 case ClassComponent:
7763 {
7764 var Component = workInProgress.type;
7765 if (isContextProvider(Component)) {
7766 pushContextProvider(workInProgress);
7767 }
7768 break;
7769 }
7770 case HostPortal:
7771 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7772 break;
7773 case ContextProvider:
7774 {
7775 var newValue = workInProgress.memoizedProps.value;
7776 pushProvider(workInProgress, newValue);
7777 break;
7778 }
7779 case Profiler:
7780 if (enableProfilerTimer) {
7781 workInProgress.effectTag |= Update;
7782 }
7783 break;
7784 case SuspenseComponent:
7785 {
7786 var state = workInProgress.memoizedState;
7787 var didTimeout = state !== null;
7788 if (didTimeout) {
7789 // If this boundary is currently timed out, we need to decide
7790 // whether to retry the primary children, or to skip over it and
7791 // go straight to the fallback. Check the priority of the primary
7792 var primaryChildFragment = workInProgress.child;
7793 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
7794 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
7795 // The primary children have pending work. Use the normal path
7796 // to attempt to render the primary children again.
7797 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7798 } else {
7799 // The primary children do not have pending work with sufficient
7800 // priority. Bailout.
7801 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7802 if (child !== null) {
7803 // The fallback children have pending work. Skip over the
7804 // primary children and work on the fallback.
7805 return child.sibling;
7806 } else {
7807 return null;
7808 }
7809 }
7810 }
7811 break;
7812 }
7813 case DehydratedSuspenseComponent:
7814 {
7815 if (enableSuspenseServerRenderer) {
7816 // We know that this component will suspend again because if it has
7817 // been unsuspended it has committed as a regular Suspense component.
7818 // If it needs to be retried, it should have work scheduled on it.
7819 workInProgress.effectTag |= DidCapture;
7820 break;
7821 }
7822 }
7823 }
7824 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7825 }
7826 } else {
7827 didReceiveUpdate = false;
7828 }
7829
7830 // Before entering the begin phase, clear the expiration time.
7831 workInProgress.expirationTime = NoWork;
7832
7833 switch (workInProgress.tag) {
7834 case IndeterminateComponent:
7835 {
7836 var elementType = workInProgress.elementType;
7837 return mountIndeterminateComponent(current$$1, workInProgress, elementType, renderExpirationTime);
7838 }
7839 case LazyComponent:
7840 {
7841 var _elementType = workInProgress.elementType;
7842 return mountLazyComponent(current$$1, workInProgress, _elementType, updateExpirationTime, renderExpirationTime);
7843 }
7844 case FunctionComponent:
7845 {
7846 var _Component = workInProgress.type;
7847 var unresolvedProps = workInProgress.pendingProps;
7848 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
7849 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
7850 }
7851 case ClassComponent:
7852 {
7853 var _Component2 = workInProgress.type;
7854 var _unresolvedProps = workInProgress.pendingProps;
7855 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
7856 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
7857 }
7858 case HostRoot:
7859 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
7860 case HostComponent:
7861 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
7862 case HostText:
7863 return updateHostText(current$$1, workInProgress);
7864 case SuspenseComponent:
7865 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7866 case HostPortal:
7867 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
7868 case ForwardRef:
7869 {
7870 var type = workInProgress.type;
7871 var _unresolvedProps2 = workInProgress.pendingProps;
7872 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
7873 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
7874 }
7875 case Fragment:
7876 return updateFragment(current$$1, workInProgress, renderExpirationTime);
7877 case Mode:
7878 return updateMode(current$$1, workInProgress, renderExpirationTime);
7879 case Profiler:
7880 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
7881 case ContextProvider:
7882 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
7883 case ContextConsumer:
7884 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
7885 case MemoComponent:
7886 {
7887 var _type2 = workInProgress.type;
7888 var _unresolvedProps3 = workInProgress.pendingProps;
7889 // Resolve outer props first, then resolve inner props.
7890 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
7891 {
7892 if (workInProgress.type !== workInProgress.elementType) {
7893 var outerPropTypes = _type2.propTypes;
7894 if (outerPropTypes) {
7895 checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
7896 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
7897 }
7898 }
7899 }
7900 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
7901 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
7902 }
7903 case SimpleMemoComponent:
7904 {
7905 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
7906 }
7907 case IncompleteClassComponent:
7908 {
7909 var _Component3 = workInProgress.type;
7910 var _unresolvedProps4 = workInProgress.pendingProps;
7911 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
7912 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
7913 }
7914 case DehydratedSuspenseComponent:
7915 {
7916 if (enableSuspenseServerRenderer) {
7917 return updateDehydratedSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7918 }
7919 break;
7920 }
7921 }
7922 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
7923}
7924
7925var valueCursor = createCursor(null);
7926
7927var rendererSigil = void 0;
7928{
7929 // Use this to detect multiple renderers using the same context
7930 rendererSigil = {};
7931}
7932
7933var currentlyRenderingFiber = null;
7934var lastContextDependency = null;
7935var lastContextWithAllBitsObserved = null;
7936
7937var isDisallowedContextReadInDEV = false;
7938
7939function resetContextDependences() {
7940 // This is called right before React yields execution, to ensure `readContext`
7941 // cannot be called outside the render phase.
7942 currentlyRenderingFiber = null;
7943 lastContextDependency = null;
7944 lastContextWithAllBitsObserved = null;
7945 {
7946 isDisallowedContextReadInDEV = false;
7947 }
7948}
7949
7950function enterDisallowedContextReadInDEV() {
7951 {
7952 isDisallowedContextReadInDEV = true;
7953 }
7954}
7955
7956function exitDisallowedContextReadInDEV() {
7957 {
7958 isDisallowedContextReadInDEV = false;
7959 }
7960}
7961
7962function pushProvider(providerFiber, nextValue) {
7963 var context = providerFiber.type._context;
7964
7965 if (isPrimaryRenderer) {
7966 push(valueCursor, context._currentValue, providerFiber);
7967
7968 context._currentValue = nextValue;
7969 {
7970 !(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;
7971 context._currentRenderer = rendererSigil;
7972 }
7973 } else {
7974 push(valueCursor, context._currentValue2, providerFiber);
7975
7976 context._currentValue2 = nextValue;
7977 {
7978 !(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;
7979 context._currentRenderer2 = rendererSigil;
7980 }
7981 }
7982}
7983
7984function popProvider(providerFiber) {
7985 var currentValue = valueCursor.current;
7986
7987 pop(valueCursor, providerFiber);
7988
7989 var context = providerFiber.type._context;
7990 if (isPrimaryRenderer) {
7991 context._currentValue = currentValue;
7992 } else {
7993 context._currentValue2 = currentValue;
7994 }
7995}
7996
7997function calculateChangedBits(context, newValue, oldValue) {
7998 if (is(oldValue, newValue)) {
7999 // No change
8000 return 0;
8001 } else {
8002 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : maxSigned31BitInt;
8003
8004 {
8005 !((changedBits & maxSigned31BitInt) === changedBits) ? warning$1(false, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits) : void 0;
8006 }
8007 return changedBits | 0;
8008 }
8009}
8010
8011function scheduleWorkOnParentPath(parent, renderExpirationTime) {
8012 // Update the child expiration time of all the ancestors, including
8013 // the alternates.
8014 var node = parent;
8015 while (node !== null) {
8016 var alternate = node.alternate;
8017 if (node.childExpirationTime < renderExpirationTime) {
8018 node.childExpirationTime = renderExpirationTime;
8019 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
8020 alternate.childExpirationTime = renderExpirationTime;
8021 }
8022 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
8023 alternate.childExpirationTime = renderExpirationTime;
8024 } else {
8025 // Neither alternate was updated, which means the rest of the
8026 // ancestor path already has sufficient priority.
8027 break;
8028 }
8029 node = node.return;
8030 }
8031}
8032
8033function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
8034 var fiber = workInProgress.child;
8035 if (fiber !== null) {
8036 // Set the return pointer of the child to the work-in-progress fiber.
8037 fiber.return = workInProgress;
8038 }
8039 while (fiber !== null) {
8040 var nextFiber = void 0;
8041
8042 // Visit this fiber.
8043 var list = fiber.contextDependencies;
8044 if (list !== null) {
8045 nextFiber = fiber.child;
8046
8047 var dependency = list.first;
8048 while (dependency !== null) {
8049 // Check if the context matches.
8050 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
8051 // Match! Schedule an update on this fiber.
8052
8053 if (fiber.tag === ClassComponent) {
8054 // Schedule a force update on the work-in-progress.
8055 var update = createUpdate(renderExpirationTime);
8056 update.tag = ForceUpdate;
8057 // TODO: Because we don't have a work-in-progress, this will add the
8058 // update to the current fiber, too, which means it will persist even if
8059 // this render is thrown away. Since it's a race condition, not sure it's
8060 // worth fixing.
8061 enqueueUpdate(fiber, update);
8062 }
8063
8064 if (fiber.expirationTime < renderExpirationTime) {
8065 fiber.expirationTime = renderExpirationTime;
8066 }
8067 var alternate = fiber.alternate;
8068 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
8069 alternate.expirationTime = renderExpirationTime;
8070 }
8071
8072 scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
8073
8074 // Mark the expiration time on the list, too.
8075 if (list.expirationTime < renderExpirationTime) {
8076 list.expirationTime = renderExpirationTime;
8077 }
8078
8079 // Since we already found a match, we can stop traversing the
8080 // dependency list.
8081 break;
8082 }
8083 dependency = dependency.next;
8084 }
8085 } else if (fiber.tag === ContextProvider) {
8086 // Don't scan deeper if this is a matching provider
8087 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
8088 } else if (enableSuspenseServerRenderer && fiber.tag === DehydratedSuspenseComponent) {
8089 // If a dehydrated suspense component is in this subtree, we don't know
8090 // if it will have any context consumers in it. The best we can do is
8091 // mark it as having updates on its children.
8092 if (fiber.expirationTime < renderExpirationTime) {
8093 fiber.expirationTime = renderExpirationTime;
8094 }
8095 var _alternate = fiber.alternate;
8096 if (_alternate !== null && _alternate.expirationTime < renderExpirationTime) {
8097 _alternate.expirationTime = renderExpirationTime;
8098 }
8099 // This is intentionally passing this fiber as the parent
8100 // because we want to schedule this fiber as having work
8101 // on its children. We'll use the childExpirationTime on
8102 // this fiber to indicate that a context has changed.
8103 scheduleWorkOnParentPath(fiber, renderExpirationTime);
8104 nextFiber = fiber.sibling;
8105 } else {
8106 // Traverse down.
8107 nextFiber = fiber.child;
8108 }
8109
8110 if (nextFiber !== null) {
8111 // Set the return pointer of the child to the work-in-progress fiber.
8112 nextFiber.return = fiber;
8113 } else {
8114 // No child. Traverse to next sibling.
8115 nextFiber = fiber;
8116 while (nextFiber !== null) {
8117 if (nextFiber === workInProgress) {
8118 // We're back to the root of this subtree. Exit.
8119 nextFiber = null;
8120 break;
8121 }
8122 var sibling = nextFiber.sibling;
8123 if (sibling !== null) {
8124 // Set the return pointer of the sibling to the work-in-progress fiber.
8125 sibling.return = nextFiber.return;
8126 nextFiber = sibling;
8127 break;
8128 }
8129 // No more siblings. Traverse up.
8130 nextFiber = nextFiber.return;
8131 }
8132 }
8133 fiber = nextFiber;
8134 }
8135}
8136
8137function prepareToReadContext(workInProgress, renderExpirationTime) {
8138 currentlyRenderingFiber = workInProgress;
8139 lastContextDependency = null;
8140 lastContextWithAllBitsObserved = null;
8141
8142 var currentDependencies = workInProgress.contextDependencies;
8143 if (currentDependencies !== null && currentDependencies.expirationTime >= renderExpirationTime) {
8144 // Context list has a pending update. Mark that this fiber performed work.
8145 markWorkInProgressReceivedUpdate();
8146 }
8147
8148 // Reset the work-in-progress list
8149 workInProgress.contextDependencies = null;
8150}
8151
8152function readContext(context, observedBits) {
8153 {
8154 // This warning would fire if you read context inside a Hook like useMemo.
8155 // Unlike the class check below, it's not enforced in production for perf.
8156 !!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;
8157 }
8158
8159 if (lastContextWithAllBitsObserved === context) {
8160 // Nothing to do. We already observe everything in this context.
8161 } else if (observedBits === false || observedBits === 0) {
8162 // Do not observe any updates.
8163 } else {
8164 var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types.
8165 if (typeof observedBits !== 'number' || observedBits === maxSigned31BitInt) {
8166 // Observe all updates.
8167 lastContextWithAllBitsObserved = context;
8168 resolvedObservedBits = maxSigned31BitInt;
8169 } else {
8170 resolvedObservedBits = observedBits;
8171 }
8172
8173 var contextItem = {
8174 context: context,
8175 observedBits: resolvedObservedBits,
8176 next: null
8177 };
8178
8179 if (lastContextDependency === null) {
8180 !(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;
8181
8182 // This is the first dependency for this component. Create a new list.
8183 lastContextDependency = contextItem;
8184 currentlyRenderingFiber.contextDependencies = {
8185 first: contextItem,
8186 expirationTime: NoWork
8187 };
8188 } else {
8189 // Append a new context item.
8190 lastContextDependency = lastContextDependency.next = contextItem;
8191 }
8192 }
8193 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
8194}
8195
8196// UpdateQueue is a linked list of prioritized updates.
8197//
8198// Like fibers, update queues come in pairs: a current queue, which represents
8199// the visible state of the screen, and a work-in-progress queue, which can be
8200// mutated and processed asynchronously before it is committed — a form of
8201// double buffering. If a work-in-progress render is discarded before finishing,
8202// we create a new work-in-progress by cloning the current queue.
8203//
8204// Both queues share a persistent, singly-linked list structure. To schedule an
8205// update, we append it to the end of both queues. Each queue maintains a
8206// pointer to first update in the persistent list that hasn't been processed.
8207// The work-in-progress pointer always has a position equal to or greater than
8208// the current queue, since we always work on that one. The current queue's
8209// pointer is only updated during the commit phase, when we swap in the
8210// work-in-progress.
8211//
8212// For example:
8213//
8214// Current pointer: A - B - C - D - E - F
8215// Work-in-progress pointer: D - E - F
8216// ^
8217// The work-in-progress queue has
8218// processed more updates than current.
8219//
8220// The reason we append to both queues is because otherwise we might drop
8221// updates without ever processing them. For example, if we only add updates to
8222// the work-in-progress queue, some updates could be lost whenever a work-in
8223// -progress render restarts by cloning from current. Similarly, if we only add
8224// updates to the current queue, the updates will be lost whenever an already
8225// in-progress queue commits and swaps with the current queue. However, by
8226// adding to both queues, we guarantee that the update will be part of the next
8227// work-in-progress. (And because the work-in-progress queue becomes the
8228// current queue once it commits, there's no danger of applying the same
8229// update twice.)
8230//
8231// Prioritization
8232// --------------
8233//
8234// Updates are not sorted by priority, but by insertion; new updates are always
8235// appended to the end of the list.
8236//
8237// The priority is still important, though. When processing the update queue
8238// during the render phase, only the updates with sufficient priority are
8239// included in the result. If we skip an update because it has insufficient
8240// priority, it remains in the queue to be processed later, during a lower
8241// priority render. Crucially, all updates subsequent to a skipped update also
8242// remain in the queue *regardless of their priority*. That means high priority
8243// updates are sometimes processed twice, at two separate priorities. We also
8244// keep track of a base state, that represents the state before the first
8245// update in the queue is applied.
8246//
8247// For example:
8248//
8249// Given a base state of '', and the following queue of updates
8250//
8251// A1 - B2 - C1 - D2
8252//
8253// where the number indicates the priority, and the update is applied to the
8254// previous state by appending a letter, React will process these updates as
8255// two separate renders, one per distinct priority level:
8256//
8257// First render, at priority 1:
8258// Base state: ''
8259// Updates: [A1, C1]
8260// Result state: 'AC'
8261//
8262// Second render, at priority 2:
8263// Base state: 'A' <- The base state does not include C1,
8264// because B2 was skipped.
8265// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
8266// Result state: 'ABCD'
8267//
8268// Because we process updates in insertion order, and rebase high priority
8269// updates when preceding updates are skipped, the final result is deterministic
8270// regardless of priority. Intermediate state may vary according to system
8271// resources, but the final state is always the same.
8272
8273var UpdateState = 0;
8274var ReplaceState = 1;
8275var ForceUpdate = 2;
8276var CaptureUpdate = 3;
8277
8278// Global state that is reset at the beginning of calling `processUpdateQueue`.
8279// It should only be read right after calling `processUpdateQueue`, via
8280// `checkHasForceUpdateAfterProcessing`.
8281var hasForceUpdate = false;
8282
8283var didWarnUpdateInsideUpdate = void 0;
8284var currentlyProcessingQueue = void 0;
8285var resetCurrentlyProcessingQueue = void 0;
8286{
8287 didWarnUpdateInsideUpdate = false;
8288 currentlyProcessingQueue = null;
8289 resetCurrentlyProcessingQueue = function () {
8290 currentlyProcessingQueue = null;
8291 };
8292}
8293
8294function createUpdateQueue(baseState) {
8295 var queue = {
8296 baseState: baseState,
8297 firstUpdate: null,
8298 lastUpdate: null,
8299 firstCapturedUpdate: null,
8300 lastCapturedUpdate: null,
8301 firstEffect: null,
8302 lastEffect: null,
8303 firstCapturedEffect: null,
8304 lastCapturedEffect: null
8305 };
8306 return queue;
8307}
8308
8309function cloneUpdateQueue(currentQueue) {
8310 var queue = {
8311 baseState: currentQueue.baseState,
8312 firstUpdate: currentQueue.firstUpdate,
8313 lastUpdate: currentQueue.lastUpdate,
8314
8315 // TODO: With resuming, if we bail out and resuse the child tree, we should
8316 // keep these effects.
8317 firstCapturedUpdate: null,
8318 lastCapturedUpdate: null,
8319
8320 firstEffect: null,
8321 lastEffect: null,
8322
8323 firstCapturedEffect: null,
8324 lastCapturedEffect: null
8325 };
8326 return queue;
8327}
8328
8329function createUpdate(expirationTime) {
8330 return {
8331 expirationTime: expirationTime,
8332
8333 tag: UpdateState,
8334 payload: null,
8335 callback: null,
8336
8337 next: null,
8338 nextEffect: null
8339 };
8340}
8341
8342function appendUpdateToQueue(queue, update) {
8343 // Append the update to the end of the list.
8344 if (queue.lastUpdate === null) {
8345 // Queue is empty
8346 queue.firstUpdate = queue.lastUpdate = update;
8347 } else {
8348 queue.lastUpdate.next = update;
8349 queue.lastUpdate = update;
8350 }
8351}
8352
8353function enqueueUpdate(fiber, update) {
8354 // Update queues are created lazily.
8355 var alternate = fiber.alternate;
8356 var queue1 = void 0;
8357 var queue2 = void 0;
8358 if (alternate === null) {
8359 // There's only one fiber.
8360 queue1 = fiber.updateQueue;
8361 queue2 = null;
8362 if (queue1 === null) {
8363 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8364 }
8365 } else {
8366 // There are two owners.
8367 queue1 = fiber.updateQueue;
8368 queue2 = alternate.updateQueue;
8369 if (queue1 === null) {
8370 if (queue2 === null) {
8371 // Neither fiber has an update queue. Create new ones.
8372 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8373 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
8374 } else {
8375 // Only one fiber has an update queue. Clone to create a new one.
8376 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
8377 }
8378 } else {
8379 if (queue2 === null) {
8380 // Only one fiber has an update queue. Clone to create a new one.
8381 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
8382 } else {
8383 // Both owners have an update queue.
8384 }
8385 }
8386 }
8387 if (queue2 === null || queue1 === queue2) {
8388 // There's only a single queue.
8389 appendUpdateToQueue(queue1, update);
8390 } else {
8391 // There are two queues. We need to append the update to both queues,
8392 // while accounting for the persistent structure of the list — we don't
8393 // want the same update to be added multiple times.
8394 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
8395 // One of the queues is not empty. We must add the update to both queues.
8396 appendUpdateToQueue(queue1, update);
8397 appendUpdateToQueue(queue2, update);
8398 } else {
8399 // Both queues are non-empty. The last update is the same in both lists,
8400 // because of structural sharing. So, only append to one of the lists.
8401 appendUpdateToQueue(queue1, update);
8402 // But we still need to update the `lastUpdate` pointer of queue2.
8403 queue2.lastUpdate = update;
8404 }
8405 }
8406
8407 {
8408 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
8409 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.');
8410 didWarnUpdateInsideUpdate = true;
8411 }
8412 }
8413}
8414
8415function enqueueCapturedUpdate(workInProgress, update) {
8416 // Captured updates go into a separate list, and only on the work-in-
8417 // progress queue.
8418 var workInProgressQueue = workInProgress.updateQueue;
8419 if (workInProgressQueue === null) {
8420 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
8421 } else {
8422 // TODO: I put this here rather than createWorkInProgress so that we don't
8423 // clone the queue unnecessarily. There's probably a better way to
8424 // structure this.
8425 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
8426 }
8427
8428 // Append the update to the end of the list.
8429 if (workInProgressQueue.lastCapturedUpdate === null) {
8430 // This is the first render phase update
8431 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
8432 } else {
8433 workInProgressQueue.lastCapturedUpdate.next = update;
8434 workInProgressQueue.lastCapturedUpdate = update;
8435 }
8436}
8437
8438function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
8439 var current = workInProgress.alternate;
8440 if (current !== null) {
8441 // If the work-in-progress queue is equal to the current queue,
8442 // we need to clone it first.
8443 if (queue === current.updateQueue) {
8444 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
8445 }
8446 }
8447 return queue;
8448}
8449
8450function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
8451 switch (update.tag) {
8452 case ReplaceState:
8453 {
8454 var _payload = update.payload;
8455 if (typeof _payload === 'function') {
8456 // Updater function
8457 {
8458 enterDisallowedContextReadInDEV();
8459 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8460 _payload.call(instance, prevState, nextProps);
8461 }
8462 }
8463 var nextState = _payload.call(instance, prevState, nextProps);
8464 {
8465 exitDisallowedContextReadInDEV();
8466 }
8467 return nextState;
8468 }
8469 // State object
8470 return _payload;
8471 }
8472 case CaptureUpdate:
8473 {
8474 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
8475 }
8476 // Intentional fallthrough
8477 case UpdateState:
8478 {
8479 var _payload2 = update.payload;
8480 var partialState = void 0;
8481 if (typeof _payload2 === 'function') {
8482 // Updater function
8483 {
8484 enterDisallowedContextReadInDEV();
8485 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8486 _payload2.call(instance, prevState, nextProps);
8487 }
8488 }
8489 partialState = _payload2.call(instance, prevState, nextProps);
8490 {
8491 exitDisallowedContextReadInDEV();
8492 }
8493 } else {
8494 // Partial state object
8495 partialState = _payload2;
8496 }
8497 if (partialState === null || partialState === undefined) {
8498 // Null and undefined are treated as no-ops.
8499 return prevState;
8500 }
8501 // Merge the partial state and the previous state.
8502 return _assign({}, prevState, partialState);
8503 }
8504 case ForceUpdate:
8505 {
8506 hasForceUpdate = true;
8507 return prevState;
8508 }
8509 }
8510 return prevState;
8511}
8512
8513function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
8514 hasForceUpdate = false;
8515
8516 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
8517
8518 {
8519 currentlyProcessingQueue = queue;
8520 }
8521
8522 // These values may change as we process the queue.
8523 var newBaseState = queue.baseState;
8524 var newFirstUpdate = null;
8525 var newExpirationTime = NoWork;
8526
8527 // Iterate through the list of updates to compute the result.
8528 var update = queue.firstUpdate;
8529 var resultState = newBaseState;
8530 while (update !== null) {
8531 var updateExpirationTime = update.expirationTime;
8532 if (updateExpirationTime < renderExpirationTime) {
8533 // This update does not have sufficient priority. Skip it.
8534 if (newFirstUpdate === null) {
8535 // This is the first skipped update. It will be the first update in
8536 // the new list.
8537 newFirstUpdate = update;
8538 // Since this is the first update that was skipped, the current result
8539 // is the new base state.
8540 newBaseState = resultState;
8541 }
8542 // Since this update will remain in the list, update the remaining
8543 // expiration time.
8544 if (newExpirationTime < updateExpirationTime) {
8545 newExpirationTime = updateExpirationTime;
8546 }
8547 } else {
8548 // This update does have sufficient priority. Process it and compute
8549 // a new result.
8550 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8551 var _callback = update.callback;
8552 if (_callback !== null) {
8553 workInProgress.effectTag |= Callback;
8554 // Set this to null, in case it was mutated during an aborted render.
8555 update.nextEffect = null;
8556 if (queue.lastEffect === null) {
8557 queue.firstEffect = queue.lastEffect = update;
8558 } else {
8559 queue.lastEffect.nextEffect = update;
8560 queue.lastEffect = update;
8561 }
8562 }
8563 }
8564 // Continue to the next update.
8565 update = update.next;
8566 }
8567
8568 // Separately, iterate though the list of captured updates.
8569 var newFirstCapturedUpdate = null;
8570 update = queue.firstCapturedUpdate;
8571 while (update !== null) {
8572 var _updateExpirationTime = update.expirationTime;
8573 if (_updateExpirationTime < renderExpirationTime) {
8574 // This update does not have sufficient priority. Skip it.
8575 if (newFirstCapturedUpdate === null) {
8576 // This is the first skipped captured update. It will be the first
8577 // update in the new list.
8578 newFirstCapturedUpdate = update;
8579 // If this is the first update that was skipped, the current result is
8580 // the new base state.
8581 if (newFirstUpdate === null) {
8582 newBaseState = resultState;
8583 }
8584 }
8585 // Since this update will remain in the list, update the remaining
8586 // expiration time.
8587 if (newExpirationTime < _updateExpirationTime) {
8588 newExpirationTime = _updateExpirationTime;
8589 }
8590 } else {
8591 // This update does have sufficient priority. Process it and compute
8592 // a new result.
8593 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8594 var _callback2 = update.callback;
8595 if (_callback2 !== null) {
8596 workInProgress.effectTag |= Callback;
8597 // Set this to null, in case it was mutated during an aborted render.
8598 update.nextEffect = null;
8599 if (queue.lastCapturedEffect === null) {
8600 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
8601 } else {
8602 queue.lastCapturedEffect.nextEffect = update;
8603 queue.lastCapturedEffect = update;
8604 }
8605 }
8606 }
8607 update = update.next;
8608 }
8609
8610 if (newFirstUpdate === null) {
8611 queue.lastUpdate = null;
8612 }
8613 if (newFirstCapturedUpdate === null) {
8614 queue.lastCapturedUpdate = null;
8615 } else {
8616 workInProgress.effectTag |= Callback;
8617 }
8618 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
8619 // We processed every update, without skipping. That means the new base
8620 // state is the same as the result state.
8621 newBaseState = resultState;
8622 }
8623
8624 queue.baseState = newBaseState;
8625 queue.firstUpdate = newFirstUpdate;
8626 queue.firstCapturedUpdate = newFirstCapturedUpdate;
8627
8628 // Set the remaining expiration time to be whatever is remaining in the queue.
8629 // This should be fine because the only two other things that contribute to
8630 // expiration time are props and context. We're already in the middle of the
8631 // begin phase by the time we start processing the queue, so we've already
8632 // dealt with the props. Context in components that specify
8633 // shouldComponentUpdate is tricky; but we'll have to account for
8634 // that regardless.
8635 workInProgress.expirationTime = newExpirationTime;
8636 workInProgress.memoizedState = resultState;
8637
8638 {
8639 currentlyProcessingQueue = null;
8640 }
8641}
8642
8643function callCallback(callback, context) {
8644 !(typeof callback === 'function') ? invariant(false, 'Invalid argument passed as callback. Expected a function. Instead received: %s', callback) : void 0;
8645 callback.call(context);
8646}
8647
8648function resetHasForceUpdateBeforeProcessing() {
8649 hasForceUpdate = false;
8650}
8651
8652function checkHasForceUpdateAfterProcessing() {
8653 return hasForceUpdate;
8654}
8655
8656function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
8657 // If the finished render included captured updates, and there are still
8658 // lower priority updates left over, we need to keep the captured updates
8659 // in the queue so that they are rebased and not dropped once we process the
8660 // queue again at the lower priority.
8661 if (finishedQueue.firstCapturedUpdate !== null) {
8662 // Join the captured update list to the end of the normal list.
8663 if (finishedQueue.lastUpdate !== null) {
8664 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
8665 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
8666 }
8667 // Clear the list of captured updates.
8668 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
8669 }
8670
8671 // Commit the effects
8672 commitUpdateEffects(finishedQueue.firstEffect, instance);
8673 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
8674
8675 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
8676 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
8677}
8678
8679function commitUpdateEffects(effect, instance) {
8680 while (effect !== null) {
8681 var _callback3 = effect.callback;
8682 if (_callback3 !== null) {
8683 effect.callback = null;
8684 callCallback(_callback3, instance);
8685 }
8686 effect = effect.nextEffect;
8687 }
8688}
8689
8690function createCapturedValue(value, source) {
8691 // If the value is an error, call this function immediately after it is thrown
8692 // so the stack is accurate.
8693 return {
8694 value: value,
8695 source: source,
8696 stack: getStackByFiberInDevAndProd(source)
8697 };
8698}
8699
8700function markUpdate(workInProgress) {
8701 // Tag the fiber with an update effect. This turns a Placement into
8702 // a PlacementAndUpdate.
8703 workInProgress.effectTag |= Update;
8704}
8705
8706function markRef$1(workInProgress) {
8707 workInProgress.effectTag |= Ref;
8708}
8709
8710var appendAllChildren = void 0;
8711var updateHostContainer = void 0;
8712var updateHostComponent$1 = void 0;
8713var updateHostText$1 = void 0;
8714if (supportsMutation) {
8715 // Mutation mode
8716
8717 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8718 // We only have the top Fiber that was created but we need recurse down its
8719 // children to find all the terminal nodes.
8720 var node = workInProgress.child;
8721 while (node !== null) {
8722 if (node.tag === HostComponent || node.tag === HostText) {
8723 appendInitialChild(parent, node.stateNode);
8724 } else if (node.tag === HostPortal) {
8725 // If we have a portal child, then we don't want to traverse
8726 // down its children. Instead, we'll get insertions from each child in
8727 // the portal directly.
8728 } else if (node.child !== null) {
8729 node.child.return = node;
8730 node = node.child;
8731 continue;
8732 }
8733 if (node === workInProgress) {
8734 return;
8735 }
8736 while (node.sibling === null) {
8737 if (node.return === null || node.return === workInProgress) {
8738 return;
8739 }
8740 node = node.return;
8741 }
8742 node.sibling.return = node.return;
8743 node = node.sibling;
8744 }
8745 };
8746
8747 updateHostContainer = function (workInProgress) {
8748 // Noop
8749 };
8750 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8751 // If we have an alternate, that means this is an update and we need to
8752 // schedule a side-effect to do the updates.
8753 var oldProps = current.memoizedProps;
8754 if (oldProps === newProps) {
8755 // In mutation mode, this is sufficient for a bailout because
8756 // we won't touch this node even if children changed.
8757 return;
8758 }
8759
8760 // If we get updated because one of our children updated, we don't
8761 // have newProps so we'll have to reuse them.
8762 // TODO: Split the update API as separate for the props vs. children.
8763 // Even better would be if children weren't special cased at all tho.
8764 var instance = workInProgress.stateNode;
8765 var currentHostContext = getHostContext();
8766 // TODO: Experiencing an error where oldProps is null. Suggests a host
8767 // component is hitting the resume path. Figure out why. Possibly
8768 // related to `hidden`.
8769 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8770 // TODO: Type this specific to this type of component.
8771 workInProgress.updateQueue = updatePayload;
8772 // If the update payload indicates that there is a change or if there
8773 // is a new ref we mark this as an update. All the work is done in commitWork.
8774 if (updatePayload) {
8775 markUpdate(workInProgress);
8776 }
8777 };
8778 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8779 // If the text differs, mark it as an update. All the work in done in commitWork.
8780 if (oldText !== newText) {
8781 markUpdate(workInProgress);
8782 }
8783 };
8784} else if (supportsPersistence) {
8785 // Persistent host tree mode
8786
8787 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8788 // We only have the top Fiber that was created but we need recurse down its
8789 // children to find all the terminal nodes.
8790 var node = workInProgress.child;
8791 while (node !== null) {
8792 // eslint-disable-next-line no-labels
8793 branches: if (node.tag === HostComponent) {
8794 var instance = node.stateNode;
8795 if (needsVisibilityToggle) {
8796 var props = node.memoizedProps;
8797 var type = node.type;
8798 if (isHidden) {
8799 // This child is inside a timed out tree. Hide it.
8800 instance = cloneHiddenInstance(instance, type, props, node);
8801 } else {
8802 // This child was previously inside a timed out tree. If it was not
8803 // updated during this render, it may need to be unhidden. Clone
8804 // again to be sure.
8805 instance = cloneUnhiddenInstance(instance, type, props, node);
8806 }
8807 node.stateNode = instance;
8808 }
8809 appendInitialChild(parent, instance);
8810 } else if (node.tag === HostText) {
8811 var _instance = node.stateNode;
8812 if (needsVisibilityToggle) {
8813 var text = node.memoizedProps;
8814 var rootContainerInstance = getRootHostContainer();
8815 var currentHostContext = getHostContext();
8816 if (isHidden) {
8817 _instance = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8818 } else {
8819 _instance = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8820 }
8821 node.stateNode = _instance;
8822 }
8823 appendInitialChild(parent, _instance);
8824 } else if (node.tag === HostPortal) {
8825 // If we have a portal child, then we don't want to traverse
8826 // down its children. Instead, we'll get insertions from each child in
8827 // the portal directly.
8828 } else if (node.tag === SuspenseComponent) {
8829 var current = node.alternate;
8830 if (current !== null) {
8831 var oldState = current.memoizedState;
8832 var newState = node.memoizedState;
8833 var oldIsHidden = oldState !== null;
8834 var newIsHidden = newState !== null;
8835 if (oldIsHidden !== newIsHidden) {
8836 // The placeholder either just timed out or switched back to the normal
8837 // children after having previously timed out. Toggle the visibility of
8838 // the direct host children.
8839 var primaryChildParent = newIsHidden ? node.child : node;
8840 if (primaryChildParent !== null) {
8841 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
8842 }
8843 // eslint-disable-next-line no-labels
8844 break branches;
8845 }
8846 }
8847 if (node.child !== null) {
8848 // Continue traversing like normal
8849 node.child.return = node;
8850 node = node.child;
8851 continue;
8852 }
8853 } else if (node.child !== null) {
8854 node.child.return = node;
8855 node = node.child;
8856 continue;
8857 }
8858 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8859 node = node;
8860 if (node === workInProgress) {
8861 return;
8862 }
8863 while (node.sibling === null) {
8864 if (node.return === null || node.return === workInProgress) {
8865 return;
8866 }
8867 node = node.return;
8868 }
8869 node.sibling.return = node.return;
8870 node = node.sibling;
8871 }
8872 };
8873
8874 // An unfortunate fork of appendAllChildren because we have two different parent types.
8875 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
8876 // We only have the top Fiber that was created but we need recurse down its
8877 // children to find all the terminal nodes.
8878 var node = workInProgress.child;
8879 while (node !== null) {
8880 // eslint-disable-next-line no-labels
8881 branches: if (node.tag === HostComponent) {
8882 var instance = node.stateNode;
8883 if (needsVisibilityToggle) {
8884 var props = node.memoizedProps;
8885 var type = node.type;
8886 if (isHidden) {
8887 // This child is inside a timed out tree. Hide it.
8888 instance = cloneHiddenInstance(instance, type, props, node);
8889 } else {
8890 // This child was previously inside a timed out tree. If it was not
8891 // updated during this render, it may need to be unhidden. Clone
8892 // again to be sure.
8893 instance = cloneUnhiddenInstance(instance, type, props, node);
8894 }
8895 node.stateNode = instance;
8896 }
8897 appendChildToContainerChildSet(containerChildSet, instance);
8898 } else if (node.tag === HostText) {
8899 var _instance2 = node.stateNode;
8900 if (needsVisibilityToggle) {
8901 var text = node.memoizedProps;
8902 var rootContainerInstance = getRootHostContainer();
8903 var currentHostContext = getHostContext();
8904 if (isHidden) {
8905 _instance2 = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8906 } else {
8907 _instance2 = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8908 }
8909 node.stateNode = _instance2;
8910 }
8911 appendChildToContainerChildSet(containerChildSet, _instance2);
8912 } else if (node.tag === HostPortal) {
8913 // If we have a portal child, then we don't want to traverse
8914 // down its children. Instead, we'll get insertions from each child in
8915 // the portal directly.
8916 } else if (node.tag === SuspenseComponent) {
8917 var current = node.alternate;
8918 if (current !== null) {
8919 var oldState = current.memoizedState;
8920 var newState = node.memoizedState;
8921 var oldIsHidden = oldState !== null;
8922 var newIsHidden = newState !== null;
8923 if (oldIsHidden !== newIsHidden) {
8924 // The placeholder either just timed out or switched back to the normal
8925 // children after having previously timed out. Toggle the visibility of
8926 // the direct host children.
8927 var primaryChildParent = newIsHidden ? node.child : node;
8928 if (primaryChildParent !== null) {
8929 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
8930 }
8931 // eslint-disable-next-line no-labels
8932 break branches;
8933 }
8934 }
8935 if (node.child !== null) {
8936 // Continue traversing like normal
8937 node.child.return = node;
8938 node = node.child;
8939 continue;
8940 }
8941 } else if (node.child !== null) {
8942 node.child.return = node;
8943 node = node.child;
8944 continue;
8945 }
8946 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8947 node = node;
8948 if (node === workInProgress) {
8949 return;
8950 }
8951 while (node.sibling === null) {
8952 if (node.return === null || node.return === workInProgress) {
8953 return;
8954 }
8955 node = node.return;
8956 }
8957 node.sibling.return = node.return;
8958 node = node.sibling;
8959 }
8960 };
8961 updateHostContainer = function (workInProgress) {
8962 var portalOrRoot = workInProgress.stateNode;
8963 var childrenUnchanged = workInProgress.firstEffect === null;
8964 if (childrenUnchanged) {
8965 // No changes, just reuse the existing instance.
8966 } else {
8967 var container = portalOrRoot.containerInfo;
8968 var newChildSet = createContainerChildSet(container);
8969 // If children might have changed, we have to add them all to the set.
8970 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
8971 portalOrRoot.pendingChildren = newChildSet;
8972 // Schedule an update on the container to swap out the container.
8973 markUpdate(workInProgress);
8974 finalizeContainerChildren(container, newChildSet);
8975 }
8976 };
8977 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8978 var currentInstance = current.stateNode;
8979 var oldProps = current.memoizedProps;
8980 // If there are no effects associated with this node, then none of our children had any updates.
8981 // This guarantees that we can reuse all of them.
8982 var childrenUnchanged = workInProgress.firstEffect === null;
8983 if (childrenUnchanged && oldProps === newProps) {
8984 // No changes, just reuse the existing instance.
8985 // Note that this might release a previous clone.
8986 workInProgress.stateNode = currentInstance;
8987 return;
8988 }
8989 var recyclableInstance = workInProgress.stateNode;
8990 var currentHostContext = getHostContext();
8991 var updatePayload = null;
8992 if (oldProps !== newProps) {
8993 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8994 }
8995 if (childrenUnchanged && updatePayload === null) {
8996 // No changes, just reuse the existing instance.
8997 // Note that this might release a previous clone.
8998 workInProgress.stateNode = currentInstance;
8999 return;
9000 }
9001 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
9002 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
9003 markUpdate(workInProgress);
9004 }
9005 workInProgress.stateNode = newInstance;
9006 if (childrenUnchanged) {
9007 // If there are no other effects in this tree, we need to flag this node as having one.
9008 // Even though we're not going to use it for anything.
9009 // Otherwise parents won't know that there are new children to propagate upwards.
9010 markUpdate(workInProgress);
9011 } else {
9012 // If children might have changed, we have to add them all to the set.
9013 appendAllChildren(newInstance, workInProgress, false, false);
9014 }
9015 };
9016 updateHostText$1 = function (current, workInProgress, oldText, newText) {
9017 if (oldText !== newText) {
9018 // If the text content differs, we'll create a new text instance for it.
9019 var rootContainerInstance = getRootHostContainer();
9020 var currentHostContext = getHostContext();
9021 workInProgress.stateNode = createTextInstance(newText, rootContainerInstance, currentHostContext, workInProgress);
9022 // We'll have to mark it as having an effect, even though we won't use the effect for anything.
9023 // This lets the parents know that at least one of their children has changed.
9024 markUpdate(workInProgress);
9025 }
9026 };
9027} else {
9028 // No host operations
9029 updateHostContainer = function (workInProgress) {
9030 // Noop
9031 };
9032 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
9033 // Noop
9034 };
9035 updateHostText$1 = function (current, workInProgress, oldText, newText) {
9036 // Noop
9037 };
9038}
9039
9040function completeWork(current, workInProgress, renderExpirationTime) {
9041 var newProps = workInProgress.pendingProps;
9042
9043 switch (workInProgress.tag) {
9044 case IndeterminateComponent:
9045 break;
9046 case LazyComponent:
9047 break;
9048 case SimpleMemoComponent:
9049 case FunctionComponent:
9050 break;
9051 case ClassComponent:
9052 {
9053 var Component = workInProgress.type;
9054 if (isContextProvider(Component)) {
9055 popContext(workInProgress);
9056 }
9057 break;
9058 }
9059 case HostRoot:
9060 {
9061 popHostContainer(workInProgress);
9062 popTopLevelContextObject(workInProgress);
9063 var fiberRoot = workInProgress.stateNode;
9064 if (fiberRoot.pendingContext) {
9065 fiberRoot.context = fiberRoot.pendingContext;
9066 fiberRoot.pendingContext = null;
9067 }
9068 if (current === null || current.child === null) {
9069 // If we hydrated, pop so that we can delete any remaining children
9070 // that weren't hydrated.
9071 popHydrationState(workInProgress);
9072 // This resets the hacky state to fix isMounted before committing.
9073 // TODO: Delete this when we delete isMounted and findDOMNode.
9074 workInProgress.effectTag &= ~Placement;
9075 }
9076 updateHostContainer(workInProgress);
9077 break;
9078 }
9079 case HostComponent:
9080 {
9081 popHostContext(workInProgress);
9082 var rootContainerInstance = getRootHostContainer();
9083 var type = workInProgress.type;
9084 if (current !== null && workInProgress.stateNode != null) {
9085 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
9086
9087 if (current.ref !== workInProgress.ref) {
9088 markRef$1(workInProgress);
9089 }
9090 } else {
9091 if (!newProps) {
9092 !(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;
9093 // This can happen when we abort work.
9094 break;
9095 }
9096
9097 var currentHostContext = getHostContext();
9098 // TODO: Move createInstance to beginWork and keep it on a context
9099 // "stack" as the parent. Then append children as we go in beginWork
9100 // or completeWork depending on we want to add then top->down or
9101 // bottom->up. Top->down is faster in IE11.
9102 var wasHydrated = popHydrationState(workInProgress);
9103 if (wasHydrated) {
9104 // TODO: Move this and createInstance step into the beginPhase
9105 // to consolidate.
9106 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
9107 // If changes to the hydrated node needs to be applied at the
9108 // commit-phase we mark this as such.
9109 markUpdate(workInProgress);
9110 }
9111 } else {
9112 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
9113
9114 appendAllChildren(instance, workInProgress, false, false);
9115
9116 // Certain renderers require commit-time effects for initial mount.
9117 // (eg DOM renderer supports auto-focus for certain elements).
9118 // Make sure such renderers get scheduled for later work.
9119 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
9120 markUpdate(workInProgress);
9121 }
9122 workInProgress.stateNode = instance;
9123 }
9124
9125 if (workInProgress.ref !== null) {
9126 // If there is a ref on a host node we need to schedule a callback
9127 markRef$1(workInProgress);
9128 }
9129 }
9130 break;
9131 }
9132 case HostText:
9133 {
9134 var newText = newProps;
9135 if (current && workInProgress.stateNode != null) {
9136 var oldText = current.memoizedProps;
9137 // If we have an alternate, that means this is an update and we need
9138 // to schedule a side-effect to do the updates.
9139 updateHostText$1(current, workInProgress, oldText, newText);
9140 } else {
9141 if (typeof newText !== 'string') {
9142 !(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;
9143 // This can happen when we abort work.
9144 }
9145 var _rootContainerInstance = getRootHostContainer();
9146 var _currentHostContext = getHostContext();
9147 var _wasHydrated = popHydrationState(workInProgress);
9148 if (_wasHydrated) {
9149 if (prepareToHydrateHostTextInstance(workInProgress)) {
9150 markUpdate(workInProgress);
9151 }
9152 } else {
9153 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
9154 }
9155 }
9156 break;
9157 }
9158 case ForwardRef:
9159 break;
9160 case SuspenseComponent:
9161 {
9162 var nextState = workInProgress.memoizedState;
9163 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
9164 // Something suspended. Re-render with the fallback children.
9165 workInProgress.expirationTime = renderExpirationTime;
9166 // Do not reset the effect list.
9167 return workInProgress;
9168 }
9169
9170 var nextDidTimeout = nextState !== null;
9171 var prevDidTimeout = current !== null && current.memoizedState !== null;
9172
9173 if (current !== null && !nextDidTimeout && prevDidTimeout) {
9174 // We just switched from the fallback to the normal children. Delete
9175 // the fallback.
9176 // TODO: Would it be better to store the fallback fragment on
9177 var currentFallbackChild = current.child.sibling;
9178 if (currentFallbackChild !== null) {
9179 // Deletions go at the beginning of the return fiber's effect list
9180 var first = workInProgress.firstEffect;
9181 if (first !== null) {
9182 workInProgress.firstEffect = currentFallbackChild;
9183 currentFallbackChild.nextEffect = first;
9184 } else {
9185 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
9186 currentFallbackChild.nextEffect = null;
9187 }
9188 currentFallbackChild.effectTag = Deletion;
9189 }
9190 }
9191
9192 if (nextDidTimeout || prevDidTimeout) {
9193 // If the children are hidden, or if they were previous hidden, schedule
9194 // an effect to toggle their visibility. This is also used to attach a
9195 // retry listener to the promise.
9196 workInProgress.effectTag |= Update;
9197 }
9198 break;
9199 }
9200 case Fragment:
9201 break;
9202 case Mode:
9203 break;
9204 case Profiler:
9205 break;
9206 case HostPortal:
9207 popHostContainer(workInProgress);
9208 updateHostContainer(workInProgress);
9209 break;
9210 case ContextProvider:
9211 // Pop provider fiber
9212 popProvider(workInProgress);
9213 break;
9214 case ContextConsumer:
9215 break;
9216 case MemoComponent:
9217 break;
9218 case IncompleteClassComponent:
9219 {
9220 // Same as class component case. I put it down here so that the tags are
9221 // sequential to ensure this switch is compiled to a jump table.
9222 var _Component = workInProgress.type;
9223 if (isContextProvider(_Component)) {
9224 popContext(workInProgress);
9225 }
9226 break;
9227 }
9228 case DehydratedSuspenseComponent:
9229 {
9230 if (enableSuspenseServerRenderer) {
9231 if (current === null) {
9232 var _wasHydrated2 = popHydrationState(workInProgress);
9233 !_wasHydrated2 ? invariant(false, 'A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React.') : void 0;
9234 skipPastDehydratedSuspenseInstance(workInProgress);
9235 } else if ((workInProgress.effectTag & DidCapture) === NoEffect) {
9236 // This boundary did not suspend so it's now hydrated.
9237 // To handle any future suspense cases, we're going to now upgrade it
9238 // to a Suspense component. We detach it from the existing current fiber.
9239 current.alternate = null;
9240 workInProgress.alternate = null;
9241 workInProgress.tag = SuspenseComponent;
9242 workInProgress.memoizedState = null;
9243 workInProgress.stateNode = null;
9244 }
9245 }
9246 break;
9247 }
9248 default:
9249 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
9250 }
9251
9252 return null;
9253}
9254
9255function shouldCaptureSuspense(workInProgress) {
9256 // In order to capture, the Suspense component must have a fallback prop.
9257 if (workInProgress.memoizedProps.fallback === undefined) {
9258 return false;
9259 }
9260 // If it was the primary children that just suspended, capture and render the
9261 // fallback. Otherwise, don't capture and bubble to the next boundary.
9262 var nextState = workInProgress.memoizedState;
9263 return nextState === null;
9264}
9265
9266// This module is forked in different environments.
9267// By default, return `true` to log errors to the console.
9268// Forks can return `false` if this isn't desirable.
9269function showErrorDialog(capturedError) {
9270 return true;
9271}
9272
9273function logCapturedError(capturedError) {
9274 var logError = showErrorDialog(capturedError);
9275
9276 // Allow injected showErrorDialog() to prevent default console.error logging.
9277 // This enables renderers like ReactNative to better manage redbox behavior.
9278 if (logError === false) {
9279 return;
9280 }
9281
9282 var error = capturedError.error;
9283 {
9284 var componentName = capturedError.componentName,
9285 componentStack = capturedError.componentStack,
9286 errorBoundaryName = capturedError.errorBoundaryName,
9287 errorBoundaryFound = capturedError.errorBoundaryFound,
9288 willRetry = capturedError.willRetry;
9289
9290 // Browsers support silencing uncaught errors by calling
9291 // `preventDefault()` in window `error` handler.
9292 // We record this information as an expando on the error.
9293
9294 if (error != null && error._suppressLogging) {
9295 if (errorBoundaryFound && willRetry) {
9296 // The error is recoverable and was silenced.
9297 // Ignore it and don't print the stack addendum.
9298 // This is handy for testing error boundaries without noise.
9299 return;
9300 }
9301 // The error is fatal. Since the silencing might have
9302 // been accidental, we'll surface it anyway.
9303 // However, the browser would have silenced the original error
9304 // so we'll print it first, and then print the stack addendum.
9305 console.error(error);
9306 // For a more detailed description of this block, see:
9307 // https://github.com/facebook/react/pull/13384
9308 }
9309
9310 var componentNameMessage = componentName ? 'The above error occurred in the <' + componentName + '> component:' : 'The above error occurred in one of your React components:';
9311
9312 var errorBoundaryMessage = void 0;
9313 // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
9314 if (errorBoundaryFound && errorBoundaryName) {
9315 if (willRetry) {
9316 errorBoundaryMessage = 'React will try to recreate this component tree from scratch ' + ('using the error boundary you provided, ' + errorBoundaryName + '.');
9317 } else {
9318 errorBoundaryMessage = 'This error was initially handled by the error boundary ' + errorBoundaryName + '.\n' + 'Recreating the tree from scratch failed so React will unmount the tree.';
9319 }
9320 } else {
9321 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.';
9322 }
9323 var combinedMessage = '' + componentNameMessage + componentStack + '\n\n' + ('' + errorBoundaryMessage);
9324
9325 // In development, we provide our own message with just the component stack.
9326 // We don't include the original error message and JS stack because the browser
9327 // has already printed it. Even if the application swallows the error, it is still
9328 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
9329 console.error(combinedMessage);
9330 }
9331}
9332
9333var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
9334{
9335 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
9336}
9337
9338var PossiblyWeakSet$1 = typeof WeakSet === 'function' ? WeakSet : Set;
9339
9340function logError(boundary, errorInfo) {
9341 var source = errorInfo.source;
9342 var stack = errorInfo.stack;
9343 if (stack === null && source !== null) {
9344 stack = getStackByFiberInDevAndProd(source);
9345 }
9346
9347 var capturedError = {
9348 componentName: source !== null ? getComponentName(source.type) : null,
9349 componentStack: stack !== null ? stack : '',
9350 error: errorInfo.value,
9351 errorBoundary: null,
9352 errorBoundaryName: null,
9353 errorBoundaryFound: false,
9354 willRetry: false
9355 };
9356
9357 if (boundary !== null && boundary.tag === ClassComponent) {
9358 capturedError.errorBoundary = boundary.stateNode;
9359 capturedError.errorBoundaryName = getComponentName(boundary.type);
9360 capturedError.errorBoundaryFound = true;
9361 capturedError.willRetry = true;
9362 }
9363
9364 try {
9365 logCapturedError(capturedError);
9366 } catch (e) {
9367 // This method must not throw, or React internal state will get messed up.
9368 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
9369 // we want to report this error outside of the normal stack as a last resort.
9370 // https://github.com/facebook/react/issues/13188
9371 setTimeout(function () {
9372 throw e;
9373 });
9374 }
9375}
9376
9377var callComponentWillUnmountWithTimer = function (current$$1, instance) {
9378 startPhaseTimer(current$$1, 'componentWillUnmount');
9379 instance.props = current$$1.memoizedProps;
9380 instance.state = current$$1.memoizedState;
9381 instance.componentWillUnmount();
9382 stopPhaseTimer();
9383};
9384
9385// Capture errors so they don't interrupt unmounting.
9386function safelyCallComponentWillUnmount(current$$1, instance) {
9387 {
9388 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
9389 if (hasCaughtError()) {
9390 var unmountError = clearCaughtError();
9391 captureCommitPhaseError(current$$1, unmountError);
9392 }
9393 }
9394}
9395
9396function safelyDetachRef(current$$1) {
9397 var ref = current$$1.ref;
9398 if (ref !== null) {
9399 if (typeof ref === 'function') {
9400 {
9401 invokeGuardedCallback(null, ref, null, null);
9402 if (hasCaughtError()) {
9403 var refError = clearCaughtError();
9404 captureCommitPhaseError(current$$1, refError);
9405 }
9406 }
9407 } else {
9408 ref.current = null;
9409 }
9410 }
9411}
9412
9413function safelyCallDestroy(current$$1, destroy) {
9414 {
9415 invokeGuardedCallback(null, destroy, null);
9416 if (hasCaughtError()) {
9417 var error = clearCaughtError();
9418 captureCommitPhaseError(current$$1, error);
9419 }
9420 }
9421}
9422
9423function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
9424 switch (finishedWork.tag) {
9425 case FunctionComponent:
9426 case ForwardRef:
9427 case SimpleMemoComponent:
9428 {
9429 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
9430 return;
9431 }
9432 case ClassComponent:
9433 {
9434 if (finishedWork.effectTag & Snapshot) {
9435 if (current$$1 !== null) {
9436 var prevProps = current$$1.memoizedProps;
9437 var prevState = current$$1.memoizedState;
9438 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
9439 var instance = finishedWork.stateNode;
9440 // We could update instance props and state here,
9441 // but instead we rely on them being set during last render.
9442 // TODO: revisit this when we implement resuming.
9443 {
9444 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9445 !(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;
9446 !(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;
9447 }
9448 }
9449 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
9450 {
9451 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
9452 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
9453 didWarnSet.add(finishedWork.type);
9454 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
9455 }
9456 }
9457 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
9458 stopPhaseTimer();
9459 }
9460 }
9461 return;
9462 }
9463 case HostRoot:
9464 case HostComponent:
9465 case HostText:
9466 case HostPortal:
9467 case IncompleteClassComponent:
9468 // Nothing to do for these component types
9469 return;
9470 default:
9471 {
9472 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.');
9473 }
9474 }
9475}
9476
9477function commitHookEffectList(unmountTag, mountTag, finishedWork) {
9478 var updateQueue = finishedWork.updateQueue;
9479 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
9480 if (lastEffect !== null) {
9481 var firstEffect = lastEffect.next;
9482 var effect = firstEffect;
9483 do {
9484 if ((effect.tag & unmountTag) !== NoEffect$1) {
9485 // Unmount
9486 var destroy = effect.destroy;
9487 effect.destroy = undefined;
9488 if (destroy !== undefined) {
9489 destroy();
9490 }
9491 }
9492 if ((effect.tag & mountTag) !== NoEffect$1) {
9493 // Mount
9494 var create = effect.create;
9495 effect.destroy = create();
9496
9497 {
9498 var _destroy = effect.destroy;
9499 if (_destroy !== undefined && typeof _destroy !== 'function') {
9500 var addendum = void 0;
9501 if (_destroy === null) {
9502 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
9503 } else if (typeof _destroy.then === 'function') {
9504 addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + '}, [someId]); // Or [] if effect doesn\'t need props or state\n\n' + 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching';
9505 } else {
9506 addendum = ' You returned: ' + _destroy;
9507 }
9508 warningWithoutStack$1(false, 'An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
9509 }
9510 }
9511 }
9512 effect = effect.next;
9513 } while (effect !== firstEffect);
9514 }
9515}
9516
9517function commitPassiveHookEffects(finishedWork) {
9518 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
9519 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
9520}
9521
9522function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
9523 switch (finishedWork.tag) {
9524 case FunctionComponent:
9525 case ForwardRef:
9526 case SimpleMemoComponent:
9527 {
9528 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
9529 break;
9530 }
9531 case ClassComponent:
9532 {
9533 var instance = finishedWork.stateNode;
9534 if (finishedWork.effectTag & Update) {
9535 if (current$$1 === null) {
9536 startPhaseTimer(finishedWork, 'componentDidMount');
9537 // We could update instance props and state here,
9538 // but instead we rely on them being set during last render.
9539 // TODO: revisit this when we implement resuming.
9540 {
9541 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9542 !(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;
9543 !(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;
9544 }
9545 }
9546 instance.componentDidMount();
9547 stopPhaseTimer();
9548 } else {
9549 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
9550 var prevState = current$$1.memoizedState;
9551 startPhaseTimer(finishedWork, 'componentDidUpdate');
9552 // We could update instance props and state here,
9553 // but instead we rely on them being set during last render.
9554 // TODO: revisit this when we implement resuming.
9555 {
9556 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9557 !(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;
9558 !(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;
9559 }
9560 }
9561 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
9562 stopPhaseTimer();
9563 }
9564 }
9565 var updateQueue = finishedWork.updateQueue;
9566 if (updateQueue !== null) {
9567 {
9568 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9569 !(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;
9570 !(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;
9571 }
9572 }
9573 // We could update instance props and state here,
9574 // but instead we rely on them being set during last render.
9575 // TODO: revisit this when we implement resuming.
9576 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
9577 }
9578 return;
9579 }
9580 case HostRoot:
9581 {
9582 var _updateQueue = finishedWork.updateQueue;
9583 if (_updateQueue !== null) {
9584 var _instance = null;
9585 if (finishedWork.child !== null) {
9586 switch (finishedWork.child.tag) {
9587 case HostComponent:
9588 _instance = getPublicInstance(finishedWork.child.stateNode);
9589 break;
9590 case ClassComponent:
9591 _instance = finishedWork.child.stateNode;
9592 break;
9593 }
9594 }
9595 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
9596 }
9597 return;
9598 }
9599 case HostComponent:
9600 {
9601 var _instance2 = finishedWork.stateNode;
9602
9603 // Renderers may schedule work to be done after host components are mounted
9604 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
9605 // These effects should only be committed when components are first mounted,
9606 // aka when there is no current/alternate.
9607 if (current$$1 === null && finishedWork.effectTag & Update) {
9608 var type = finishedWork.type;
9609 var props = finishedWork.memoizedProps;
9610
9611 }
9612
9613 return;
9614 }
9615 case HostText:
9616 {
9617 // We have no life-cycles associated with text.
9618 return;
9619 }
9620 case HostPortal:
9621 {
9622 // We have no life-cycles associated with portals.
9623 return;
9624 }
9625 case Profiler:
9626 {
9627 if (enableProfilerTimer) {
9628 var onRender = finishedWork.memoizedProps.onRender;
9629
9630 if (enableSchedulerTracing) {
9631 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
9632 } else {
9633 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
9634 }
9635 }
9636 return;
9637 }
9638 case SuspenseComponent:
9639 break;
9640 case IncompleteClassComponent:
9641 break;
9642 default:
9643 {
9644 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.');
9645 }
9646 }
9647}
9648
9649function hideOrUnhideAllChildren(finishedWork, isHidden) {
9650 if (supportsMutation) {
9651 // We only have the top Fiber that was inserted but we need to recurse down its
9652 var node = finishedWork;
9653 while (true) {
9654 if (node.tag === HostComponent) {
9655 var instance = node.stateNode;
9656 if (isHidden) {
9657 hideInstance(instance);
9658 } else {
9659 unhideInstance(node.stateNode, node.memoizedProps);
9660 }
9661 } else if (node.tag === HostText) {
9662 var _instance3 = node.stateNode;
9663 if (isHidden) {
9664 hideTextInstance(_instance3);
9665 } else {
9666 unhideTextInstance(_instance3, node.memoizedProps);
9667 }
9668 } else if (node.tag === SuspenseComponent && node.memoizedState !== null) {
9669 // Found a nested Suspense component that timed out. Skip over the
9670 var fallbackChildFragment = node.child.sibling;
9671 fallbackChildFragment.return = node;
9672 node = fallbackChildFragment;
9673 continue;
9674 } else if (node.child !== null) {
9675 node.child.return = node;
9676 node = node.child;
9677 continue;
9678 }
9679 if (node === finishedWork) {
9680 return;
9681 }
9682 while (node.sibling === null) {
9683 if (node.return === null || node.return === finishedWork) {
9684 return;
9685 }
9686 node = node.return;
9687 }
9688 node.sibling.return = node.return;
9689 node = node.sibling;
9690 }
9691 }
9692}
9693
9694function commitAttachRef(finishedWork) {
9695 var ref = finishedWork.ref;
9696 if (ref !== null) {
9697 var instance = finishedWork.stateNode;
9698 var instanceToUse = void 0;
9699 switch (finishedWork.tag) {
9700 case HostComponent:
9701 instanceToUse = getPublicInstance(instance);
9702 break;
9703 default:
9704 instanceToUse = instance;
9705 }
9706 if (typeof ref === 'function') {
9707 ref(instanceToUse);
9708 } else {
9709 {
9710 if (!ref.hasOwnProperty('current')) {
9711 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
9712 }
9713 }
9714
9715 ref.current = instanceToUse;
9716 }
9717 }
9718}
9719
9720function commitDetachRef(current$$1) {
9721 var currentRef = current$$1.ref;
9722 if (currentRef !== null) {
9723 if (typeof currentRef === 'function') {
9724 currentRef(null);
9725 } else {
9726 currentRef.current = null;
9727 }
9728 }
9729}
9730
9731// User-originating errors (lifecycles and refs) should not interrupt
9732// deletion, so don't let them throw. Host-originating errors should
9733// interrupt deletion, so it's okay
9734function commitUnmount(current$$1) {
9735 onCommitUnmount(current$$1);
9736
9737 switch (current$$1.tag) {
9738 case FunctionComponent:
9739 case ForwardRef:
9740 case MemoComponent:
9741 case SimpleMemoComponent:
9742 {
9743 var updateQueue = current$$1.updateQueue;
9744 if (updateQueue !== null) {
9745 var lastEffect = updateQueue.lastEffect;
9746 if (lastEffect !== null) {
9747 var firstEffect = lastEffect.next;
9748 var effect = firstEffect;
9749 do {
9750 var destroy = effect.destroy;
9751 if (destroy !== undefined) {
9752 safelyCallDestroy(current$$1, destroy);
9753 }
9754 effect = effect.next;
9755 } while (effect !== firstEffect);
9756 }
9757 }
9758 break;
9759 }
9760 case ClassComponent:
9761 {
9762 safelyDetachRef(current$$1);
9763 var instance = current$$1.stateNode;
9764 if (typeof instance.componentWillUnmount === 'function') {
9765 safelyCallComponentWillUnmount(current$$1, instance);
9766 }
9767 return;
9768 }
9769 case HostComponent:
9770 {
9771 safelyDetachRef(current$$1);
9772 return;
9773 }
9774 case HostPortal:
9775 {
9776 // TODO: this is recursive.
9777 // We are also not using this parent because
9778 // the portal will get pushed immediately.
9779 if (supportsMutation) {
9780 unmountHostComponents(current$$1);
9781 } else if (supportsPersistence) {
9782 emptyPortalContainer(current$$1);
9783 }
9784 return;
9785 }
9786 }
9787}
9788
9789function commitNestedUnmounts(root) {
9790 // While we're inside a removed host node we don't want to call
9791 // removeChild on the inner nodes because they're removed by the top
9792 // call anyway. We also want to call componentWillUnmount on all
9793 // composites before this host node is removed from the tree. Therefore
9794 var node = root;
9795 while (true) {
9796 commitUnmount(node);
9797 // Visit children because they may contain more composite or host nodes.
9798 // Skip portals because commitUnmount() currently visits them recursively.
9799 if (node.child !== null && (
9800 // If we use mutation we drill down into portals using commitUnmount above.
9801 // If we don't use mutation we drill down into portals here instead.
9802 !supportsMutation || node.tag !== HostPortal)) {
9803 node.child.return = node;
9804 node = node.child;
9805 continue;
9806 }
9807 if (node === root) {
9808 return;
9809 }
9810 while (node.sibling === null) {
9811 if (node.return === null || node.return === root) {
9812 return;
9813 }
9814 node = node.return;
9815 }
9816 node.sibling.return = node.return;
9817 node = node.sibling;
9818 }
9819}
9820
9821function detachFiber(current$$1) {
9822 // Cut off the return pointers to disconnect it from the tree. Ideally, we
9823 // should clear the child pointer of the parent alternate to let this
9824 // get GC:ed but we don't know which for sure which parent is the current
9825 // one so we'll settle for GC:ing the subtree of this child. This child
9826 // itself will be GC:ed when the parent updates the next time.
9827 current$$1.return = null;
9828 current$$1.child = null;
9829 current$$1.memoizedState = null;
9830 current$$1.updateQueue = null;
9831 var alternate = current$$1.alternate;
9832 if (alternate !== null) {
9833 alternate.return = null;
9834 alternate.child = null;
9835 alternate.memoizedState = null;
9836 alternate.updateQueue = null;
9837 }
9838}
9839
9840function emptyPortalContainer(current$$1) {
9841 if (!supportsPersistence) {
9842 return;
9843 }
9844
9845 var portal = current$$1.stateNode;
9846 var containerInfo = portal.containerInfo;
9847
9848 var emptyChildSet = createContainerChildSet(containerInfo);
9849 replaceContainerChildren(containerInfo, emptyChildSet);
9850}
9851
9852function commitContainer(finishedWork) {
9853 if (!supportsPersistence) {
9854 return;
9855 }
9856
9857 switch (finishedWork.tag) {
9858 case ClassComponent:
9859 {
9860 return;
9861 }
9862 case HostComponent:
9863 {
9864 return;
9865 }
9866 case HostText:
9867 {
9868 return;
9869 }
9870 case HostRoot:
9871 case HostPortal:
9872 {
9873 var portalOrRoot = finishedWork.stateNode;
9874 var containerInfo = portalOrRoot.containerInfo,
9875 _pendingChildren = portalOrRoot.pendingChildren;
9876
9877 replaceContainerChildren(containerInfo, _pendingChildren);
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 getHostParentFiber(fiber) {
9888 var parent = fiber.return;
9889 while (parent !== null) {
9890 if (isHostParent(parent)) {
9891 return parent;
9892 }
9893 parent = parent.return;
9894 }
9895 invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.');
9896}
9897
9898function isHostParent(fiber) {
9899 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
9900}
9901
9902function getHostSibling(fiber) {
9903 // We're going to search forward into the tree until we find a sibling host
9904 // node. Unfortunately, if multiple insertions are done in a row we have to
9905 // search past them. This leads to exponential search for the next sibling.
9906 var node = fiber;
9907 siblings: while (true) {
9908 // If we didn't find anything, let's try the next sibling.
9909 while (node.sibling === null) {
9910 if (node.return === null || isHostParent(node.return)) {
9911 // If we pop out of the root or hit the parent the fiber we are the
9912 // last sibling.
9913 return null;
9914 }
9915 node = node.return;
9916 }
9917 node.sibling.return = node.return;
9918 node = node.sibling;
9919 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedSuspenseComponent) {
9920 // If it is not host node and, we might have a host node inside it.
9921 // Try to search down until we find one.
9922 if (node.effectTag & Placement) {
9923 // If we don't have a child, try the siblings instead.
9924 continue siblings;
9925 }
9926 // If we don't have a child, try the siblings instead.
9927 // We also skip portals because they are not part of this host tree.
9928 if (node.child === null || node.tag === HostPortal) {
9929 continue siblings;
9930 } else {
9931 node.child.return = node;
9932 node = node.child;
9933 }
9934 }
9935 // Check if this host node is stable or about to be placed.
9936 if (!(node.effectTag & Placement)) {
9937 // Found it!
9938 return node.stateNode;
9939 }
9940 }
9941}
9942
9943function commitPlacement(finishedWork) {
9944 if (!supportsMutation) {
9945 return;
9946 }
9947
9948 // Recursively insert all host nodes into the parent.
9949 var parentFiber = getHostParentFiber(finishedWork);
9950
9951 // Note: these two variables *must* always be updated together.
9952 var parent = void 0;
9953 var isContainer = void 0;
9954
9955 switch (parentFiber.tag) {
9956 case HostComponent:
9957 parent = parentFiber.stateNode;
9958 isContainer = false;
9959 break;
9960 case HostRoot:
9961 parent = parentFiber.stateNode.containerInfo;
9962 isContainer = true;
9963 break;
9964 case HostPortal:
9965 parent = parentFiber.stateNode.containerInfo;
9966 isContainer = true;
9967 break;
9968 default:
9969 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
9970 }
9971 if (parentFiber.effectTag & ContentReset) {
9972 // Reset the text content of the parent before doing any insertions
9973 parentFiber.effectTag &= ~ContentReset;
9974 }
9975
9976 var before = getHostSibling(finishedWork);
9977 // We only have the top Fiber that was inserted but we need to recurse down its
9978 // children to find all the terminal nodes.
9979 var node = finishedWork;
9980 while (true) {
9981 if (node.tag === HostComponent || node.tag === HostText) {
9982 if (before) {
9983 if (isContainer) {
9984 insertInContainerBefore(parent, node.stateNode, before);
9985 } else {
9986 insertBefore(parent, node.stateNode, before);
9987 }
9988 } else {
9989 if (isContainer) {
9990 appendChildToContainer(parent, node.stateNode);
9991 } else {
9992 appendChild(parent, node.stateNode);
9993 }
9994 }
9995 } else if (node.tag === HostPortal) {
9996 // If the insertion itself is a portal, then we don't want to traverse
9997 // down its children. Instead, we'll get insertions from each child in
9998 // the portal directly.
9999 } else if (node.child !== null) {
10000 node.child.return = node;
10001 node = node.child;
10002 continue;
10003 }
10004 if (node === finishedWork) {
10005 return;
10006 }
10007 while (node.sibling === null) {
10008 if (node.return === null || node.return === finishedWork) {
10009 return;
10010 }
10011 node = node.return;
10012 }
10013 node.sibling.return = node.return;
10014 node = node.sibling;
10015 }
10016}
10017
10018function unmountHostComponents(current$$1) {
10019 // We only have the top Fiber that was deleted but we need to recurse down its
10020 var node = current$$1;
10021
10022 // Each iteration, currentParent is populated with node's host parent if not
10023 // currentParentIsValid.
10024 var currentParentIsValid = false;
10025
10026 // Note: these two variables *must* always be updated together.
10027 var currentParent = void 0;
10028 var currentParentIsContainer = void 0;
10029
10030 while (true) {
10031 if (!currentParentIsValid) {
10032 var parent = node.return;
10033 findParent: while (true) {
10034 !(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;
10035 switch (parent.tag) {
10036 case HostComponent:
10037 currentParent = parent.stateNode;
10038 currentParentIsContainer = false;
10039 break findParent;
10040 case HostRoot:
10041 currentParent = parent.stateNode.containerInfo;
10042 currentParentIsContainer = true;
10043 break findParent;
10044 case HostPortal:
10045 currentParent = parent.stateNode.containerInfo;
10046 currentParentIsContainer = true;
10047 break findParent;
10048 }
10049 parent = parent.return;
10050 }
10051 currentParentIsValid = true;
10052 }
10053
10054 if (node.tag === HostComponent || node.tag === HostText) {
10055 commitNestedUnmounts(node);
10056 // After all the children have unmounted, it is now safe to remove the
10057 // node from the tree.
10058 if (currentParentIsContainer) {
10059 removeChildFromContainer(currentParent, node.stateNode);
10060 } else {
10061 removeChild(currentParent, node.stateNode);
10062 }
10063 // Don't visit children because we already visited them.
10064 } else if (enableSuspenseServerRenderer && node.tag === DehydratedSuspenseComponent) {
10065 // Delete the dehydrated suspense boundary and all of its content.
10066 if (currentParentIsContainer) {
10067 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);
10068 } else {
10069 clearSuspenseBoundary(currentParent, node.stateNode);
10070 }
10071 } else if (node.tag === HostPortal) {
10072 if (node.child !== null) {
10073 // When we go into a portal, it becomes the parent to remove from.
10074 // We will reassign it back when we pop the portal on the way up.
10075 currentParent = node.stateNode.containerInfo;
10076 currentParentIsContainer = true;
10077 // Visit children because portals might contain host components.
10078 node.child.return = node;
10079 node = node.child;
10080 continue;
10081 }
10082 } else {
10083 commitUnmount(node);
10084 // Visit children because we may find more host components below.
10085 if (node.child !== null) {
10086 node.child.return = node;
10087 node = node.child;
10088 continue;
10089 }
10090 }
10091 if (node === current$$1) {
10092 return;
10093 }
10094 while (node.sibling === null) {
10095 if (node.return === null || node.return === current$$1) {
10096 return;
10097 }
10098 node = node.return;
10099 if (node.tag === HostPortal) {
10100 // When we go out of the portal, we need to restore the parent.
10101 // Since we don't keep a stack of them, we will search for it.
10102 currentParentIsValid = false;
10103 }
10104 }
10105 node.sibling.return = node.return;
10106 node = node.sibling;
10107 }
10108}
10109
10110function commitDeletion(current$$1) {
10111 if (supportsMutation) {
10112 // Recursively delete all host nodes from the parent.
10113 // Detach refs and call componentWillUnmount() on the whole subtree.
10114 unmountHostComponents(current$$1);
10115 } else {
10116 // Detach refs and call componentWillUnmount() on the whole subtree.
10117 commitNestedUnmounts(current$$1);
10118 }
10119 detachFiber(current$$1);
10120}
10121
10122function commitWork(current$$1, finishedWork) {
10123 if (!supportsMutation) {
10124 switch (finishedWork.tag) {
10125 case FunctionComponent:
10126 case ForwardRef:
10127 case MemoComponent:
10128 case SimpleMemoComponent:
10129 {
10130 // Note: We currently never use MountMutation, but useLayout uses
10131 // UnmountMutation.
10132 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
10133 return;
10134 }
10135 }
10136
10137 commitContainer(finishedWork);
10138 return;
10139 }
10140
10141 switch (finishedWork.tag) {
10142 case FunctionComponent:
10143 case ForwardRef:
10144 case MemoComponent:
10145 case SimpleMemoComponent:
10146 {
10147 // Note: We currently never use MountMutation, but useLayout uses
10148 // UnmountMutation.
10149 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
10150 return;
10151 }
10152 case ClassComponent:
10153 {
10154 return;
10155 }
10156 case HostComponent:
10157 {
10158 var instance = finishedWork.stateNode;
10159 if (instance != null) {
10160 // Commit the work prepared earlier.
10161 var newProps = finishedWork.memoizedProps;
10162 // For hydration we reuse the update path but we treat the oldProps
10163 // as the newProps. The updatePayload will contain the real change in
10164 // this case.
10165 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
10166 var type = finishedWork.type;
10167 // TODO: Type the updateQueue to be specific to host components.
10168 var updatePayload = finishedWork.updateQueue;
10169 finishedWork.updateQueue = null;
10170 if (updatePayload !== null) {
10171 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
10172 }
10173 }
10174 return;
10175 }
10176 case HostText:
10177 {
10178 !(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;
10179 var textInstance = finishedWork.stateNode;
10180 var newText = finishedWork.memoizedProps;
10181 // For hydration we reuse the update path but we treat the oldProps
10182 // as the newProps. The updatePayload will contain the real change in
10183 // this case.
10184 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
10185 commitTextUpdate(textInstance, oldText, newText);
10186 return;
10187 }
10188 case HostRoot:
10189 {
10190 return;
10191 }
10192 case Profiler:
10193 {
10194 return;
10195 }
10196 case SuspenseComponent:
10197 {
10198 var newState = finishedWork.memoizedState;
10199
10200 var newDidTimeout = void 0;
10201 var primaryChildParent = finishedWork;
10202 if (newState === null) {
10203 newDidTimeout = false;
10204 } else {
10205 newDidTimeout = true;
10206 primaryChildParent = finishedWork.child;
10207 if (newState.timedOutAt === NoWork) {
10208 // If the children had not already timed out, record the time.
10209 // This is used to compute the elapsed time during subsequent
10210 // attempts to render the children.
10211 newState.timedOutAt = requestCurrentTime();
10212 }
10213 }
10214
10215 if (primaryChildParent !== null) {
10216 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
10217 }
10218
10219 // If this boundary just timed out, then it will have a set of thenables.
10220 // For each thenable, attach a listener so that when it resolves, React
10221 // attempts to re-render the boundary in the primary (pre-timeout) state.
10222 var thenables = finishedWork.updateQueue;
10223 if (thenables !== null) {
10224 finishedWork.updateQueue = null;
10225 var retryCache = finishedWork.stateNode;
10226 if (retryCache === null) {
10227 retryCache = finishedWork.stateNode = new PossiblyWeakSet$1();
10228 }
10229 thenables.forEach(function (thenable) {
10230 // Memoize using the boundary fiber to prevent redundant listeners.
10231 var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable);
10232 if (enableSchedulerTracing) {
10233 retry = unstable_wrap(retry);
10234 }
10235 if (!retryCache.has(thenable)) {
10236 retryCache.add(thenable);
10237 thenable.then(retry, retry);
10238 }
10239 });
10240 }
10241
10242 return;
10243 }
10244 case IncompleteClassComponent:
10245 {
10246 return;
10247 }
10248 default:
10249 {
10250 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.');
10251 }
10252 }
10253}
10254
10255function commitResetTextContent(current$$1) {
10256 if (!supportsMutation) {
10257 return;
10258 }
10259 resetTextContent(current$$1.stateNode);
10260}
10261
10262var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
10263var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
10264
10265function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
10266 var update = createUpdate(expirationTime);
10267 // Unmount the root by rendering null.
10268 update.tag = CaptureUpdate;
10269 // Caution: React DevTools currently depends on this property
10270 // being called "element".
10271 update.payload = { element: null };
10272 var error = errorInfo.value;
10273 update.callback = function () {
10274 onUncaughtError(error);
10275 logError(fiber, errorInfo);
10276 };
10277 return update;
10278}
10279
10280function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
10281 var update = createUpdate(expirationTime);
10282 update.tag = CaptureUpdate;
10283 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
10284 if (typeof getDerivedStateFromError === 'function') {
10285 var error = errorInfo.value;
10286 update.payload = function () {
10287 return getDerivedStateFromError(error);
10288 };
10289 }
10290
10291 var inst = fiber.stateNode;
10292 if (inst !== null && typeof inst.componentDidCatch === 'function') {
10293 update.callback = function callback() {
10294 if (typeof getDerivedStateFromError !== 'function') {
10295 // To preserve the preexisting retry behavior of error boundaries,
10296 // we keep track of which ones already failed during this batch.
10297 // This gets reset before we yield back to the browser.
10298 // TODO: Warn in strict mode if getDerivedStateFromError is
10299 // not defined.
10300 markLegacyErrorBoundaryAsFailed(this);
10301 }
10302 var error = errorInfo.value;
10303 var stack = errorInfo.stack;
10304 logError(fiber, errorInfo);
10305 this.componentDidCatch(error, {
10306 componentStack: stack !== null ? stack : ''
10307 });
10308 {
10309 if (typeof getDerivedStateFromError !== 'function') {
10310 // If componentDidCatch is the only error boundary method defined,
10311 // then it needs to call setState to recover from errors.
10312 // If no state update is scheduled then the boundary will swallow the error.
10313 !(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;
10314 }
10315 }
10316 };
10317 }
10318 return update;
10319}
10320
10321function attachPingListener(root, renderExpirationTime, thenable) {
10322 // Attach a listener to the promise to "ping" the root and retry. But
10323 // only if one does not already exist for the current render expiration
10324 // time (which acts like a "thread ID" here).
10325 var pingCache = root.pingCache;
10326 var threadIDs = void 0;
10327 if (pingCache === null) {
10328 pingCache = root.pingCache = new PossiblyWeakMap();
10329 threadIDs = new Set();
10330 pingCache.set(thenable, threadIDs);
10331 } else {
10332 threadIDs = pingCache.get(thenable);
10333 if (threadIDs === undefined) {
10334 threadIDs = new Set();
10335 pingCache.set(thenable, threadIDs);
10336 }
10337 }
10338 if (!threadIDs.has(renderExpirationTime)) {
10339 // Memoize using the thread ID to prevent redundant listeners.
10340 threadIDs.add(renderExpirationTime);
10341 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
10342 if (enableSchedulerTracing) {
10343 ping = unstable_wrap(ping);
10344 }
10345 thenable.then(ping, ping);
10346 }
10347}
10348
10349function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
10350 // The source fiber did not complete.
10351 sourceFiber.effectTag |= Incomplete;
10352 // Its effect list is no longer valid.
10353 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
10354
10355 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
10356 // This is a thenable.
10357 var thenable = value;
10358
10359 // Find the earliest timeout threshold of all the placeholders in the
10360 // ancestor path. We could avoid this traversal by storing the thresholds on
10361 // the stack, but we choose not to because we only hit this path if we're
10362 // IO-bound (i.e. if something suspends). Whereas the stack is used even in
10363 // the non-IO- bound case.
10364 var _workInProgress = returnFiber;
10365 var earliestTimeoutMs = -1;
10366 var startTimeMs = -1;
10367 do {
10368 if (_workInProgress.tag === SuspenseComponent) {
10369 var current$$1 = _workInProgress.alternate;
10370 if (current$$1 !== null) {
10371 var currentState = current$$1.memoizedState;
10372 if (currentState !== null) {
10373 // Reached a boundary that already timed out. Do not search
10374 // any further.
10375 var timedOutAt = currentState.timedOutAt;
10376 startTimeMs = expirationTimeToMs(timedOutAt);
10377 // Do not search any further.
10378 break;
10379 }
10380 }
10381 var timeoutPropMs = _workInProgress.pendingProps.maxDuration;
10382 if (typeof timeoutPropMs === 'number') {
10383 if (timeoutPropMs <= 0) {
10384 earliestTimeoutMs = 0;
10385 } else if (earliestTimeoutMs === -1 || timeoutPropMs < earliestTimeoutMs) {
10386 earliestTimeoutMs = timeoutPropMs;
10387 }
10388 }
10389 }
10390 // If there is a DehydratedSuspenseComponent we don't have to do anything because
10391 // if something suspends inside it, we will simply leave that as dehydrated. It
10392 // will never timeout.
10393 _workInProgress = _workInProgress.return;
10394 } while (_workInProgress !== null);
10395
10396 // Schedule the nearest Suspense to re-render the timed out view.
10397 _workInProgress = returnFiber;
10398 do {
10399 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress)) {
10400 // Found the nearest boundary.
10401
10402 // Stash the promise on the boundary fiber. If the boundary times out, we'll
10403 var thenables = _workInProgress.updateQueue;
10404 if (thenables === null) {
10405 var updateQueue = new Set();
10406 updateQueue.add(thenable);
10407 _workInProgress.updateQueue = updateQueue;
10408 } else {
10409 thenables.add(thenable);
10410 }
10411
10412 // If the boundary is outside of concurrent mode, we should *not*
10413 // suspend the commit. Pretend as if the suspended component rendered
10414 // null and keep rendering. In the commit phase, we'll schedule a
10415 // subsequent synchronous update to re-render the Suspense.
10416 //
10417 // Note: It doesn't matter whether the component that suspended was
10418 // inside a concurrent mode tree. If the Suspense is outside of it, we
10419 // should *not* suspend the commit.
10420 if ((_workInProgress.mode & ConcurrentMode) === NoEffect) {
10421 _workInProgress.effectTag |= DidCapture;
10422
10423 // We're going to commit this fiber even though it didn't complete.
10424 // But we shouldn't call any lifecycle methods or callbacks. Remove
10425 // all lifecycle effect tags.
10426 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
10427
10428 if (sourceFiber.tag === ClassComponent) {
10429 var currentSourceFiber = sourceFiber.alternate;
10430 if (currentSourceFiber === null) {
10431 // This is a new mount. Change the tag so it's not mistaken for a
10432 // completed class component. For example, we should not call
10433 // componentWillUnmount if it is deleted.
10434 sourceFiber.tag = IncompleteClassComponent;
10435 } else {
10436 // When we try rendering again, we should not reuse the current fiber,
10437 // since it's known to be in an inconsistent state. Use a force updte to
10438 // prevent a bail out.
10439 var update = createUpdate(Sync);
10440 update.tag = ForceUpdate;
10441 enqueueUpdate(sourceFiber, update);
10442 }
10443 }
10444
10445 // The source fiber did not complete. Mark it with Sync priority to
10446 // indicate that it still has pending work.
10447 sourceFiber.expirationTime = Sync;
10448
10449 // Exit without suspending.
10450 return;
10451 }
10452
10453 // Confirmed that the boundary is in a concurrent mode tree. Continue
10454 // with the normal suspend path.
10455
10456 attachPingListener(root, renderExpirationTime, thenable);
10457
10458 var absoluteTimeoutMs = void 0;
10459 if (earliestTimeoutMs === -1) {
10460 // If no explicit threshold is given, default to an arbitrarily large
10461 // value. The actual size doesn't matter because the threshold for the
10462 // whole tree will be clamped to the expiration time.
10463 absoluteTimeoutMs = maxSigned31BitInt;
10464 } else {
10465 if (startTimeMs === -1) {
10466 // This suspend happened outside of any already timed-out
10467 // placeholders. We don't know exactly when the update was
10468 // scheduled, but we can infer an approximate start time from the
10469 // expiration time. First, find the earliest uncommitted expiration
10470 // time in the tree, including work that is suspended. Then subtract
10471 // the offset used to compute an async update's expiration time.
10472 // This will cause high priority (interactive) work to expire
10473 // earlier than necessary, but we can account for this by adjusting
10474 // for the Just Noticeable Difference.
10475 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, renderExpirationTime);
10476 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
10477 startTimeMs = earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
10478 }
10479 absoluteTimeoutMs = startTimeMs + earliestTimeoutMs;
10480 }
10481
10482 // Mark the earliest timeout in the suspended fiber's ancestor path.
10483 // After completing the root, we'll take the largest of all the
10484 // suspended fiber's timeouts and use it to compute a timeout for the
10485 // whole tree.
10486 renderDidSuspend(root, absoluteTimeoutMs, renderExpirationTime);
10487
10488 _workInProgress.effectTag |= ShouldCapture;
10489 _workInProgress.expirationTime = renderExpirationTime;
10490 return;
10491 } else if (enableSuspenseServerRenderer && _workInProgress.tag === DehydratedSuspenseComponent) {
10492 attachPingListener(root, renderExpirationTime, thenable);
10493
10494 // Since we already have a current fiber, we can eagerly add a retry listener.
10495 var retryCache = _workInProgress.memoizedState;
10496 if (retryCache === null) {
10497 retryCache = _workInProgress.memoizedState = new PossiblyWeakSet();
10498 var _current = _workInProgress.alternate;
10499 !_current ? invariant(false, 'A dehydrated suspense boundary must commit before trying to render. This is probably a bug in React.') : void 0;
10500 _current.memoizedState = retryCache;
10501 }
10502 // Memoize using the boundary fiber to prevent redundant listeners.
10503 if (!retryCache.has(thenable)) {
10504 retryCache.add(thenable);
10505 var retry = retryTimedOutBoundary.bind(null, _workInProgress, thenable);
10506 if (enableSchedulerTracing) {
10507 retry = unstable_wrap(retry);
10508 }
10509 thenable.then(retry, retry);
10510 }
10511 _workInProgress.effectTag |= ShouldCapture;
10512 _workInProgress.expirationTime = renderExpirationTime;
10513 return;
10514 }
10515 // This boundary already captured during this render. Continue to the next
10516 // boundary.
10517 _workInProgress = _workInProgress.return;
10518 } while (_workInProgress !== null);
10519 // No boundary was found. Fallthrough to error mode.
10520 // TODO: Use invariant so the message is stripped in prod?
10521 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));
10522 }
10523
10524 // We didn't find a boundary that could handle this type of exception. Start
10525 // over and traverse parent path again, this time treating the exception
10526 // as an error.
10527 renderDidError();
10528 value = createCapturedValue(value, sourceFiber);
10529 var workInProgress = returnFiber;
10530 do {
10531 switch (workInProgress.tag) {
10532 case HostRoot:
10533 {
10534 var _errorInfo = value;
10535 workInProgress.effectTag |= ShouldCapture;
10536 workInProgress.expirationTime = renderExpirationTime;
10537 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
10538 enqueueCapturedUpdate(workInProgress, _update);
10539 return;
10540 }
10541 case ClassComponent:
10542 // Capture and retry
10543 var errorInfo = value;
10544 var ctor = workInProgress.type;
10545 var instance = workInProgress.stateNode;
10546 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
10547 workInProgress.effectTag |= ShouldCapture;
10548 workInProgress.expirationTime = renderExpirationTime;
10549 // Schedule the error boundary to re-render using updated state
10550 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
10551 enqueueCapturedUpdate(workInProgress, _update2);
10552 return;
10553 }
10554 break;
10555 default:
10556 break;
10557 }
10558 workInProgress = workInProgress.return;
10559 } while (workInProgress !== null);
10560}
10561
10562function unwindWork(workInProgress, renderExpirationTime) {
10563 switch (workInProgress.tag) {
10564 case ClassComponent:
10565 {
10566 var Component = workInProgress.type;
10567 if (isContextProvider(Component)) {
10568 popContext(workInProgress);
10569 }
10570 var effectTag = workInProgress.effectTag;
10571 if (effectTag & ShouldCapture) {
10572 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
10573 return workInProgress;
10574 }
10575 return null;
10576 }
10577 case HostRoot:
10578 {
10579 popHostContainer(workInProgress);
10580 popTopLevelContextObject(workInProgress);
10581 var _effectTag = workInProgress.effectTag;
10582 !((_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;
10583 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
10584 return workInProgress;
10585 }
10586 case HostComponent:
10587 {
10588 // TODO: popHydrationState
10589 popHostContext(workInProgress);
10590 return null;
10591 }
10592 case SuspenseComponent:
10593 {
10594 var _effectTag2 = workInProgress.effectTag;
10595 if (_effectTag2 & ShouldCapture) {
10596 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture;
10597 // Captured a suspense effect. Re-render the boundary.
10598 return workInProgress;
10599 }
10600 return null;
10601 }
10602 case DehydratedSuspenseComponent:
10603 {
10604 if (enableSuspenseServerRenderer) {
10605 // TODO: popHydrationState
10606 var _effectTag3 = workInProgress.effectTag;
10607 if (_effectTag3 & ShouldCapture) {
10608 workInProgress.effectTag = _effectTag3 & ~ShouldCapture | DidCapture;
10609 // Captured a suspense effect. Re-render the boundary.
10610 return workInProgress;
10611 }
10612 }
10613 return null;
10614 }
10615 case HostPortal:
10616 popHostContainer(workInProgress);
10617 return null;
10618 case ContextProvider:
10619 popProvider(workInProgress);
10620 return null;
10621 default:
10622 return null;
10623 }
10624}
10625
10626function unwindInterruptedWork(interruptedWork) {
10627 switch (interruptedWork.tag) {
10628 case ClassComponent:
10629 {
10630 var childContextTypes = interruptedWork.type.childContextTypes;
10631 if (childContextTypes !== null && childContextTypes !== undefined) {
10632 popContext(interruptedWork);
10633 }
10634 break;
10635 }
10636 case HostRoot:
10637 {
10638 popHostContainer(interruptedWork);
10639 popTopLevelContextObject(interruptedWork);
10640 break;
10641 }
10642 case HostComponent:
10643 {
10644 popHostContext(interruptedWork);
10645 break;
10646 }
10647 case HostPortal:
10648 popHostContainer(interruptedWork);
10649 break;
10650 case ContextProvider:
10651 popProvider(interruptedWork);
10652 break;
10653 default:
10654 break;
10655 }
10656}
10657
10658var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
10659var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
10660
10661
10662var didWarnAboutStateTransition = void 0;
10663var didWarnSetStateChildContext = void 0;
10664var warnAboutUpdateOnUnmounted = void 0;
10665var warnAboutInvalidUpdates = void 0;
10666
10667if (enableSchedulerTracing) {
10668 // Provide explicit error message when production+profiling bundle of e.g. react-dom
10669 // is used with production (non-profiling) bundle of scheduler/tracing
10670 !(__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;
10671}
10672
10673{
10674 didWarnAboutStateTransition = false;
10675 didWarnSetStateChildContext = false;
10676 var didWarnStateUpdateForUnmountedComponent = {};
10677
10678 warnAboutUpdateOnUnmounted = function (fiber, isClass) {
10679 // We show the whole stack but dedupe on the top component's name because
10680 // the problematic code almost always lies inside that component.
10681 var componentName = getComponentName(fiber.type) || 'ReactComponent';
10682 if (didWarnStateUpdateForUnmountedComponent[componentName]) {
10683 return;
10684 }
10685 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));
10686 didWarnStateUpdateForUnmountedComponent[componentName] = true;
10687 };
10688
10689 warnAboutInvalidUpdates = function (instance) {
10690 switch (phase) {
10691 case 'getChildContext':
10692 if (didWarnSetStateChildContext) {
10693 return;
10694 }
10695 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
10696 didWarnSetStateChildContext = true;
10697 break;
10698 case 'render':
10699 if (didWarnAboutStateTransition) {
10700 return;
10701 }
10702 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.');
10703 didWarnAboutStateTransition = true;
10704 break;
10705 }
10706 };
10707}
10708
10709var isWorking = false;
10710
10711// The next work in progress fiber that we're currently working on.
10712var nextUnitOfWork = null;
10713var nextRoot = null;
10714// The time at which we're currently rendering work.
10715var nextRenderExpirationTime = NoWork;
10716var nextLatestAbsoluteTimeoutMs = -1;
10717var nextRenderDidError = false;
10718
10719// The next fiber with an effect that we're currently committing.
10720var nextEffect = null;
10721
10722var isCommitting$1 = false;
10723var rootWithPendingPassiveEffects = null;
10724var passiveEffectCallbackHandle = null;
10725var passiveEffectCallback = null;
10726
10727var legacyErrorBoundariesThatAlreadyFailed = null;
10728
10729// Used for performance tracking.
10730var interruptedBy = null;
10731
10732var stashedWorkInProgressProperties = void 0;
10733var replayUnitOfWork = void 0;
10734var mayReplayFailedUnitOfWork = void 0;
10735var isReplayingFailedUnitOfWork = void 0;
10736var originalReplayError = void 0;
10737var rethrowOriginalError = void 0;
10738if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10739 stashedWorkInProgressProperties = null;
10740 mayReplayFailedUnitOfWork = true;
10741 isReplayingFailedUnitOfWork = false;
10742 originalReplayError = null;
10743 replayUnitOfWork = function (failedUnitOfWork, thrownValue, isYieldy) {
10744 if (thrownValue !== null && typeof thrownValue === 'object' && typeof thrownValue.then === 'function') {
10745 // Don't replay promises. Treat everything else like an error.
10746 // TODO: Need to figure out a different strategy if/when we add
10747 // support for catching other types.
10748 return;
10749 }
10750
10751 // Restore the original state of the work-in-progress
10752 if (stashedWorkInProgressProperties === null) {
10753 // This should never happen. Don't throw because this code is DEV-only.
10754 warningWithoutStack$1(false, 'Could not replay rendering after an error. This is likely a bug in React. ' + 'Please file an issue.');
10755 return;
10756 }
10757 assignFiberPropertiesInDEV(failedUnitOfWork, stashedWorkInProgressProperties);
10758
10759 switch (failedUnitOfWork.tag) {
10760 case HostRoot:
10761 popHostContainer(failedUnitOfWork);
10762 popTopLevelContextObject(failedUnitOfWork);
10763 break;
10764 case HostComponent:
10765 popHostContext(failedUnitOfWork);
10766 break;
10767 case ClassComponent:
10768 {
10769 var Component = failedUnitOfWork.type;
10770 if (isContextProvider(Component)) {
10771 popContext(failedUnitOfWork);
10772 }
10773 break;
10774 }
10775 case HostPortal:
10776 popHostContainer(failedUnitOfWork);
10777 break;
10778 case ContextProvider:
10779 popProvider(failedUnitOfWork);
10780 break;
10781 }
10782 // Replay the begin phase.
10783 isReplayingFailedUnitOfWork = true;
10784 originalReplayError = thrownValue;
10785 invokeGuardedCallback(null, workLoop, null, isYieldy);
10786 isReplayingFailedUnitOfWork = false;
10787 originalReplayError = null;
10788 if (hasCaughtError()) {
10789 var replayError = clearCaughtError();
10790 if (replayError != null && thrownValue != null) {
10791 try {
10792 // Reading the expando property is intentionally
10793 // inside `try` because it might be a getter or Proxy.
10794 if (replayError._suppressLogging) {
10795 // Also suppress logging for the original error.
10796 thrownValue._suppressLogging = true;
10797 }
10798 } catch (inner) {
10799 // Ignore.
10800 }
10801 }
10802 } else {
10803 // If the begin phase did not fail the second time, set this pointer
10804 // back to the original value.
10805 nextUnitOfWork = failedUnitOfWork;
10806 }
10807 };
10808 rethrowOriginalError = function () {
10809 throw originalReplayError;
10810 };
10811}
10812
10813function resetStack() {
10814 if (nextUnitOfWork !== null) {
10815 var interruptedWork = nextUnitOfWork.return;
10816 while (interruptedWork !== null) {
10817 unwindInterruptedWork(interruptedWork);
10818 interruptedWork = interruptedWork.return;
10819 }
10820 }
10821
10822 {
10823 ReactStrictModeWarnings.discardPendingWarnings();
10824 checkThatStackIsEmpty();
10825 }
10826
10827 nextRoot = null;
10828 nextRenderExpirationTime = NoWork;
10829 nextLatestAbsoluteTimeoutMs = -1;
10830 nextRenderDidError = false;
10831 nextUnitOfWork = null;
10832}
10833
10834function commitAllHostEffects() {
10835 while (nextEffect !== null) {
10836 {
10837 setCurrentFiber(nextEffect);
10838 }
10839 recordEffect();
10840
10841 var effectTag = nextEffect.effectTag;
10842
10843 if (effectTag & ContentReset) {
10844 commitResetTextContent(nextEffect);
10845 }
10846
10847 if (effectTag & Ref) {
10848 var current$$1 = nextEffect.alternate;
10849 if (current$$1 !== null) {
10850 commitDetachRef(current$$1);
10851 }
10852 }
10853
10854 // The following switch statement is only concerned about placement,
10855 // updates, and deletions. To avoid needing to add a case for every
10856 // possible bitmap value, we remove the secondary effects from the
10857 // effect tag and switch on that value.
10858 var primaryEffectTag = effectTag & (Placement | Update | Deletion);
10859 switch (primaryEffectTag) {
10860 case Placement:
10861 {
10862 commitPlacement(nextEffect);
10863 // Clear the "placement" from effect tag so that we know that this is inserted, before
10864 // any life-cycles like componentDidMount gets called.
10865 // TODO: findDOMNode doesn't rely on this any more but isMounted
10866 // does and isMounted is deprecated anyway so we should be able
10867 // to kill this.
10868 nextEffect.effectTag &= ~Placement;
10869 break;
10870 }
10871 case PlacementAndUpdate:
10872 {
10873 // Placement
10874 commitPlacement(nextEffect);
10875 // Clear the "placement" from effect tag so that we know that this is inserted, before
10876 // any life-cycles like componentDidMount gets called.
10877 nextEffect.effectTag &= ~Placement;
10878
10879 // Update
10880 var _current = nextEffect.alternate;
10881 commitWork(_current, nextEffect);
10882 break;
10883 }
10884 case Update:
10885 {
10886 var _current2 = nextEffect.alternate;
10887 commitWork(_current2, nextEffect);
10888 break;
10889 }
10890 case Deletion:
10891 {
10892 commitDeletion(nextEffect);
10893 break;
10894 }
10895 }
10896 nextEffect = nextEffect.nextEffect;
10897 }
10898
10899 {
10900 resetCurrentFiber();
10901 }
10902}
10903
10904function commitBeforeMutationLifecycles() {
10905 while (nextEffect !== null) {
10906 {
10907 setCurrentFiber(nextEffect);
10908 }
10909
10910 var effectTag = nextEffect.effectTag;
10911 if (effectTag & Snapshot) {
10912 recordEffect();
10913 var current$$1 = nextEffect.alternate;
10914 commitBeforeMutationLifeCycles(current$$1, nextEffect);
10915 }
10916
10917 nextEffect = nextEffect.nextEffect;
10918 }
10919
10920 {
10921 resetCurrentFiber();
10922 }
10923}
10924
10925function commitAllLifeCycles(finishedRoot, committedExpirationTime) {
10926 {
10927 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
10928 ReactStrictModeWarnings.flushLegacyContextWarning();
10929
10930 if (warnAboutDeprecatedLifecycles) {
10931 ReactStrictModeWarnings.flushPendingDeprecationWarnings();
10932 }
10933 }
10934 while (nextEffect !== null) {
10935 {
10936 setCurrentFiber(nextEffect);
10937 }
10938 var effectTag = nextEffect.effectTag;
10939
10940 if (effectTag & (Update | Callback)) {
10941 recordEffect();
10942 var current$$1 = nextEffect.alternate;
10943 commitLifeCycles(finishedRoot, current$$1, nextEffect, committedExpirationTime);
10944 }
10945
10946 if (effectTag & Ref) {
10947 recordEffect();
10948 commitAttachRef(nextEffect);
10949 }
10950
10951 if (effectTag & Passive) {
10952 rootWithPendingPassiveEffects = finishedRoot;
10953 }
10954
10955 nextEffect = nextEffect.nextEffect;
10956 }
10957 {
10958 resetCurrentFiber();
10959 }
10960}
10961
10962function commitPassiveEffects(root, firstEffect) {
10963 rootWithPendingPassiveEffects = null;
10964 passiveEffectCallbackHandle = null;
10965 passiveEffectCallback = null;
10966
10967 // Set this to true to prevent re-entrancy
10968 var previousIsRendering = isRendering;
10969 isRendering = true;
10970
10971 var effect = firstEffect;
10972 do {
10973 {
10974 setCurrentFiber(effect);
10975 }
10976
10977 if (effect.effectTag & Passive) {
10978 var didError = false;
10979 var error = void 0;
10980 {
10981 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
10982 if (hasCaughtError()) {
10983 didError = true;
10984 error = clearCaughtError();
10985 }
10986 }
10987 if (didError) {
10988 captureCommitPhaseError(effect, error);
10989 }
10990 }
10991 effect = effect.nextEffect;
10992 } while (effect !== null);
10993 {
10994 resetCurrentFiber();
10995 }
10996
10997 isRendering = previousIsRendering;
10998
10999 // Check if work was scheduled by one of the effects
11000 var rootExpirationTime = root.expirationTime;
11001 if (rootExpirationTime !== NoWork) {
11002 requestWork(root, rootExpirationTime);
11003 }
11004 // Flush any sync work that was scheduled by effects
11005 if (!isBatchingUpdates && !isRendering) {
11006 performSyncWork();
11007 }
11008}
11009
11010function isAlreadyFailedLegacyErrorBoundary(instance) {
11011 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
11012}
11013
11014function markLegacyErrorBoundaryAsFailed(instance) {
11015 if (legacyErrorBoundariesThatAlreadyFailed === null) {
11016 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
11017 } else {
11018 legacyErrorBoundariesThatAlreadyFailed.add(instance);
11019 }
11020}
11021
11022function flushPassiveEffects$1() {
11023 if (passiveEffectCallbackHandle !== null) {
11024 cancelPassiveEffects(passiveEffectCallbackHandle);
11025 }
11026 if (passiveEffectCallback !== null) {
11027 // We call the scheduled callback instead of commitPassiveEffects directly
11028 // to ensure tracing works correctly.
11029 passiveEffectCallback();
11030 }
11031}
11032
11033function commitRoot(root, finishedWork) {
11034 isWorking = true;
11035 isCommitting$1 = true;
11036 startCommitTimer();
11037
11038 !(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;
11039 var committedExpirationTime = root.pendingCommitExpirationTime;
11040 !(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;
11041 root.pendingCommitExpirationTime = NoWork;
11042
11043 // Update the pending priority levels to account for the work that we are
11044 // about to commit. This needs to happen before calling the lifecycles, since
11045 // they may schedule additional updates.
11046 var updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
11047 var childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
11048 var earliestRemainingTimeBeforeCommit = childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit ? childExpirationTimeBeforeCommit : updateExpirationTimeBeforeCommit;
11049 markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
11050
11051 var prevInteractions = null;
11052 if (enableSchedulerTracing) {
11053 // Restore any pending interactions at this point,
11054 // So that cascading work triggered during the render phase will be accounted for.
11055 prevInteractions = __interactionsRef.current;
11056 __interactionsRef.current = root.memoizedInteractions;
11057 }
11058
11059 // Reset this to null before calling lifecycles
11060 ReactCurrentOwner$1.current = null;
11061
11062 var firstEffect = void 0;
11063 if (finishedWork.effectTag > PerformedWork) {
11064 // A fiber's effect list consists only of its children, not itself. So if
11065 // the root has an effect, we need to add it to the end of the list. The
11066 // resulting list is the set that would belong to the root's parent, if
11067 // it had one; that is, all the effects in the tree including the root.
11068 if (finishedWork.lastEffect !== null) {
11069 finishedWork.lastEffect.nextEffect = finishedWork;
11070 firstEffect = finishedWork.firstEffect;
11071 } else {
11072 firstEffect = finishedWork;
11073 }
11074 } else {
11075 // There is no effect on the root.
11076 firstEffect = finishedWork.firstEffect;
11077 }
11078
11079 prepareForCommit(root.containerInfo);
11080
11081 // Invoke instances of getSnapshotBeforeUpdate before mutation.
11082 nextEffect = firstEffect;
11083 startCommitSnapshotEffectsTimer();
11084 while (nextEffect !== null) {
11085 var didError = false;
11086 var error = void 0;
11087 {
11088 invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
11089 if (hasCaughtError()) {
11090 didError = true;
11091 error = clearCaughtError();
11092 }
11093 }
11094 if (didError) {
11095 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11096 captureCommitPhaseError(nextEffect, error);
11097 // Clean-up
11098 if (nextEffect !== null) {
11099 nextEffect = nextEffect.nextEffect;
11100 }
11101 }
11102 }
11103 stopCommitSnapshotEffectsTimer();
11104
11105 if (enableProfilerTimer) {
11106 // Mark the current commit time to be shared by all Profilers in this batch.
11107 // This enables them to be grouped later.
11108 recordCommitTime();
11109 }
11110
11111 // Commit all the side-effects within a tree. We'll do this in two passes.
11112 // The first pass performs all the host insertions, updates, deletions and
11113 // ref unmounts.
11114 nextEffect = firstEffect;
11115 startCommitHostEffectsTimer();
11116 while (nextEffect !== null) {
11117 var _didError = false;
11118 var _error = void 0;
11119 {
11120 invokeGuardedCallback(null, commitAllHostEffects, null);
11121 if (hasCaughtError()) {
11122 _didError = true;
11123 _error = clearCaughtError();
11124 }
11125 }
11126 if (_didError) {
11127 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11128 captureCommitPhaseError(nextEffect, _error);
11129 // Clean-up
11130 if (nextEffect !== null) {
11131 nextEffect = nextEffect.nextEffect;
11132 }
11133 }
11134 }
11135 stopCommitHostEffectsTimer();
11136
11137 resetAfterCommit(root.containerInfo);
11138
11139 // The work-in-progress tree is now the current tree. This must come after
11140 // the first pass of the commit phase, so that the previous tree is still
11141 // current during componentWillUnmount, but before the second pass, so that
11142 // the finished work is current during componentDidMount/Update.
11143 root.current = finishedWork;
11144
11145 // In the second pass we'll perform all life-cycles and ref callbacks.
11146 // Life-cycles happen as a separate pass so that all placements, updates,
11147 // and deletions in the entire tree have already been invoked.
11148 // This pass also triggers any renderer-specific initial effects.
11149 nextEffect = firstEffect;
11150 startCommitLifeCyclesTimer();
11151 while (nextEffect !== null) {
11152 var _didError2 = false;
11153 var _error2 = void 0;
11154 {
11155 invokeGuardedCallback(null, commitAllLifeCycles, null, root, committedExpirationTime);
11156 if (hasCaughtError()) {
11157 _didError2 = true;
11158 _error2 = clearCaughtError();
11159 }
11160 }
11161 if (_didError2) {
11162 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11163 captureCommitPhaseError(nextEffect, _error2);
11164 if (nextEffect !== null) {
11165 nextEffect = nextEffect.nextEffect;
11166 }
11167 }
11168 }
11169
11170 if (firstEffect !== null && rootWithPendingPassiveEffects !== null) {
11171 // This commit included a passive effect. These do not need to fire until
11172 // after the next paint. Schedule an callback to fire them in an async
11173 // event. To ensure serial execution, the callback will be flushed early if
11174 // we enter rootWithPendingPassiveEffects commit phase before then.
11175 var callback = commitPassiveEffects.bind(null, root, firstEffect);
11176 if (enableSchedulerTracing) {
11177 // TODO: Avoid this extra callback by mutating the tracing ref directly,
11178 // like we do at the beginning of commitRoot. I've opted not to do that
11179 // here because that code is still in flux.
11180 callback = unstable_wrap(callback);
11181 }
11182 passiveEffectCallbackHandle = unstable_runWithPriority(unstable_NormalPriority, function () {
11183 return schedulePassiveEffects(callback);
11184 });
11185 passiveEffectCallback = callback;
11186 }
11187
11188 isCommitting$1 = false;
11189 isWorking = false;
11190 stopCommitLifeCyclesTimer();
11191 stopCommitTimer();
11192 onCommitRoot(finishedWork.stateNode);
11193 if (true && ReactFiberInstrumentation_1.debugTool) {
11194 ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork);
11195 }
11196
11197 var updateExpirationTimeAfterCommit = finishedWork.expirationTime;
11198 var childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
11199 var earliestRemainingTimeAfterCommit = childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit ? childExpirationTimeAfterCommit : updateExpirationTimeAfterCommit;
11200 if (earliestRemainingTimeAfterCommit === NoWork) {
11201 // If there's no remaining work, we can clear the set of already failed
11202 // error boundaries.
11203 legacyErrorBoundariesThatAlreadyFailed = null;
11204 }
11205 onCommit(root, earliestRemainingTimeAfterCommit);
11206
11207 if (enableSchedulerTracing) {
11208 __interactionsRef.current = prevInteractions;
11209
11210 var subscriber = void 0;
11211
11212 try {
11213 subscriber = __subscriberRef.current;
11214 if (subscriber !== null && root.memoizedInteractions.size > 0) {
11215 var threadID = computeThreadID(committedExpirationTime, root.interactionThreadID);
11216 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
11217 }
11218 } catch (error) {
11219 // It's not safe for commitRoot() to throw.
11220 // Store the error for now and we'll re-throw in finishRendering().
11221 if (!hasUnhandledError) {
11222 hasUnhandledError = true;
11223 unhandledError = error;
11224 }
11225 } finally {
11226 // Clear completed interactions from the pending Map.
11227 // Unless the render was suspended or cascading work was scheduled,
11228 // In which case– leave pending interactions until the subsequent render.
11229 var pendingInteractionMap = root.pendingInteractionMap;
11230 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11231 // Only decrement the pending interaction count if we're done.
11232 // If there's still work at the current priority,
11233 // That indicates that we are waiting for suspense data.
11234 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
11235 pendingInteractionMap.delete(scheduledExpirationTime);
11236
11237 scheduledInteractions.forEach(function (interaction) {
11238 interaction.__count--;
11239
11240 if (subscriber !== null && interaction.__count === 0) {
11241 try {
11242 subscriber.onInteractionScheduledWorkCompleted(interaction);
11243 } catch (error) {
11244 // It's not safe for commitRoot() to throw.
11245 // Store the error for now and we'll re-throw in finishRendering().
11246 if (!hasUnhandledError) {
11247 hasUnhandledError = true;
11248 unhandledError = error;
11249 }
11250 }
11251 }
11252 });
11253 }
11254 });
11255 }
11256 }
11257}
11258
11259function resetChildExpirationTime(workInProgress, renderTime) {
11260 if (renderTime !== Never && workInProgress.childExpirationTime === Never) {
11261 // The children of this component are hidden. Don't bubble their
11262 // expiration times.
11263 return;
11264 }
11265
11266 var newChildExpirationTime = NoWork;
11267
11268 // Bubble up the earliest expiration time.
11269 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11270 // We're in profiling mode.
11271 // Let's use this same traversal to update the render durations.
11272 var actualDuration = workInProgress.actualDuration;
11273 var treeBaseDuration = workInProgress.selfBaseDuration;
11274
11275 // When a fiber is cloned, its actualDuration is reset to 0.
11276 // This value will only be updated if work is done on the fiber (i.e. it doesn't bailout).
11277 // When work is done, it should bubble to the parent's actualDuration.
11278 // If the fiber has not been cloned though, (meaning no work was done),
11279 // Then this value will reflect the amount of time spent working on a previous render.
11280 // In that case it should not bubble.
11281 // We determine whether it was cloned by comparing the child pointer.
11282 var shouldBubbleActualDurations = workInProgress.alternate === null || workInProgress.child !== workInProgress.alternate.child;
11283
11284 var child = workInProgress.child;
11285 while (child !== null) {
11286 var childUpdateExpirationTime = child.expirationTime;
11287 var childChildExpirationTime = child.childExpirationTime;
11288 if (childUpdateExpirationTime > newChildExpirationTime) {
11289 newChildExpirationTime = childUpdateExpirationTime;
11290 }
11291 if (childChildExpirationTime > newChildExpirationTime) {
11292 newChildExpirationTime = childChildExpirationTime;
11293 }
11294 if (shouldBubbleActualDurations) {
11295 actualDuration += child.actualDuration;
11296 }
11297 treeBaseDuration += child.treeBaseDuration;
11298 child = child.sibling;
11299 }
11300 workInProgress.actualDuration = actualDuration;
11301 workInProgress.treeBaseDuration = treeBaseDuration;
11302 } else {
11303 var _child = workInProgress.child;
11304 while (_child !== null) {
11305 var _childUpdateExpirationTime = _child.expirationTime;
11306 var _childChildExpirationTime = _child.childExpirationTime;
11307 if (_childUpdateExpirationTime > newChildExpirationTime) {
11308 newChildExpirationTime = _childUpdateExpirationTime;
11309 }
11310 if (_childChildExpirationTime > newChildExpirationTime) {
11311 newChildExpirationTime = _childChildExpirationTime;
11312 }
11313 _child = _child.sibling;
11314 }
11315 }
11316
11317 workInProgress.childExpirationTime = newChildExpirationTime;
11318}
11319
11320function completeUnitOfWork(workInProgress) {
11321 // Attempt to complete the current unit of work, then move to the
11322 // next sibling. If there are no more siblings, return to the
11323 // parent fiber.
11324 while (true) {
11325 // The current, flushed, state of this fiber is the alternate.
11326 // Ideally nothing should rely on this, but relying on it here
11327 // means that we don't need an additional field on the work in
11328 // progress.
11329 var current$$1 = workInProgress.alternate;
11330 {
11331 setCurrentFiber(workInProgress);
11332 }
11333
11334 var returnFiber = workInProgress.return;
11335 var siblingFiber = workInProgress.sibling;
11336
11337 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
11338 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11339 // Don't replay if it fails during completion phase.
11340 mayReplayFailedUnitOfWork = false;
11341 }
11342 // This fiber completed.
11343 // Remember we're completing this unit so we can find a boundary if it fails.
11344 nextUnitOfWork = workInProgress;
11345 if (enableProfilerTimer) {
11346 if (workInProgress.mode & ProfileMode) {
11347 startProfilerTimer(workInProgress);
11348 }
11349 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
11350 if (workInProgress.mode & ProfileMode) {
11351 // Update render duration assuming we didn't error.
11352 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11353 }
11354 } else {
11355 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
11356 }
11357 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11358 // We're out of completion phase so replaying is fine now.
11359 mayReplayFailedUnitOfWork = true;
11360 }
11361 stopWorkTimer(workInProgress);
11362 resetChildExpirationTime(workInProgress, nextRenderExpirationTime);
11363 {
11364 resetCurrentFiber();
11365 }
11366
11367 if (nextUnitOfWork !== null) {
11368 // Completing this fiber spawned new work. Work on that next.
11369 return nextUnitOfWork;
11370 }
11371
11372 if (returnFiber !== null &&
11373 // Do not append effects to parents if a sibling failed to complete
11374 (returnFiber.effectTag & Incomplete) === NoEffect) {
11375 // Append all the effects of the subtree and this fiber onto the effect
11376 // list of the parent. The completion order of the children affects the
11377 // side-effect order.
11378 if (returnFiber.firstEffect === null) {
11379 returnFiber.firstEffect = workInProgress.firstEffect;
11380 }
11381 if (workInProgress.lastEffect !== null) {
11382 if (returnFiber.lastEffect !== null) {
11383 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
11384 }
11385 returnFiber.lastEffect = workInProgress.lastEffect;
11386 }
11387
11388 // If this fiber had side-effects, we append it AFTER the children's
11389 // side-effects. We can perform certain side-effects earlier if
11390 // needed, by doing multiple passes over the effect list. We don't want
11391 // to schedule our own side-effect on our own list because if end up
11392 // reusing children we'll schedule this effect onto itself since we're
11393 // at the end.
11394 var effectTag = workInProgress.effectTag;
11395 // Skip both NoWork and PerformedWork tags when creating the effect list.
11396 // PerformedWork effect is read by React DevTools but shouldn't be committed.
11397 if (effectTag > PerformedWork) {
11398 if (returnFiber.lastEffect !== null) {
11399 returnFiber.lastEffect.nextEffect = workInProgress;
11400 } else {
11401 returnFiber.firstEffect = workInProgress;
11402 }
11403 returnFiber.lastEffect = workInProgress;
11404 }
11405 }
11406
11407 if (true && ReactFiberInstrumentation_1.debugTool) {
11408 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11409 }
11410
11411 if (siblingFiber !== null) {
11412 // If there is more work to do in this returnFiber, do that next.
11413 return siblingFiber;
11414 } else if (returnFiber !== null) {
11415 // If there's no more work in this returnFiber. Complete the returnFiber.
11416 workInProgress = returnFiber;
11417 continue;
11418 } else {
11419 // We've reached the root.
11420 return null;
11421 }
11422 } else {
11423 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11424 // Record the render duration for the fiber that errored.
11425 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11426
11427 // Include the time spent working on failed children before continuing.
11428 var actualDuration = workInProgress.actualDuration;
11429 var child = workInProgress.child;
11430 while (child !== null) {
11431 actualDuration += child.actualDuration;
11432 child = child.sibling;
11433 }
11434 workInProgress.actualDuration = actualDuration;
11435 }
11436
11437 // This fiber did not complete because something threw. Pop values off
11438 // the stack without entering the complete phase. If this is a boundary,
11439 // capture values if possible.
11440 var next = unwindWork(workInProgress, nextRenderExpirationTime);
11441 // Because this fiber did not complete, don't reset its expiration time.
11442 if (workInProgress.effectTag & DidCapture) {
11443 // Restarting an error boundary
11444 stopFailedWorkTimer(workInProgress);
11445 } else {
11446 stopWorkTimer(workInProgress);
11447 }
11448
11449 {
11450 resetCurrentFiber();
11451 }
11452
11453 if (next !== null) {
11454 stopWorkTimer(workInProgress);
11455 if (true && ReactFiberInstrumentation_1.debugTool) {
11456 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11457 }
11458
11459 // If completing this work spawned new work, do that next. We'll come
11460 // back here again.
11461 // Since we're restarting, remove anything that is not a host effect
11462 // from the effect tag.
11463 next.effectTag &= HostEffectMask;
11464 return next;
11465 }
11466
11467 if (returnFiber !== null) {
11468 // Mark the parent fiber as incomplete and clear its effect list.
11469 returnFiber.firstEffect = returnFiber.lastEffect = null;
11470 returnFiber.effectTag |= Incomplete;
11471 }
11472
11473 if (true && ReactFiberInstrumentation_1.debugTool) {
11474 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11475 }
11476
11477 if (siblingFiber !== null) {
11478 // If there is more work to do in this returnFiber, do that next.
11479 return siblingFiber;
11480 } else if (returnFiber !== null) {
11481 // If there's no more work in this returnFiber. Complete the returnFiber.
11482 workInProgress = returnFiber;
11483 continue;
11484 } else {
11485 return null;
11486 }
11487 }
11488 }
11489
11490 // Without this explicit null return Flow complains of invalid return type
11491 // TODO Remove the above while(true) loop
11492 // eslint-disable-next-line no-unreachable
11493 return null;
11494}
11495
11496function performUnitOfWork(workInProgress) {
11497 // The current, flushed, state of this fiber is the alternate.
11498 // Ideally nothing should rely on this, but relying on it here
11499 // means that we don't need an additional field on the work in
11500 // progress.
11501 var current$$1 = workInProgress.alternate;
11502
11503 // See if beginning this work spawns more work.
11504 startWorkTimer(workInProgress);
11505 {
11506 setCurrentFiber(workInProgress);
11507 }
11508
11509 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11510 stashedWorkInProgressProperties = assignFiberPropertiesInDEV(stashedWorkInProgressProperties, workInProgress);
11511 }
11512
11513 var next = void 0;
11514 if (enableProfilerTimer) {
11515 if (workInProgress.mode & ProfileMode) {
11516 startProfilerTimer(workInProgress);
11517 }
11518
11519 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11520 workInProgress.memoizedProps = workInProgress.pendingProps;
11521
11522 if (workInProgress.mode & ProfileMode) {
11523 // Record the render duration assuming we didn't bailout (or error).
11524 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
11525 }
11526 } else {
11527 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11528 workInProgress.memoizedProps = workInProgress.pendingProps;
11529 }
11530
11531 {
11532 resetCurrentFiber();
11533 if (isReplayingFailedUnitOfWork) {
11534 // Currently replaying a failed unit of work. This should be unreachable,
11535 // because the render phase is meant to be idempotent, and it should
11536 // have thrown again. Since it didn't, rethrow the original error, so
11537 // React's internal stack is not misaligned.
11538 rethrowOriginalError();
11539 }
11540 }
11541 if (true && ReactFiberInstrumentation_1.debugTool) {
11542 ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress);
11543 }
11544
11545 if (next === null) {
11546 // If this doesn't spawn new work, complete the current work.
11547 next = completeUnitOfWork(workInProgress);
11548 }
11549
11550 ReactCurrentOwner$1.current = null;
11551
11552 return next;
11553}
11554
11555function workLoop(isYieldy) {
11556 if (!isYieldy) {
11557 // Flush work without yielding
11558 while (nextUnitOfWork !== null) {
11559 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11560 }
11561 } else {
11562 // Flush asynchronous work until there's a higher priority event
11563 while (nextUnitOfWork !== null && !shouldYieldToRenderer()) {
11564 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11565 }
11566 }
11567}
11568
11569function renderRoot(root, isYieldy) {
11570 !!isWorking ? invariant(false, 'renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11571
11572 flushPassiveEffects$1();
11573
11574 isWorking = true;
11575 var previousDispatcher = ReactCurrentDispatcher.current;
11576 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
11577
11578 var expirationTime = root.nextExpirationTimeToWorkOn;
11579
11580 // Check if we're starting from a fresh stack, or if we're resuming from
11581 // previously yielded work.
11582 if (expirationTime !== nextRenderExpirationTime || root !== nextRoot || nextUnitOfWork === null) {
11583 // Reset the stack and start working from the root.
11584 resetStack();
11585 nextRoot = root;
11586 nextRenderExpirationTime = expirationTime;
11587 nextUnitOfWork = createWorkInProgress(nextRoot.current, null, nextRenderExpirationTime);
11588 root.pendingCommitExpirationTime = NoWork;
11589
11590 if (enableSchedulerTracing) {
11591 // Determine which interactions this batch of work currently includes,
11592 // So that we can accurately attribute time spent working on it,
11593 var interactions = new Set();
11594 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11595 if (scheduledExpirationTime >= expirationTime) {
11596 scheduledInteractions.forEach(function (interaction) {
11597 return interactions.add(interaction);
11598 });
11599 }
11600 });
11601
11602 // Store the current set of interactions on the FiberRoot for a few reasons:
11603 // We can re-use it in hot functions like renderRoot() without having to recalculate it.
11604 // We will also use it in commitWork() to pass to any Profiler onRender() hooks.
11605 // This also provides DevTools with a way to access it when the onCommitRoot() hook is called.
11606 root.memoizedInteractions = interactions;
11607
11608 if (interactions.size > 0) {
11609 var subscriber = __subscriberRef.current;
11610 if (subscriber !== null) {
11611 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11612 try {
11613 subscriber.onWorkStarted(interactions, threadID);
11614 } catch (error) {
11615 // Work thrown by an interaction tracing subscriber should be rethrown,
11616 // But only once it's safe (to avoid leaving the scheduler in an invalid state).
11617 // Store the error for now and we'll re-throw in finishRendering().
11618 if (!hasUnhandledError) {
11619 hasUnhandledError = true;
11620 unhandledError = error;
11621 }
11622 }
11623 }
11624 }
11625 }
11626 }
11627
11628 var prevInteractions = null;
11629 if (enableSchedulerTracing) {
11630 // We're about to start new traced work.
11631 // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
11632 prevInteractions = __interactionsRef.current;
11633 __interactionsRef.current = root.memoizedInteractions;
11634 }
11635
11636 var didFatal = false;
11637
11638 startWorkLoopTimer(nextUnitOfWork);
11639
11640 do {
11641 try {
11642 workLoop(isYieldy);
11643 } catch (thrownValue) {
11644 resetContextDependences();
11645 resetHooks();
11646
11647 // Reset in case completion throws.
11648 // This is only used in DEV and when replaying is on.
11649 var mayReplay = void 0;
11650 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11651 mayReplay = mayReplayFailedUnitOfWork;
11652 mayReplayFailedUnitOfWork = true;
11653 }
11654
11655 if (nextUnitOfWork === null) {
11656 // This is a fatal error.
11657 didFatal = true;
11658 onUncaughtError(thrownValue);
11659 } else {
11660 if (enableProfilerTimer && nextUnitOfWork.mode & ProfileMode) {
11661 // Record the time spent rendering before an error was thrown.
11662 // This avoids inaccurate Profiler durations in the case of a suspended render.
11663 stopProfilerTimerIfRunningAndRecordDelta(nextUnitOfWork, true);
11664 }
11665
11666 {
11667 // Reset global debug state
11668 // We assume this is defined in DEV
11669 resetCurrentlyProcessingQueue();
11670 }
11671
11672 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11673 if (mayReplay) {
11674 var failedUnitOfWork = nextUnitOfWork;
11675 replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
11676 }
11677 }
11678
11679 // TODO: we already know this isn't true in some cases.
11680 // At least this shows a nicer error message until we figure out the cause.
11681 // https://github.com/facebook/react/issues/12449#issuecomment-386727431
11682 !(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;
11683
11684 var sourceFiber = nextUnitOfWork;
11685 var returnFiber = sourceFiber.return;
11686 if (returnFiber === null) {
11687 // This is the root. The root could capture its own errors. However,
11688 // we don't know if it errors before or after we pushed the host
11689 // context. This information is needed to avoid a stack mismatch.
11690 // Because we're not sure, treat this as a fatal error. We could track
11691 // which phase it fails in, but doesn't seem worth it. At least
11692 // for now.
11693 didFatal = true;
11694 onUncaughtError(thrownValue);
11695 } else {
11696 throwException(root, returnFiber, sourceFiber, thrownValue, nextRenderExpirationTime);
11697 nextUnitOfWork = completeUnitOfWork(sourceFiber);
11698 continue;
11699 }
11700 }
11701 }
11702 break;
11703 } while (true);
11704
11705 if (enableSchedulerTracing) {
11706 // Traced work is done for now; restore the previous interactions.
11707 __interactionsRef.current = prevInteractions;
11708 }
11709
11710 // We're done performing work. Time to clean up.
11711 isWorking = false;
11712 ReactCurrentDispatcher.current = previousDispatcher;
11713 resetContextDependences();
11714 resetHooks();
11715
11716 // Yield back to main thread.
11717 if (didFatal) {
11718 var _didCompleteRoot = false;
11719 stopWorkLoopTimer(interruptedBy, _didCompleteRoot);
11720 interruptedBy = null;
11721 // There was a fatal error.
11722 {
11723 resetStackAfterFatalErrorInDev();
11724 }
11725 // `nextRoot` points to the in-progress root. A non-null value indicates
11726 // that we're in the middle of an async render. Set it to null to indicate
11727 // there's no more work to be done in the current batch.
11728 nextRoot = null;
11729 onFatal(root);
11730 return;
11731 }
11732
11733 if (nextUnitOfWork !== null) {
11734 // There's still remaining async work in this tree, but we ran out of time
11735 // in the current frame. Yield back to the renderer. Unless we're
11736 // interrupted by a higher priority update, we'll continue later from where
11737 // we left off.
11738 var _didCompleteRoot2 = false;
11739 stopWorkLoopTimer(interruptedBy, _didCompleteRoot2);
11740 interruptedBy = null;
11741 onYield(root);
11742 return;
11743 }
11744
11745 // We completed the whole tree.
11746 var didCompleteRoot = true;
11747 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
11748 var rootWorkInProgress = root.current.alternate;
11749 !(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;
11750
11751 // `nextRoot` points to the in-progress root. A non-null value indicates
11752 // that we're in the middle of an async render. Set it to null to indicate
11753 // there's no more work to be done in the current batch.
11754 nextRoot = null;
11755 interruptedBy = null;
11756
11757 if (nextRenderDidError) {
11758 // There was an error
11759 if (hasLowerPriorityWork(root, expirationTime)) {
11760 // There's lower priority work. If so, it may have the effect of fixing
11761 // the exception that was just thrown. Exit without committing. This is
11762 // similar to a suspend, but without a timeout because we're not waiting
11763 // for a promise to resolve. React will restart at the lower
11764 // priority level.
11765 markSuspendedPriorityLevel(root, expirationTime);
11766 var suspendedExpirationTime = expirationTime;
11767 var rootExpirationTime = root.expirationTime;
11768 onSuspend(root, rootWorkInProgress, suspendedExpirationTime, rootExpirationTime, -1 // Indicates no timeout
11769 );
11770 return;
11771 } else if (
11772 // There's no lower priority work, but we're rendering asynchronously.
11773 // Synchronously attempt to render the same level one more time. This is
11774 // similar to a suspend, but without a timeout because we're not waiting
11775 // for a promise to resolve.
11776 !root.didError && isYieldy) {
11777 root.didError = true;
11778 var _suspendedExpirationTime = root.nextExpirationTimeToWorkOn = expirationTime;
11779 var _rootExpirationTime = root.expirationTime = Sync;
11780 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime, _rootExpirationTime, -1 // Indicates no timeout
11781 );
11782 return;
11783 }
11784 }
11785
11786 if (isYieldy && nextLatestAbsoluteTimeoutMs !== -1) {
11787 // The tree was suspended.
11788 var _suspendedExpirationTime2 = expirationTime;
11789 markSuspendedPriorityLevel(root, _suspendedExpirationTime2);
11790
11791 // Find the earliest uncommitted expiration time in the tree, including
11792 // work that is suspended. The timeout threshold cannot be longer than
11793 // the overall expiration.
11794 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, expirationTime);
11795 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
11796 if (earliestExpirationTimeMs < nextLatestAbsoluteTimeoutMs) {
11797 nextLatestAbsoluteTimeoutMs = earliestExpirationTimeMs;
11798 }
11799
11800 // Subtract the current time from the absolute timeout to get the number
11801 // of milliseconds until the timeout. In other words, convert an absolute
11802 // timestamp to a relative time. This is the value that is passed
11803 // to `setTimeout`.
11804 var currentTimeMs = expirationTimeToMs(requestCurrentTime());
11805 var msUntilTimeout = nextLatestAbsoluteTimeoutMs - currentTimeMs;
11806 msUntilTimeout = msUntilTimeout < 0 ? 0 : msUntilTimeout;
11807
11808 // TODO: Account for the Just Noticeable Difference
11809
11810 var _rootExpirationTime2 = root.expirationTime;
11811 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime2, _rootExpirationTime2, msUntilTimeout);
11812 return;
11813 }
11814
11815 // Ready to commit.
11816 onComplete(root, rootWorkInProgress, expirationTime);
11817}
11818
11819function captureCommitPhaseError(sourceFiber, value) {
11820 var expirationTime = Sync;
11821 var fiber = sourceFiber.return;
11822 while (fiber !== null) {
11823 switch (fiber.tag) {
11824 case ClassComponent:
11825 var ctor = fiber.type;
11826 var instance = fiber.stateNode;
11827 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
11828 var errorInfo = createCapturedValue(value, sourceFiber);
11829 var update = createClassErrorUpdate(fiber, errorInfo, expirationTime);
11830 enqueueUpdate(fiber, update);
11831 scheduleWork(fiber, expirationTime);
11832 return;
11833 }
11834 break;
11835 case HostRoot:
11836 {
11837 var _errorInfo = createCapturedValue(value, sourceFiber);
11838 var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime);
11839 enqueueUpdate(fiber, _update);
11840 scheduleWork(fiber, expirationTime);
11841 return;
11842 }
11843 }
11844 fiber = fiber.return;
11845 }
11846
11847 if (sourceFiber.tag === HostRoot) {
11848 // Error was thrown at the root. There is no parent, so the root
11849 // itself should capture it.
11850 var rootFiber = sourceFiber;
11851 var _errorInfo2 = createCapturedValue(value, rootFiber);
11852 var _update2 = createRootErrorUpdate(rootFiber, _errorInfo2, expirationTime);
11853 enqueueUpdate(rootFiber, _update2);
11854 scheduleWork(rootFiber, expirationTime);
11855 }
11856}
11857
11858function computeThreadID(expirationTime, interactionThreadID) {
11859 // Interaction threads are unique per root and expiration time.
11860 return expirationTime * 1000 + interactionThreadID;
11861}
11862
11863function computeExpirationForFiber(currentTime, fiber) {
11864 var priorityLevel = unstable_getCurrentPriorityLevel();
11865
11866 var expirationTime = void 0;
11867 if ((fiber.mode & ConcurrentMode) === NoContext) {
11868 // Outside of concurrent mode, updates are always synchronous.
11869 expirationTime = Sync;
11870 } else if (isWorking && !isCommitting$1) {
11871 // During render phase, updates expire during as the current render.
11872 expirationTime = nextRenderExpirationTime;
11873 } else {
11874 switch (priorityLevel) {
11875 case unstable_ImmediatePriority:
11876 expirationTime = Sync;
11877 break;
11878 case unstable_UserBlockingPriority:
11879 expirationTime = computeInteractiveExpiration(currentTime);
11880 break;
11881 case unstable_NormalPriority:
11882 // This is a normal, concurrent update
11883 expirationTime = computeAsyncExpiration(currentTime);
11884 break;
11885 case unstable_LowPriority:
11886 case unstable_IdlePriority:
11887 expirationTime = Never;
11888 break;
11889 default:
11890 invariant(false, 'Unknown priority level. This error is likely caused by a bug in React. Please file an issue.');
11891 }
11892
11893 // If we're in the middle of rendering a tree, do not update at the same
11894 // expiration time that is already rendering.
11895 if (nextRoot !== null && expirationTime === nextRenderExpirationTime) {
11896 expirationTime -= 1;
11897 }
11898 }
11899
11900 // Keep track of the lowest pending interactive expiration time. This
11901 // allows us to synchronously flush all interactive updates
11902 // when needed.
11903 // TODO: Move this to renderer?
11904 return expirationTime;
11905}
11906
11907function renderDidSuspend(root, absoluteTimeoutMs, suspendedTime) {
11908 // Schedule the timeout.
11909 if (absoluteTimeoutMs >= 0 && nextLatestAbsoluteTimeoutMs < absoluteTimeoutMs) {
11910 nextLatestAbsoluteTimeoutMs = absoluteTimeoutMs;
11911 }
11912}
11913
11914function renderDidError() {
11915 nextRenderDidError = true;
11916}
11917
11918function pingSuspendedRoot(root, thenable, pingTime) {
11919 // A promise that previously suspended React from committing has resolved.
11920 // If React is still suspended, try again at the previous level (pingTime).
11921
11922 var pingCache = root.pingCache;
11923 if (pingCache !== null) {
11924 // The thenable resolved, so we no longer need to memoize, because it will
11925 // never be thrown again.
11926 pingCache.delete(thenable);
11927 }
11928
11929 if (nextRoot !== null && nextRenderExpirationTime === pingTime) {
11930 // Received a ping at the same priority level at which we're currently
11931 // rendering. Restart from the root.
11932 nextRoot = null;
11933 } else {
11934 // Confirm that the root is still suspended at this level. Otherwise exit.
11935 if (isPriorityLevelSuspended(root, pingTime)) {
11936 // Ping at the original level
11937 markPingedPriorityLevel(root, pingTime);
11938 var rootExpirationTime = root.expirationTime;
11939 if (rootExpirationTime !== NoWork) {
11940 requestWork(root, rootExpirationTime);
11941 }
11942 }
11943 }
11944}
11945
11946function retryTimedOutBoundary(boundaryFiber, thenable) {
11947 // The boundary fiber (a Suspense component) previously timed out and was
11948 // rendered in its fallback state. One of the promises that suspended it has
11949 // resolved, which means at least part of the tree was likely unblocked. Try
11950 var retryCache = void 0;
11951 if (enableSuspenseServerRenderer) {
11952 switch (boundaryFiber.tag) {
11953 case SuspenseComponent:
11954 retryCache = boundaryFiber.stateNode;
11955 break;
11956 case DehydratedSuspenseComponent:
11957 retryCache = boundaryFiber.memoizedState;
11958 break;
11959 default:
11960 invariant(false, 'Pinged unknown suspense boundary type. This is probably a bug in React.');
11961 }
11962 } else {
11963 retryCache = boundaryFiber.stateNode;
11964 }
11965 if (retryCache !== null) {
11966 // The thenable resolved, so we no longer need to memoize, because it will
11967 // never be thrown again.
11968 retryCache.delete(thenable);
11969 }
11970
11971 var currentTime = requestCurrentTime();
11972 var retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
11973 var root = scheduleWorkToRoot(boundaryFiber, retryTime);
11974 if (root !== null) {
11975 markPendingPriorityLevel(root, retryTime);
11976 var rootExpirationTime = root.expirationTime;
11977 if (rootExpirationTime !== NoWork) {
11978 requestWork(root, rootExpirationTime);
11979 }
11980 }
11981}
11982
11983function scheduleWorkToRoot(fiber, expirationTime) {
11984 recordScheduleUpdate();
11985
11986 {
11987 if (fiber.tag === ClassComponent) {
11988 var instance = fiber.stateNode;
11989 warnAboutInvalidUpdates(instance);
11990 }
11991 }
11992
11993 // Update the source fiber's expiration time
11994 if (fiber.expirationTime < expirationTime) {
11995 fiber.expirationTime = expirationTime;
11996 }
11997 var alternate = fiber.alternate;
11998 if (alternate !== null && alternate.expirationTime < expirationTime) {
11999 alternate.expirationTime = expirationTime;
12000 }
12001 // Walk the parent path to the root and update the child expiration time.
12002 var node = fiber.return;
12003 var root = null;
12004 if (node === null && fiber.tag === HostRoot) {
12005 root = fiber.stateNode;
12006 } else {
12007 while (node !== null) {
12008 alternate = node.alternate;
12009 if (node.childExpirationTime < expirationTime) {
12010 node.childExpirationTime = expirationTime;
12011 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
12012 alternate.childExpirationTime = expirationTime;
12013 }
12014 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
12015 alternate.childExpirationTime = expirationTime;
12016 }
12017 if (node.return === null && node.tag === HostRoot) {
12018 root = node.stateNode;
12019 break;
12020 }
12021 node = node.return;
12022 }
12023 }
12024
12025 if (enableSchedulerTracing) {
12026 if (root !== null) {
12027 var interactions = __interactionsRef.current;
12028 if (interactions.size > 0) {
12029 var pendingInteractionMap = root.pendingInteractionMap;
12030 var pendingInteractions = pendingInteractionMap.get(expirationTime);
12031 if (pendingInteractions != null) {
12032 interactions.forEach(function (interaction) {
12033 if (!pendingInteractions.has(interaction)) {
12034 // Update the pending async work count for previously unscheduled interaction.
12035 interaction.__count++;
12036 }
12037
12038 pendingInteractions.add(interaction);
12039 });
12040 } else {
12041 pendingInteractionMap.set(expirationTime, new Set(interactions));
12042
12043 // Update the pending async work count for the current interactions.
12044 interactions.forEach(function (interaction) {
12045 interaction.__count++;
12046 });
12047 }
12048
12049 var subscriber = __subscriberRef.current;
12050 if (subscriber !== null) {
12051 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
12052 subscriber.onWorkScheduled(interactions, threadID);
12053 }
12054 }
12055 }
12056 }
12057 return root;
12058}
12059
12060function warnIfNotCurrentlyBatchingInDev(fiber) {
12061 {
12062 if (isRendering === false && isBatchingUpdates === false) {
12063 warningWithoutStack$1(false, 'An update to %s inside a test was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see in the browser." + ' Learn more at https://fb.me/react-wrap-tests-with-act' + '%s', getComponentName(fiber.type), getStackByFiberInDevAndProd(fiber));
12064 }
12065 }
12066}
12067
12068function scheduleWork(fiber, expirationTime) {
12069 var root = scheduleWorkToRoot(fiber, expirationTime);
12070 if (root === null) {
12071 {
12072 switch (fiber.tag) {
12073 case ClassComponent:
12074 warnAboutUpdateOnUnmounted(fiber, true);
12075 break;
12076 case FunctionComponent:
12077 case ForwardRef:
12078 case MemoComponent:
12079 case SimpleMemoComponent:
12080 warnAboutUpdateOnUnmounted(fiber, false);
12081 break;
12082 }
12083 }
12084 return;
12085 }
12086
12087 if (!isWorking && nextRenderExpirationTime !== NoWork && expirationTime > nextRenderExpirationTime) {
12088 // This is an interruption. (Used for performance tracking.)
12089 interruptedBy = fiber;
12090 resetStack();
12091 }
12092 markPendingPriorityLevel(root, expirationTime);
12093 if (
12094 // If we're in the render phase, we don't need to schedule this root
12095 // for an update, because we'll do it before we exit...
12096 !isWorking || isCommitting$1 ||
12097 // ...unless this is a different root than the one we're rendering.
12098 nextRoot !== root) {
12099 var rootExpirationTime = root.expirationTime;
12100 requestWork(root, rootExpirationTime);
12101 }
12102 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
12103 // Reset this back to zero so subsequent updates don't throw.
12104 nestedUpdateCount = 0;
12105 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.');
12106 }
12107}
12108
12109function syncUpdates(fn, a, b, c, d) {
12110 return unstable_runWithPriority(unstable_ImmediatePriority, function () {
12111 return fn(a, b, c, d);
12112 });
12113}
12114
12115// TODO: Everything below this is written as if it has been lifted to the
12116// renderers. I'll do this in a follow-up.
12117
12118// Linked-list of roots
12119var firstScheduledRoot = null;
12120var lastScheduledRoot = null;
12121
12122var callbackExpirationTime = NoWork;
12123var callbackID = void 0;
12124var isRendering = false;
12125var nextFlushedRoot = null;
12126var nextFlushedExpirationTime = NoWork;
12127var hasUnhandledError = false;
12128var unhandledError = null;
12129
12130var isBatchingUpdates = false;
12131var isUnbatchingUpdates = false;
12132
12133var completedBatches = null;
12134
12135var originalStartTimeMs = now();
12136var currentRendererTime = msToExpirationTime(originalStartTimeMs);
12137var currentSchedulerTime = currentRendererTime;
12138
12139// Use these to prevent an infinite loop of nested updates
12140var NESTED_UPDATE_LIMIT = 50;
12141var nestedUpdateCount = 0;
12142var lastCommittedRootDuringThisBatch = null;
12143
12144function recomputeCurrentRendererTime() {
12145 var currentTimeMs = now() - originalStartTimeMs;
12146 currentRendererTime = msToExpirationTime(currentTimeMs);
12147}
12148
12149function scheduleCallbackWithExpirationTime(root, expirationTime) {
12150 if (callbackExpirationTime !== NoWork) {
12151 // A callback is already scheduled. Check its expiration time (timeout).
12152 if (expirationTime < callbackExpirationTime) {
12153 // Existing callback has sufficient timeout. Exit.
12154 return;
12155 } else {
12156 if (callbackID !== null) {
12157 // Existing callback has insufficient timeout. Cancel and schedule a
12158 // new one.
12159 cancelDeferredCallback$$1(callbackID);
12160 }
12161 }
12162 // The request callback timer is already running. Don't start a new one.
12163 } else {
12164 startRequestCallbackTimer();
12165 }
12166
12167 callbackExpirationTime = expirationTime;
12168 var currentMs = now() - originalStartTimeMs;
12169 var expirationTimeMs = expirationTimeToMs(expirationTime);
12170 var timeout = expirationTimeMs - currentMs;
12171 callbackID = scheduleDeferredCallback$$1(performAsyncWork, { timeout: timeout });
12172}
12173
12174// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and
12175// onYield is called upon exiting. We use these in lieu of returning a tuple.
12176// I've also chosen not to inline them into renderRoot because these will
12177// eventually be lifted into the renderer.
12178function onFatal(root) {
12179 root.finishedWork = null;
12180}
12181
12182function onComplete(root, finishedWork, expirationTime) {
12183 root.pendingCommitExpirationTime = expirationTime;
12184 root.finishedWork = finishedWork;
12185}
12186
12187function onSuspend(root, finishedWork, suspendedExpirationTime, rootExpirationTime, msUntilTimeout) {
12188 root.expirationTime = rootExpirationTime;
12189 if (msUntilTimeout === 0 && !shouldYieldToRenderer()) {
12190 // Don't wait an additional tick. Commit the tree immediately.
12191 root.pendingCommitExpirationTime = suspendedExpirationTime;
12192 root.finishedWork = finishedWork;
12193 } else if (msUntilTimeout > 0) {
12194 // Wait `msUntilTimeout` milliseconds before committing.
12195 root.timeoutHandle = scheduleTimeout(onTimeout.bind(null, root, finishedWork, suspendedExpirationTime), msUntilTimeout);
12196 }
12197}
12198
12199function onYield(root) {
12200 root.finishedWork = null;
12201}
12202
12203function onTimeout(root, finishedWork, suspendedExpirationTime) {
12204 // The root timed out. Commit it.
12205 root.pendingCommitExpirationTime = suspendedExpirationTime;
12206 root.finishedWork = finishedWork;
12207 // Read the current time before entering the commit phase. We can be
12208 // certain this won't cause tearing related to batching of event updates
12209 // because we're at the top of a timer event.
12210 recomputeCurrentRendererTime();
12211 currentSchedulerTime = currentRendererTime;
12212 flushRoot(root, suspendedExpirationTime);
12213}
12214
12215function onCommit(root, expirationTime) {
12216 root.expirationTime = expirationTime;
12217 root.finishedWork = null;
12218}
12219
12220function requestCurrentTime() {
12221 // requestCurrentTime is called by the scheduler to compute an expiration
12222 // time.
12223 //
12224 // Expiration times are computed by adding to the current time (the start
12225 // time). However, if two updates are scheduled within the same event, we
12226 // should treat their start times as simultaneous, even if the actual clock
12227 // time has advanced between the first and second call.
12228
12229 // In other words, because expiration times determine how updates are batched,
12230 // we want all updates of like priority that occur within the same event to
12231 // receive the same expiration time. Otherwise we get tearing.
12232 //
12233 // We keep track of two separate times: the current "renderer" time and the
12234 // current "scheduler" time. The renderer time can be updated whenever; it
12235 // only exists to minimize the calls performance.now.
12236 //
12237 // But the scheduler time can only be updated if there's no pending work, or
12238 // if we know for certain that we're not in the middle of an event.
12239
12240 if (isRendering) {
12241 // We're already rendering. Return the most recently read time.
12242 return currentSchedulerTime;
12243 }
12244 // Check if there's pending work.
12245 findHighestPriorityRoot();
12246 if (nextFlushedExpirationTime === NoWork || nextFlushedExpirationTime === Never) {
12247 // If there's no pending work, or if the pending work is offscreen, we can
12248 // read the current time without risk of tearing.
12249 recomputeCurrentRendererTime();
12250 currentSchedulerTime = currentRendererTime;
12251 return currentSchedulerTime;
12252 }
12253 // There's already pending work. We might be in the middle of a browser
12254 // event. If we were to read the current time, it could cause multiple updates
12255 // within the same event to receive different expiration times, leading to
12256 // tearing. Return the last read time. During the next idle callback, the
12257 // time will be updated.
12258 return currentSchedulerTime;
12259}
12260
12261// requestWork is called by the scheduler whenever a root receives an update.
12262// It's up to the renderer to call renderRoot at some point in the future.
12263function requestWork(root, expirationTime) {
12264 addRootToSchedule(root, expirationTime);
12265 if (isRendering) {
12266 // Prevent reentrancy. Remaining work will be scheduled at the end of
12267 // the currently rendering batch.
12268 return;
12269 }
12270
12271 if (isBatchingUpdates) {
12272 // Flush work at the end of the batch.
12273 if (isUnbatchingUpdates) {
12274 // ...unless we're inside unbatchedUpdates, in which case we should
12275 // flush it now.
12276 nextFlushedRoot = root;
12277 nextFlushedExpirationTime = Sync;
12278 performWorkOnRoot(root, Sync, false);
12279 }
12280 return;
12281 }
12282
12283 // TODO: Get rid of Sync and use current time?
12284 if (expirationTime === Sync) {
12285 performSyncWork();
12286 } else {
12287 scheduleCallbackWithExpirationTime(root, expirationTime);
12288 }
12289}
12290
12291function addRootToSchedule(root, expirationTime) {
12292 // Add the root to the schedule.
12293 // Check if this root is already part of the schedule.
12294 if (root.nextScheduledRoot === null) {
12295 // This root is not already scheduled. Add it.
12296 root.expirationTime = expirationTime;
12297 if (lastScheduledRoot === null) {
12298 firstScheduledRoot = lastScheduledRoot = root;
12299 root.nextScheduledRoot = root;
12300 } else {
12301 lastScheduledRoot.nextScheduledRoot = root;
12302 lastScheduledRoot = root;
12303 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12304 }
12305 } else {
12306 // This root is already scheduled, but its priority may have increased.
12307 var remainingExpirationTime = root.expirationTime;
12308 if (expirationTime > remainingExpirationTime) {
12309 // Update the priority.
12310 root.expirationTime = expirationTime;
12311 }
12312 }
12313}
12314
12315function findHighestPriorityRoot() {
12316 var highestPriorityWork = NoWork;
12317 var highestPriorityRoot = null;
12318 if (lastScheduledRoot !== null) {
12319 var previousScheduledRoot = lastScheduledRoot;
12320 var root = firstScheduledRoot;
12321 while (root !== null) {
12322 var remainingExpirationTime = root.expirationTime;
12323 if (remainingExpirationTime === NoWork) {
12324 // This root no longer has work. Remove it from the scheduler.
12325
12326 // TODO: This check is redudant, but Flow is confused by the branch
12327 // below where we set lastScheduledRoot to null, even though we break
12328 // from the loop right after.
12329 !(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;
12330 if (root === root.nextScheduledRoot) {
12331 // This is the only root in the list.
12332 root.nextScheduledRoot = null;
12333 firstScheduledRoot = lastScheduledRoot = null;
12334 break;
12335 } else if (root === firstScheduledRoot) {
12336 // This is the first root in the list.
12337 var next = root.nextScheduledRoot;
12338 firstScheduledRoot = next;
12339 lastScheduledRoot.nextScheduledRoot = next;
12340 root.nextScheduledRoot = null;
12341 } else if (root === lastScheduledRoot) {
12342 // This is the last root in the list.
12343 lastScheduledRoot = previousScheduledRoot;
12344 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12345 root.nextScheduledRoot = null;
12346 break;
12347 } else {
12348 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
12349 root.nextScheduledRoot = null;
12350 }
12351 root = previousScheduledRoot.nextScheduledRoot;
12352 } else {
12353 if (remainingExpirationTime > highestPriorityWork) {
12354 // Update the priority, if it's higher
12355 highestPriorityWork = remainingExpirationTime;
12356 highestPriorityRoot = root;
12357 }
12358 if (root === lastScheduledRoot) {
12359 break;
12360 }
12361 if (highestPriorityWork === Sync) {
12362 // Sync is highest priority by definition so
12363 // we can stop searching.
12364 break;
12365 }
12366 previousScheduledRoot = root;
12367 root = root.nextScheduledRoot;
12368 }
12369 }
12370 }
12371
12372 nextFlushedRoot = highestPriorityRoot;
12373 nextFlushedExpirationTime = highestPriorityWork;
12374}
12375
12376// TODO: This wrapper exists because many of the older tests (the ones that use
12377// flushDeferredPri) rely on the number of times `shouldYield` is called. We
12378// should get rid of it.
12379var didYield = false;
12380function shouldYieldToRenderer() {
12381 if (didYield) {
12382 return true;
12383 }
12384 if (shouldYield$$1()) {
12385 didYield = true;
12386 return true;
12387 }
12388 return false;
12389}
12390
12391function performAsyncWork() {
12392 try {
12393 if (!shouldYieldToRenderer()) {
12394 // The callback timed out. That means at least one update has expired.
12395 // Iterate through the root schedule. If they contain expired work, set
12396 // the next render expiration time to the current time. This has the effect
12397 // of flushing all expired work in a single batch, instead of flushing each
12398 // level one at a time.
12399 if (firstScheduledRoot !== null) {
12400 recomputeCurrentRendererTime();
12401 var root = firstScheduledRoot;
12402 do {
12403 didExpireAtExpirationTime(root, currentRendererTime);
12404 // The root schedule is circular, so this is never null.
12405 root = root.nextScheduledRoot;
12406 } while (root !== firstScheduledRoot);
12407 }
12408 }
12409 performWork(NoWork, true);
12410 } finally {
12411 didYield = false;
12412 }
12413}
12414
12415function performSyncWork() {
12416 performWork(Sync, false);
12417}
12418
12419function performWork(minExpirationTime, isYieldy) {
12420 // Keep working on roots until there's no more work, or until there's a higher
12421 // priority event.
12422 findHighestPriorityRoot();
12423
12424 if (isYieldy) {
12425 recomputeCurrentRendererTime();
12426 currentSchedulerTime = currentRendererTime;
12427
12428 if (enableUserTimingAPI) {
12429 var didExpire = nextFlushedExpirationTime > currentRendererTime;
12430 var timeout = expirationTimeToMs(nextFlushedExpirationTime);
12431 stopRequestCallbackTimer(didExpire, timeout);
12432 }
12433
12434 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime && !(didYield && currentRendererTime > nextFlushedExpirationTime)) {
12435 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, currentRendererTime > nextFlushedExpirationTime);
12436 findHighestPriorityRoot();
12437 recomputeCurrentRendererTime();
12438 currentSchedulerTime = currentRendererTime;
12439 }
12440 } else {
12441 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime) {
12442 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
12443 findHighestPriorityRoot();
12444 }
12445 }
12446
12447 // We're done flushing work. Either we ran out of time in this callback,
12448 // or there's no more work left with sufficient priority.
12449
12450 // If we're inside a callback, set this to false since we just completed it.
12451 if (isYieldy) {
12452 callbackExpirationTime = NoWork;
12453 callbackID = null;
12454 }
12455 // If there's work left over, schedule a new callback.
12456 if (nextFlushedExpirationTime !== NoWork) {
12457 scheduleCallbackWithExpirationTime(nextFlushedRoot, nextFlushedExpirationTime);
12458 }
12459
12460 // Clean-up.
12461 finishRendering();
12462}
12463
12464function flushRoot(root, expirationTime) {
12465 !!isRendering ? invariant(false, 'work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method.') : void 0;
12466 // Perform work on root as if the given expiration time is the current time.
12467 // This has the effect of synchronously flushing all work up to and
12468 // including the given time.
12469 nextFlushedRoot = root;
12470 nextFlushedExpirationTime = expirationTime;
12471 performWorkOnRoot(root, expirationTime, false);
12472 // Flush any sync work that was scheduled by lifecycles
12473 performSyncWork();
12474}
12475
12476function finishRendering() {
12477 nestedUpdateCount = 0;
12478 lastCommittedRootDuringThisBatch = null;
12479
12480 if (completedBatches !== null) {
12481 var batches = completedBatches;
12482 completedBatches = null;
12483 for (var i = 0; i < batches.length; i++) {
12484 var batch = batches[i];
12485 try {
12486 batch._onComplete();
12487 } catch (error) {
12488 if (!hasUnhandledError) {
12489 hasUnhandledError = true;
12490 unhandledError = error;
12491 }
12492 }
12493 }
12494 }
12495
12496 if (hasUnhandledError) {
12497 var error = unhandledError;
12498 unhandledError = null;
12499 hasUnhandledError = false;
12500 throw error;
12501 }
12502}
12503
12504function performWorkOnRoot(root, expirationTime, isYieldy) {
12505 !!isRendering ? invariant(false, 'performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
12506
12507 isRendering = true;
12508
12509 // Check if this is async work or sync/expired work.
12510 if (!isYieldy) {
12511 // Flush work without yielding.
12512 // TODO: Non-yieldy work does not necessarily imply expired work. A renderer
12513 // may want to perform some work without yielding, but also without
12514 // requiring the root to complete (by triggering placeholders).
12515
12516 var finishedWork = root.finishedWork;
12517 if (finishedWork !== null) {
12518 // This root is already complete. We can commit it.
12519 completeRoot(root, finishedWork, expirationTime);
12520 } else {
12521 root.finishedWork = null;
12522 // If this root previously suspended, clear its existing timeout, since
12523 // we're about to try rendering again.
12524 var timeoutHandle = root.timeoutHandle;
12525 if (timeoutHandle !== noTimeout) {
12526 root.timeoutHandle = noTimeout;
12527 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12528 cancelTimeout(timeoutHandle);
12529 }
12530 renderRoot(root, isYieldy);
12531 finishedWork = root.finishedWork;
12532 if (finishedWork !== null) {
12533 // We've completed the root. Commit it.
12534 completeRoot(root, finishedWork, expirationTime);
12535 }
12536 }
12537 } else {
12538 // Flush async work.
12539 var _finishedWork = root.finishedWork;
12540 if (_finishedWork !== null) {
12541 // This root is already complete. We can commit it.
12542 completeRoot(root, _finishedWork, expirationTime);
12543 } else {
12544 root.finishedWork = null;
12545 // If this root previously suspended, clear its existing timeout, since
12546 // we're about to try rendering again.
12547 var _timeoutHandle = root.timeoutHandle;
12548 if (_timeoutHandle !== noTimeout) {
12549 root.timeoutHandle = noTimeout;
12550 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12551 cancelTimeout(_timeoutHandle);
12552 }
12553 renderRoot(root, isYieldy);
12554 _finishedWork = root.finishedWork;
12555 if (_finishedWork !== null) {
12556 // We've completed the root. Check the if we should yield one more time
12557 // before committing.
12558 if (!shouldYieldToRenderer()) {
12559 // Still time left. Commit the root.
12560 completeRoot(root, _finishedWork, expirationTime);
12561 } else {
12562 // There's no time left. Mark this root as complete. We'll come
12563 // back and commit it later.
12564 root.finishedWork = _finishedWork;
12565 }
12566 }
12567 }
12568 }
12569
12570 isRendering = false;
12571}
12572
12573function completeRoot(root, finishedWork, expirationTime) {
12574 // Check if there's a batch that matches this expiration time.
12575 var firstBatch = root.firstBatch;
12576 if (firstBatch !== null && firstBatch._expirationTime >= expirationTime) {
12577 if (completedBatches === null) {
12578 completedBatches = [firstBatch];
12579 } else {
12580 completedBatches.push(firstBatch);
12581 }
12582 if (firstBatch._defer) {
12583 // This root is blocked from committing by a batch. Unschedule it until
12584 // we receive another update.
12585 root.finishedWork = finishedWork;
12586 root.expirationTime = NoWork;
12587 return;
12588 }
12589 }
12590
12591 // Commit the root.
12592 root.finishedWork = null;
12593
12594 // Check if this is a nested update (a sync update scheduled during the
12595 // commit phase).
12596 if (root === lastCommittedRootDuringThisBatch) {
12597 // If the next root is the same as the previous root, this is a nested
12598 // update. To prevent an infinite loop, increment the nested update count.
12599 nestedUpdateCount++;
12600 } else {
12601 // Reset whenever we switch roots.
12602 lastCommittedRootDuringThisBatch = root;
12603 nestedUpdateCount = 0;
12604 }
12605 unstable_runWithPriority(unstable_ImmediatePriority, function () {
12606 commitRoot(root, finishedWork);
12607 });
12608}
12609
12610function onUncaughtError(error) {
12611 !(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;
12612 // Unschedule this root so we don't work on it again until there's
12613 // another update.
12614 nextFlushedRoot.expirationTime = NoWork;
12615 if (!hasUnhandledError) {
12616 hasUnhandledError = true;
12617 unhandledError = error;
12618 }
12619}
12620
12621// TODO: Batching should be implemented at the renderer level, not inside
12622// the reconciler.
12623function batchedUpdates(fn, a) {
12624 var previousIsBatchingUpdates = isBatchingUpdates;
12625 isBatchingUpdates = true;
12626 try {
12627 return fn(a);
12628 } finally {
12629 isBatchingUpdates = previousIsBatchingUpdates;
12630 if (!isBatchingUpdates && !isRendering) {
12631 performSyncWork();
12632 }
12633 }
12634}
12635
12636// TODO: Batching should be implemented at the renderer level, not within
12637// the reconciler.
12638function flushSync(fn, a) {
12639 !!isRendering ? invariant(false, 'flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.') : void 0;
12640 var previousIsBatchingUpdates = isBatchingUpdates;
12641 isBatchingUpdates = true;
12642 try {
12643 return syncUpdates(fn, a);
12644 } finally {
12645 isBatchingUpdates = previousIsBatchingUpdates;
12646 performSyncWork();
12647 }
12648}
12649
12650// 0 is PROD, 1 is DEV.
12651// Might add PROFILE later.
12652
12653
12654var didWarnAboutNestedUpdates = void 0;
12655{
12656 didWarnAboutNestedUpdates = false;
12657
12658}
12659
12660function getContextForSubtree(parentComponent) {
12661 if (!parentComponent) {
12662 return emptyContextObject;
12663 }
12664
12665 var fiber = get(parentComponent);
12666 var parentContext = findCurrentUnmaskedContext(fiber);
12667
12668 if (fiber.tag === ClassComponent) {
12669 var Component = fiber.type;
12670 if (isContextProvider(Component)) {
12671 return processChildContext(fiber, Component, parentContext);
12672 }
12673 }
12674
12675 return parentContext;
12676}
12677
12678function scheduleRootUpdate(current$$1, element, expirationTime, callback) {
12679 {
12680 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
12681 didWarnAboutNestedUpdates = true;
12682 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');
12683 }
12684 }
12685
12686 var update = createUpdate(expirationTime);
12687 // Caution: React DevTools currently depends on this property
12688 // being called "element".
12689 update.payload = { element: element };
12690
12691 callback = callback === undefined ? null : callback;
12692 if (callback !== null) {
12693 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
12694 update.callback = callback;
12695 }
12696
12697 flushPassiveEffects$1();
12698 enqueueUpdate(current$$1, update);
12699 scheduleWork(current$$1, expirationTime);
12700
12701 return expirationTime;
12702}
12703
12704function updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback) {
12705 // TODO: If this is a nested container, this won't be the root.
12706 var current$$1 = container.current;
12707
12708 {
12709 if (ReactFiberInstrumentation_1.debugTool) {
12710 if (current$$1.alternate === null) {
12711 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
12712 } else if (element === null) {
12713 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
12714 } else {
12715 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
12716 }
12717 }
12718 }
12719
12720 var context = getContextForSubtree(parentComponent);
12721 if (container.context === null) {
12722 container.context = context;
12723 } else {
12724 container.pendingContext = context;
12725 }
12726
12727 return scheduleRootUpdate(current$$1, element, expirationTime, callback);
12728}
12729
12730function createContainer(containerInfo, isConcurrent, hydrate) {
12731 return createFiberRoot(containerInfo, isConcurrent, hydrate);
12732}
12733
12734function updateContainer(element, container, parentComponent, callback) {
12735 var current$$1 = container.current;
12736 var currentTime = requestCurrentTime();
12737 var expirationTime = computeExpirationForFiber(currentTime, current$$1);
12738 return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback);
12739}
12740
12741function getPublicRootInstance(container) {
12742 var containerFiber = container.current;
12743 if (!containerFiber.child) {
12744 return null;
12745 }
12746 switch (containerFiber.child.tag) {
12747 case HostComponent:
12748 return getPublicInstance(containerFiber.child.stateNode);
12749 default:
12750 return containerFiber.child.stateNode;
12751 }
12752}
12753
12754
12755
12756var overrideProps = null;
12757
12758{
12759 var copyWithSetImpl = function (obj, path, idx, value) {
12760 if (idx >= path.length) {
12761 return value;
12762 }
12763 var key = path[idx];
12764 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
12765 // $FlowFixMe number or string is fine here
12766 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
12767 return updated;
12768 };
12769
12770 var copyWithSet = function (obj, path, value) {
12771 return copyWithSetImpl(obj, path, 0, value);
12772 };
12773
12774 // Support DevTools props for function components, forwardRef, memo, host components, etc.
12775 overrideProps = function (fiber, path, value) {
12776 flushPassiveEffects$1();
12777 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
12778 if (fiber.alternate) {
12779 fiber.alternate.pendingProps = fiber.pendingProps;
12780 }
12781 scheduleWork(fiber, Sync);
12782 };
12783}
12784
12785function injectIntoDevTools(devToolsConfig) {
12786 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
12787 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
12788
12789
12790 return injectInternals(_assign({}, devToolsConfig, {
12791 overrideProps: overrideProps,
12792 currentDispatcherRef: ReactCurrentDispatcher,
12793 findHostInstanceByFiber: function (fiber) {
12794 var hostFiber = findCurrentHostFiber(fiber);
12795 if (hostFiber === null) {
12796 return null;
12797 }
12798 return hostFiber.stateNode;
12799 },
12800 findFiberByHostInstance: function (instance) {
12801 if (!findFiberByHostInstance) {
12802 // Might not be implemented by the renderer.
12803 return null;
12804 }
12805 return findFiberByHostInstance(instance);
12806 }
12807 }));
12808}
12809
12810// This file intentionally does *not* have the Flow annotation.
12811// Don't add it. See `./inline-typed.js` for an explanation.
12812
12813// TODO: this is special because it gets imported during build.
12814
12815var ReactVersion = '16.8.5';
12816
12817var _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; }; }();
12818
12819function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12820
12821function _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; }
12822
12823// for .act's return value
12824
12825
12826var defaultTestOptions = {
12827 createNodeMock: function () {
12828 return null;
12829 }
12830};
12831
12832function toJSON(inst) {
12833 if (inst.isHidden) {
12834 // Omit timed out children from output entirely. This seems like the least
12835 // surprising behavior. We could perhaps add a separate API that includes
12836 // them, if it turns out people need it.
12837 return null;
12838 }
12839 switch (inst.tag) {
12840 case 'TEXT':
12841 return inst.text;
12842 case 'INSTANCE':
12843 {
12844 /* eslint-disable no-unused-vars */
12845 // We don't include the `children` prop in JSON.
12846 // Instead, we will include the actual rendered children.
12847 var _inst$props = inst.props,
12848 _children = _inst$props.children,
12849 _props = _objectWithoutProperties(_inst$props, ['children']);
12850 /* eslint-enable */
12851
12852
12853 var renderedChildren = null;
12854 if (inst.children && inst.children.length) {
12855 for (var i = 0; i < inst.children.length; i++) {
12856 var renderedChild = toJSON(inst.children[i]);
12857 if (renderedChild !== null) {
12858 if (renderedChildren === null) {
12859 renderedChildren = [renderedChild];
12860 } else {
12861 renderedChildren.push(renderedChild);
12862 }
12863 }
12864 }
12865 }
12866 var json = {
12867 type: inst.type,
12868 props: _props,
12869 children: renderedChildren
12870 };
12871 Object.defineProperty(json, '$$typeof', {
12872 value: Symbol.for('react.test.json')
12873 });
12874 return json;
12875 }
12876 default:
12877 throw new Error('Unexpected node type in toJSON: ' + inst.tag);
12878 }
12879}
12880
12881function childrenToTree(node) {
12882 if (!node) {
12883 return null;
12884 }
12885 var children = nodeAndSiblingsArray(node);
12886 if (children.length === 0) {
12887 return null;
12888 } else if (children.length === 1) {
12889 return toTree(children[0]);
12890 }
12891 return flatten(children.map(toTree));
12892}
12893
12894function nodeAndSiblingsArray(nodeWithSibling) {
12895 var array = [];
12896 var node = nodeWithSibling;
12897 while (node != null) {
12898 array.push(node);
12899 node = node.sibling;
12900 }
12901 return array;
12902}
12903
12904function flatten(arr) {
12905 var result = [];
12906 var stack = [{ i: 0, array: arr }];
12907 while (stack.length) {
12908 var n = stack.pop();
12909 while (n.i < n.array.length) {
12910 var el = n.array[n.i];
12911 n.i += 1;
12912 if (Array.isArray(el)) {
12913 stack.push(n);
12914 stack.push({ i: 0, array: el });
12915 break;
12916 }
12917 result.push(el);
12918 }
12919 }
12920 return result;
12921}
12922
12923function toTree(node) {
12924 if (node == null) {
12925 return null;
12926 }
12927 switch (node.tag) {
12928 case HostRoot:
12929 return childrenToTree(node.child);
12930 case HostPortal:
12931 return childrenToTree(node.child);
12932 case ClassComponent:
12933 return {
12934 nodeType: 'component',
12935 type: node.type,
12936 props: _assign({}, node.memoizedProps),
12937 instance: node.stateNode,
12938 rendered: childrenToTree(node.child)
12939 };
12940 case FunctionComponent:
12941 case SimpleMemoComponent:
12942 return {
12943 nodeType: 'component',
12944 type: node.type,
12945 props: _assign({}, node.memoizedProps),
12946 instance: null,
12947 rendered: childrenToTree(node.child)
12948 };
12949 case HostComponent:
12950 {
12951 return {
12952 nodeType: 'host',
12953 type: node.type,
12954 props: _assign({}, node.memoizedProps),
12955 instance: null, // TODO: use createNodeMock here somehow?
12956 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
12957 };
12958 }
12959 case HostText:
12960 return node.stateNode.text;
12961 case Fragment:
12962 case ContextProvider:
12963 case ContextConsumer:
12964 case Mode:
12965 case Profiler:
12966 case ForwardRef:
12967 case MemoComponent:
12968 case IncompleteClassComponent:
12969 return childrenToTree(node.child);
12970 default:
12971 invariant(false, 'toTree() does not yet know how to handle nodes with tag=%s', node.tag);
12972 }
12973}
12974
12975var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent,
12976// Normally skipped, but used when there's more than one root child.
12977HostRoot]);
12978
12979function getChildren(parent) {
12980 var children = [];
12981 var startingNode = parent;
12982 var node = startingNode;
12983 if (node.child === null) {
12984 return children;
12985 }
12986 node.child.return = node;
12987 node = node.child;
12988 outer: while (true) {
12989 var descend = false;
12990 if (validWrapperTypes.has(node.tag)) {
12991 children.push(wrapFiber(node));
12992 } else if (node.tag === HostText) {
12993 children.push('' + node.memoizedProps);
12994 } else {
12995 descend = true;
12996 }
12997 if (descend && node.child !== null) {
12998 node.child.return = node;
12999 node = node.child;
13000 continue;
13001 }
13002 while (node.sibling === null) {
13003 if (node.return === startingNode) {
13004 break outer;
13005 }
13006 node = node.return;
13007 }
13008 node.sibling.return = node.return;
13009 node = node.sibling;
13010 }
13011 return children;
13012}
13013
13014var ReactTestInstance = function () {
13015 ReactTestInstance.prototype._currentFiber = function _currentFiber() {
13016 // Throws if this component has been unmounted.
13017 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
13018 !(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;
13019 return fiber;
13020 };
13021
13022 function ReactTestInstance(fiber) {
13023 _classCallCheck(this, ReactTestInstance);
13024
13025 !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;
13026 this._fiber = fiber;
13027 }
13028
13029 // Custom search functions
13030 ReactTestInstance.prototype.find = function find(predicate) {
13031 return expectOne(this.findAll(predicate, { deep: false }), 'matching custom predicate: ' + predicate.toString());
13032 };
13033
13034 ReactTestInstance.prototype.findByType = function findByType(type) {
13035 return expectOne(this.findAllByType(type, { deep: false }), 'with node type: "' + (type.displayName || type.name) + '"');
13036 };
13037
13038 ReactTestInstance.prototype.findByProps = function findByProps(props) {
13039 return expectOne(this.findAllByProps(props, { deep: false }), 'with props: ' + JSON.stringify(props));
13040 };
13041
13042 ReactTestInstance.prototype.findAll = function findAll(predicate) {
13043 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
13044
13045 return _findAll(this, predicate, options);
13046 };
13047
13048 ReactTestInstance.prototype.findAllByType = function findAllByType(type) {
13049 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
13050
13051 return _findAll(this, function (node) {
13052 return node.type === type;
13053 }, options);
13054 };
13055
13056 ReactTestInstance.prototype.findAllByProps = function findAllByProps(props) {
13057 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
13058
13059 return _findAll(this, function (node) {
13060 return node.props && propsMatch(node.props, props);
13061 }, options);
13062 };
13063
13064 _createClass(ReactTestInstance, [{
13065 key: 'instance',
13066 get: function () {
13067 if (this._fiber.tag === HostComponent) {
13068 return getPublicInstance(this._fiber.stateNode);
13069 } else {
13070 return this._fiber.stateNode;
13071 }
13072 }
13073 }, {
13074 key: 'type',
13075 get: function () {
13076 return this._fiber.type;
13077 }
13078 }, {
13079 key: 'props',
13080 get: function () {
13081 return this._currentFiber().memoizedProps;
13082 }
13083 }, {
13084 key: 'parent',
13085 get: function () {
13086 var parent = this._fiber.return;
13087 while (parent !== null) {
13088 if (validWrapperTypes.has(parent.tag)) {
13089 if (parent.tag === HostRoot) {
13090 // Special case: we only "materialize" instances for roots
13091 // if they have more than a single child. So we'll check that now.
13092 if (getChildren(parent).length < 2) {
13093 return null;
13094 }
13095 }
13096 return wrapFiber(parent);
13097 }
13098 parent = parent.return;
13099 }
13100 return null;
13101 }
13102 }, {
13103 key: 'children',
13104 get: function () {
13105 return getChildren(this._currentFiber());
13106 }
13107 }]);
13108
13109 return ReactTestInstance;
13110}();
13111
13112function _findAll(root, predicate, options) {
13113 var deep = options ? options.deep : true;
13114 var results = [];
13115
13116 if (predicate(root)) {
13117 results.push(root);
13118 if (!deep) {
13119 return results;
13120 }
13121 }
13122
13123 root.children.forEach(function (child) {
13124 if (typeof child === 'string') {
13125 return;
13126 }
13127 results.push.apply(results, _findAll(child, predicate, options));
13128 });
13129
13130 return results;
13131}
13132
13133function expectOne(all, message) {
13134 if (all.length === 1) {
13135 return all[0];
13136 }
13137
13138 var prefix = all.length === 0 ? 'No instances found ' : 'Expected 1 but found ' + all.length + ' instances ';
13139
13140 throw new Error(prefix + message);
13141}
13142
13143function propsMatch(props, filter) {
13144 for (var key in filter) {
13145 if (props[key] !== filter[key]) {
13146 return false;
13147 }
13148 }
13149 return true;
13150}
13151
13152var ReactTestRendererFiber = {
13153 create: function (element, options) {
13154 var createNodeMock = defaultTestOptions.createNodeMock;
13155 var isConcurrent = false;
13156 if (typeof options === 'object' && options !== null) {
13157 if (typeof options.createNodeMock === 'function') {
13158 createNodeMock = options.createNodeMock;
13159 }
13160 if (options.unstable_isConcurrent === true) {
13161 isConcurrent = true;
13162 }
13163 }
13164 var container = {
13165 children: [],
13166 createNodeMock: createNodeMock,
13167 tag: 'CONTAINER'
13168 };
13169 var root = createContainer(container, isConcurrent, false);
13170 !(root != null) ? invariant(false, 'something went wrong') : void 0;
13171 updateContainer(element, root, null, null);
13172
13173 var entry = {
13174 root: undefined, // makes flow happy
13175 // we define a 'getter' for 'root' below using 'Object.defineProperty'
13176 toJSON: function () {
13177 if (root == null || root.current == null || container == null) {
13178 return null;
13179 }
13180 if (container.children.length === 0) {
13181 return null;
13182 }
13183 if (container.children.length === 1) {
13184 return toJSON(container.children[0]);
13185 }
13186 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
13187 // Omit timed out children from output entirely, including the fact that we
13188 // temporarily wrap fallback and timed out children in an array.
13189 return toJSON(container.children[1]);
13190 }
13191 var renderedChildren = null;
13192 if (container.children && container.children.length) {
13193 for (var i = 0; i < container.children.length; i++) {
13194 var renderedChild = toJSON(container.children[i]);
13195 if (renderedChild !== null) {
13196 if (renderedChildren === null) {
13197 renderedChildren = [renderedChild];
13198 } else {
13199 renderedChildren.push(renderedChild);
13200 }
13201 }
13202 }
13203 }
13204 return renderedChildren;
13205 },
13206 toTree: function () {
13207 if (root == null || root.current == null) {
13208 return null;
13209 }
13210 return toTree(root.current);
13211 },
13212 update: function (newElement) {
13213 if (root == null || root.current == null) {
13214 return;
13215 }
13216 updateContainer(newElement, root, null, null);
13217 },
13218 unmount: function () {
13219 if (root == null || root.current == null) {
13220 return;
13221 }
13222 updateContainer(null, root, null, null);
13223 container = null;
13224 root = null;
13225 },
13226 getInstance: function () {
13227 if (root == null || root.current == null) {
13228 return null;
13229 }
13230 return getPublicRootInstance(root);
13231 },
13232
13233
13234 unstable_flushAll: flushAll,
13235 unstable_flushSync: function (fn) {
13236 clearYields();
13237 return flushSync(fn);
13238 },
13239
13240 unstable_flushNumberOfYields: flushNumberOfYields,
13241 unstable_clearYields: clearYields
13242 };
13243
13244 Object.defineProperty(entry, 'root', {
13245 configurable: true,
13246 enumerable: true,
13247 get: function () {
13248 if (root === null) {
13249 throw new Error("Can't access .root on unmounted test renderer");
13250 }
13251 var children = getChildren(root.current);
13252 if (children.length === 0) {
13253 throw new Error("Can't access .root on unmounted test renderer");
13254 } else if (children.length === 1) {
13255 // Normally, we skip the root and just give you the child.
13256 return children[0];
13257 } else {
13258 // However, we give you the root if there's more than one root child.
13259 // We could make this the behavior for all cases but it would be a breaking change.
13260 return wrapFiber(root.current);
13261 }
13262 }
13263 });
13264
13265 return entry;
13266 },
13267
13268
13269 unstable_yield: yieldValue,
13270 unstable_clearYields: clearYields,
13271
13272 /* eslint-disable camelcase */
13273 unstable_batchedUpdates: batchedUpdates,
13274 /* eslint-enable camelcase */
13275
13276 unstable_setNowImplementation: setNowImplementation,
13277
13278 act: function (callback) {
13279 // note: keep these warning messages in sync with
13280 // createNoop.js and ReactTestUtils.js
13281 var result = batchedUpdates(callback);
13282 {
13283 if (result !== undefined) {
13284 var addendum = void 0;
13285 if (result !== null && typeof result.then === 'function') {
13286 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';
13287 } else {
13288 addendum = ' You returned: ' + result;
13289 }
13290 warningWithoutStack$1(false, 'The callback passed to TestRenderer.act(...) function must not return anything.%s', addendum);
13291 }
13292 }
13293 flushPassiveEffects();
13294 // we want the user to not expect a return,
13295 // but we want to warn if they use it like they can await on it.
13296 return {
13297 then: function () {
13298 {
13299 warningWithoutStack$1(false, 'Do not await the result of calling TestRenderer.act(...), it is not a Promise.');
13300 }
13301 }
13302 };
13303 }
13304};
13305
13306// root used to flush effects during .act() calls
13307var actRoot = createContainer({
13308 children: [],
13309 createNodeMock: defaultTestOptions.createNodeMock,
13310 tag: 'CONTAINER'
13311}, true, false);
13312
13313function flushPassiveEffects() {
13314 // Trick to flush passive effects without exposing an internal API:
13315 // Create a throwaway root and schedule a dummy update on it.
13316 updateContainer(null, actRoot, null, null);
13317}
13318
13319var fiberToWrapper = new WeakMap();
13320function wrapFiber(fiber) {
13321 var wrapper = fiberToWrapper.get(fiber);
13322 if (wrapper === undefined && fiber.alternate !== null) {
13323 wrapper = fiberToWrapper.get(fiber.alternate);
13324 }
13325 if (wrapper === undefined) {
13326 wrapper = new ReactTestInstance(fiber);
13327 fiberToWrapper.set(fiber, wrapper);
13328 }
13329 return wrapper;
13330}
13331
13332// Enable ReactTestRenderer to be used to test DevTools integration.
13333injectIntoDevTools({
13334 findFiberByHostInstance: function () {
13335 throw new Error('TestRenderer does not support findFiberByHostInstance()');
13336 },
13337 bundleType: 1,
13338 version: ReactVersion,
13339 rendererPackageName: 'react-test-renderer'
13340});
13341
13342
13343
13344var ReactTestRenderer = Object.freeze({
13345 default: ReactTestRendererFiber
13346});
13347
13348var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
13349
13350// TODO: decide on the top-level export form.
13351// This is hacky but makes it work with both Rollup and Jest.
13352var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
13353
13354return reactTestRenderer;
13355
13356})));