UNPKG

463 kBJavaScriptView Raw
1/** @license React v16.7.0
2 * react-test-renderer.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
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// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
147// nor polyfill, then a plain number is used for performance.
148var hasSymbol = typeof Symbol === 'function' && Symbol.for;
149
150var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
151var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
152var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
153var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
154var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
155var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
156var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
157
158var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
159var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
160var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
161var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
162var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
163
164var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
165var FAUX_ITERATOR_SYMBOL = '@@iterator';
166
167function getIteratorFn(maybeIterable) {
168 if (maybeIterable === null || typeof maybeIterable !== 'object') {
169 return null;
170 }
171 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
172 if (typeof maybeIterator === 'function') {
173 return maybeIterator;
174 }
175 return null;
176}
177
178var Pending = 0;
179var Resolved = 1;
180var Rejected = 2;
181
182function refineResolvedLazyComponent(lazyComponent) {
183 return lazyComponent._status === Resolved ? lazyComponent._result : null;
184}
185
186function getWrappedName(outerType, innerType, wrapperName) {
187 var functionName = innerType.displayName || innerType.name || '';
188 return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
189}
190
191function getComponentName(type) {
192 if (type == null) {
193 // Host root, text node or just invalid type.
194 return null;
195 }
196 {
197 if (typeof type.tag === 'number') {
198 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
199 }
200 }
201 if (typeof type === 'function') {
202 return type.displayName || type.name || null;
203 }
204 if (typeof type === 'string') {
205 return type;
206 }
207 switch (type) {
208 case REACT_CONCURRENT_MODE_TYPE:
209 return 'ConcurrentMode';
210 case REACT_FRAGMENT_TYPE:
211 return 'Fragment';
212 case REACT_PORTAL_TYPE:
213 return 'Portal';
214 case REACT_PROFILER_TYPE:
215 return 'Profiler';
216 case REACT_STRICT_MODE_TYPE:
217 return 'StrictMode';
218 case REACT_SUSPENSE_TYPE:
219 return 'Suspense';
220 }
221 if (typeof type === 'object') {
222 switch (type.$$typeof) {
223 case REACT_CONTEXT_TYPE:
224 return 'Context.Consumer';
225 case REACT_PROVIDER_TYPE:
226 return 'Context.Provider';
227 case REACT_FORWARD_REF_TYPE:
228 return getWrappedName(type, type.render, 'ForwardRef');
229 case REACT_MEMO_TYPE:
230 return getComponentName(type.type);
231 case REACT_LAZY_TYPE:
232 {
233 var thenable = type;
234 var resolvedThenable = refineResolvedLazyComponent(thenable);
235 if (resolvedThenable) {
236 return getComponentName(resolvedThenable);
237 }
238 }
239 }
240 }
241 return null;
242}
243
244var FunctionComponent = 0;
245var ClassComponent = 1;
246var IndeterminateComponent = 2; // Before we know whether it is function or class
247var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
248var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
249var HostComponent = 5;
250var HostText = 6;
251var Fragment = 7;
252var Mode = 8;
253var ContextConsumer = 9;
254var ContextProvider = 10;
255var ForwardRef = 11;
256var Profiler = 12;
257var SuspenseComponent = 13;
258var MemoComponent = 14;
259var SimpleMemoComponent = 15;
260var LazyComponent = 16;
261var IncompleteClassComponent = 17;
262
263// Don't change these two values. They're used by React Dev Tools.
264var NoEffect = /* */0;
265var PerformedWork = /* */1;
266
267// You can change the rest (and add more).
268var Placement = /* */2;
269var Update = /* */4;
270var PlacementAndUpdate = /* */6;
271var Deletion = /* */8;
272var ContentReset = /* */16;
273var Callback = /* */32;
274var DidCapture = /* */64;
275var Ref = /* */128;
276var Snapshot = /* */256;
277var Passive = /* */512;
278
279// Passive & Update & Callback & Ref & Snapshot
280var LifecycleEffectMask = /* */932;
281
282// Union of all host effects
283var HostEffectMask = /* */1023;
284
285var Incomplete = /* */1024;
286var ShouldCapture = /* */2048;
287
288var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
289
290var MOUNTING = 1;
291var MOUNTED = 2;
292var UNMOUNTED = 3;
293
294function isFiberMountedImpl(fiber) {
295 var node = fiber;
296 if (!fiber.alternate) {
297 // If there is no alternate, this might be a new tree that isn't inserted
298 // yet. If it is, then it will have a pending insertion effect on it.
299 if ((node.effectTag & Placement) !== NoEffect) {
300 return MOUNTING;
301 }
302 while (node.return) {
303 node = node.return;
304 if ((node.effectTag & Placement) !== NoEffect) {
305 return MOUNTING;
306 }
307 }
308 } else {
309 while (node.return) {
310 node = node.return;
311 }
312 }
313 if (node.tag === HostRoot) {
314 // TODO: Check if this was a nested HostRoot when used with
315 // renderContainerIntoSubtree.
316 return MOUNTED;
317 }
318 // If we didn't hit the root, that means that we're in an disconnected tree
319 // that has been unmounted.
320 return UNMOUNTED;
321}
322
323function isFiberMounted(fiber) {
324 return isFiberMountedImpl(fiber) === MOUNTED;
325}
326
327function isMounted(component) {
328 {
329 var owner = ReactCurrentOwner.current;
330 if (owner !== null && owner.tag === ClassComponent) {
331 var ownerFiber = owner;
332 var instance = ownerFiber.stateNode;
333 !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;
334 instance._warnedAboutRefsInRender = true;
335 }
336 }
337
338 var fiber = get(component);
339 if (!fiber) {
340 return false;
341 }
342 return isFiberMountedImpl(fiber) === MOUNTED;
343}
344
345function assertIsMounted(fiber) {
346 !(isFiberMountedImpl(fiber) === MOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
347}
348
349function findCurrentFiberUsingSlowPath(fiber) {
350 var alternate = fiber.alternate;
351 if (!alternate) {
352 // If there is no alternate, then we only need to check if it is mounted.
353 var state = isFiberMountedImpl(fiber);
354 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
355 if (state === MOUNTING) {
356 return null;
357 }
358 return fiber;
359 }
360 // If we have two possible branches, we'll walk backwards up to the root
361 // to see what path the root points to. On the way we may hit one of the
362 // special cases and we'll deal with them.
363 var a = fiber;
364 var b = alternate;
365 while (true) {
366 var parentA = a.return;
367 var parentB = parentA ? parentA.alternate : null;
368 if (!parentA || !parentB) {
369 // We're at the root.
370 break;
371 }
372
373 // If both copies of the parent fiber point to the same child, we can
374 // assume that the child is current. This happens when we bailout on low
375 // priority: the bailed out fiber's child reuses the current child.
376 if (parentA.child === parentB.child) {
377 var child = parentA.child;
378 while (child) {
379 if (child === a) {
380 // We've determined that A is the current branch.
381 assertIsMounted(parentA);
382 return fiber;
383 }
384 if (child === b) {
385 // We've determined that B is the current branch.
386 assertIsMounted(parentA);
387 return alternate;
388 }
389 child = child.sibling;
390 }
391 // We should never have an alternate for any mounting node. So the only
392 // way this could possibly happen is if this was unmounted, if at all.
393 invariant(false, 'Unable to find node on an unmounted component.');
394 }
395
396 if (a.return !== b.return) {
397 // The return pointer of A and the return pointer of B point to different
398 // fibers. We assume that return pointers never criss-cross, so A must
399 // belong to the child set of A.return, and B must belong to the child
400 // set of B.return.
401 a = parentA;
402 b = parentB;
403 } else {
404 // The return pointers point to the same fiber. We'll have to use the
405 // default, slow path: scan the child sets of each parent alternate to see
406 // which child belongs to which set.
407 //
408 // Search parent A's child set
409 var didFindChild = false;
410 var _child = parentA.child;
411 while (_child) {
412 if (_child === a) {
413 didFindChild = true;
414 a = parentA;
415 b = parentB;
416 break;
417 }
418 if (_child === b) {
419 didFindChild = true;
420 b = parentA;
421 a = parentB;
422 break;
423 }
424 _child = _child.sibling;
425 }
426 if (!didFindChild) {
427 // Search parent B's child set
428 _child = parentB.child;
429 while (_child) {
430 if (_child === a) {
431 didFindChild = true;
432 a = parentB;
433 b = parentA;
434 break;
435 }
436 if (_child === b) {
437 didFindChild = true;
438 b = parentB;
439 a = parentA;
440 break;
441 }
442 _child = _child.sibling;
443 }
444 !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;
445 }
446 }
447
448 !(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;
449 }
450 // If the root is not a host container, we're in a disconnected tree. I.e.
451 // unmounted.
452 !(a.tag === HostRoot) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
453 if (a.stateNode.current === a) {
454 // We've determined that A is the current branch.
455 return fiber;
456 }
457 // Otherwise B has to be current branch.
458 return alternate;
459}
460
461function findCurrentHostFiber(parent) {
462 var currentParent = findCurrentFiberUsingSlowPath(parent);
463 if (!currentParent) {
464 return null;
465 }
466
467 // Next we'll drill down this component to find the first HostComponent/Text.
468 var node = currentParent;
469 while (true) {
470 if (node.tag === HostComponent || node.tag === HostText) {
471 return node;
472 } else if (node.child) {
473 node.child.return = node;
474 node = node.child;
475 continue;
476 }
477 if (node === currentParent) {
478 return null;
479 }
480 while (!node.sibling) {
481 if (!node.return || node.return === currentParent) {
482 return null;
483 }
484 node = node.return;
485 }
486 node.sibling.return = node.return;
487 node = node.sibling;
488 }
489 // Flow needs the return null here, but ESLint complains about it.
490 // eslint-disable-next-line no-unreachable
491 return null;
492}
493
494/**
495 * Similar to invariant but only logs a warning if the condition is not met.
496 * This can be used to log issues in development environments in critical
497 * paths. Removing the logging code for production environments will keep the
498 * same logic and follow the same code paths.
499 */
500
501var warning = warningWithoutStack$1;
502
503{
504 warning = function (condition, format) {
505 if (condition) {
506 return;
507 }
508 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
509 var stack = ReactDebugCurrentFrame.getStackAddendum();
510 // eslint-disable-next-line react-internal/warning-and-invariant-args
511
512 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
513 args[_key - 2] = arguments[_key];
514 }
515
516 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
517 };
518}
519
520var warning$1 = warning;
521
522// Current virtual time
523var nowImplementation = function () {
524 return 0;
525};
526var scheduledCallback = null;
527var yieldedValues = [];
528
529var didStop = false;
530var expectedNumberOfYields = -1;
531
532function scheduleDeferredCallback$1(callback, options) {
533 scheduledCallback = callback;
534 var fakeCallbackId = 0;
535 return fakeCallbackId;
536}
537
538function cancelDeferredCallback$1(timeoutID) {
539 scheduledCallback = null;
540}
541
542function setNowImplementation(implementation) {
543 nowImplementation = implementation;
544}
545
546function shouldYield$1() {
547 if (expectedNumberOfYields !== -1 && yieldedValues.length >= expectedNumberOfYields) {
548 // We yielded at least as many values as expected. Stop rendering.
549 didStop = true;
550 return true;
551 }
552 // Keep rendering.
553 return false;
554}
555
556function flushAll() {
557 yieldedValues = [];
558 while (scheduledCallback !== null) {
559 var cb = scheduledCallback;
560 scheduledCallback = null;
561 cb();
562 }
563 var values = yieldedValues;
564 yieldedValues = [];
565 return values;
566}
567
568function flushNumberOfYields(count) {
569 expectedNumberOfYields = count;
570 didStop = false;
571 yieldedValues = [];
572 try {
573 while (scheduledCallback !== null && !didStop) {
574 var cb = scheduledCallback;
575 scheduledCallback = null;
576 cb();
577 }
578 return yieldedValues;
579 } finally {
580 expectedNumberOfYields = -1;
581 didStop = false;
582 yieldedValues = [];
583 }
584}
585
586function yieldValue(value) {
587 yieldedValues.push(value);
588}
589
590function clearYields() {
591 var values = yieldedValues;
592 yieldedValues = [];
593 return values;
594}
595
596// Renderers that don't support persistence
597// can re-export everything from this module.
598
599function shim() {
600 invariant(false, 'The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.');
601}
602
603// Persistence (when unsupported)
604var supportsPersistence = false;
605var cloneInstance = shim;
606var createContainerChildSet = shim;
607var appendChildToContainerChildSet = shim;
608var finalizeContainerChildren = shim;
609var replaceContainerChildren = shim;
610var cloneHiddenInstance = shim;
611var cloneUnhiddenInstance = shim;
612var createHiddenTextInstance = shim;
613
614// Renderers that don't support hydration
615// can re-export everything from this module.
616
617function shim$1() {
618 invariant(false, 'The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.');
619}
620
621// Hydration (when unsupported)
622var supportsHydration = false;
623var canHydrateInstance = shim$1;
624var canHydrateTextInstance = shim$1;
625var getNextHydratableSibling = shim$1;
626var getFirstHydratableChild = shim$1;
627var hydrateInstance = shim$1;
628var hydrateTextInstance = shim$1;
629var didNotMatchHydratedContainerTextInstance = shim$1;
630var didNotMatchHydratedTextInstance = shim$1;
631var didNotHydrateContainerInstance = shim$1;
632var didNotHydrateInstance = shim$1;
633var didNotFindHydratableContainerInstance = shim$1;
634var didNotFindHydratableContainerTextInstance = shim$1;
635var didNotFindHydratableInstance = shim$1;
636var didNotFindHydratableTextInstance = shim$1;
637
638var NO_CONTEXT = {};
639var UPDATE_SIGNAL = {};
640{
641 Object.freeze(NO_CONTEXT);
642 Object.freeze(UPDATE_SIGNAL);
643}
644
645function getPublicInstance(inst) {
646 switch (inst.tag) {
647 case 'INSTANCE':
648 var _createNodeMock = inst.rootContainerInstance.createNodeMock;
649 return _createNodeMock({
650 type: inst.type,
651 props: inst.props
652 });
653 default:
654 return inst;
655 }
656}
657
658function appendChild(parentInstance, child) {
659 {
660 !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;
661 }
662 var index = parentInstance.children.indexOf(child);
663 if (index !== -1) {
664 parentInstance.children.splice(index, 1);
665 }
666 parentInstance.children.push(child);
667}
668
669function insertBefore(parentInstance, child, beforeChild) {
670 var index = parentInstance.children.indexOf(child);
671 if (index !== -1) {
672 parentInstance.children.splice(index, 1);
673 }
674 var beforeIndex = parentInstance.children.indexOf(beforeChild);
675 parentInstance.children.splice(beforeIndex, 0, child);
676}
677
678function removeChild(parentInstance, child) {
679 var index = parentInstance.children.indexOf(child);
680 parentInstance.children.splice(index, 1);
681}
682
683function getRootHostContext(rootContainerInstance) {
684 return NO_CONTEXT;
685}
686
687function getChildHostContext(parentHostContext, type, rootContainerInstance) {
688 return NO_CONTEXT;
689}
690
691function prepareForCommit(containerInfo) {
692 // noop
693}
694
695function resetAfterCommit(containerInfo) {
696 // noop
697}
698
699function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
700 return {
701 type: type,
702 props: props,
703 isHidden: false,
704 children: [],
705 rootContainerInstance: rootContainerInstance,
706 tag: 'INSTANCE'
707 };
708}
709
710function appendInitialChild(parentInstance, child) {
711 var index = parentInstance.children.indexOf(child);
712 if (index !== -1) {
713 parentInstance.children.splice(index, 1);
714 }
715 parentInstance.children.push(child);
716}
717
718function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
719 return false;
720}
721
722function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
723 return UPDATE_SIGNAL;
724}
725
726function shouldSetTextContent(type, props) {
727 return false;
728}
729
730function shouldDeprioritizeSubtree(type, props) {
731 return false;
732}
733
734function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
735 return {
736 text: text,
737 isHidden: false,
738 tag: 'TEXT'
739 };
740}
741
742var isPrimaryRenderer = false;
743// This approach enables `now` to be mocked by tests,
744// Even after the reconciler has initialized and read host config values.
745var now = function () {
746 return nowImplementation();
747};
748var scheduleDeferredCallback$$1 = scheduleDeferredCallback$1;
749var cancelDeferredCallback$$1 = cancelDeferredCallback$1;
750var shouldYield$$1 = shouldYield$1;
751
752var scheduleTimeout = setTimeout;
753var cancelTimeout = clearTimeout;
754var noTimeout = -1;
755
756// -------------------
757// Mutation
758// -------------------
759
760var supportsMutation = true;
761
762function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
763 instance.type = type;
764 instance.props = newProps;
765}
766
767
768
769function commitTextUpdate(textInstance, oldText, newText) {
770 textInstance.text = newText;
771}
772
773function resetTextContent(testElement) {
774 // noop
775}
776
777var appendChildToContainer = appendChild;
778var insertInContainerBefore = insertBefore;
779var removeChildFromContainer = removeChild;
780
781function hideInstance(instance) {
782 instance.isHidden = true;
783}
784
785function hideTextInstance(textInstance) {
786 textInstance.isHidden = true;
787}
788
789function unhideInstance(instance, props) {
790 instance.isHidden = false;
791}
792
793function unhideTextInstance(textInstance, text) {
794 textInstance.isHidden = false;
795}
796
797/**
798 * Copyright (c) 2013-present, Facebook, Inc.
799 *
800 * This source code is licensed under the MIT license found in the
801 * LICENSE file in the root directory of this source tree.
802 */
803
804
805
806var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
807
808var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
809
810/**
811 * Copyright (c) 2013-present, Facebook, Inc.
812 *
813 * This source code is licensed under the MIT license found in the
814 * LICENSE file in the root directory of this source tree.
815 */
816
817
818
819var printWarning = function() {};
820
821{
822 var ReactPropTypesSecret = ReactPropTypesSecret_1;
823 var loggedTypeFailures = {};
824
825 printWarning = function(text) {
826 var message = 'Warning: ' + text;
827 if (typeof console !== 'undefined') {
828 console.error(message);
829 }
830 try {
831 // --- Welcome to debugging React ---
832 // This error was thrown as a convenience so that you can use this stack
833 // to find the callsite that caused this warning to fire.
834 throw new Error(message);
835 } catch (x) {}
836 };
837}
838
839/**
840 * Assert that the values match with the type specs.
841 * Error messages are memorized and will only be shown once.
842 *
843 * @param {object} typeSpecs Map of name to a ReactPropType
844 * @param {object} values Runtime values that need to be type-checked
845 * @param {string} location e.g. "prop", "context", "child context"
846 * @param {string} componentName Name of the component for error messages.
847 * @param {?Function} getStack Returns the component stack.
848 * @private
849 */
850function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
851 {
852 for (var typeSpecName in typeSpecs) {
853 if (typeSpecs.hasOwnProperty(typeSpecName)) {
854 var error;
855 // Prop type validation may throw. In case they do, we don't want to
856 // fail the render phase where it didn't fail before. So we log it.
857 // After these have been cleaned up, we'll let them throw.
858 try {
859 // This is intentionally an invariant that gets caught. It's the same
860 // behavior as without this statement except with a better message.
861 if (typeof typeSpecs[typeSpecName] !== 'function') {
862 var err = Error(
863 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
864 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
865 );
866 err.name = 'Invariant Violation';
867 throw err;
868 }
869 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
870 } catch (ex) {
871 error = ex;
872 }
873 if (error && !(error instanceof Error)) {
874 printWarning(
875 (componentName || 'React class') + ': type specification of ' +
876 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
877 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
878 'You may have forgotten to pass an argument to the type checker ' +
879 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
880 'shape all require an argument).'
881 );
882
883 }
884 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
885 // Only monitor this failure once because there tends to be a lot of the
886 // same error.
887 loggedTypeFailures[error.message] = true;
888
889 var stack = getStack ? getStack() : '';
890
891 printWarning(
892 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
893 );
894 }
895 }
896 }
897 }
898}
899
900var checkPropTypes_1 = checkPropTypes;
901
902var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
903
904var describeComponentFrame = function (name, source, ownerName) {
905 var sourceInfo = '';
906 if (source) {
907 var path = source.fileName;
908 var fileName = path.replace(BEFORE_SLASH_RE, '');
909 {
910 // In DEV, include code for a common special case:
911 // prefer "folder/index.js" instead of just "index.js".
912 if (/^index\./.test(fileName)) {
913 var match = path.match(BEFORE_SLASH_RE);
914 if (match) {
915 var pathBeforeSlash = match[1];
916 if (pathBeforeSlash) {
917 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
918 fileName = folderName + '/' + fileName;
919 }
920 }
921 }
922 }
923 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
924 } else if (ownerName) {
925 sourceInfo = ' (created by ' + ownerName + ')';
926 }
927 return '\n in ' + (name || 'Unknown') + sourceInfo;
928};
929
930var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
931
932function describeFiber(fiber) {
933 switch (fiber.tag) {
934 case HostRoot:
935 case HostPortal:
936 case HostText:
937 case Fragment:
938 case ContextProvider:
939 case ContextConsumer:
940 return '';
941 default:
942 var owner = fiber._debugOwner;
943 var source = fiber._debugSource;
944 var name = getComponentName(fiber.type);
945 var ownerName = null;
946 if (owner) {
947 ownerName = getComponentName(owner.type);
948 }
949 return describeComponentFrame(name, source, ownerName);
950 }
951}
952
953function getStackByFiberInDevAndProd(workInProgress) {
954 var info = '';
955 var node = workInProgress;
956 do {
957 info += describeFiber(node);
958 node = node.return;
959 } while (node);
960 return info;
961}
962
963var current = null;
964var phase = null;
965
966function getCurrentFiberOwnerNameInDevOrNull() {
967 {
968 if (current === null) {
969 return null;
970 }
971 var owner = current._debugOwner;
972 if (owner !== null && typeof owner !== 'undefined') {
973 return getComponentName(owner.type);
974 }
975 }
976 return null;
977}
978
979function getCurrentFiberStackInDev() {
980 {
981 if (current === null) {
982 return '';
983 }
984 // Safe because if current fiber exists, we are reconciling,
985 // and it is guaranteed to be the work-in-progress version.
986 return getStackByFiberInDevAndProd(current);
987 }
988 return '';
989}
990
991function resetCurrentFiber() {
992 {
993 ReactDebugCurrentFrame.getCurrentStack = null;
994 current = null;
995 phase = null;
996 }
997}
998
999function setCurrentFiber(fiber) {
1000 {
1001 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1002 current = fiber;
1003 phase = null;
1004 }
1005}
1006
1007function setCurrentPhase(lifeCyclePhase) {
1008 {
1009 phase = lifeCyclePhase;
1010 }
1011}
1012
1013var debugRenderPhaseSideEffects = false;
1014var debugRenderPhaseSideEffectsForStrictMode = false;
1015var enableUserTimingAPI = true;
1016var enableHooks = false;
1017var warnAboutDeprecatedLifecycles = false;
1018var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
1019var enableProfilerTimer = false;
1020var enableSchedulerTracing = false;
1021
1022
1023
1024
1025
1026
1027// Only used in www builds.
1028
1029// Prefix measurements so that it's possible to filter them.
1030// Longer prefixes are hard to read in DevTools.
1031var reactEmoji = '\u269B';
1032var warningEmoji = '\u26D4';
1033var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
1034
1035// Keep track of current fiber so that we know the path to unwind on pause.
1036// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1037var currentFiber = null;
1038// If we're in the middle of user code, which fiber and method is it?
1039// Reusing `currentFiber` would be confusing for this because user code fiber
1040// can change during commit phase too, but we don't need to unwind it (since
1041// lifecycles in the commit phase don't resemble a tree).
1042var currentPhase = null;
1043var currentPhaseFiber = null;
1044// Did lifecycle hook schedule an update? This is often a performance problem,
1045// so we will keep track of it, and include it in the report.
1046// Track commits caused by cascading updates.
1047var isCommitting = false;
1048var hasScheduledUpdateInCurrentCommit = false;
1049var hasScheduledUpdateInCurrentPhase = false;
1050var commitCountInCurrentWorkLoop = 0;
1051var effectCountInCurrentCommit = 0;
1052var isWaitingForCallback = false;
1053// During commits, we only show a measurement once per method name
1054// to avoid stretch the commit phase with measurement overhead.
1055var labelsInCurrentCommit = new Set();
1056
1057var formatMarkName = function (markName) {
1058 return reactEmoji + ' ' + markName;
1059};
1060
1061var formatLabel = function (label, warning) {
1062 var prefix = warning ? warningEmoji + ' ' : reactEmoji + ' ';
1063 var suffix = warning ? ' Warning: ' + warning : '';
1064 return '' + prefix + label + suffix;
1065};
1066
1067var beginMark = function (markName) {
1068 performance.mark(formatMarkName(markName));
1069};
1070
1071var clearMark = function (markName) {
1072 performance.clearMarks(formatMarkName(markName));
1073};
1074
1075var endMark = function (label, markName, warning) {
1076 var formattedMarkName = formatMarkName(markName);
1077 var formattedLabel = formatLabel(label, warning);
1078 try {
1079 performance.measure(formattedLabel, formattedMarkName);
1080 } catch (err) {}
1081 // If previous mark was missing for some reason, this will throw.
1082 // This could only happen if React crashed in an unexpected place earlier.
1083 // Don't pile on with more errors.
1084
1085 // Clear marks immediately to avoid growing buffer.
1086 performance.clearMarks(formattedMarkName);
1087 performance.clearMeasures(formattedLabel);
1088};
1089
1090var getFiberMarkName = function (label, debugID) {
1091 return label + ' (#' + debugID + ')';
1092};
1093
1094var getFiberLabel = function (componentName, isMounted, phase) {
1095 if (phase === null) {
1096 // These are composite component total time measurements.
1097 return componentName + ' [' + (isMounted ? 'update' : 'mount') + ']';
1098 } else {
1099 // Composite component methods.
1100 return componentName + '.' + phase;
1101 }
1102};
1103
1104var beginFiberMark = function (fiber, phase) {
1105 var componentName = getComponentName(fiber.type) || 'Unknown';
1106 var debugID = fiber._debugID;
1107 var isMounted = fiber.alternate !== null;
1108 var label = getFiberLabel(componentName, isMounted, phase);
1109
1110 if (isCommitting && labelsInCurrentCommit.has(label)) {
1111 // During the commit phase, we don't show duplicate labels because
1112 // there is a fixed overhead for every measurement, and we don't
1113 // want to stretch the commit phase beyond necessary.
1114 return false;
1115 }
1116 labelsInCurrentCommit.add(label);
1117
1118 var markName = getFiberMarkName(label, debugID);
1119 beginMark(markName);
1120 return true;
1121};
1122
1123var clearFiberMark = function (fiber, phase) {
1124 var componentName = getComponentName(fiber.type) || 'Unknown';
1125 var debugID = fiber._debugID;
1126 var isMounted = fiber.alternate !== null;
1127 var label = getFiberLabel(componentName, isMounted, phase);
1128 var markName = getFiberMarkName(label, debugID);
1129 clearMark(markName);
1130};
1131
1132var endFiberMark = function (fiber, phase, warning) {
1133 var componentName = getComponentName(fiber.type) || 'Unknown';
1134 var debugID = fiber._debugID;
1135 var isMounted = fiber.alternate !== null;
1136 var label = getFiberLabel(componentName, isMounted, phase);
1137 var markName = getFiberMarkName(label, debugID);
1138 endMark(label, markName, warning);
1139};
1140
1141var shouldIgnoreFiber = function (fiber) {
1142 // Host components should be skipped in the timeline.
1143 // We could check typeof fiber.type, but does this work with RN?
1144 switch (fiber.tag) {
1145 case HostRoot:
1146 case HostComponent:
1147 case HostText:
1148 case HostPortal:
1149 case Fragment:
1150 case ContextProvider:
1151 case ContextConsumer:
1152 case Mode:
1153 return true;
1154 default:
1155 return false;
1156 }
1157};
1158
1159var clearPendingPhaseMeasurement = function () {
1160 if (currentPhase !== null && currentPhaseFiber !== null) {
1161 clearFiberMark(currentPhaseFiber, currentPhase);
1162 }
1163 currentPhaseFiber = null;
1164 currentPhase = null;
1165 hasScheduledUpdateInCurrentPhase = false;
1166};
1167
1168var pauseTimers = function () {
1169 // Stops all currently active measurements so that they can be resumed
1170 // if we continue in a later deferred loop from the same unit of work.
1171 var fiber = currentFiber;
1172 while (fiber) {
1173 if (fiber._debugIsCurrentlyTiming) {
1174 endFiberMark(fiber, null, null);
1175 }
1176 fiber = fiber.return;
1177 }
1178};
1179
1180var resumeTimersRecursively = function (fiber) {
1181 if (fiber.return !== null) {
1182 resumeTimersRecursively(fiber.return);
1183 }
1184 if (fiber._debugIsCurrentlyTiming) {
1185 beginFiberMark(fiber, null);
1186 }
1187};
1188
1189var resumeTimers = function () {
1190 // Resumes all measurements that were active during the last deferred loop.
1191 if (currentFiber !== null) {
1192 resumeTimersRecursively(currentFiber);
1193 }
1194};
1195
1196function recordEffect() {
1197 if (enableUserTimingAPI) {
1198 effectCountInCurrentCommit++;
1199 }
1200}
1201
1202function recordScheduleUpdate() {
1203 if (enableUserTimingAPI) {
1204 if (isCommitting) {
1205 hasScheduledUpdateInCurrentCommit = true;
1206 }
1207 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1208 hasScheduledUpdateInCurrentPhase = true;
1209 }
1210 }
1211}
1212
1213function startRequestCallbackTimer() {
1214 if (enableUserTimingAPI) {
1215 if (supportsUserTiming && !isWaitingForCallback) {
1216 isWaitingForCallback = true;
1217 beginMark('(Waiting for async callback...)');
1218 }
1219 }
1220}
1221
1222function stopRequestCallbackTimer(didExpire, expirationTime) {
1223 if (enableUserTimingAPI) {
1224 if (supportsUserTiming) {
1225 isWaitingForCallback = false;
1226 var warning = didExpire ? 'React was blocked by main thread' : null;
1227 endMark('(Waiting for async callback... will force flush in ' + expirationTime + ' ms)', '(Waiting for async callback...)', warning);
1228 }
1229 }
1230}
1231
1232function startWorkTimer(fiber) {
1233 if (enableUserTimingAPI) {
1234 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1235 return;
1236 }
1237 // If we pause, this is the fiber to unwind from.
1238 currentFiber = fiber;
1239 if (!beginFiberMark(fiber, null)) {
1240 return;
1241 }
1242 fiber._debugIsCurrentlyTiming = true;
1243 }
1244}
1245
1246function cancelWorkTimer(fiber) {
1247 if (enableUserTimingAPI) {
1248 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1249 return;
1250 }
1251 // Remember we shouldn't complete measurement for this fiber.
1252 // Otherwise flamechart will be deep even for small updates.
1253 fiber._debugIsCurrentlyTiming = false;
1254 clearFiberMark(fiber, null);
1255 }
1256}
1257
1258function stopWorkTimer(fiber) {
1259 if (enableUserTimingAPI) {
1260 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1261 return;
1262 }
1263 // If we pause, its parent is the fiber to unwind from.
1264 currentFiber = fiber.return;
1265 if (!fiber._debugIsCurrentlyTiming) {
1266 return;
1267 }
1268 fiber._debugIsCurrentlyTiming = false;
1269 endFiberMark(fiber, null, null);
1270 }
1271}
1272
1273function stopFailedWorkTimer(fiber) {
1274 if (enableUserTimingAPI) {
1275 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1276 return;
1277 }
1278 // If we pause, its parent is the fiber to unwind from.
1279 currentFiber = fiber.return;
1280 if (!fiber._debugIsCurrentlyTiming) {
1281 return;
1282 }
1283 fiber._debugIsCurrentlyTiming = false;
1284 var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1285 endFiberMark(fiber, null, warning);
1286 }
1287}
1288
1289function startPhaseTimer(fiber, phase) {
1290 if (enableUserTimingAPI) {
1291 if (!supportsUserTiming) {
1292 return;
1293 }
1294 clearPendingPhaseMeasurement();
1295 if (!beginFiberMark(fiber, phase)) {
1296 return;
1297 }
1298 currentPhaseFiber = fiber;
1299 currentPhase = phase;
1300 }
1301}
1302
1303function stopPhaseTimer() {
1304 if (enableUserTimingAPI) {
1305 if (!supportsUserTiming) {
1306 return;
1307 }
1308 if (currentPhase !== null && currentPhaseFiber !== null) {
1309 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1310 endFiberMark(currentPhaseFiber, currentPhase, warning);
1311 }
1312 currentPhase = null;
1313 currentPhaseFiber = null;
1314 }
1315}
1316
1317function startWorkLoopTimer(nextUnitOfWork) {
1318 if (enableUserTimingAPI) {
1319 currentFiber = nextUnitOfWork;
1320 if (!supportsUserTiming) {
1321 return;
1322 }
1323 commitCountInCurrentWorkLoop = 0;
1324 // This is top level call.
1325 // Any other measurements are performed within.
1326 beginMark('(React Tree Reconciliation)');
1327 // Resume any measurements that were in progress during the last loop.
1328 resumeTimers();
1329 }
1330}
1331
1332function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1333 if (enableUserTimingAPI) {
1334 if (!supportsUserTiming) {
1335 return;
1336 }
1337 var warning = null;
1338 if (interruptedBy !== null) {
1339 if (interruptedBy.tag === HostRoot) {
1340 warning = 'A top-level update interrupted the previous render';
1341 } else {
1342 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1343 warning = 'An update to ' + componentName + ' interrupted the previous render';
1344 }
1345 } else if (commitCountInCurrentWorkLoop > 1) {
1346 warning = 'There were cascading updates';
1347 }
1348 commitCountInCurrentWorkLoop = 0;
1349 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)';
1350 // Pause any measurements until the next loop.
1351 pauseTimers();
1352 endMark(label, '(React Tree Reconciliation)', warning);
1353 }
1354}
1355
1356function startCommitTimer() {
1357 if (enableUserTimingAPI) {
1358 if (!supportsUserTiming) {
1359 return;
1360 }
1361 isCommitting = true;
1362 hasScheduledUpdateInCurrentCommit = false;
1363 labelsInCurrentCommit.clear();
1364 beginMark('(Committing Changes)');
1365 }
1366}
1367
1368function stopCommitTimer() {
1369 if (enableUserTimingAPI) {
1370 if (!supportsUserTiming) {
1371 return;
1372 }
1373
1374 var warning = null;
1375 if (hasScheduledUpdateInCurrentCommit) {
1376 warning = 'Lifecycle hook scheduled a cascading update';
1377 } else if (commitCountInCurrentWorkLoop > 0) {
1378 warning = 'Caused by a cascading update in earlier commit';
1379 }
1380 hasScheduledUpdateInCurrentCommit = false;
1381 commitCountInCurrentWorkLoop++;
1382 isCommitting = false;
1383 labelsInCurrentCommit.clear();
1384
1385 endMark('(Committing Changes)', '(Committing Changes)', warning);
1386 }
1387}
1388
1389function startCommitSnapshotEffectsTimer() {
1390 if (enableUserTimingAPI) {
1391 if (!supportsUserTiming) {
1392 return;
1393 }
1394 effectCountInCurrentCommit = 0;
1395 beginMark('(Committing Snapshot Effects)');
1396 }
1397}
1398
1399function stopCommitSnapshotEffectsTimer() {
1400 if (enableUserTimingAPI) {
1401 if (!supportsUserTiming) {
1402 return;
1403 }
1404 var count = effectCountInCurrentCommit;
1405 effectCountInCurrentCommit = 0;
1406 endMark('(Committing Snapshot Effects: ' + count + ' Total)', '(Committing Snapshot Effects)', null);
1407 }
1408}
1409
1410function startCommitHostEffectsTimer() {
1411 if (enableUserTimingAPI) {
1412 if (!supportsUserTiming) {
1413 return;
1414 }
1415 effectCountInCurrentCommit = 0;
1416 beginMark('(Committing Host Effects)');
1417 }
1418}
1419
1420function stopCommitHostEffectsTimer() {
1421 if (enableUserTimingAPI) {
1422 if (!supportsUserTiming) {
1423 return;
1424 }
1425 var count = effectCountInCurrentCommit;
1426 effectCountInCurrentCommit = 0;
1427 endMark('(Committing Host Effects: ' + count + ' Total)', '(Committing Host Effects)', null);
1428 }
1429}
1430
1431function startCommitLifeCyclesTimer() {
1432 if (enableUserTimingAPI) {
1433 if (!supportsUserTiming) {
1434 return;
1435 }
1436 effectCountInCurrentCommit = 0;
1437 beginMark('(Calling Lifecycle Methods)');
1438 }
1439}
1440
1441function stopCommitLifeCyclesTimer() {
1442 if (enableUserTimingAPI) {
1443 if (!supportsUserTiming) {
1444 return;
1445 }
1446 var count = effectCountInCurrentCommit;
1447 effectCountInCurrentCommit = 0;
1448 endMark('(Calling Lifecycle Methods: ' + count + ' Total)', '(Calling Lifecycle Methods)', null);
1449 }
1450}
1451
1452var valueStack = [];
1453
1454var fiberStack = void 0;
1455
1456{
1457 fiberStack = [];
1458}
1459
1460var index = -1;
1461
1462function createCursor(defaultValue) {
1463 return {
1464 current: defaultValue
1465 };
1466}
1467
1468function pop(cursor, fiber) {
1469 if (index < 0) {
1470 {
1471 warningWithoutStack$1(false, 'Unexpected pop.');
1472 }
1473 return;
1474 }
1475
1476 {
1477 if (fiber !== fiberStack[index]) {
1478 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1479 }
1480 }
1481
1482 cursor.current = valueStack[index];
1483
1484 valueStack[index] = null;
1485
1486 {
1487 fiberStack[index] = null;
1488 }
1489
1490 index--;
1491}
1492
1493function push(cursor, value, fiber) {
1494 index++;
1495
1496 valueStack[index] = cursor.current;
1497
1498 {
1499 fiberStack[index] = fiber;
1500 }
1501
1502 cursor.current = value;
1503}
1504
1505function checkThatStackIsEmpty() {
1506 {
1507 if (index !== -1) {
1508 warningWithoutStack$1(false, 'Expected an empty stack. Something was not reset properly.');
1509 }
1510 }
1511}
1512
1513function resetStackAfterFatalErrorInDev() {
1514 {
1515 index = -1;
1516 valueStack.length = 0;
1517 fiberStack.length = 0;
1518 }
1519}
1520
1521var warnedAboutMissingGetChildContext = void 0;
1522
1523{
1524 warnedAboutMissingGetChildContext = {};
1525}
1526
1527var emptyContextObject = {};
1528{
1529 Object.freeze(emptyContextObject);
1530}
1531
1532// A cursor to the current merged context object on the stack.
1533var contextStackCursor = createCursor(emptyContextObject);
1534// A cursor to a boolean indicating whether the context has changed.
1535var didPerformWorkStackCursor = createCursor(false);
1536// Keep track of the previous context object that was on the stack.
1537// We use this to get access to the parent context after we have already
1538// pushed the next context provider, and now need to merge their contexts.
1539var previousContext = emptyContextObject;
1540
1541function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1542 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1543 // If the fiber is a context provider itself, when we read its context
1544 // we may have already pushed its own child context on the stack. A context
1545 // provider should not "see" its own child context. Therefore we read the
1546 // previous (parent) context instead for a context provider.
1547 return previousContext;
1548 }
1549 return contextStackCursor.current;
1550}
1551
1552function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1553 var instance = workInProgress.stateNode;
1554 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1555 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1556}
1557
1558function getMaskedContext(workInProgress, unmaskedContext) {
1559 var type = workInProgress.type;
1560 var contextTypes = type.contextTypes;
1561 if (!contextTypes) {
1562 return emptyContextObject;
1563 }
1564
1565 // Avoid recreating masked context unless unmasked context has changed.
1566 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1567 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1568 var instance = workInProgress.stateNode;
1569 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1570 return instance.__reactInternalMemoizedMaskedChildContext;
1571 }
1572
1573 var context = {};
1574 for (var key in contextTypes) {
1575 context[key] = unmaskedContext[key];
1576 }
1577
1578 {
1579 var name = getComponentName(type) || 'Unknown';
1580 checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1581 }
1582
1583 // Cache unmasked context so we can avoid recreating masked context unless necessary.
1584 // Context is created before the class component is instantiated so check for instance.
1585 if (instance) {
1586 cacheContext(workInProgress, unmaskedContext, context);
1587 }
1588
1589 return context;
1590}
1591
1592function hasContextChanged() {
1593 return didPerformWorkStackCursor.current;
1594}
1595
1596function isContextProvider(type) {
1597 var childContextTypes = type.childContextTypes;
1598 return childContextTypes !== null && childContextTypes !== undefined;
1599}
1600
1601function popContext(fiber) {
1602 pop(didPerformWorkStackCursor, fiber);
1603 pop(contextStackCursor, fiber);
1604}
1605
1606function popTopLevelContextObject(fiber) {
1607 pop(didPerformWorkStackCursor, fiber);
1608 pop(contextStackCursor, fiber);
1609}
1610
1611function pushTopLevelContextObject(fiber, context, didChange) {
1612 !(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;
1613
1614 push(contextStackCursor, context, fiber);
1615 push(didPerformWorkStackCursor, didChange, fiber);
1616}
1617
1618function processChildContext(fiber, type, parentContext) {
1619 var instance = fiber.stateNode;
1620 var childContextTypes = type.childContextTypes;
1621
1622 // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1623 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1624 if (typeof instance.getChildContext !== 'function') {
1625 {
1626 var componentName = getComponentName(type) || 'Unknown';
1627
1628 if (!warnedAboutMissingGetChildContext[componentName]) {
1629 warnedAboutMissingGetChildContext[componentName] = true;
1630 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);
1631 }
1632 }
1633 return parentContext;
1634 }
1635
1636 var childContext = void 0;
1637 {
1638 setCurrentPhase('getChildContext');
1639 }
1640 startPhaseTimer(fiber, 'getChildContext');
1641 childContext = instance.getChildContext();
1642 stopPhaseTimer();
1643 {
1644 setCurrentPhase(null);
1645 }
1646 for (var contextKey in childContext) {
1647 !(contextKey in childContextTypes) ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(type) || 'Unknown', contextKey) : void 0;
1648 }
1649 {
1650 var name = getComponentName(type) || 'Unknown';
1651 checkPropTypes_1(childContextTypes, childContext, 'child context', name,
1652 // In practice, there is one case in which we won't get a stack. It's when
1653 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1654 // context from the parent component instance. The stack will be missing
1655 // because it's outside of the reconciliation, and so the pointer has not
1656 // been set. This is rare and doesn't matter. We'll also remove that API.
1657 getCurrentFiberStackInDev);
1658 }
1659
1660 return _assign({}, parentContext, childContext);
1661}
1662
1663function pushContextProvider(workInProgress) {
1664 var instance = workInProgress.stateNode;
1665 // We push the context as early as possible to ensure stack integrity.
1666 // If the instance does not exist yet, we will push null at first,
1667 // and replace it on the stack later when invalidating the context.
1668 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject;
1669
1670 // Remember the parent context so we can merge with it later.
1671 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1672 previousContext = contextStackCursor.current;
1673 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1674 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1675
1676 return true;
1677}
1678
1679function invalidateContextProvider(workInProgress, type, didChange) {
1680 var instance = workInProgress.stateNode;
1681 !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;
1682
1683 if (didChange) {
1684 // Merge parent and own context.
1685 // Skip this if we're not updating due to sCU.
1686 // This avoids unnecessarily recomputing memoized values.
1687 var mergedContext = processChildContext(workInProgress, type, previousContext);
1688 instance.__reactInternalMemoizedMergedChildContext = mergedContext;
1689
1690 // Replace the old (or empty) context with the new one.
1691 // It is important to unwind the context in the reverse order.
1692 pop(didPerformWorkStackCursor, workInProgress);
1693 pop(contextStackCursor, workInProgress);
1694 // Now push the new context and mark that it has changed.
1695 push(contextStackCursor, mergedContext, workInProgress);
1696 push(didPerformWorkStackCursor, didChange, workInProgress);
1697 } else {
1698 pop(didPerformWorkStackCursor, workInProgress);
1699 push(didPerformWorkStackCursor, didChange, workInProgress);
1700 }
1701}
1702
1703function findCurrentUnmaskedContext(fiber) {
1704 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1705 // makes sense elsewhere
1706 !(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;
1707
1708 var node = fiber;
1709 do {
1710 switch (node.tag) {
1711 case HostRoot:
1712 return node.stateNode.context;
1713 case ClassComponent:
1714 {
1715 var Component = node.type;
1716 if (isContextProvider(Component)) {
1717 return node.stateNode.__reactInternalMemoizedMergedChildContext;
1718 }
1719 break;
1720 }
1721 }
1722 node = node.return;
1723 } while (node !== null);
1724 invariant(false, 'Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.');
1725}
1726
1727var onCommitFiberRoot = null;
1728var onCommitFiberUnmount = null;
1729var hasLoggedError = false;
1730
1731function catchErrors(fn) {
1732 return function (arg) {
1733 try {
1734 return fn(arg);
1735 } catch (err) {
1736 if (true && !hasLoggedError) {
1737 hasLoggedError = true;
1738 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
1739 }
1740 }
1741 };
1742}
1743
1744var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
1745
1746function injectInternals(internals) {
1747 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
1748 // No DevTools
1749 return false;
1750 }
1751 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
1752 if (hook.isDisabled) {
1753 // This isn't a real property on the hook, but it can be set to opt out
1754 // of DevTools integration and associated warnings and logs.
1755 // https://github.com/facebook/react/issues/3877
1756 return true;
1757 }
1758 if (!hook.supportsFiber) {
1759 {
1760 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');
1761 }
1762 // DevTools exists, even though it doesn't support Fiber.
1763 return true;
1764 }
1765 try {
1766 var rendererID = hook.inject(internals);
1767 // We have successfully injected, so now it is safe to set up hooks.
1768 onCommitFiberRoot = catchErrors(function (root) {
1769 return hook.onCommitFiberRoot(rendererID, root);
1770 });
1771 onCommitFiberUnmount = catchErrors(function (fiber) {
1772 return hook.onCommitFiberUnmount(rendererID, fiber);
1773 });
1774 } catch (err) {
1775 // Catch all errors because it is unsafe to throw during initialization.
1776 {
1777 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
1778 }
1779 }
1780 // DevTools exists
1781 return true;
1782}
1783
1784function onCommitRoot(root) {
1785 if (typeof onCommitFiberRoot === 'function') {
1786 onCommitFiberRoot(root);
1787 }
1788}
1789
1790function onCommitUnmount(fiber) {
1791 if (typeof onCommitFiberUnmount === 'function') {
1792 onCommitFiberUnmount(fiber);
1793 }
1794}
1795
1796// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
1797// Math.pow(2, 30) - 1
1798// 0b111111111111111111111111111111
1799var maxSigned31BitInt = 1073741823;
1800
1801var NoWork = 0;
1802var Never = 1;
1803var Sync = maxSigned31BitInt;
1804
1805var UNIT_SIZE = 10;
1806var MAGIC_NUMBER_OFFSET = maxSigned31BitInt - 1;
1807
1808// 1 unit of expiration time represents 10ms.
1809function msToExpirationTime(ms) {
1810 // Always add an offset so that we don't clash with the magic number for NoWork.
1811 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
1812}
1813
1814function expirationTimeToMs(expirationTime) {
1815 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
1816}
1817
1818function ceiling(num, precision) {
1819 return ((num / precision | 0) + 1) * precision;
1820}
1821
1822function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
1823 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
1824}
1825
1826var LOW_PRIORITY_EXPIRATION = 5000;
1827var LOW_PRIORITY_BATCH_SIZE = 250;
1828
1829function computeAsyncExpiration(currentTime) {
1830 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
1831}
1832
1833// We intentionally set a higher expiration time for interactive updates in
1834// dev than in production.
1835//
1836// If the main thread is being blocked so long that you hit the expiration,
1837// it's a problem that could be solved with better scheduling.
1838//
1839// People will be more likely to notice this and fix it with the long
1840// expiration time in development.
1841//
1842// In production we opt for better UX at the risk of masking scheduling
1843// problems, by expiring fast.
1844var HIGH_PRIORITY_EXPIRATION = 500;
1845var HIGH_PRIORITY_BATCH_SIZE = 100;
1846
1847function computeInteractiveExpiration(currentTime) {
1848 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
1849}
1850
1851var NoContext = 0;
1852var ConcurrentMode = 1;
1853var StrictMode = 2;
1854var ProfileMode = 4;
1855
1856var hasBadMapPolyfill = void 0;
1857
1858{
1859 hasBadMapPolyfill = false;
1860 try {
1861 var nonExtensibleObject = Object.preventExtensions({});
1862 var testMap = new Map([[nonExtensibleObject, null]]);
1863 var testSet = new Set([nonExtensibleObject]);
1864 // This is necessary for Rollup to not consider these unused.
1865 // https://github.com/rollup/rollup/issues/1771
1866 // TODO: we can remove these if Rollup fixes the bug.
1867 testMap.set(0, 0);
1868 testSet.add(0);
1869 } catch (e) {
1870 // TODO: Consider warning about bad polyfills
1871 hasBadMapPolyfill = true;
1872 }
1873}
1874
1875// A Fiber is work on a Component that needs to be done or was done. There can
1876// be more than one per component.
1877
1878
1879var debugCounter = void 0;
1880
1881{
1882 debugCounter = 1;
1883}
1884
1885function FiberNode(tag, pendingProps, key, mode) {
1886 // Instance
1887 this.tag = tag;
1888 this.key = key;
1889 this.elementType = null;
1890 this.type = null;
1891 this.stateNode = null;
1892
1893 // Fiber
1894 this.return = null;
1895 this.child = null;
1896 this.sibling = null;
1897 this.index = 0;
1898
1899 this.ref = null;
1900
1901 this.pendingProps = pendingProps;
1902 this.memoizedProps = null;
1903 this.updateQueue = null;
1904 this.memoizedState = null;
1905 this.firstContextDependency = null;
1906
1907 this.mode = mode;
1908
1909 // Effects
1910 this.effectTag = NoEffect;
1911 this.nextEffect = null;
1912
1913 this.firstEffect = null;
1914 this.lastEffect = null;
1915
1916 this.expirationTime = NoWork;
1917 this.childExpirationTime = NoWork;
1918
1919 this.alternate = null;
1920
1921 if (enableProfilerTimer) {
1922 // Note: The following is done to avoid a v8 performance cliff.
1923 //
1924 // Initializing the fields below to smis and later updating them with
1925 // double values will cause Fibers to end up having separate shapes.
1926 // This behavior/bug has something to do with Object.preventExtension().
1927 // Fortunately this only impacts DEV builds.
1928 // Unfortunately it makes React unusably slow for some applications.
1929 // To work around this, initialize the fields below with doubles.
1930 //
1931 // Learn more about this here:
1932 // https://github.com/facebook/react/issues/14365
1933 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
1934 this.actualDuration = Number.NaN;
1935 this.actualStartTime = Number.NaN;
1936 this.selfBaseDuration = Number.NaN;
1937 this.treeBaseDuration = Number.NaN;
1938
1939 // It's okay to replace the initial doubles with smis after initialization.
1940 // This won't trigger the performance cliff mentioned above,
1941 // and it simplifies other profiler code (including DevTools).
1942 this.actualDuration = 0;
1943 this.actualStartTime = -1;
1944 this.selfBaseDuration = 0;
1945 this.treeBaseDuration = 0;
1946 }
1947
1948 {
1949 this._debugID = debugCounter++;
1950 this._debugSource = null;
1951 this._debugOwner = null;
1952 this._debugIsCurrentlyTiming = false;
1953 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
1954 Object.preventExtensions(this);
1955 }
1956 }
1957}
1958
1959// This is a constructor function, rather than a POJO constructor, still
1960// please ensure we do the following:
1961// 1) Nobody should add any instance methods on this. Instance methods can be
1962// more difficult to predict when they get optimized and they are almost
1963// never inlined properly in static compilers.
1964// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
1965// always know when it is a fiber.
1966// 3) We might want to experiment with using numeric keys since they are easier
1967// to optimize in a non-JIT environment.
1968// 4) We can easily go from a constructor to a createFiber object literal if that
1969// is faster.
1970// 5) It should be easy to port this to a C struct and keep a C implementation
1971// compatible.
1972var createFiber = function (tag, pendingProps, key, mode) {
1973 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
1974 return new FiberNode(tag, pendingProps, key, mode);
1975};
1976
1977function shouldConstruct(Component) {
1978 var prototype = Component.prototype;
1979 return !!(prototype && prototype.isReactComponent);
1980}
1981
1982function isSimpleFunctionComponent(type) {
1983 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
1984}
1985
1986function resolveLazyComponentTag(Component) {
1987 if (typeof Component === 'function') {
1988 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
1989 } else if (Component !== undefined && Component !== null) {
1990 var $$typeof = Component.$$typeof;
1991 if ($$typeof === REACT_FORWARD_REF_TYPE) {
1992 return ForwardRef;
1993 }
1994 if ($$typeof === REACT_MEMO_TYPE) {
1995 return MemoComponent;
1996 }
1997 }
1998 return IndeterminateComponent;
1999}
2000
2001// This is used to create an alternate fiber to do work on.
2002function createWorkInProgress(current, pendingProps, expirationTime) {
2003 var workInProgress = current.alternate;
2004 if (workInProgress === null) {
2005 // We use a double buffering pooling technique because we know that we'll
2006 // only ever need at most two versions of a tree. We pool the "other" unused
2007 // node that we're free to reuse. This is lazily created to avoid allocating
2008 // extra objects for things that are never updated. It also allow us to
2009 // reclaim the extra memory if needed.
2010 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
2011 workInProgress.elementType = current.elementType;
2012 workInProgress.type = current.type;
2013 workInProgress.stateNode = current.stateNode;
2014
2015 {
2016 // DEV-only fields
2017 workInProgress._debugID = current._debugID;
2018 workInProgress._debugSource = current._debugSource;
2019 workInProgress._debugOwner = current._debugOwner;
2020 }
2021
2022 workInProgress.alternate = current;
2023 current.alternate = workInProgress;
2024 } else {
2025 workInProgress.pendingProps = pendingProps;
2026
2027 // We already have an alternate.
2028 // Reset the effect tag.
2029 workInProgress.effectTag = NoEffect;
2030
2031 // The effect list is no longer valid.
2032 workInProgress.nextEffect = null;
2033 workInProgress.firstEffect = null;
2034 workInProgress.lastEffect = null;
2035
2036 if (enableProfilerTimer) {
2037 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
2038 // This prevents time from endlessly accumulating in new commits.
2039 // This has the downside of resetting values for different priority renders,
2040 // But works for yielding (the common case) and should support resuming.
2041 workInProgress.actualDuration = 0;
2042 workInProgress.actualStartTime = -1;
2043 }
2044 }
2045
2046 workInProgress.childExpirationTime = current.childExpirationTime;
2047 workInProgress.expirationTime = current.expirationTime;
2048
2049 workInProgress.child = current.child;
2050 workInProgress.memoizedProps = current.memoizedProps;
2051 workInProgress.memoizedState = current.memoizedState;
2052 workInProgress.updateQueue = current.updateQueue;
2053 workInProgress.firstContextDependency = current.firstContextDependency;
2054
2055 // These will be overridden during the parent's reconciliation
2056 workInProgress.sibling = current.sibling;
2057 workInProgress.index = current.index;
2058 workInProgress.ref = current.ref;
2059
2060 if (enableProfilerTimer) {
2061 workInProgress.selfBaseDuration = current.selfBaseDuration;
2062 workInProgress.treeBaseDuration = current.treeBaseDuration;
2063 }
2064
2065 return workInProgress;
2066}
2067
2068function createHostRootFiber(isConcurrent) {
2069 var mode = isConcurrent ? ConcurrentMode | StrictMode : NoContext;
2070
2071 if (enableProfilerTimer && isDevToolsPresent) {
2072 // Always collect profile timings when DevTools are present.
2073 // This enables DevTools to start capturing timing at any point–
2074 // Without some nodes in the tree having empty base times.
2075 mode |= ProfileMode;
2076 }
2077
2078 return createFiber(HostRoot, null, null, mode);
2079}
2080
2081function createFiberFromTypeAndProps(type, // React$ElementType
2082key, pendingProps, owner, mode, expirationTime) {
2083 var fiber = void 0;
2084
2085 var fiberTag = IndeterminateComponent;
2086 // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
2087 var resolvedType = type;
2088 if (typeof type === 'function') {
2089 if (shouldConstruct(type)) {
2090 fiberTag = ClassComponent;
2091 }
2092 } else if (typeof type === 'string') {
2093 fiberTag = HostComponent;
2094 } else {
2095 getTag: switch (type) {
2096 case REACT_FRAGMENT_TYPE:
2097 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
2098 case REACT_CONCURRENT_MODE_TYPE:
2099 return createFiberFromMode(pendingProps, mode | ConcurrentMode | StrictMode, expirationTime, key);
2100 case REACT_STRICT_MODE_TYPE:
2101 return createFiberFromMode(pendingProps, mode | StrictMode, expirationTime, key);
2102 case REACT_PROFILER_TYPE:
2103 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
2104 case REACT_SUSPENSE_TYPE:
2105 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
2106 default:
2107 {
2108 if (typeof type === 'object' && type !== null) {
2109 switch (type.$$typeof) {
2110 case REACT_PROVIDER_TYPE:
2111 fiberTag = ContextProvider;
2112 break getTag;
2113 case REACT_CONTEXT_TYPE:
2114 // This is a consumer
2115 fiberTag = ContextConsumer;
2116 break getTag;
2117 case REACT_FORWARD_REF_TYPE:
2118 fiberTag = ForwardRef;
2119 break getTag;
2120 case REACT_MEMO_TYPE:
2121 fiberTag = MemoComponent;
2122 break getTag;
2123 case REACT_LAZY_TYPE:
2124 fiberTag = LazyComponent;
2125 resolvedType = null;
2126 break getTag;
2127 }
2128 }
2129 var info = '';
2130 {
2131 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2132 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.';
2133 }
2134 var ownerName = owner ? getComponentName(owner.type) : null;
2135 if (ownerName) {
2136 info += '\n\nCheck the render method of `' + ownerName + '`.';
2137 }
2138 }
2139 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);
2140 }
2141 }
2142 }
2143
2144 fiber = createFiber(fiberTag, pendingProps, key, mode);
2145 fiber.elementType = type;
2146 fiber.type = resolvedType;
2147 fiber.expirationTime = expirationTime;
2148
2149 return fiber;
2150}
2151
2152function createFiberFromElement(element, mode, expirationTime) {
2153 var owner = null;
2154 {
2155 owner = element._owner;
2156 }
2157 var type = element.type;
2158 var key = element.key;
2159 var pendingProps = element.props;
2160 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
2161 {
2162 fiber._debugSource = element._source;
2163 fiber._debugOwner = element._owner;
2164 }
2165 return fiber;
2166}
2167
2168function createFiberFromFragment(elements, mode, expirationTime, key) {
2169 var fiber = createFiber(Fragment, elements, key, mode);
2170 fiber.expirationTime = expirationTime;
2171 return fiber;
2172}
2173
2174function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
2175 {
2176 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
2177 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
2178 }
2179 }
2180
2181 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode);
2182 // TODO: The Profiler fiber shouldn't have a type. It has a tag.
2183 fiber.elementType = REACT_PROFILER_TYPE;
2184 fiber.type = REACT_PROFILER_TYPE;
2185 fiber.expirationTime = expirationTime;
2186
2187 return fiber;
2188}
2189
2190function createFiberFromMode(pendingProps, mode, expirationTime, key) {
2191 var fiber = createFiber(Mode, pendingProps, key, mode);
2192
2193 // TODO: The Mode fiber shouldn't have a type. It has a tag.
2194 var type = (mode & ConcurrentMode) === NoContext ? REACT_STRICT_MODE_TYPE : REACT_CONCURRENT_MODE_TYPE;
2195 fiber.elementType = type;
2196 fiber.type = type;
2197
2198 fiber.expirationTime = expirationTime;
2199 return fiber;
2200}
2201
2202function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
2203 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode);
2204
2205 // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
2206 var type = REACT_SUSPENSE_TYPE;
2207 fiber.elementType = type;
2208 fiber.type = type;
2209
2210 fiber.expirationTime = expirationTime;
2211 return fiber;
2212}
2213
2214function createFiberFromText(content, mode, expirationTime) {
2215 var fiber = createFiber(HostText, content, null, mode);
2216 fiber.expirationTime = expirationTime;
2217 return fiber;
2218}
2219
2220function createFiberFromHostInstanceForDeletion() {
2221 var fiber = createFiber(HostComponent, null, null, NoContext);
2222 // TODO: These should not need a type.
2223 fiber.elementType = 'DELETED';
2224 fiber.type = 'DELETED';
2225 return fiber;
2226}
2227
2228function createFiberFromPortal(portal, mode, expirationTime) {
2229 var pendingProps = portal.children !== null ? portal.children : [];
2230 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
2231 fiber.expirationTime = expirationTime;
2232 fiber.stateNode = {
2233 containerInfo: portal.containerInfo,
2234 pendingChildren: null, // Used by persistent updates
2235 implementation: portal.implementation
2236 };
2237 return fiber;
2238}
2239
2240// Used for stashing WIP properties to replay failed work in DEV.
2241function assignFiberPropertiesInDEV(target, source) {
2242 if (target === null) {
2243 // This Fiber's initial properties will always be overwritten.
2244 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
2245 target = createFiber(IndeterminateComponent, null, null, NoContext);
2246 }
2247
2248 // This is intentionally written as a list of all properties.
2249 // We tried to use Object.assign() instead but this is called in
2250 // the hottest path, and Object.assign() was too slow:
2251 // https://github.com/facebook/react/issues/12502
2252 // This code is DEV-only so size is not a concern.
2253
2254 target.tag = source.tag;
2255 target.key = source.key;
2256 target.elementType = source.elementType;
2257 target.type = source.type;
2258 target.stateNode = source.stateNode;
2259 target.return = source.return;
2260 target.child = source.child;
2261 target.sibling = source.sibling;
2262 target.index = source.index;
2263 target.ref = source.ref;
2264 target.pendingProps = source.pendingProps;
2265 target.memoizedProps = source.memoizedProps;
2266 target.updateQueue = source.updateQueue;
2267 target.memoizedState = source.memoizedState;
2268 target.firstContextDependency = source.firstContextDependency;
2269 target.mode = source.mode;
2270 target.effectTag = source.effectTag;
2271 target.nextEffect = source.nextEffect;
2272 target.firstEffect = source.firstEffect;
2273 target.lastEffect = source.lastEffect;
2274 target.expirationTime = source.expirationTime;
2275 target.childExpirationTime = source.childExpirationTime;
2276 target.alternate = source.alternate;
2277 if (enableProfilerTimer) {
2278 target.actualDuration = source.actualDuration;
2279 target.actualStartTime = source.actualStartTime;
2280 target.selfBaseDuration = source.selfBaseDuration;
2281 target.treeBaseDuration = source.treeBaseDuration;
2282 }
2283 target._debugID = source._debugID;
2284 target._debugSource = source._debugSource;
2285 target._debugOwner = source._debugOwner;
2286 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
2287 return target;
2288}
2289
2290var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2291
2292var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing;
2293var __interactionsRef = _ReactInternals$Sched.__interactionsRef;
2294var __subscriberRef = _ReactInternals$Sched.__subscriberRef;
2295var unstable_clear = _ReactInternals$Sched.unstable_clear;
2296var unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent;
2297var unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID;
2298var unstable_subscribe = _ReactInternals$Sched.unstable_subscribe;
2299var unstable_trace = _ReactInternals$Sched.unstable_trace;
2300var unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe;
2301var unstable_wrap = _ReactInternals$Sched.unstable_wrap;
2302
2303// TODO: This should be lifted into the renderer.
2304
2305
2306// The following attributes are only used by interaction tracing builds.
2307// They enable interactions to be associated with their async work,
2308// And expose interaction metadata to the React DevTools Profiler plugin.
2309// Note that these attributes are only defined when the enableSchedulerTracing flag is enabled.
2310
2311
2312// Exported FiberRoot type includes all properties,
2313// To avoid requiring potentially error-prone :any casts throughout the project.
2314// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracing is true).
2315// The types are defined separately within this file to ensure they stay in sync.
2316// (We don't have to use an inline :any cast when enableSchedulerTracing is disabled.)
2317
2318
2319function createFiberRoot(containerInfo, isConcurrent, hydrate) {
2320 // Cyclic construction. This cheats the type system right now because
2321 // stateNode is any.
2322 var uninitializedFiber = createHostRootFiber(isConcurrent);
2323
2324 var root = void 0;
2325 if (enableSchedulerTracing) {
2326 root = {
2327 current: uninitializedFiber,
2328 containerInfo: containerInfo,
2329 pendingChildren: null,
2330
2331 earliestPendingTime: NoWork,
2332 latestPendingTime: NoWork,
2333 earliestSuspendedTime: NoWork,
2334 latestSuspendedTime: NoWork,
2335 latestPingedTime: NoWork,
2336
2337 pingCache: null,
2338
2339 didError: false,
2340
2341 pendingCommitExpirationTime: NoWork,
2342 finishedWork: null,
2343 timeoutHandle: noTimeout,
2344 context: null,
2345 pendingContext: null,
2346 hydrate: hydrate,
2347 nextExpirationTimeToWorkOn: NoWork,
2348 expirationTime: NoWork,
2349 firstBatch: null,
2350 nextScheduledRoot: null,
2351
2352 interactionThreadID: unstable_getThreadID(),
2353 memoizedInteractions: new Set(),
2354 pendingInteractionMap: new Map()
2355 };
2356 } else {
2357 root = {
2358 current: uninitializedFiber,
2359 containerInfo: containerInfo,
2360 pendingChildren: null,
2361
2362 pingCache: null,
2363
2364 earliestPendingTime: NoWork,
2365 latestPendingTime: NoWork,
2366 earliestSuspendedTime: NoWork,
2367 latestSuspendedTime: NoWork,
2368 latestPingedTime: NoWork,
2369
2370 didError: false,
2371
2372 pendingCommitExpirationTime: NoWork,
2373 finishedWork: null,
2374 timeoutHandle: noTimeout,
2375 context: null,
2376 pendingContext: null,
2377 hydrate: hydrate,
2378 nextExpirationTimeToWorkOn: NoWork,
2379 expirationTime: NoWork,
2380 firstBatch: null,
2381 nextScheduledRoot: null
2382 };
2383 }
2384
2385 uninitializedFiber.stateNode = root;
2386
2387 // The reason for the way the Flow types are structured in this file,
2388 // Is to avoid needing :any casts everywhere interaction tracing fields are used.
2389 // Unfortunately that requires an :any cast for non-interaction tracing capable builds.
2390 // $FlowFixMe Remove this :any cast and replace it with something better.
2391 return root;
2392}
2393
2394var ReactInternals$2 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2395
2396var _ReactInternals$Sched$1 = ReactInternals$2.Scheduler;
2397var unstable_cancelCallback = _ReactInternals$Sched$1.unstable_cancelCallback;
2398var unstable_now = _ReactInternals$Sched$1.unstable_now;
2399var unstable_scheduleCallback = _ReactInternals$Sched$1.unstable_scheduleCallback;
2400var unstable_shouldYield = _ReactInternals$Sched$1.unstable_shouldYield;
2401var unstable_getFirstCallbackNode = _ReactInternals$Sched$1.unstable_getFirstCallbackNode;
2402var unstable_continueExecution = _ReactInternals$Sched$1.unstable_continueExecution;
2403var unstable_pauseExecution = _ReactInternals$Sched$1.unstable_pauseExecution;
2404
2405var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
2406 var funcArgs = Array.prototype.slice.call(arguments, 3);
2407 try {
2408 func.apply(context, funcArgs);
2409 } catch (error) {
2410 this.onError(error);
2411 }
2412};
2413
2414{
2415 // In DEV mode, we swap out invokeGuardedCallback for a special version
2416 // that plays more nicely with the browser's DevTools. The idea is to preserve
2417 // "Pause on exceptions" behavior. Because React wraps all user-provided
2418 // functions in invokeGuardedCallback, and the production version of
2419 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
2420 // like caught exceptions, and the DevTools won't pause unless the developer
2421 // takes the extra step of enabling pause on caught exceptions. This is
2422 // untintuitive, though, because even though React has caught the error, from
2423 // the developer's perspective, the error is uncaught.
2424 //
2425 // To preserve the expected "Pause on exceptions" behavior, we don't use a
2426 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
2427 // DOM node, and call the user-provided callback from inside an event handler
2428 // for that fake event. If the callback throws, the error is "captured" using
2429 // a global event handler. But because the error happens in a different
2430 // event loop context, it does not interrupt the normal program flow.
2431 // Effectively, this gives us try-catch behavior without actually using
2432 // try-catch. Neat!
2433
2434 // Check that the browser supports the APIs we need to implement our special
2435 // DEV version of invokeGuardedCallback
2436 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
2437 var fakeNode = document.createElement('react');
2438
2439 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
2440 // If document doesn't exist we know for sure we will crash in this method
2441 // when we call document.createEvent(). However this can cause confusing
2442 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
2443 // So we preemptively throw with a better message instead.
2444 !(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;
2445 var evt = document.createEvent('Event');
2446
2447 // Keeps track of whether the user-provided callback threw an error. We
2448 // set this to true at the beginning, then set it to false right after
2449 // calling the function. If the function errors, `didError` will never be
2450 // set to false. This strategy works even if the browser is flaky and
2451 // fails to call our global error handler, because it doesn't rely on
2452 // the error event at all.
2453 var didError = true;
2454
2455 // Keeps track of the value of window.event so that we can reset it
2456 // during the callback to let user code access window.event in the
2457 // browsers that support it.
2458 var windowEvent = window.event;
2459
2460 // Keeps track of the descriptor of window.event to restore it after event
2461 // dispatching: https://github.com/facebook/react/issues/13688
2462 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
2463
2464 // Create an event handler for our fake event. We will synchronously
2465 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
2466 // call the user-provided callback.
2467 var funcArgs = Array.prototype.slice.call(arguments, 3);
2468 function callCallback() {
2469 // We immediately remove the callback from event listeners so that
2470 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
2471 // nested call would trigger the fake event handlers of any call higher
2472 // in the stack.
2473 fakeNode.removeEventListener(evtType, callCallback, false);
2474
2475 // We check for window.hasOwnProperty('event') to prevent the
2476 // window.event assignment in both IE <= 10 as they throw an error
2477 // "Member not found" in strict mode, and in Firefox which does not
2478 // support window.event.
2479 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
2480 window.event = windowEvent;
2481 }
2482
2483 func.apply(context, funcArgs);
2484 didError = false;
2485 }
2486
2487 // Create a global error event handler. We use this to capture the value
2488 // that was thrown. It's possible that this error handler will fire more
2489 // than once; for example, if non-React code also calls `dispatchEvent`
2490 // and a handler for that event throws. We should be resilient to most of
2491 // those cases. Even if our error event handler fires more than once, the
2492 // last error event is always used. If the callback actually does error,
2493 // we know that the last error event is the correct one, because it's not
2494 // possible for anything else to have happened in between our callback
2495 // erroring and the code that follows the `dispatchEvent` call below. If
2496 // the callback doesn't error, but the error event was fired, we know to
2497 // ignore it because `didError` will be false, as described above.
2498 var error = void 0;
2499 // Use this to track whether the error event is ever called.
2500 var didSetError = false;
2501 var isCrossOriginError = false;
2502
2503 function handleWindowError(event) {
2504 error = event.error;
2505 didSetError = true;
2506 if (error === null && event.colno === 0 && event.lineno === 0) {
2507 isCrossOriginError = true;
2508 }
2509 if (event.defaultPrevented) {
2510 // Some other error handler has prevented default.
2511 // Browsers silence the error report if this happens.
2512 // We'll remember this to later decide whether to log it or not.
2513 if (error != null && typeof error === 'object') {
2514 try {
2515 error._suppressLogging = true;
2516 } catch (inner) {
2517 // Ignore.
2518 }
2519 }
2520 }
2521 }
2522
2523 // Create a fake event type.
2524 var evtType = 'react-' + (name ? name : 'invokeguardedcallback');
2525
2526 // Attach our event handlers
2527 window.addEventListener('error', handleWindowError);
2528 fakeNode.addEventListener(evtType, callCallback, false);
2529
2530 // Synchronously dispatch our fake event. If the user-provided function
2531 // errors, it will trigger our global error handler.
2532 evt.initEvent(evtType, false, false);
2533 fakeNode.dispatchEvent(evt);
2534
2535 if (windowEventDescriptor) {
2536 Object.defineProperty(window, 'event', windowEventDescriptor);
2537 }
2538
2539 if (didError) {
2540 if (!didSetError) {
2541 // The callback errored, but the error event never fired.
2542 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.');
2543 } else if (isCrossOriginError) {
2544 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.');
2545 }
2546 this.onError(error);
2547 }
2548
2549 // Remove our event listeners
2550 window.removeEventListener('error', handleWindowError);
2551 };
2552
2553 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
2554 }
2555}
2556
2557var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
2558
2559// Used by Fiber to simulate a try-catch.
2560var hasError = false;
2561var caughtError = null;
2562
2563var reporter = {
2564 onError: function (error) {
2565 hasError = true;
2566 caughtError = error;
2567 }
2568};
2569
2570/**
2571 * Call a function while guarding against errors that happens within it.
2572 * Returns an error if it throws, otherwise null.
2573 *
2574 * In production, this is implemented using a try-catch. The reason we don't
2575 * use a try-catch directly is so that we can swap out a different
2576 * implementation in DEV mode.
2577 *
2578 * @param {String} name of the guard to use for logging or debugging
2579 * @param {Function} func The function to invoke
2580 * @param {*} context The context to use when calling the function
2581 * @param {...*} args Arguments for function
2582 */
2583function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
2584 hasError = false;
2585 caughtError = null;
2586 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
2587}
2588
2589/**
2590 * Same as invokeGuardedCallback, but instead of returning an error, it stores
2591 * it in a global so it can be rethrown by `rethrowCaughtError` later.
2592 * TODO: See if caughtError and rethrowError can be unified.
2593 *
2594 * @param {String} name of the guard to use for logging or debugging
2595 * @param {Function} func The function to invoke
2596 * @param {*} context The context to use when calling the function
2597 * @param {...*} args Arguments for function
2598 */
2599
2600
2601/**
2602 * During execution of guarded functions we will capture the first error which
2603 * we will rethrow to be handled by the top level error handler.
2604 */
2605
2606
2607function hasCaughtError() {
2608 return hasError;
2609}
2610
2611function clearCaughtError() {
2612 if (hasError) {
2613 var error = caughtError;
2614 hasError = false;
2615 caughtError = null;
2616 return error;
2617 } else {
2618 invariant(false, 'clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.');
2619 }
2620}
2621
2622/**
2623 * Forked from fbjs/warning:
2624 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2625 *
2626 * Only change is we use console.warn instead of console.error,
2627 * and do nothing when 'console' is not supported.
2628 * This really simplifies the code.
2629 * ---
2630 * Similar to invariant but only logs a warning if the condition is not met.
2631 * This can be used to log issues in development environments in critical
2632 * paths. Removing the logging code for production environments will keep the
2633 * same logic and follow the same code paths.
2634 */
2635
2636var lowPriorityWarning = function () {};
2637
2638{
2639 var printWarning$1 = function (format) {
2640 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2641 args[_key - 1] = arguments[_key];
2642 }
2643
2644 var argIndex = 0;
2645 var message = 'Warning: ' + format.replace(/%s/g, function () {
2646 return args[argIndex++];
2647 });
2648 if (typeof console !== 'undefined') {
2649 console.warn(message);
2650 }
2651 try {
2652 // --- Welcome to debugging React ---
2653 // This error was thrown as a convenience so that you can use this stack
2654 // to find the callsite that caused this warning to fire.
2655 throw new Error(message);
2656 } catch (x) {}
2657 };
2658
2659 lowPriorityWarning = function (condition, format) {
2660 if (format === undefined) {
2661 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
2662 }
2663 if (!condition) {
2664 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2665 args[_key2 - 2] = arguments[_key2];
2666 }
2667
2668 printWarning$1.apply(undefined, [format].concat(args));
2669 }
2670 };
2671}
2672
2673var lowPriorityWarning$1 = lowPriorityWarning;
2674
2675var ReactStrictModeWarnings = {
2676 discardPendingWarnings: function () {},
2677 flushPendingDeprecationWarnings: function () {},
2678 flushPendingUnsafeLifecycleWarnings: function () {},
2679 recordDeprecationWarnings: function (fiber, instance) {},
2680 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2681 recordLegacyContextWarning: function (fiber, instance) {},
2682 flushLegacyContextWarning: function () {}
2683};
2684
2685{
2686 var LIFECYCLE_SUGGESTIONS = {
2687 UNSAFE_componentWillMount: 'componentDidMount',
2688 UNSAFE_componentWillReceiveProps: 'static getDerivedStateFromProps',
2689 UNSAFE_componentWillUpdate: 'componentDidUpdate'
2690 };
2691
2692 var pendingComponentWillMountWarnings = [];
2693 var pendingComponentWillReceivePropsWarnings = [];
2694 var pendingComponentWillUpdateWarnings = [];
2695 var pendingUnsafeLifecycleWarnings = new Map();
2696 var pendingLegacyContextWarning = new Map();
2697
2698 // Tracks components we have already warned about.
2699 var didWarnAboutDeprecatedLifecycles = new Set();
2700 var didWarnAboutUnsafeLifecycles = new Set();
2701 var didWarnAboutLegacyContext = new Set();
2702
2703 var setToSortedString = function (set) {
2704 var array = [];
2705 set.forEach(function (value) {
2706 array.push(value);
2707 });
2708 return array.sort().join(', ');
2709 };
2710
2711 ReactStrictModeWarnings.discardPendingWarnings = function () {
2712 pendingComponentWillMountWarnings = [];
2713 pendingComponentWillReceivePropsWarnings = [];
2714 pendingComponentWillUpdateWarnings = [];
2715 pendingUnsafeLifecycleWarnings = new Map();
2716 pendingLegacyContextWarning = new Map();
2717 };
2718
2719 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2720 pendingUnsafeLifecycleWarnings.forEach(function (lifecycleWarningsMap, strictRoot) {
2721 var lifecyclesWarningMesages = [];
2722
2723 Object.keys(lifecycleWarningsMap).forEach(function (lifecycle) {
2724 var lifecycleWarnings = lifecycleWarningsMap[lifecycle];
2725 if (lifecycleWarnings.length > 0) {
2726 var componentNames = new Set();
2727 lifecycleWarnings.forEach(function (fiber) {
2728 componentNames.add(getComponentName(fiber.type) || 'Component');
2729 didWarnAboutUnsafeLifecycles.add(fiber.type);
2730 });
2731
2732 var formatted = lifecycle.replace('UNSAFE_', '');
2733 var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle];
2734 var sortedComponentNames = setToSortedString(componentNames);
2735
2736 lifecyclesWarningMesages.push(formatted + ': Please update the following components to use ' + (suggestion + ' instead: ' + sortedComponentNames));
2737 }
2738 });
2739
2740 if (lifecyclesWarningMesages.length > 0) {
2741 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2742
2743 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, lifecyclesWarningMesages.join('\n\n'));
2744 }
2745 });
2746
2747 pendingUnsafeLifecycleWarnings = new Map();
2748 };
2749
2750 var findStrictRoot = function (fiber) {
2751 var maybeStrictRoot = null;
2752
2753 var node = fiber;
2754 while (node !== null) {
2755 if (node.mode & StrictMode) {
2756 maybeStrictRoot = node;
2757 }
2758 node = node.return;
2759 }
2760
2761 return maybeStrictRoot;
2762 };
2763
2764 ReactStrictModeWarnings.flushPendingDeprecationWarnings = function () {
2765 if (pendingComponentWillMountWarnings.length > 0) {
2766 var uniqueNames = new Set();
2767 pendingComponentWillMountWarnings.forEach(function (fiber) {
2768 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2769 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2770 });
2771
2772 var sortedNames = setToSortedString(uniqueNames);
2773
2774 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);
2775
2776 pendingComponentWillMountWarnings = [];
2777 }
2778
2779 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2780 var _uniqueNames = new Set();
2781 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2782 _uniqueNames.add(getComponentName(fiber.type) || 'Component');
2783 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2784 });
2785
2786 var _sortedNames = setToSortedString(_uniqueNames);
2787
2788 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);
2789
2790 pendingComponentWillReceivePropsWarnings = [];
2791 }
2792
2793 if (pendingComponentWillUpdateWarnings.length > 0) {
2794 var _uniqueNames2 = new Set();
2795 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2796 _uniqueNames2.add(getComponentName(fiber.type) || 'Component');
2797 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2798 });
2799
2800 var _sortedNames2 = setToSortedString(_uniqueNames2);
2801
2802 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);
2803
2804 pendingComponentWillUpdateWarnings = [];
2805 }
2806 };
2807
2808 ReactStrictModeWarnings.recordDeprecationWarnings = function (fiber, instance) {
2809 // Dedup strategy: Warn once per component.
2810 if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) {
2811 return;
2812 }
2813
2814 // Don't warn about react-lifecycles-compat polyfilled components.
2815 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
2816 pendingComponentWillMountWarnings.push(fiber);
2817 }
2818 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2819 pendingComponentWillReceivePropsWarnings.push(fiber);
2820 }
2821 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2822 pendingComponentWillUpdateWarnings.push(fiber);
2823 }
2824 };
2825
2826 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2827 var strictRoot = findStrictRoot(fiber);
2828 if (strictRoot === null) {
2829 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.');
2830 return;
2831 }
2832
2833 // Dedup strategy: Warn once per component.
2834 // This is difficult to track any other way since component names
2835 // are often vague and are likely to collide between 3rd party libraries.
2836 // An expand property is probably okay to use here since it's DEV-only,
2837 // and will only be set in the event of serious warnings.
2838 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2839 return;
2840 }
2841
2842 var warningsForRoot = void 0;
2843 if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) {
2844 warningsForRoot = {
2845 UNSAFE_componentWillMount: [],
2846 UNSAFE_componentWillReceiveProps: [],
2847 UNSAFE_componentWillUpdate: []
2848 };
2849
2850 pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot);
2851 } else {
2852 warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot);
2853 }
2854
2855 var unsafeLifecycles = [];
2856 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillMount === 'function') {
2857 unsafeLifecycles.push('UNSAFE_componentWillMount');
2858 }
2859 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2860 unsafeLifecycles.push('UNSAFE_componentWillReceiveProps');
2861 }
2862 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillUpdate === 'function') {
2863 unsafeLifecycles.push('UNSAFE_componentWillUpdate');
2864 }
2865
2866 if (unsafeLifecycles.length > 0) {
2867 unsafeLifecycles.forEach(function (lifecycle) {
2868 warningsForRoot[lifecycle].push(fiber);
2869 });
2870 }
2871 };
2872
2873 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2874 var strictRoot = findStrictRoot(fiber);
2875 if (strictRoot === null) {
2876 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.');
2877 return;
2878 }
2879
2880 // Dedup strategy: Warn once per component.
2881 if (didWarnAboutLegacyContext.has(fiber.type)) {
2882 return;
2883 }
2884
2885 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2886
2887 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2888 if (warningsForRoot === undefined) {
2889 warningsForRoot = [];
2890 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2891 }
2892 warningsForRoot.push(fiber);
2893 }
2894 };
2895
2896 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2897 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2898 var uniqueNames = new Set();
2899 fiberArray.forEach(function (fiber) {
2900 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2901 didWarnAboutLegacyContext.add(fiber.type);
2902 });
2903
2904 var sortedNames = setToSortedString(uniqueNames);
2905 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2906
2907 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);
2908 });
2909 };
2910}
2911
2912// This lets us hook into Fiber to debug what it's doing.
2913// See https://github.com/facebook/react/pull/8033.
2914// This is not part of the public API, not even for React DevTools.
2915// You may only inject a debugTool if you work on React Fiber itself.
2916var ReactFiberInstrumentation = {
2917 debugTool: null
2918};
2919
2920var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
2921
2922// TODO: Offscreen updates should never suspend. However, a promise that
2923// suspended inside an offscreen subtree should be able to ping at the priority
2924// of the outer render.
2925
2926function markPendingPriorityLevel(root, expirationTime) {
2927 // If there's a gap between completing a failed root and retrying it,
2928 // additional updates may be scheduled. Clear `didError`, in case the update
2929 // is sufficient to fix the error.
2930 root.didError = false;
2931
2932 // Update the latest and earliest pending times
2933 var earliestPendingTime = root.earliestPendingTime;
2934 if (earliestPendingTime === NoWork) {
2935 // No other pending updates.
2936 root.earliestPendingTime = root.latestPendingTime = expirationTime;
2937 } else {
2938 if (earliestPendingTime < expirationTime) {
2939 // This is the earliest pending update.
2940 root.earliestPendingTime = expirationTime;
2941 } else {
2942 var latestPendingTime = root.latestPendingTime;
2943 if (latestPendingTime > expirationTime) {
2944 // This is the latest pending update
2945 root.latestPendingTime = expirationTime;
2946 }
2947 }
2948 }
2949 findNextExpirationTimeToWorkOn(expirationTime, root);
2950}
2951
2952function markCommittedPriorityLevels(root, earliestRemainingTime) {
2953 root.didError = false;
2954
2955 if (earliestRemainingTime === NoWork) {
2956 // Fast path. There's no remaining work. Clear everything.
2957 root.earliestPendingTime = NoWork;
2958 root.latestPendingTime = NoWork;
2959 root.earliestSuspendedTime = NoWork;
2960 root.latestSuspendedTime = NoWork;
2961 root.latestPingedTime = NoWork;
2962 findNextExpirationTimeToWorkOn(NoWork, root);
2963 return;
2964 }
2965
2966 if (earliestRemainingTime < root.latestPingedTime) {
2967 root.latestPingedTime = NoWork;
2968 }
2969
2970 // Let's see if the previous latest known pending level was just flushed.
2971 var latestPendingTime = root.latestPendingTime;
2972 if (latestPendingTime !== NoWork) {
2973 if (latestPendingTime > earliestRemainingTime) {
2974 // We've flushed all the known pending levels.
2975 root.earliestPendingTime = root.latestPendingTime = NoWork;
2976 } else {
2977 var earliestPendingTime = root.earliestPendingTime;
2978 if (earliestPendingTime > earliestRemainingTime) {
2979 // We've flushed the earliest known pending level. Set this to the
2980 // latest pending time.
2981 root.earliestPendingTime = root.latestPendingTime;
2982 }
2983 }
2984 }
2985
2986 // Now let's handle the earliest remaining level in the whole tree. We need to
2987 // decide whether to treat it as a pending level or as suspended. Check
2988 // it falls within the range of known suspended levels.
2989
2990 var earliestSuspendedTime = root.earliestSuspendedTime;
2991 if (earliestSuspendedTime === NoWork) {
2992 // There's no suspended work. Treat the earliest remaining level as a
2993 // pending level.
2994 markPendingPriorityLevel(root, earliestRemainingTime);
2995 findNextExpirationTimeToWorkOn(NoWork, root);
2996 return;
2997 }
2998
2999 var latestSuspendedTime = root.latestSuspendedTime;
3000 if (earliestRemainingTime < latestSuspendedTime) {
3001 // The earliest remaining level is later than all the suspended work. That
3002 // means we've flushed all the suspended work.
3003 root.earliestSuspendedTime = NoWork;
3004 root.latestSuspendedTime = NoWork;
3005 root.latestPingedTime = NoWork;
3006
3007 // There's no suspended work. Treat the earliest remaining level as a
3008 // pending level.
3009 markPendingPriorityLevel(root, earliestRemainingTime);
3010 findNextExpirationTimeToWorkOn(NoWork, root);
3011 return;
3012 }
3013
3014 if (earliestRemainingTime > earliestSuspendedTime) {
3015 // The earliest remaining time is earlier than all the suspended work.
3016 // Treat it as a pending update.
3017 markPendingPriorityLevel(root, earliestRemainingTime);
3018 findNextExpirationTimeToWorkOn(NoWork, root);
3019 return;
3020 }
3021
3022 // The earliest remaining time falls within the range of known suspended
3023 // levels. We should treat this as suspended work.
3024 findNextExpirationTimeToWorkOn(NoWork, root);
3025}
3026
3027function hasLowerPriorityWork(root, erroredExpirationTime) {
3028 var latestPendingTime = root.latestPendingTime;
3029 var latestSuspendedTime = root.latestSuspendedTime;
3030 var latestPingedTime = root.latestPingedTime;
3031 return latestPendingTime !== NoWork && latestPendingTime < erroredExpirationTime || latestSuspendedTime !== NoWork && latestSuspendedTime < erroredExpirationTime || latestPingedTime !== NoWork && latestPingedTime < erroredExpirationTime;
3032}
3033
3034function isPriorityLevelSuspended(root, expirationTime) {
3035 var earliestSuspendedTime = root.earliestSuspendedTime;
3036 var latestSuspendedTime = root.latestSuspendedTime;
3037 return earliestSuspendedTime !== NoWork && expirationTime <= earliestSuspendedTime && expirationTime >= latestSuspendedTime;
3038}
3039
3040function markSuspendedPriorityLevel(root, suspendedTime) {
3041 root.didError = false;
3042 clearPing(root, suspendedTime);
3043
3044 // First, check the known pending levels and update them if needed.
3045 var earliestPendingTime = root.earliestPendingTime;
3046 var latestPendingTime = root.latestPendingTime;
3047 if (earliestPendingTime === suspendedTime) {
3048 if (latestPendingTime === suspendedTime) {
3049 // Both known pending levels were suspended. Clear them.
3050 root.earliestPendingTime = root.latestPendingTime = NoWork;
3051 } else {
3052 // The earliest pending level was suspended. Clear by setting it to the
3053 // latest pending level.
3054 root.earliestPendingTime = latestPendingTime;
3055 }
3056 } else if (latestPendingTime === suspendedTime) {
3057 // The latest pending level was suspended. Clear by setting it to the
3058 // latest pending level.
3059 root.latestPendingTime = earliestPendingTime;
3060 }
3061
3062 // Finally, update the known suspended levels.
3063 var earliestSuspendedTime = root.earliestSuspendedTime;
3064 var latestSuspendedTime = root.latestSuspendedTime;
3065 if (earliestSuspendedTime === NoWork) {
3066 // No other suspended levels.
3067 root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime;
3068 } else {
3069 if (earliestSuspendedTime < suspendedTime) {
3070 // This is the earliest suspended level.
3071 root.earliestSuspendedTime = suspendedTime;
3072 } else if (latestSuspendedTime > suspendedTime) {
3073 // This is the latest suspended level
3074 root.latestSuspendedTime = suspendedTime;
3075 }
3076 }
3077
3078 findNextExpirationTimeToWorkOn(suspendedTime, root);
3079}
3080
3081function markPingedPriorityLevel(root, pingedTime) {
3082 root.didError = false;
3083
3084 // TODO: When we add back resuming, we need to ensure the progressed work
3085 // is thrown out and not reused during the restarted render. One way to
3086 // invalidate the progressed work is to restart at expirationTime + 1.
3087 var latestPingedTime = root.latestPingedTime;
3088 if (latestPingedTime === NoWork || latestPingedTime > pingedTime) {
3089 root.latestPingedTime = pingedTime;
3090 }
3091 findNextExpirationTimeToWorkOn(pingedTime, root);
3092}
3093
3094function clearPing(root, completedTime) {
3095 var latestPingedTime = root.latestPingedTime;
3096 if (latestPingedTime >= completedTime) {
3097 root.latestPingedTime = NoWork;
3098 }
3099}
3100
3101function findEarliestOutstandingPriorityLevel(root, renderExpirationTime) {
3102 var earliestExpirationTime = renderExpirationTime;
3103
3104 var earliestPendingTime = root.earliestPendingTime;
3105 var earliestSuspendedTime = root.earliestSuspendedTime;
3106 if (earliestPendingTime > earliestExpirationTime) {
3107 earliestExpirationTime = earliestPendingTime;
3108 }
3109 if (earliestSuspendedTime > earliestExpirationTime) {
3110 earliestExpirationTime = earliestSuspendedTime;
3111 }
3112 return earliestExpirationTime;
3113}
3114
3115function didExpireAtExpirationTime(root, currentTime) {
3116 var expirationTime = root.expirationTime;
3117 if (expirationTime !== NoWork && currentTime <= expirationTime) {
3118 // The root has expired. Flush all work up to the current time.
3119 root.nextExpirationTimeToWorkOn = currentTime;
3120 }
3121}
3122
3123function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
3124 var earliestSuspendedTime = root.earliestSuspendedTime;
3125 var latestSuspendedTime = root.latestSuspendedTime;
3126 var earliestPendingTime = root.earliestPendingTime;
3127 var latestPingedTime = root.latestPingedTime;
3128
3129 // Work on the earliest pending time. Failing that, work on the latest
3130 // pinged time.
3131 var nextExpirationTimeToWorkOn = earliestPendingTime !== NoWork ? earliestPendingTime : latestPingedTime;
3132
3133 // If there is no pending or pinged work, check if there's suspended work
3134 // that's lower priority than what we just completed.
3135 if (nextExpirationTimeToWorkOn === NoWork && (completedExpirationTime === NoWork || latestSuspendedTime < completedExpirationTime)) {
3136 // The lowest priority suspended work is the work most likely to be
3137 // committed next. Let's start rendering it again, so that if it times out,
3138 // it's ready to commit.
3139 nextExpirationTimeToWorkOn = latestSuspendedTime;
3140 }
3141
3142 var expirationTime = nextExpirationTimeToWorkOn;
3143 if (expirationTime !== NoWork && earliestSuspendedTime > expirationTime) {
3144 // Expire using the earliest known expiration time.
3145 expirationTime = earliestSuspendedTime;
3146 }
3147
3148 root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn;
3149 root.expirationTime = expirationTime;
3150}
3151
3152// UpdateQueue is a linked list of prioritized updates.
3153//
3154// Like fibers, update queues come in pairs: a current queue, which represents
3155// the visible state of the screen, and a work-in-progress queue, which is
3156// can be mutated and processed asynchronously before it is committed — a form
3157// of double buffering. If a work-in-progress render is discarded before
3158// finishing, we create a new work-in-progress by cloning the current queue.
3159//
3160// Both queues share a persistent, singly-linked list structure. To schedule an
3161// update, we append it to the end of both queues. Each queue maintains a
3162// pointer to first update in the persistent list that hasn't been processed.
3163// The work-in-progress pointer always has a position equal to or greater than
3164// the current queue, since we always work on that one. The current queue's
3165// pointer is only updated during the commit phase, when we swap in the
3166// work-in-progress.
3167//
3168// For example:
3169//
3170// Current pointer: A - B - C - D - E - F
3171// Work-in-progress pointer: D - E - F
3172// ^
3173// The work-in-progress queue has
3174// processed more updates than current.
3175//
3176// The reason we append to both queues is because otherwise we might drop
3177// updates without ever processing them. For example, if we only add updates to
3178// the work-in-progress queue, some updates could be lost whenever a work-in
3179// -progress render restarts by cloning from current. Similarly, if we only add
3180// updates to the current queue, the updates will be lost whenever an already
3181// in-progress queue commits and swaps with the current queue. However, by
3182// adding to both queues, we guarantee that the update will be part of the next
3183// work-in-progress. (And because the work-in-progress queue becomes the
3184// current queue once it commits, there's no danger of applying the same
3185// update twice.)
3186//
3187// Prioritization
3188// --------------
3189//
3190// Updates are not sorted by priority, but by insertion; new updates are always
3191// appended to the end of the list.
3192//
3193// The priority is still important, though. When processing the update queue
3194// during the render phase, only the updates with sufficient priority are
3195// included in the result. If we skip an update because it has insufficient
3196// priority, it remains in the queue to be processed later, during a lower
3197// priority render. Crucially, all updates subsequent to a skipped update also
3198// remain in the queue *regardless of their priority*. That means high priority
3199// updates are sometimes processed twice, at two separate priorities. We also
3200// keep track of a base state, that represents the state before the first
3201// update in the queue is applied.
3202//
3203// For example:
3204//
3205// Given a base state of '', and the following queue of updates
3206//
3207// A1 - B2 - C1 - D2
3208//
3209// where the number indicates the priority, and the update is applied to the
3210// previous state by appending a letter, React will process these updates as
3211// two separate renders, one per distinct priority level:
3212//
3213// First render, at priority 1:
3214// Base state: ''
3215// Updates: [A1, C1]
3216// Result state: 'AC'
3217//
3218// Second render, at priority 2:
3219// Base state: 'A' <- The base state does not include C1,
3220// because B2 was skipped.
3221// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
3222// Result state: 'ABCD'
3223//
3224// Because we process updates in insertion order, and rebase high priority
3225// updates when preceding updates are skipped, the final result is deterministic
3226// regardless of priority. Intermediate state may vary according to system
3227// resources, but the final state is always the same.
3228
3229var UpdateState = 0;
3230var ReplaceState = 1;
3231var ForceUpdate = 2;
3232var CaptureUpdate = 3;
3233
3234// Global state that is reset at the beginning of calling `processUpdateQueue`.
3235// It should only be read right after calling `processUpdateQueue`, via
3236// `checkHasForceUpdateAfterProcessing`.
3237var hasForceUpdate = false;
3238
3239var didWarnUpdateInsideUpdate = void 0;
3240var currentlyProcessingQueue = void 0;
3241var resetCurrentlyProcessingQueue = void 0;
3242{
3243 didWarnUpdateInsideUpdate = false;
3244 currentlyProcessingQueue = null;
3245 resetCurrentlyProcessingQueue = function () {
3246 currentlyProcessingQueue = null;
3247 };
3248}
3249
3250function createUpdateQueue(baseState) {
3251 var queue = {
3252 baseState: baseState,
3253 firstUpdate: null,
3254 lastUpdate: null,
3255 firstCapturedUpdate: null,
3256 lastCapturedUpdate: null,
3257 firstEffect: null,
3258 lastEffect: null,
3259 firstCapturedEffect: null,
3260 lastCapturedEffect: null
3261 };
3262 return queue;
3263}
3264
3265function cloneUpdateQueue(currentQueue) {
3266 var queue = {
3267 baseState: currentQueue.baseState,
3268 firstUpdate: currentQueue.firstUpdate,
3269 lastUpdate: currentQueue.lastUpdate,
3270
3271 // TODO: With resuming, if we bail out and resuse the child tree, we should
3272 // keep these effects.
3273 firstCapturedUpdate: null,
3274 lastCapturedUpdate: null,
3275
3276 firstEffect: null,
3277 lastEffect: null,
3278
3279 firstCapturedEffect: null,
3280 lastCapturedEffect: null
3281 };
3282 return queue;
3283}
3284
3285function createUpdate(expirationTime) {
3286 return {
3287 expirationTime: expirationTime,
3288
3289 tag: UpdateState,
3290 payload: null,
3291 callback: null,
3292
3293 next: null,
3294 nextEffect: null
3295 };
3296}
3297
3298function appendUpdateToQueue(queue, update) {
3299 // Append the update to the end of the list.
3300 if (queue.lastUpdate === null) {
3301 // Queue is empty
3302 queue.firstUpdate = queue.lastUpdate = update;
3303 } else {
3304 queue.lastUpdate.next = update;
3305 queue.lastUpdate = update;
3306 }
3307}
3308
3309function enqueueUpdate(fiber, update) {
3310 // Update queues are created lazily.
3311 var alternate = fiber.alternate;
3312 var queue1 = void 0;
3313 var queue2 = void 0;
3314 if (alternate === null) {
3315 // There's only one fiber.
3316 queue1 = fiber.updateQueue;
3317 queue2 = null;
3318 if (queue1 === null) {
3319 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3320 }
3321 } else {
3322 // There are two owners.
3323 queue1 = fiber.updateQueue;
3324 queue2 = alternate.updateQueue;
3325 if (queue1 === null) {
3326 if (queue2 === null) {
3327 // Neither fiber has an update queue. Create new ones.
3328 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3329 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
3330 } else {
3331 // Only one fiber has an update queue. Clone to create a new one.
3332 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
3333 }
3334 } else {
3335 if (queue2 === null) {
3336 // Only one fiber has an update queue. Clone to create a new one.
3337 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
3338 } else {
3339 // Both owners have an update queue.
3340 }
3341 }
3342 }
3343 if (queue2 === null || queue1 === queue2) {
3344 // There's only a single queue.
3345 appendUpdateToQueue(queue1, update);
3346 } else {
3347 // There are two queues. We need to append the update to both queues,
3348 // while accounting for the persistent structure of the list — we don't
3349 // want the same update to be added multiple times.
3350 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
3351 // One of the queues is not empty. We must add the update to both queues.
3352 appendUpdateToQueue(queue1, update);
3353 appendUpdateToQueue(queue2, update);
3354 } else {
3355 // Both queues are non-empty. The last update is the same in both lists,
3356 // because of structural sharing. So, only append to one of the lists.
3357 appendUpdateToQueue(queue1, update);
3358 // But we still need to update the `lastUpdate` pointer of queue2.
3359 queue2.lastUpdate = update;
3360 }
3361 }
3362
3363 {
3364 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
3365 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.');
3366 didWarnUpdateInsideUpdate = true;
3367 }
3368 }
3369}
3370
3371function enqueueCapturedUpdate(workInProgress, update) {
3372 // Captured updates go into a separate list, and only on the work-in-
3373 // progress queue.
3374 var workInProgressQueue = workInProgress.updateQueue;
3375 if (workInProgressQueue === null) {
3376 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
3377 } else {
3378 // TODO: I put this here rather than createWorkInProgress so that we don't
3379 // clone the queue unnecessarily. There's probably a better way to
3380 // structure this.
3381 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
3382 }
3383
3384 // Append the update to the end of the list.
3385 if (workInProgressQueue.lastCapturedUpdate === null) {
3386 // This is the first render phase update
3387 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
3388 } else {
3389 workInProgressQueue.lastCapturedUpdate.next = update;
3390 workInProgressQueue.lastCapturedUpdate = update;
3391 }
3392}
3393
3394function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
3395 var current = workInProgress.alternate;
3396 if (current !== null) {
3397 // If the work-in-progress queue is equal to the current queue,
3398 // we need to clone it first.
3399 if (queue === current.updateQueue) {
3400 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
3401 }
3402 }
3403 return queue;
3404}
3405
3406function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
3407 switch (update.tag) {
3408 case ReplaceState:
3409 {
3410 var _payload = update.payload;
3411 if (typeof _payload === 'function') {
3412 // Updater function
3413 {
3414 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3415 _payload.call(instance, prevState, nextProps);
3416 }
3417 }
3418 return _payload.call(instance, prevState, nextProps);
3419 }
3420 // State object
3421 return _payload;
3422 }
3423 case CaptureUpdate:
3424 {
3425 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
3426 }
3427 // Intentional fallthrough
3428 case UpdateState:
3429 {
3430 var _payload2 = update.payload;
3431 var partialState = void 0;
3432 if (typeof _payload2 === 'function') {
3433 // Updater function
3434 {
3435 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3436 _payload2.call(instance, prevState, nextProps);
3437 }
3438 }
3439 partialState = _payload2.call(instance, prevState, nextProps);
3440 } else {
3441 // Partial state object
3442 partialState = _payload2;
3443 }
3444 if (partialState === null || partialState === undefined) {
3445 // Null and undefined are treated as no-ops.
3446 return prevState;
3447 }
3448 // Merge the partial state and the previous state.
3449 return _assign({}, prevState, partialState);
3450 }
3451 case ForceUpdate:
3452 {
3453 hasForceUpdate = true;
3454 return prevState;
3455 }
3456 }
3457 return prevState;
3458}
3459
3460function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
3461 hasForceUpdate = false;
3462
3463 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
3464
3465 {
3466 currentlyProcessingQueue = queue;
3467 }
3468
3469 // These values may change as we process the queue.
3470 var newBaseState = queue.baseState;
3471 var newFirstUpdate = null;
3472 var newExpirationTime = NoWork;
3473
3474 // Iterate through the list of updates to compute the result.
3475 var update = queue.firstUpdate;
3476 var resultState = newBaseState;
3477 while (update !== null) {
3478 var updateExpirationTime = update.expirationTime;
3479 if (updateExpirationTime < renderExpirationTime) {
3480 // This update does not have sufficient priority. Skip it.
3481 if (newFirstUpdate === null) {
3482 // This is the first skipped update. It will be the first update in
3483 // the new list.
3484 newFirstUpdate = update;
3485 // Since this is the first update that was skipped, the current result
3486 // is the new base state.
3487 newBaseState = resultState;
3488 }
3489 // Since this update will remain in the list, update the remaining
3490 // expiration time.
3491 if (newExpirationTime < updateExpirationTime) {
3492 newExpirationTime = updateExpirationTime;
3493 }
3494 } else {
3495 // This update does have sufficient priority. Process it and compute
3496 // a new result.
3497 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3498 var _callback = update.callback;
3499 if (_callback !== null) {
3500 workInProgress.effectTag |= Callback;
3501 // Set this to null, in case it was mutated during an aborted render.
3502 update.nextEffect = null;
3503 if (queue.lastEffect === null) {
3504 queue.firstEffect = queue.lastEffect = update;
3505 } else {
3506 queue.lastEffect.nextEffect = update;
3507 queue.lastEffect = update;
3508 }
3509 }
3510 }
3511 // Continue to the next update.
3512 update = update.next;
3513 }
3514
3515 // Separately, iterate though the list of captured updates.
3516 var newFirstCapturedUpdate = null;
3517 update = queue.firstCapturedUpdate;
3518 while (update !== null) {
3519 var _updateExpirationTime = update.expirationTime;
3520 if (_updateExpirationTime < renderExpirationTime) {
3521 // This update does not have sufficient priority. Skip it.
3522 if (newFirstCapturedUpdate === null) {
3523 // This is the first skipped captured update. It will be the first
3524 // update in the new list.
3525 newFirstCapturedUpdate = update;
3526 // If this is the first update that was skipped, the current result is
3527 // the new base state.
3528 if (newFirstUpdate === null) {
3529 newBaseState = resultState;
3530 }
3531 }
3532 // Since this update will remain in the list, update the remaining
3533 // expiration time.
3534 if (newExpirationTime < _updateExpirationTime) {
3535 newExpirationTime = _updateExpirationTime;
3536 }
3537 } else {
3538 // This update does have sufficient priority. Process it and compute
3539 // a new result.
3540 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3541 var _callback2 = update.callback;
3542 if (_callback2 !== null) {
3543 workInProgress.effectTag |= Callback;
3544 // Set this to null, in case it was mutated during an aborted render.
3545 update.nextEffect = null;
3546 if (queue.lastCapturedEffect === null) {
3547 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
3548 } else {
3549 queue.lastCapturedEffect.nextEffect = update;
3550 queue.lastCapturedEffect = update;
3551 }
3552 }
3553 }
3554 update = update.next;
3555 }
3556
3557 if (newFirstUpdate === null) {
3558 queue.lastUpdate = null;
3559 }
3560 if (newFirstCapturedUpdate === null) {
3561 queue.lastCapturedUpdate = null;
3562 } else {
3563 workInProgress.effectTag |= Callback;
3564 }
3565 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
3566 // We processed every update, without skipping. That means the new base
3567 // state is the same as the result state.
3568 newBaseState = resultState;
3569 }
3570
3571 queue.baseState = newBaseState;
3572 queue.firstUpdate = newFirstUpdate;
3573 queue.firstCapturedUpdate = newFirstCapturedUpdate;
3574
3575 // Set the remaining expiration time to be whatever is remaining in the queue.
3576 // This should be fine because the only two other things that contribute to
3577 // expiration time are props and context. We're already in the middle of the
3578 // begin phase by the time we start processing the queue, so we've already
3579 // dealt with the props. Context in components that specify
3580 // shouldComponentUpdate is tricky; but we'll have to account for
3581 // that regardless.
3582 workInProgress.expirationTime = newExpirationTime;
3583 workInProgress.memoizedState = resultState;
3584
3585 {
3586 currentlyProcessingQueue = null;
3587 }
3588}
3589
3590function callCallback(callback, context) {
3591 !(typeof callback === 'function') ? invariant(false, 'Invalid argument passed as callback. Expected a function. Instead received: %s', callback) : void 0;
3592 callback.call(context);
3593}
3594
3595function resetHasForceUpdateBeforeProcessing() {
3596 hasForceUpdate = false;
3597}
3598
3599function checkHasForceUpdateAfterProcessing() {
3600 return hasForceUpdate;
3601}
3602
3603function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
3604 // If the finished render included captured updates, and there are still
3605 // lower priority updates left over, we need to keep the captured updates
3606 // in the queue so that they are rebased and not dropped once we process the
3607 // queue again at the lower priority.
3608 if (finishedQueue.firstCapturedUpdate !== null) {
3609 // Join the captured update list to the end of the normal list.
3610 if (finishedQueue.lastUpdate !== null) {
3611 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
3612 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
3613 }
3614 // Clear the list of captured updates.
3615 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
3616 }
3617
3618 // Commit the effects
3619 commitUpdateEffects(finishedQueue.firstEffect, instance);
3620 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
3621
3622 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
3623 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
3624}
3625
3626function commitUpdateEffects(effect, instance) {
3627 while (effect !== null) {
3628 var _callback3 = effect.callback;
3629 if (_callback3 !== null) {
3630 effect.callback = null;
3631 callCallback(_callback3, instance);
3632 }
3633 effect = effect.nextEffect;
3634 }
3635}
3636
3637function createCapturedValue(value, source) {
3638 // If the value is an error, call this function immediately after it is thrown
3639 // so the stack is accurate.
3640 return {
3641 value: value,
3642 source: source,
3643 stack: getStackByFiberInDevAndProd(source)
3644 };
3645}
3646
3647var valueCursor = createCursor(null);
3648
3649var rendererSigil = void 0;
3650{
3651 // Use this to detect multiple renderers using the same context
3652 rendererSigil = {};
3653}
3654
3655var currentlyRenderingFiber = null;
3656var lastContextDependency = null;
3657var lastContextWithAllBitsObserved = null;
3658
3659function resetContextDependences() {
3660 // This is called right before React yields execution, to ensure `readContext`
3661 // cannot be called outside the render phase.
3662 currentlyRenderingFiber = null;
3663 lastContextDependency = null;
3664 lastContextWithAllBitsObserved = null;
3665}
3666
3667function pushProvider(providerFiber, nextValue) {
3668 var context = providerFiber.type._context;
3669
3670 if (isPrimaryRenderer) {
3671 push(valueCursor, context._currentValue, providerFiber);
3672
3673 context._currentValue = nextValue;
3674 {
3675 !(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;
3676 context._currentRenderer = rendererSigil;
3677 }
3678 } else {
3679 push(valueCursor, context._currentValue2, providerFiber);
3680
3681 context._currentValue2 = nextValue;
3682 {
3683 !(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;
3684 context._currentRenderer2 = rendererSigil;
3685 }
3686 }
3687}
3688
3689function popProvider(providerFiber) {
3690 var currentValue = valueCursor.current;
3691
3692 pop(valueCursor, providerFiber);
3693
3694 var context = providerFiber.type._context;
3695 if (isPrimaryRenderer) {
3696 context._currentValue = currentValue;
3697 } else {
3698 context._currentValue2 = currentValue;
3699 }
3700}
3701
3702function calculateChangedBits(context, newValue, oldValue) {
3703 // Use Object.is to compare the new context value to the old value. Inlined
3704 // Object.is polyfill.
3705 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3706 if (oldValue === newValue && (oldValue !== 0 || 1 / oldValue === 1 / newValue) || oldValue !== oldValue && newValue !== newValue // eslint-disable-line no-self-compare
3707 ) {
3708 // No change
3709 return 0;
3710 } else {
3711 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : maxSigned31BitInt;
3712
3713 {
3714 !((changedBits & maxSigned31BitInt) === changedBits) ? warning$1(false, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits) : void 0;
3715 }
3716 return changedBits | 0;
3717 }
3718}
3719
3720function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
3721 var fiber = workInProgress.child;
3722 if (fiber !== null) {
3723 // Set the return pointer of the child to the work-in-progress fiber.
3724 fiber.return = workInProgress;
3725 }
3726 while (fiber !== null) {
3727 var nextFiber = void 0;
3728
3729 // Visit this fiber.
3730 var dependency = fiber.firstContextDependency;
3731 if (dependency !== null) {
3732 do {
3733 // Check if the context matches.
3734 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
3735 // Match! Schedule an update on this fiber.
3736
3737 if (fiber.tag === ClassComponent) {
3738 // Schedule a force update on the work-in-progress.
3739 var update = createUpdate(renderExpirationTime);
3740 update.tag = ForceUpdate;
3741 // TODO: Because we don't have a work-in-progress, this will add the
3742 // update to the current fiber, too, which means it will persist even if
3743 // this render is thrown away. Since it's a race condition, not sure it's
3744 // worth fixing.
3745 enqueueUpdate(fiber, update);
3746 }
3747
3748 if (fiber.expirationTime < renderExpirationTime) {
3749 fiber.expirationTime = renderExpirationTime;
3750 }
3751 var alternate = fiber.alternate;
3752 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
3753 alternate.expirationTime = renderExpirationTime;
3754 }
3755 // Update the child expiration time of all the ancestors, including
3756 // the alternates.
3757 var node = fiber.return;
3758 while (node !== null) {
3759 alternate = node.alternate;
3760 if (node.childExpirationTime < renderExpirationTime) {
3761 node.childExpirationTime = renderExpirationTime;
3762 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3763 alternate.childExpirationTime = renderExpirationTime;
3764 }
3765 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3766 alternate.childExpirationTime = renderExpirationTime;
3767 } else {
3768 // Neither alternate was updated, which means the rest of the
3769 // ancestor path already has sufficient priority.
3770 break;
3771 }
3772 node = node.return;
3773 }
3774 }
3775 nextFiber = fiber.child;
3776 dependency = dependency.next;
3777 } while (dependency !== null);
3778 } else if (fiber.tag === ContextProvider) {
3779 // Don't scan deeper if this is a matching provider
3780 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
3781 } else {
3782 // Traverse down.
3783 nextFiber = fiber.child;
3784 }
3785
3786 if (nextFiber !== null) {
3787 // Set the return pointer of the child to the work-in-progress fiber.
3788 nextFiber.return = fiber;
3789 } else {
3790 // No child. Traverse to next sibling.
3791 nextFiber = fiber;
3792 while (nextFiber !== null) {
3793 if (nextFiber === workInProgress) {
3794 // We're back to the root of this subtree. Exit.
3795 nextFiber = null;
3796 break;
3797 }
3798 var sibling = nextFiber.sibling;
3799 if (sibling !== null) {
3800 // Set the return pointer of the sibling to the work-in-progress fiber.
3801 sibling.return = nextFiber.return;
3802 nextFiber = sibling;
3803 break;
3804 }
3805 // No more siblings. Traverse up.
3806 nextFiber = nextFiber.return;
3807 }
3808 }
3809 fiber = nextFiber;
3810 }
3811}
3812
3813function prepareToReadContext(workInProgress, renderExpirationTime) {
3814 currentlyRenderingFiber = workInProgress;
3815 lastContextDependency = null;
3816 lastContextWithAllBitsObserved = null;
3817
3818 // Reset the work-in-progress list
3819 workInProgress.firstContextDependency = null;
3820}
3821
3822function readContext(context, observedBits) {
3823 if (lastContextWithAllBitsObserved === context) {
3824 // Nothing to do. We already observe everything in this context.
3825 } else if (observedBits === false || observedBits === 0) {
3826 // Do not observe any updates.
3827 } else {
3828 var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types.
3829 if (typeof observedBits !== 'number' || observedBits === maxSigned31BitInt) {
3830 // Observe all updates.
3831 lastContextWithAllBitsObserved = context;
3832 resolvedObservedBits = maxSigned31BitInt;
3833 } else {
3834 resolvedObservedBits = observedBits;
3835 }
3836
3837 var contextItem = {
3838 context: context,
3839 observedBits: resolvedObservedBits,
3840 next: null
3841 };
3842
3843 if (lastContextDependency === null) {
3844 !(currentlyRenderingFiber !== null) ? invariant(false, 'Context can only be read while React is rendering, e.g. inside the render method or getDerivedStateFromProps.') : void 0;
3845 // This is the first dependency in the list
3846 currentlyRenderingFiber.firstContextDependency = lastContextDependency = contextItem;
3847 } else {
3848 // Append a new context item.
3849 lastContextDependency = lastContextDependency.next = contextItem;
3850 }
3851 }
3852 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
3853}
3854
3855var NoEffect$1 = /* */0;
3856var UnmountSnapshot = /* */2;
3857var UnmountMutation = /* */4;
3858var MountMutation = /* */8;
3859var UnmountLayout = /* */16;
3860var MountLayout = /* */32;
3861var MountPassive = /* */64;
3862var UnmountPassive = /* */128;
3863
3864function areHookInputsEqual(arr1, arr2) {
3865 // Don't bother comparing lengths in prod because these arrays should be
3866 // passed inline.
3867 {
3868 !(arr1.length === arr2.length) ? warning$1(false, 'Detected a variable number of hook dependencies. The length of the ' + 'dependencies array should be constant between renders.\n\n' + 'Previous: %s\n' + 'Incoming: %s', arr1.join(', '), arr2.join(', ')) : void 0;
3869 }
3870 for (var i = 0; i < arr1.length; i++) {
3871 // Inlined Object.is polyfill.
3872 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3873 var val1 = arr1[i];
3874 var val2 = arr2[i];
3875 if (val1 === val2 && (val1 !== 0 || 1 / val1 === 1 / val2) || val1 !== val1 && val2 !== val2 // eslint-disable-line no-self-compare
3876 ) {
3877 continue;
3878 }
3879 return false;
3880 }
3881 return true;
3882}
3883
3884// These are set right before calling the component.
3885var renderExpirationTime = NoWork;
3886// The work-in-progress fiber. I've named it differently to distinguish it from
3887// the work-in-progress hook.
3888var currentlyRenderingFiber$1 = null;
3889
3890// Hooks are stored as a linked list on the fiber's memoizedState field. The
3891// current hook list is the list that belongs to the current fiber. The
3892// work-in-progress hook list is a new list that will be added to the
3893// work-in-progress fiber.
3894var firstCurrentHook = null;
3895var currentHook = null;
3896var firstWorkInProgressHook = null;
3897var workInProgressHook = null;
3898
3899var remainingExpirationTime = NoWork;
3900var componentUpdateQueue = null;
3901
3902// Updates scheduled during render will trigger an immediate re-render at the
3903// end of the current pass. We can't store these updates on the normal queue,
3904// because if the work is aborted, they should be discarded. Because this is
3905// a relatively rare case, we also don't want to add an additional field to
3906// either the hook or queue object types. So we store them in a lazily create
3907// map of queue -> render-phase updates, which are discarded once the component
3908// completes without re-rendering.
3909
3910// Whether the work-in-progress hook is a re-rendered hook
3911var isReRender = false;
3912// Whether an update was scheduled during the currently executing render pass.
3913var didScheduleRenderPhaseUpdate = false;
3914// Lazily created map of render-phase updates
3915var renderPhaseUpdates = null;
3916// Counter to prevent infinite loops.
3917var numberOfReRenders = 0;
3918var RE_RENDER_LIMIT = 25;
3919
3920function resolveCurrentlyRenderingFiber() {
3921 !(currentlyRenderingFiber$1 !== null) ? invariant(false, 'Hooks can only be called inside the body of a function component.') : void 0;
3922 return currentlyRenderingFiber$1;
3923}
3924
3925function prepareToUseHooks(current, workInProgress, nextRenderExpirationTime) {
3926 if (!enableHooks) {
3927 return;
3928 }
3929 renderExpirationTime = nextRenderExpirationTime;
3930 currentlyRenderingFiber$1 = workInProgress;
3931 firstCurrentHook = current !== null ? current.memoizedState : null;
3932
3933 // The following should have already been reset
3934 // currentHook = null;
3935 // workInProgressHook = null;
3936
3937 // remainingExpirationTime = NoWork;
3938 // componentUpdateQueue = null;
3939
3940 // isReRender = false;
3941 // didScheduleRenderPhaseUpdate = false;
3942 // renderPhaseUpdates = null;
3943 // numberOfReRenders = 0;
3944}
3945
3946function finishHooks(Component, props, children, refOrContext) {
3947 if (!enableHooks) {
3948 return children;
3949 }
3950
3951 // This must be called after every function component to prevent hooks from
3952 // being used in classes.
3953
3954 while (didScheduleRenderPhaseUpdate) {
3955 // Updates were scheduled during the render phase. They are stored in
3956 // the `renderPhaseUpdates` map. Call the component again, reusing the
3957 // work-in-progress hooks and applying the additional updates on top. Keep
3958 // restarting until no more updates are scheduled.
3959 didScheduleRenderPhaseUpdate = false;
3960 numberOfReRenders += 1;
3961
3962 // Start over from the beginning of the list
3963 currentHook = null;
3964 workInProgressHook = null;
3965 componentUpdateQueue = null;
3966
3967 children = Component(props, refOrContext);
3968 }
3969 renderPhaseUpdates = null;
3970 numberOfReRenders = 0;
3971
3972 var renderedWork = currentlyRenderingFiber$1;
3973
3974 renderedWork.memoizedState = firstWorkInProgressHook;
3975 renderedWork.expirationTime = remainingExpirationTime;
3976 renderedWork.updateQueue = componentUpdateQueue;
3977
3978 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
3979
3980 renderExpirationTime = NoWork;
3981 currentlyRenderingFiber$1 = null;
3982
3983 firstCurrentHook = null;
3984 currentHook = null;
3985 firstWorkInProgressHook = null;
3986 workInProgressHook = null;
3987
3988 remainingExpirationTime = NoWork;
3989 componentUpdateQueue = null;
3990
3991 // Always set during createWorkInProgress
3992 // isReRender = false;
3993
3994 // These were reset above
3995 // didScheduleRenderPhaseUpdate = false;
3996 // renderPhaseUpdates = null;
3997 // numberOfReRenders = 0;
3998
3999 !!didRenderTooFewHooks ? invariant(false, 'Rendered fewer hooks than expected. This may be caused by an accidental early return statement.') : void 0;
4000
4001 return children;
4002}
4003
4004function resetHooks() {
4005 if (!enableHooks) {
4006 return;
4007 }
4008
4009 // This is called instead of `finishHooks` if the component throws. It's also
4010 // called inside mountIndeterminateComponent if we determine the component
4011 // is a module-style component.
4012 renderExpirationTime = NoWork;
4013 currentlyRenderingFiber$1 = null;
4014
4015 firstCurrentHook = null;
4016 currentHook = null;
4017 firstWorkInProgressHook = null;
4018 workInProgressHook = null;
4019
4020 remainingExpirationTime = NoWork;
4021 componentUpdateQueue = null;
4022
4023 // Always set during createWorkInProgress
4024 // isReRender = false;
4025
4026 didScheduleRenderPhaseUpdate = false;
4027 renderPhaseUpdates = null;
4028 numberOfReRenders = 0;
4029}
4030
4031function createHook() {
4032 return {
4033 memoizedState: null,
4034
4035 baseState: null,
4036 queue: null,
4037 baseUpdate: null,
4038
4039 next: null
4040 };
4041}
4042
4043function cloneHook(hook) {
4044 return {
4045 memoizedState: hook.memoizedState,
4046
4047 baseState: hook.baseState,
4048 queue: hook.queue,
4049 baseUpdate: hook.baseUpdate,
4050
4051 next: null
4052 };
4053}
4054
4055function createWorkInProgressHook() {
4056 if (workInProgressHook === null) {
4057 // This is the first hook in the list
4058 if (firstWorkInProgressHook === null) {
4059 isReRender = false;
4060 currentHook = firstCurrentHook;
4061 if (currentHook === null) {
4062 // This is a newly mounted hook
4063 workInProgressHook = createHook();
4064 } else {
4065 // Clone the current hook.
4066 workInProgressHook = cloneHook(currentHook);
4067 }
4068 firstWorkInProgressHook = workInProgressHook;
4069 } else {
4070 // There's already a work-in-progress. Reuse it.
4071 isReRender = true;
4072 currentHook = firstCurrentHook;
4073 workInProgressHook = firstWorkInProgressHook;
4074 }
4075 } else {
4076 if (workInProgressHook.next === null) {
4077 isReRender = false;
4078 var hook = void 0;
4079 if (currentHook === null) {
4080 // This is a newly mounted hook
4081 hook = createHook();
4082 } else {
4083 currentHook = currentHook.next;
4084 if (currentHook === null) {
4085 // This is a newly mounted hook
4086 hook = createHook();
4087 } else {
4088 // Clone the current hook.
4089 hook = cloneHook(currentHook);
4090 }
4091 }
4092 // Append to the end of the list
4093 workInProgressHook = workInProgressHook.next = hook;
4094 } else {
4095 // There's already a work-in-progress. Reuse it.
4096 isReRender = true;
4097 workInProgressHook = workInProgressHook.next;
4098 currentHook = currentHook !== null ? currentHook.next : null;
4099 }
4100 }
4101 return workInProgressHook;
4102}
4103
4104function createFunctionComponentUpdateQueue() {
4105 return {
4106 lastEffect: null
4107 };
4108}
4109
4110function basicStateReducer(state, action) {
4111 return typeof action === 'function' ? action(state) : action;
4112}
4113
4114function useContext(context, observedBits) {
4115 // Ensure we're in a function component (class components support only the
4116 // .unstable_read() form)
4117 resolveCurrentlyRenderingFiber();
4118 return readContext(context, observedBits);
4119}
4120
4121function useState(initialState) {
4122 return useReducer(basicStateReducer,
4123 // useReducer has a special case to support lazy useState initializers
4124 initialState);
4125}
4126
4127function useReducer(reducer, initialState, initialAction) {
4128 currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber();
4129 workInProgressHook = createWorkInProgressHook();
4130 var queue = workInProgressHook.queue;
4131 if (queue !== null) {
4132 // Already have a queue, so this is an update.
4133 if (isReRender) {
4134 // This is a re-render. Apply the new render phase updates to the previous
4135 var _dispatch2 = queue.dispatch;
4136 if (renderPhaseUpdates !== null) {
4137 // Render phase updates are stored in a map of queue -> linked list
4138 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
4139 if (firstRenderPhaseUpdate !== undefined) {
4140 renderPhaseUpdates.delete(queue);
4141 var newState = workInProgressHook.memoizedState;
4142 var update = firstRenderPhaseUpdate;
4143 do {
4144 // Process this render phase update. We don't have to check the
4145 // priority because it will always be the same as the current
4146 // render's.
4147 var _action = update.action;
4148 newState = reducer(newState, _action);
4149 update = update.next;
4150 } while (update !== null);
4151
4152 workInProgressHook.memoizedState = newState;
4153
4154 // Don't persist the state accumlated from the render phase updates to
4155 // the base state unless the queue is empty.
4156 // TODO: Not sure if this is the desired semantics, but it's what we
4157 // do for gDSFP. I can't remember why.
4158 if (workInProgressHook.baseUpdate === queue.last) {
4159 workInProgressHook.baseState = newState;
4160 }
4161
4162 return [newState, _dispatch2];
4163 }
4164 }
4165 return [workInProgressHook.memoizedState, _dispatch2];
4166 }
4167
4168 // The last update in the entire queue
4169 var _last = queue.last;
4170 // The last update that is part of the base state.
4171 var _baseUpdate = workInProgressHook.baseUpdate;
4172
4173 // Find the first unprocessed update.
4174 var first = void 0;
4175 if (_baseUpdate !== null) {
4176 if (_last !== null) {
4177 // For the first update, the queue is a circular linked list where
4178 // `queue.last.next = queue.first`. Once the first update commits, and
4179 // the `baseUpdate` is no longer empty, we can unravel the list.
4180 _last.next = null;
4181 }
4182 first = _baseUpdate.next;
4183 } else {
4184 first = _last !== null ? _last.next : null;
4185 }
4186 if (first !== null) {
4187 var _newState = workInProgressHook.baseState;
4188 var newBaseState = null;
4189 var newBaseUpdate = null;
4190 var prevUpdate = _baseUpdate;
4191 var _update = first;
4192 var didSkip = false;
4193 do {
4194 var updateExpirationTime = _update.expirationTime;
4195 if (updateExpirationTime < renderExpirationTime) {
4196 // Priority is insufficient. Skip this update. If this is the first
4197 // skipped update, the previous update/state is the new base
4198 // update/state.
4199 if (!didSkip) {
4200 didSkip = true;
4201 newBaseUpdate = prevUpdate;
4202 newBaseState = _newState;
4203 }
4204 // Update the remaining priority in the queue.
4205 if (updateExpirationTime > remainingExpirationTime) {
4206 remainingExpirationTime = updateExpirationTime;
4207 }
4208 } else {
4209 // Process this update.
4210 var _action2 = _update.action;
4211 _newState = reducer(_newState, _action2);
4212 }
4213 prevUpdate = _update;
4214 _update = _update.next;
4215 } while (_update !== null && _update !== first);
4216
4217 if (!didSkip) {
4218 newBaseUpdate = prevUpdate;
4219 newBaseState = _newState;
4220 }
4221
4222 workInProgressHook.memoizedState = _newState;
4223 workInProgressHook.baseUpdate = newBaseUpdate;
4224 workInProgressHook.baseState = newBaseState;
4225 }
4226
4227 var _dispatch = queue.dispatch;
4228 return [workInProgressHook.memoizedState, _dispatch];
4229 }
4230
4231 // There's no existing queue, so this is the initial render.
4232 if (reducer === basicStateReducer) {
4233 // Special case for `useState`.
4234 if (typeof initialState === 'function') {
4235 initialState = initialState();
4236 }
4237 } else if (initialAction !== undefined && initialAction !== null) {
4238 initialState = reducer(initialState, initialAction);
4239 }
4240 workInProgressHook.memoizedState = workInProgressHook.baseState = initialState;
4241 queue = workInProgressHook.queue = {
4242 last: null,
4243 dispatch: null
4244 };
4245 var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
4246 return [workInProgressHook.memoizedState, dispatch];
4247}
4248
4249function pushEffect(tag, create, destroy, inputs) {
4250 var effect = {
4251 tag: tag,
4252 create: create,
4253 destroy: destroy,
4254 inputs: inputs,
4255 // Circular
4256 next: null
4257 };
4258 if (componentUpdateQueue === null) {
4259 componentUpdateQueue = createFunctionComponentUpdateQueue();
4260 componentUpdateQueue.lastEffect = effect.next = effect;
4261 } else {
4262 var _lastEffect = componentUpdateQueue.lastEffect;
4263 if (_lastEffect === null) {
4264 componentUpdateQueue.lastEffect = effect.next = effect;
4265 } else {
4266 var firstEffect = _lastEffect.next;
4267 _lastEffect.next = effect;
4268 effect.next = firstEffect;
4269 componentUpdateQueue.lastEffect = effect;
4270 }
4271 }
4272 return effect;
4273}
4274
4275function useRef(initialValue) {
4276 currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber();
4277 workInProgressHook = createWorkInProgressHook();
4278 var ref = void 0;
4279
4280 if (workInProgressHook.memoizedState === null) {
4281 ref = { current: initialValue };
4282 {
4283 Object.seal(ref);
4284 }
4285 workInProgressHook.memoizedState = ref;
4286 } else {
4287 ref = workInProgressHook.memoizedState;
4288 }
4289 return ref;
4290}
4291
4292function useLayoutEffect(create, inputs) {
4293 useEffectImpl(Update, UnmountMutation | MountLayout, create, inputs);
4294}
4295
4296function useEffect(create, inputs) {
4297 useEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, inputs);
4298}
4299
4300function useEffectImpl(fiberEffectTag, hookEffectTag, create, inputs) {
4301 currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber();
4302 workInProgressHook = createWorkInProgressHook();
4303
4304 var nextInputs = inputs !== undefined && inputs !== null ? inputs : [create];
4305 var destroy = null;
4306 if (currentHook !== null) {
4307 var prevEffect = currentHook.memoizedState;
4308 destroy = prevEffect.destroy;
4309 if (areHookInputsEqual(nextInputs, prevEffect.inputs)) {
4310 pushEffect(NoEffect$1, create, destroy, nextInputs);
4311 return;
4312 }
4313 }
4314
4315 currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
4316 workInProgressHook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextInputs);
4317}
4318
4319function useImperativeMethods(ref, create, inputs) {
4320 // TODO: If inputs are provided, should we skip comparing the ref itself?
4321 var nextInputs = inputs !== null && inputs !== undefined ? inputs.concat([ref]) : [ref, create];
4322
4323 // TODO: I've implemented this on top of useEffect because it's almost the
4324 // same thing, and it would require an equal amount of code. It doesn't seem
4325 // like a common enough use case to justify the additional size.
4326 useLayoutEffect(function () {
4327 if (typeof ref === 'function') {
4328 var refCallback = ref;
4329 var _inst = create();
4330 refCallback(_inst);
4331 return function () {
4332 return refCallback(null);
4333 };
4334 } else if (ref !== null && ref !== undefined) {
4335 var refObject = ref;
4336 var _inst2 = create();
4337 refObject.current = _inst2;
4338 return function () {
4339 refObject.current = null;
4340 };
4341 }
4342 }, nextInputs);
4343}
4344
4345function useCallback(callback, inputs) {
4346 currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber();
4347 workInProgressHook = createWorkInProgressHook();
4348
4349 var nextInputs = inputs !== undefined && inputs !== null ? inputs : [callback];
4350
4351 var prevState = workInProgressHook.memoizedState;
4352 if (prevState !== null) {
4353 var prevInputs = prevState[1];
4354 if (areHookInputsEqual(nextInputs, prevInputs)) {
4355 return prevState[0];
4356 }
4357 }
4358 workInProgressHook.memoizedState = [callback, nextInputs];
4359 return callback;
4360}
4361
4362function useMemo(nextCreate, inputs) {
4363 currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber();
4364 workInProgressHook = createWorkInProgressHook();
4365
4366 var nextInputs = inputs !== undefined && inputs !== null ? inputs : [nextCreate];
4367
4368 var prevState = workInProgressHook.memoizedState;
4369 if (prevState !== null) {
4370 var prevInputs = prevState[1];
4371 if (areHookInputsEqual(nextInputs, prevInputs)) {
4372 return prevState[0];
4373 }
4374 }
4375
4376 var nextValue = nextCreate();
4377 workInProgressHook.memoizedState = [nextValue, nextInputs];
4378 return nextValue;
4379}
4380
4381function dispatchAction(fiber, queue, action) {
4382 !(numberOfReRenders < RE_RENDER_LIMIT) ? invariant(false, 'Too many re-renders. React limits the number of renders to prevent an infinite loop.') : void 0;
4383
4384 var alternate = fiber.alternate;
4385 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
4386 // This is a render phase update. Stash it in a lazily-created map of
4387 // queue -> linked list of updates. After this render pass, we'll restart
4388 // and apply the stashed updates on top of the work-in-progress hook.
4389 didScheduleRenderPhaseUpdate = true;
4390 var update = {
4391 expirationTime: renderExpirationTime,
4392 action: action,
4393 next: null
4394 };
4395 if (renderPhaseUpdates === null) {
4396 renderPhaseUpdates = new Map();
4397 }
4398 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
4399 if (firstRenderPhaseUpdate === undefined) {
4400 renderPhaseUpdates.set(queue, update);
4401 } else {
4402 // Append the update to the end of the list.
4403 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
4404 while (lastRenderPhaseUpdate.next !== null) {
4405 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
4406 }
4407 lastRenderPhaseUpdate.next = update;
4408 }
4409 } else {
4410 var currentTime = requestCurrentTime();
4411 var _expirationTime = computeExpirationForFiber(currentTime, fiber);
4412 var _update2 = {
4413 expirationTime: _expirationTime,
4414 action: action,
4415 next: null
4416 };
4417 flushPassiveEffects();
4418 // Append the update to the end of the list.
4419 var _last2 = queue.last;
4420 if (_last2 === null) {
4421 // This is the first update. Create a circular list.
4422 _update2.next = _update2;
4423 } else {
4424 var first = _last2.next;
4425 if (first !== null) {
4426 // Still circular.
4427 _update2.next = first;
4428 }
4429 _last2.next = _update2;
4430 }
4431 queue.last = _update2;
4432 scheduleWork(fiber, _expirationTime);
4433 }
4434}
4435
4436var NO_CONTEXT$1 = {};
4437
4438var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
4439var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
4440var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
4441
4442function requiredContext(c) {
4443 !(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;
4444 return c;
4445}
4446
4447function getRootHostContainer() {
4448 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4449 return rootInstance;
4450}
4451
4452function pushHostContainer(fiber, nextRootInstance) {
4453 // Push current root instance onto the stack;
4454 // This allows us to reset root when portals are popped.
4455 push(rootInstanceStackCursor, nextRootInstance, fiber);
4456 // Track the context and the Fiber that provided it.
4457 // This enables us to pop only Fibers that provide unique contexts.
4458 push(contextFiberStackCursor, fiber, fiber);
4459
4460 // Finally, we need to push the host context to the stack.
4461 // However, we can't just call getRootHostContext() and push it because
4462 // we'd have a different number of entries on the stack depending on
4463 // whether getRootHostContext() throws somewhere in renderer code or not.
4464 // So we push an empty value first. This lets us safely unwind on errors.
4465 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
4466 var nextRootContext = getRootHostContext(nextRootInstance);
4467 // Now that we know this function doesn't throw, replace it.
4468 pop(contextStackCursor$1, fiber);
4469 push(contextStackCursor$1, nextRootContext, fiber);
4470}
4471
4472function popHostContainer(fiber) {
4473 pop(contextStackCursor$1, fiber);
4474 pop(contextFiberStackCursor, fiber);
4475 pop(rootInstanceStackCursor, fiber);
4476}
4477
4478function getHostContext() {
4479 var context = requiredContext(contextStackCursor$1.current);
4480 return context;
4481}
4482
4483function pushHostContext(fiber) {
4484 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4485 var context = requiredContext(contextStackCursor$1.current);
4486 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
4487
4488 // Don't push this Fiber's context unless it's unique.
4489 if (context === nextContext) {
4490 return;
4491 }
4492
4493 // Track the context and the Fiber that provided it.
4494 // This enables us to pop only Fibers that provide unique contexts.
4495 push(contextFiberStackCursor, fiber, fiber);
4496 push(contextStackCursor$1, nextContext, fiber);
4497}
4498
4499function popHostContext(fiber) {
4500 // Do not pop unless this Fiber provided the current context.
4501 // pushHostContext() only pushes Fibers that provide unique contexts.
4502 if (contextFiberStackCursor.current !== fiber) {
4503 return;
4504 }
4505
4506 pop(contextStackCursor$1, fiber);
4507 pop(contextFiberStackCursor, fiber);
4508}
4509
4510var commitTime = 0;
4511var profilerStartTime = -1;
4512
4513function getCommitTime() {
4514 return commitTime;
4515}
4516
4517function recordCommitTime() {
4518 if (!enableProfilerTimer) {
4519 return;
4520 }
4521 commitTime = now();
4522}
4523
4524function startProfilerTimer(fiber) {
4525 if (!enableProfilerTimer) {
4526 return;
4527 }
4528
4529 profilerStartTime = now();
4530
4531 if (fiber.actualStartTime < 0) {
4532 fiber.actualStartTime = now();
4533 }
4534}
4535
4536function stopProfilerTimerIfRunning(fiber) {
4537 if (!enableProfilerTimer) {
4538 return;
4539 }
4540 profilerStartTime = -1;
4541}
4542
4543function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
4544 if (!enableProfilerTimer) {
4545 return;
4546 }
4547
4548 if (profilerStartTime >= 0) {
4549 var elapsedTime = now() - profilerStartTime;
4550 fiber.actualDuration += elapsedTime;
4551 if (overrideBaseTime) {
4552 fiber.selfBaseDuration = elapsedTime;
4553 }
4554 profilerStartTime = -1;
4555 }
4556}
4557
4558/*eslint-disable no-self-compare */
4559
4560var hasOwnProperty = Object.prototype.hasOwnProperty;
4561
4562/**
4563 * inlined Object.is polyfill to avoid requiring consumers ship their own
4564 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
4565 */
4566function is(x, y) {
4567 // SameValue algorithm
4568 if (x === y) {
4569 // Steps 1-5, 7-10
4570 // Steps 6.b-6.e: +0 != -0
4571 // Added the nonzero y check to make Flow happy, but it is redundant
4572 return x !== 0 || y !== 0 || 1 / x === 1 / y;
4573 } else {
4574 // Step 6.a: NaN == NaN
4575 return x !== x && y !== y;
4576 }
4577}
4578
4579/**
4580 * Performs equality by iterating through keys on an object and returning false
4581 * when any key has values which are not strictly equal between the arguments.
4582 * Returns true when the values of all keys are strictly equal.
4583 */
4584function shallowEqual(objA, objB) {
4585 if (is(objA, objB)) {
4586 return true;
4587 }
4588
4589 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
4590 return false;
4591 }
4592
4593 var keysA = Object.keys(objA);
4594 var keysB = Object.keys(objB);
4595
4596 if (keysA.length !== keysB.length) {
4597 return false;
4598 }
4599
4600 // Test for A's keys different from B.
4601 for (var i = 0; i < keysA.length; i++) {
4602 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
4603 return false;
4604 }
4605 }
4606
4607 return true;
4608}
4609
4610function resolveDefaultProps(Component, baseProps) {
4611 if (Component && Component.defaultProps) {
4612 // Resolve default props. Taken from ReactElement
4613 var props = _assign({}, baseProps);
4614 var defaultProps = Component.defaultProps;
4615 for (var propName in defaultProps) {
4616 if (props[propName] === undefined) {
4617 props[propName] = defaultProps[propName];
4618 }
4619 }
4620 return props;
4621 }
4622 return baseProps;
4623}
4624
4625function readLazyComponentType(lazyComponent) {
4626 var status = lazyComponent._status;
4627 var result = lazyComponent._result;
4628 switch (status) {
4629 case Resolved:
4630 {
4631 var Component = result;
4632 return Component;
4633 }
4634 case Rejected:
4635 {
4636 var error = result;
4637 throw error;
4638 }
4639 case Pending:
4640 {
4641 var thenable = result;
4642 throw thenable;
4643 }
4644 default:
4645 {
4646 lazyComponent._status = Pending;
4647 var ctor = lazyComponent._ctor;
4648 var _thenable = ctor();
4649 _thenable.then(function (moduleObject) {
4650 if (lazyComponent._status === Pending) {
4651 var defaultExport = moduleObject.default;
4652 {
4653 if (defaultExport === undefined) {
4654 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);
4655 }
4656 }
4657 lazyComponent._status = Resolved;
4658 lazyComponent._result = defaultExport;
4659 }
4660 }, function (error) {
4661 if (lazyComponent._status === Pending) {
4662 lazyComponent._status = Rejected;
4663 lazyComponent._result = error;
4664 }
4665 });
4666 lazyComponent._result = _thenable;
4667 throw _thenable;
4668 }
4669 }
4670}
4671
4672var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
4673
4674function readContext$1(contextType) {
4675 var dispatcher = ReactCurrentOwner$3.currentDispatcher;
4676 return dispatcher.readContext(contextType);
4677}
4678
4679var fakeInternalInstance = {};
4680var isArray$1 = Array.isArray;
4681
4682// React.Component uses a shared frozen object by default.
4683// We'll use it to determine whether we need to initialize legacy refs.
4684var emptyRefsObject = new React.Component().refs;
4685
4686var didWarnAboutStateAssignmentForComponent = void 0;
4687var didWarnAboutUninitializedState = void 0;
4688var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0;
4689var didWarnAboutLegacyLifecyclesAndDerivedState = void 0;
4690var didWarnAboutUndefinedDerivedState = void 0;
4691var warnOnUndefinedDerivedState = void 0;
4692var warnOnInvalidCallback = void 0;
4693var didWarnAboutDirectlyAssigningPropsToState = void 0;
4694var didWarnAboutContextTypeAndContextTypes = void 0;
4695var didWarnAboutInvalidateContextType = void 0;
4696
4697{
4698 didWarnAboutStateAssignmentForComponent = new Set();
4699 didWarnAboutUninitializedState = new Set();
4700 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
4701 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
4702 didWarnAboutDirectlyAssigningPropsToState = new Set();
4703 didWarnAboutUndefinedDerivedState = new Set();
4704 didWarnAboutContextTypeAndContextTypes = new Set();
4705 didWarnAboutInvalidateContextType = new Set();
4706
4707 var didWarnOnInvalidCallback = new Set();
4708
4709 warnOnInvalidCallback = function (callback, callerName) {
4710 if (callback === null || typeof callback === 'function') {
4711 return;
4712 }
4713 var key = callerName + '_' + callback;
4714 if (!didWarnOnInvalidCallback.has(key)) {
4715 didWarnOnInvalidCallback.add(key);
4716 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
4717 }
4718 };
4719
4720 warnOnUndefinedDerivedState = function (type, partialState) {
4721 if (partialState === undefined) {
4722 var componentName = getComponentName(type) || 'Component';
4723 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
4724 didWarnAboutUndefinedDerivedState.add(componentName);
4725 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
4726 }
4727 }
4728 };
4729
4730 // This is so gross but it's at least non-critical and can be removed if
4731 // it causes problems. This is meant to give a nicer error message for
4732 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
4733 // ...)) which otherwise throws a "_processChildContext is not a function"
4734 // exception.
4735 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
4736 enumerable: false,
4737 value: function () {
4738 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).');
4739 }
4740 });
4741 Object.freeze(fakeInternalInstance);
4742}
4743
4744function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
4745 var prevState = workInProgress.memoizedState;
4746
4747 {
4748 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4749 // Invoke the function an extra time to help detect side-effects.
4750 getDerivedStateFromProps(nextProps, prevState);
4751 }
4752 }
4753
4754 var partialState = getDerivedStateFromProps(nextProps, prevState);
4755
4756 {
4757 warnOnUndefinedDerivedState(ctor, partialState);
4758 }
4759 // Merge the partial state and the previous state.
4760 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
4761 workInProgress.memoizedState = memoizedState;
4762
4763 // Once the update queue is empty, persist the derived state onto the
4764 // base state.
4765 var updateQueue = workInProgress.updateQueue;
4766 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
4767 updateQueue.baseState = memoizedState;
4768 }
4769}
4770
4771var classComponentUpdater = {
4772 isMounted: isMounted,
4773 enqueueSetState: function (inst, payload, callback) {
4774 var fiber = get(inst);
4775 var currentTime = requestCurrentTime();
4776 var expirationTime = computeExpirationForFiber(currentTime, fiber);
4777
4778 var update = createUpdate(expirationTime);
4779 update.payload = payload;
4780 if (callback !== undefined && callback !== null) {
4781 {
4782 warnOnInvalidCallback(callback, 'setState');
4783 }
4784 update.callback = callback;
4785 }
4786
4787 flushPassiveEffects();
4788 enqueueUpdate(fiber, update);
4789 scheduleWork(fiber, expirationTime);
4790 },
4791 enqueueReplaceState: function (inst, payload, callback) {
4792 var fiber = get(inst);
4793 var currentTime = requestCurrentTime();
4794 var expirationTime = computeExpirationForFiber(currentTime, fiber);
4795
4796 var update = createUpdate(expirationTime);
4797 update.tag = ReplaceState;
4798 update.payload = payload;
4799
4800 if (callback !== undefined && callback !== null) {
4801 {
4802 warnOnInvalidCallback(callback, 'replaceState');
4803 }
4804 update.callback = callback;
4805 }
4806
4807 flushPassiveEffects();
4808 enqueueUpdate(fiber, update);
4809 scheduleWork(fiber, expirationTime);
4810 },
4811 enqueueForceUpdate: function (inst, callback) {
4812 var fiber = get(inst);
4813 var currentTime = requestCurrentTime();
4814 var expirationTime = computeExpirationForFiber(currentTime, fiber);
4815
4816 var update = createUpdate(expirationTime);
4817 update.tag = ForceUpdate;
4818
4819 if (callback !== undefined && callback !== null) {
4820 {
4821 warnOnInvalidCallback(callback, 'forceUpdate');
4822 }
4823 update.callback = callback;
4824 }
4825
4826 flushPassiveEffects();
4827 enqueueUpdate(fiber, update);
4828 scheduleWork(fiber, expirationTime);
4829 }
4830};
4831
4832function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
4833 var instance = workInProgress.stateNode;
4834 if (typeof instance.shouldComponentUpdate === 'function') {
4835 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
4836 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
4837 stopPhaseTimer();
4838
4839 {
4840 !(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;
4841 }
4842
4843 return shouldUpdate;
4844 }
4845
4846 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
4847 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
4848 }
4849
4850 return true;
4851}
4852
4853function checkClassInstance(workInProgress, ctor, newProps) {
4854 var instance = workInProgress.stateNode;
4855 {
4856 var name = getComponentName(ctor) || 'Component';
4857 var renderPresent = instance.render;
4858
4859 if (!renderPresent) {
4860 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
4861 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
4862 } else {
4863 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
4864 }
4865 }
4866
4867 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
4868 !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;
4869 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
4870 !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;
4871 var noInstancePropTypes = !instance.propTypes;
4872 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
4873 var noInstanceContextType = !instance.contextType;
4874 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
4875 var noInstanceContextTypes = !instance.contextTypes;
4876 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
4877
4878 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
4879 didWarnAboutContextTypeAndContextTypes.add(ctor);
4880 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
4881 }
4882
4883 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
4884 !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;
4885 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
4886 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');
4887 }
4888 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
4889 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
4890 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
4891 !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;
4892 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
4893 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
4894 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
4895 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
4896 var hasMutatedProps = instance.props !== newProps;
4897 !(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;
4898 var noInstanceDefaultProps = !instance.defaultProps;
4899 !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;
4900
4901 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
4902 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
4903 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
4904 }
4905
4906 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
4907 !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;
4908 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
4909 !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;
4910 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
4911 !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;
4912 var _state = instance.state;
4913 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
4914 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
4915 }
4916 if (typeof instance.getChildContext === 'function') {
4917 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
4918 }
4919 }
4920}
4921
4922function adoptClassInstance(workInProgress, instance) {
4923 instance.updater = classComponentUpdater;
4924 workInProgress.stateNode = instance;
4925 // The instance needs access to the fiber so that it can schedule updates
4926 set(instance, workInProgress);
4927 {
4928 instance._reactInternalInstance = fakeInternalInstance;
4929 }
4930}
4931
4932function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
4933 var isLegacyContextConsumer = false;
4934 var unmaskedContext = emptyContextObject;
4935 var context = null;
4936 var contextType = ctor.contextType;
4937 if (typeof contextType === 'object' && contextType !== null) {
4938 {
4939 if (contextType.$$typeof !== REACT_CONTEXT_TYPE && !didWarnAboutInvalidateContextType.has(ctor)) {
4940 didWarnAboutInvalidateContextType.add(ctor);
4941 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');
4942 }
4943 }
4944
4945 context = readContext$1(contextType);
4946 } else {
4947 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4948 var contextTypes = ctor.contextTypes;
4949 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
4950 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
4951 }
4952
4953 // Instantiate twice to help detect side-effects.
4954 {
4955 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4956 new ctor(props, context); // eslint-disable-line no-new
4957 }
4958 }
4959
4960 var instance = new ctor(props, context);
4961 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
4962 adoptClassInstance(workInProgress, instance);
4963
4964 {
4965 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
4966 var componentName = getComponentName(ctor) || 'Component';
4967 if (!didWarnAboutUninitializedState.has(componentName)) {
4968 didWarnAboutUninitializedState.add(componentName);
4969 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);
4970 }
4971 }
4972
4973 // If new component APIs are defined, "unsafe" lifecycles won't be called.
4974 // Warn about these lifecycles if they are present.
4975 // Don't warn about react-lifecycles-compat polyfilled methods though.
4976 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
4977 var foundWillMountName = null;
4978 var foundWillReceivePropsName = null;
4979 var foundWillUpdateName = null;
4980 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
4981 foundWillMountName = 'componentWillMount';
4982 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
4983 foundWillMountName = 'UNSAFE_componentWillMount';
4984 }
4985 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
4986 foundWillReceivePropsName = 'componentWillReceiveProps';
4987 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4988 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
4989 }
4990 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
4991 foundWillUpdateName = 'componentWillUpdate';
4992 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4993 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
4994 }
4995 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
4996 var _componentName = getComponentName(ctor) || 'Component';
4997 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
4998 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
4999 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
5000 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 : '');
5001 }
5002 }
5003 }
5004 }
5005
5006 // Cache unmasked context so we can avoid recreating masked context unless necessary.
5007 // ReactFiberContext usually updates this cache but can't for newly-created instances.
5008 if (isLegacyContextConsumer) {
5009 cacheContext(workInProgress, unmaskedContext, context);
5010 }
5011
5012 return instance;
5013}
5014
5015function callComponentWillMount(workInProgress, instance) {
5016 startPhaseTimer(workInProgress, 'componentWillMount');
5017 var oldState = instance.state;
5018
5019 if (typeof instance.componentWillMount === 'function') {
5020 instance.componentWillMount();
5021 }
5022 if (typeof instance.UNSAFE_componentWillMount === 'function') {
5023 instance.UNSAFE_componentWillMount();
5024 }
5025
5026 stopPhaseTimer();
5027
5028 if (oldState !== instance.state) {
5029 {
5030 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');
5031 }
5032 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
5033 }
5034}
5035
5036function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
5037 var oldState = instance.state;
5038 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
5039 if (typeof instance.componentWillReceiveProps === 'function') {
5040 instance.componentWillReceiveProps(newProps, nextContext);
5041 }
5042 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
5043 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
5044 }
5045 stopPhaseTimer();
5046
5047 if (instance.state !== oldState) {
5048 {
5049 var componentName = getComponentName(workInProgress.type) || 'Component';
5050 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
5051 didWarnAboutStateAssignmentForComponent.add(componentName);
5052 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
5053 }
5054 }
5055 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
5056 }
5057}
5058
5059// Invokes the mount life-cycles on a previously never rendered instance.
5060function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
5061 {
5062 checkClassInstance(workInProgress, ctor, newProps);
5063 }
5064
5065 var instance = workInProgress.stateNode;
5066 instance.props = newProps;
5067 instance.state = workInProgress.memoizedState;
5068 instance.refs = emptyRefsObject;
5069
5070 var contextType = ctor.contextType;
5071 if (typeof contextType === 'object' && contextType !== null) {
5072 instance.context = readContext$1(contextType);
5073 } else {
5074 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
5075 instance.context = getMaskedContext(workInProgress, unmaskedContext);
5076 }
5077
5078 {
5079 if (instance.state === newProps) {
5080 var componentName = getComponentName(ctor) || 'Component';
5081 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
5082 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
5083 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);
5084 }
5085 }
5086
5087 if (workInProgress.mode & StrictMode) {
5088 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
5089
5090 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
5091 }
5092
5093 if (warnAboutDeprecatedLifecycles) {
5094 ReactStrictModeWarnings.recordDeprecationWarnings(workInProgress, instance);
5095 }
5096 }
5097
5098 var updateQueue = workInProgress.updateQueue;
5099 if (updateQueue !== null) {
5100 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
5101 instance.state = workInProgress.memoizedState;
5102 }
5103
5104 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
5105 if (typeof getDerivedStateFromProps === 'function') {
5106 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
5107 instance.state = workInProgress.memoizedState;
5108 }
5109
5110 // In order to support react-lifecycles-compat polyfilled components,
5111 // Unsafe lifecycles should not be invoked for components using the new APIs.
5112 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
5113 callComponentWillMount(workInProgress, instance);
5114 // If we had additional state updates during this life-cycle, let's
5115 // process them now.
5116 updateQueue = workInProgress.updateQueue;
5117 if (updateQueue !== null) {
5118 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
5119 instance.state = workInProgress.memoizedState;
5120 }
5121 }
5122
5123 if (typeof instance.componentDidMount === 'function') {
5124 workInProgress.effectTag |= Update;
5125 }
5126}
5127
5128function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
5129 var instance = workInProgress.stateNode;
5130
5131 var oldProps = workInProgress.memoizedProps;
5132 instance.props = oldProps;
5133
5134 var oldContext = instance.context;
5135 var contextType = ctor.contextType;
5136 var nextContext = void 0;
5137 if (typeof contextType === 'object' && contextType !== null) {
5138 nextContext = readContext$1(contextType);
5139 } else {
5140 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
5141 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
5142 }
5143
5144 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
5145 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
5146
5147 // Note: During these life-cycles, instance.props/instance.state are what
5148 // ever the previously attempted to render - not the "current". However,
5149 // during componentDidUpdate we pass the "current" props.
5150
5151 // In order to support react-lifecycles-compat polyfilled components,
5152 // Unsafe lifecycles should not be invoked for components using the new APIs.
5153 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
5154 if (oldProps !== newProps || oldContext !== nextContext) {
5155 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
5156 }
5157 }
5158
5159 resetHasForceUpdateBeforeProcessing();
5160
5161 var oldState = workInProgress.memoizedState;
5162 var newState = instance.state = oldState;
5163 var updateQueue = workInProgress.updateQueue;
5164 if (updateQueue !== null) {
5165 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
5166 newState = workInProgress.memoizedState;
5167 }
5168 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
5169 // If an update was already in progress, we should schedule an Update
5170 // effect even though we're bailing out, so that cWU/cDU are called.
5171 if (typeof instance.componentDidMount === 'function') {
5172 workInProgress.effectTag |= Update;
5173 }
5174 return false;
5175 }
5176
5177 if (typeof getDerivedStateFromProps === 'function') {
5178 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
5179 newState = workInProgress.memoizedState;
5180 }
5181
5182 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
5183
5184 if (shouldUpdate) {
5185 // In order to support react-lifecycles-compat polyfilled components,
5186 // Unsafe lifecycles should not be invoked for components using the new APIs.
5187 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
5188 startPhaseTimer(workInProgress, 'componentWillMount');
5189 if (typeof instance.componentWillMount === 'function') {
5190 instance.componentWillMount();
5191 }
5192 if (typeof instance.UNSAFE_componentWillMount === 'function') {
5193 instance.UNSAFE_componentWillMount();
5194 }
5195 stopPhaseTimer();
5196 }
5197 if (typeof instance.componentDidMount === 'function') {
5198 workInProgress.effectTag |= Update;
5199 }
5200 } else {
5201 // If an update was already in progress, we should schedule an Update
5202 // effect even though we're bailing out, so that cWU/cDU are called.
5203 if (typeof instance.componentDidMount === 'function') {
5204 workInProgress.effectTag |= Update;
5205 }
5206
5207 // If shouldComponentUpdate returned false, we should still update the
5208 // memoized state to indicate that this work can be reused.
5209 workInProgress.memoizedProps = newProps;
5210 workInProgress.memoizedState = newState;
5211 }
5212
5213 // Update the existing instance's state, props, and context pointers even
5214 // if shouldComponentUpdate returns false.
5215 instance.props = newProps;
5216 instance.state = newState;
5217 instance.context = nextContext;
5218
5219 return shouldUpdate;
5220}
5221
5222// Invokes the update life-cycles and returns false if it shouldn't rerender.
5223function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
5224 var instance = workInProgress.stateNode;
5225
5226 var oldProps = workInProgress.memoizedProps;
5227 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
5228
5229 var oldContext = instance.context;
5230 var contextType = ctor.contextType;
5231 var nextContext = void 0;
5232 if (typeof contextType === 'object' && contextType !== null) {
5233 nextContext = readContext$1(contextType);
5234 } else {
5235 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
5236 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
5237 }
5238
5239 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
5240 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
5241
5242 // Note: During these life-cycles, instance.props/instance.state are what
5243 // ever the previously attempted to render - not the "current". However,
5244 // during componentDidUpdate we pass the "current" props.
5245
5246 // In order to support react-lifecycles-compat polyfilled components,
5247 // Unsafe lifecycles should not be invoked for components using the new APIs.
5248 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
5249 if (oldProps !== newProps || oldContext !== nextContext) {
5250 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
5251 }
5252 }
5253
5254 resetHasForceUpdateBeforeProcessing();
5255
5256 var oldState = workInProgress.memoizedState;
5257 var newState = instance.state = oldState;
5258 var updateQueue = workInProgress.updateQueue;
5259 if (updateQueue !== null) {
5260 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
5261 newState = workInProgress.memoizedState;
5262 }
5263
5264 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
5265 // If an update was already in progress, we should schedule an Update
5266 // effect even though we're bailing out, so that cWU/cDU are called.
5267 if (typeof instance.componentDidUpdate === 'function') {
5268 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
5269 workInProgress.effectTag |= Update;
5270 }
5271 }
5272 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
5273 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
5274 workInProgress.effectTag |= Snapshot;
5275 }
5276 }
5277 return false;
5278 }
5279
5280 if (typeof getDerivedStateFromProps === 'function') {
5281 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
5282 newState = workInProgress.memoizedState;
5283 }
5284
5285 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
5286
5287 if (shouldUpdate) {
5288 // In order to support react-lifecycles-compat polyfilled components,
5289 // Unsafe lifecycles should not be invoked for components using the new APIs.
5290 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
5291 startPhaseTimer(workInProgress, 'componentWillUpdate');
5292 if (typeof instance.componentWillUpdate === 'function') {
5293 instance.componentWillUpdate(newProps, newState, nextContext);
5294 }
5295 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
5296 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
5297 }
5298 stopPhaseTimer();
5299 }
5300 if (typeof instance.componentDidUpdate === 'function') {
5301 workInProgress.effectTag |= Update;
5302 }
5303 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
5304 workInProgress.effectTag |= Snapshot;
5305 }
5306 } else {
5307 // If an update was already in progress, we should schedule an Update
5308 // effect even though we're bailing out, so that cWU/cDU are called.
5309 if (typeof instance.componentDidUpdate === 'function') {
5310 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
5311 workInProgress.effectTag |= Update;
5312 }
5313 }
5314 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
5315 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
5316 workInProgress.effectTag |= Snapshot;
5317 }
5318 }
5319
5320 // If shouldComponentUpdate returned false, we should still update the
5321 // memoized props/state to indicate that this work can be reused.
5322 workInProgress.memoizedProps = newProps;
5323 workInProgress.memoizedState = newState;
5324 }
5325
5326 // Update the existing instance's state, props, and context pointers even
5327 // if shouldComponentUpdate returns false.
5328 instance.props = newProps;
5329 instance.state = newState;
5330 instance.context = nextContext;
5331
5332 return shouldUpdate;
5333}
5334
5335var didWarnAboutMaps = void 0;
5336var didWarnAboutGenerators = void 0;
5337var didWarnAboutStringRefInStrictMode = void 0;
5338var ownerHasKeyUseWarning = void 0;
5339var ownerHasFunctionTypeWarning = void 0;
5340var warnForMissingKey = function (child) {};
5341
5342{
5343 didWarnAboutMaps = false;
5344 didWarnAboutGenerators = false;
5345 didWarnAboutStringRefInStrictMode = {};
5346
5347 /**
5348 * Warn if there's no key explicitly set on dynamic arrays of children or
5349 * object keys are not valid. This allows us to keep track of children between
5350 * updates.
5351 */
5352 ownerHasKeyUseWarning = {};
5353 ownerHasFunctionTypeWarning = {};
5354
5355 warnForMissingKey = function (child) {
5356 if (child === null || typeof child !== 'object') {
5357 return;
5358 }
5359 if (!child._store || child._store.validated || child.key != null) {
5360 return;
5361 }
5362 !(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;
5363 child._store.validated = true;
5364
5365 var currentComponentErrorInfo = 'Each child in an array or iterator should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
5366 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
5367 return;
5368 }
5369 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
5370
5371 warning$1(false, 'Each child in an array or iterator should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
5372 };
5373}
5374
5375var isArray = Array.isArray;
5376
5377function coerceRef(returnFiber, current$$1, element) {
5378 var mixedRef = element.ref;
5379 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
5380 {
5381 if (returnFiber.mode & StrictMode) {
5382 var componentName = getComponentName(returnFiber.type) || 'Component';
5383 if (!didWarnAboutStringRefInStrictMode[componentName]) {
5384 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));
5385 didWarnAboutStringRefInStrictMode[componentName] = true;
5386 }
5387 }
5388 }
5389
5390 if (element._owner) {
5391 var owner = element._owner;
5392 var inst = void 0;
5393 if (owner) {
5394 var ownerFiber = owner;
5395 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Function components cannot have refs.') : void 0;
5396 inst = ownerFiber.stateNode;
5397 }
5398 !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;
5399 var stringRef = '' + mixedRef;
5400 // Check if previous string ref matches new string ref
5401 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
5402 return current$$1.ref;
5403 }
5404 var ref = function (value) {
5405 var refs = inst.refs;
5406 if (refs === emptyRefsObject) {
5407 // This is a lazy pooled frozen object, so we need to initialize.
5408 refs = inst.refs = {};
5409 }
5410 if (value === null) {
5411 delete refs[stringRef];
5412 } else {
5413 refs[stringRef] = value;
5414 }
5415 };
5416 ref._stringRef = stringRef;
5417 return ref;
5418 } else {
5419 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.') : void 0;
5420 !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;
5421 }
5422 }
5423 return mixedRef;
5424}
5425
5426function throwOnInvalidObjectType(returnFiber, newChild) {
5427 if (returnFiber.type !== 'textarea') {
5428 var addendum = '';
5429 {
5430 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
5431 }
5432 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);
5433 }
5434}
5435
5436function warnOnFunctionType() {
5437 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();
5438
5439 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
5440 return;
5441 }
5442 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
5443
5444 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.');
5445}
5446
5447// This wrapper function exists because I expect to clone the code in each path
5448// to be able to optimize each path individually by branching early. This needs
5449// a compiler or we can do it manually. Helpers that don't need this branching
5450// live outside of this function.
5451function ChildReconciler(shouldTrackSideEffects) {
5452 function deleteChild(returnFiber, childToDelete) {
5453 if (!shouldTrackSideEffects) {
5454 // Noop.
5455 return;
5456 }
5457 // Deletions are added in reversed order so we add it to the front.
5458 // At this point, the return fiber's effect list is empty except for
5459 // deletions, so we can just append the deletion to the list. The remaining
5460 // effects aren't added until the complete phase. Once we implement
5461 // resuming, this may not be true.
5462 var last = returnFiber.lastEffect;
5463 if (last !== null) {
5464 last.nextEffect = childToDelete;
5465 returnFiber.lastEffect = childToDelete;
5466 } else {
5467 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
5468 }
5469 childToDelete.nextEffect = null;
5470 childToDelete.effectTag = Deletion;
5471 }
5472
5473 function deleteRemainingChildren(returnFiber, currentFirstChild) {
5474 if (!shouldTrackSideEffects) {
5475 // Noop.
5476 return null;
5477 }
5478
5479 // TODO: For the shouldClone case, this could be micro-optimized a bit by
5480 // assuming that after the first child we've already added everything.
5481 var childToDelete = currentFirstChild;
5482 while (childToDelete !== null) {
5483 deleteChild(returnFiber, childToDelete);
5484 childToDelete = childToDelete.sibling;
5485 }
5486 return null;
5487 }
5488
5489 function mapRemainingChildren(returnFiber, currentFirstChild) {
5490 // Add the remaining children to a temporary map so that we can find them by
5491 // keys quickly. Implicit (null) keys get added to this set with their index
5492 var existingChildren = new Map();
5493
5494 var existingChild = currentFirstChild;
5495 while (existingChild !== null) {
5496 if (existingChild.key !== null) {
5497 existingChildren.set(existingChild.key, existingChild);
5498 } else {
5499 existingChildren.set(existingChild.index, existingChild);
5500 }
5501 existingChild = existingChild.sibling;
5502 }
5503 return existingChildren;
5504 }
5505
5506 function useFiber(fiber, pendingProps, expirationTime) {
5507 // We currently set sibling to null and index to 0 here because it is easy
5508 // to forget to do before returning it. E.g. for the single child case.
5509 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
5510 clone.index = 0;
5511 clone.sibling = null;
5512 return clone;
5513 }
5514
5515 function placeChild(newFiber, lastPlacedIndex, newIndex) {
5516 newFiber.index = newIndex;
5517 if (!shouldTrackSideEffects) {
5518 // Noop.
5519 return lastPlacedIndex;
5520 }
5521 var current$$1 = newFiber.alternate;
5522 if (current$$1 !== null) {
5523 var oldIndex = current$$1.index;
5524 if (oldIndex < lastPlacedIndex) {
5525 // This is a move.
5526 newFiber.effectTag = Placement;
5527 return lastPlacedIndex;
5528 } else {
5529 // This item can stay in place.
5530 return oldIndex;
5531 }
5532 } else {
5533 // This is an insertion.
5534 newFiber.effectTag = Placement;
5535 return lastPlacedIndex;
5536 }
5537 }
5538
5539 function placeSingleChild(newFiber) {
5540 // This is simpler for the single child case. We only need to do a
5541 // placement for inserting new children.
5542 if (shouldTrackSideEffects && newFiber.alternate === null) {
5543 newFiber.effectTag = Placement;
5544 }
5545 return newFiber;
5546 }
5547
5548 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
5549 if (current$$1 === null || current$$1.tag !== HostText) {
5550 // Insert
5551 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
5552 created.return = returnFiber;
5553 return created;
5554 } else {
5555 // Update
5556 var existing = useFiber(current$$1, textContent, expirationTime);
5557 existing.return = returnFiber;
5558 return existing;
5559 }
5560 }
5561
5562 function updateElement(returnFiber, current$$1, element, expirationTime) {
5563 if (current$$1 !== null && current$$1.elementType === element.type) {
5564 // Move based on index
5565 var existing = useFiber(current$$1, element.props, expirationTime);
5566 existing.ref = coerceRef(returnFiber, current$$1, element);
5567 existing.return = returnFiber;
5568 {
5569 existing._debugSource = element._source;
5570 existing._debugOwner = element._owner;
5571 }
5572 return existing;
5573 } else {
5574 // Insert
5575 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
5576 created.ref = coerceRef(returnFiber, current$$1, element);
5577 created.return = returnFiber;
5578 return created;
5579 }
5580 }
5581
5582 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
5583 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
5584 // Insert
5585 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
5586 created.return = returnFiber;
5587 return created;
5588 } else {
5589 // Update
5590 var existing = useFiber(current$$1, portal.children || [], expirationTime);
5591 existing.return = returnFiber;
5592 return existing;
5593 }
5594 }
5595
5596 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
5597 if (current$$1 === null || current$$1.tag !== Fragment) {
5598 // Insert
5599 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
5600 created.return = returnFiber;
5601 return created;
5602 } else {
5603 // Update
5604 var existing = useFiber(current$$1, fragment, expirationTime);
5605 existing.return = returnFiber;
5606 return existing;
5607 }
5608 }
5609
5610 function createChild(returnFiber, newChild, expirationTime) {
5611 if (typeof newChild === 'string' || typeof newChild === 'number') {
5612 // Text nodes don't have keys. If the previous node is implicitly keyed
5613 // we can continue to replace it without aborting even if it is not a text
5614 // node.
5615 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
5616 created.return = returnFiber;
5617 return created;
5618 }
5619
5620 if (typeof newChild === 'object' && newChild !== null) {
5621 switch (newChild.$$typeof) {
5622 case REACT_ELEMENT_TYPE:
5623 {
5624 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
5625 _created.ref = coerceRef(returnFiber, null, newChild);
5626 _created.return = returnFiber;
5627 return _created;
5628 }
5629 case REACT_PORTAL_TYPE:
5630 {
5631 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
5632 _created2.return = returnFiber;
5633 return _created2;
5634 }
5635 }
5636
5637 if (isArray(newChild) || getIteratorFn(newChild)) {
5638 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
5639 _created3.return = returnFiber;
5640 return _created3;
5641 }
5642
5643 throwOnInvalidObjectType(returnFiber, newChild);
5644 }
5645
5646 {
5647 if (typeof newChild === 'function') {
5648 warnOnFunctionType();
5649 }
5650 }
5651
5652 return null;
5653 }
5654
5655 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
5656 // Update the fiber if the keys match, otherwise return null.
5657
5658 var key = oldFiber !== null ? oldFiber.key : null;
5659
5660 if (typeof newChild === 'string' || typeof newChild === 'number') {
5661 // Text nodes don't have keys. If the previous node is implicitly keyed
5662 // we can continue to replace it without aborting even if it is not a text
5663 // node.
5664 if (key !== null) {
5665 return null;
5666 }
5667 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
5668 }
5669
5670 if (typeof newChild === 'object' && newChild !== null) {
5671 switch (newChild.$$typeof) {
5672 case REACT_ELEMENT_TYPE:
5673 {
5674 if (newChild.key === key) {
5675 if (newChild.type === REACT_FRAGMENT_TYPE) {
5676 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
5677 }
5678 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
5679 } else {
5680 return null;
5681 }
5682 }
5683 case REACT_PORTAL_TYPE:
5684 {
5685 if (newChild.key === key) {
5686 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
5687 } else {
5688 return null;
5689 }
5690 }
5691 }
5692
5693 if (isArray(newChild) || getIteratorFn(newChild)) {
5694 if (key !== null) {
5695 return null;
5696 }
5697
5698 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
5699 }
5700
5701 throwOnInvalidObjectType(returnFiber, newChild);
5702 }
5703
5704 {
5705 if (typeof newChild === 'function') {
5706 warnOnFunctionType();
5707 }
5708 }
5709
5710 return null;
5711 }
5712
5713 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
5714 if (typeof newChild === 'string' || typeof newChild === 'number') {
5715 // Text nodes don't have keys, so we neither have to check the old nor
5716 // new node for the key. If both are text nodes, they match.
5717 var matchedFiber = existingChildren.get(newIdx) || null;
5718 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
5719 }
5720
5721 if (typeof newChild === 'object' && newChild !== null) {
5722 switch (newChild.$$typeof) {
5723 case REACT_ELEMENT_TYPE:
5724 {
5725 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5726 if (newChild.type === REACT_FRAGMENT_TYPE) {
5727 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
5728 }
5729 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
5730 }
5731 case REACT_PORTAL_TYPE:
5732 {
5733 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5734 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
5735 }
5736 }
5737
5738 if (isArray(newChild) || getIteratorFn(newChild)) {
5739 var _matchedFiber3 = existingChildren.get(newIdx) || null;
5740 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
5741 }
5742
5743 throwOnInvalidObjectType(returnFiber, newChild);
5744 }
5745
5746 {
5747 if (typeof newChild === 'function') {
5748 warnOnFunctionType();
5749 }
5750 }
5751
5752 return null;
5753 }
5754
5755 /**
5756 * Warns if there is a duplicate or missing key
5757 */
5758 function warnOnInvalidKey(child, knownKeys) {
5759 {
5760 if (typeof child !== 'object' || child === null) {
5761 return knownKeys;
5762 }
5763 switch (child.$$typeof) {
5764 case REACT_ELEMENT_TYPE:
5765 case REACT_PORTAL_TYPE:
5766 warnForMissingKey(child);
5767 var key = child.key;
5768 if (typeof key !== 'string') {
5769 break;
5770 }
5771 if (knownKeys === null) {
5772 knownKeys = new Set();
5773 knownKeys.add(key);
5774 break;
5775 }
5776 if (!knownKeys.has(key)) {
5777 knownKeys.add(key);
5778 break;
5779 }
5780 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);
5781 break;
5782 default:
5783 break;
5784 }
5785 }
5786 return knownKeys;
5787 }
5788
5789 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
5790 // This algorithm can't optimize by searching from boths ends since we
5791 // don't have backpointers on fibers. I'm trying to see how far we can get
5792 // with that model. If it ends up not being worth the tradeoffs, we can
5793 // add it later.
5794
5795 // Even with a two ended optimization, we'd want to optimize for the case
5796 // where there are few changes and brute force the comparison instead of
5797 // going for the Map. It'd like to explore hitting that path first in
5798 // forward-only mode and only go for the Map once we notice that we need
5799 // lots of look ahead. This doesn't handle reversal as well as two ended
5800 // search but that's unusual. Besides, for the two ended optimization to
5801 // work on Iterables, we'd need to copy the whole set.
5802
5803 // In this first iteration, we'll just live with hitting the bad case
5804 // (adding everything to a Map) in for every insert/move.
5805
5806 // If you change this code, also update reconcileChildrenIterator() which
5807 // uses the same algorithm.
5808
5809 {
5810 // First, validate keys.
5811 var knownKeys = null;
5812 for (var i = 0; i < newChildren.length; i++) {
5813 var child = newChildren[i];
5814 knownKeys = warnOnInvalidKey(child, knownKeys);
5815 }
5816 }
5817
5818 var resultingFirstChild = null;
5819 var previousNewFiber = null;
5820
5821 var oldFiber = currentFirstChild;
5822 var lastPlacedIndex = 0;
5823 var newIdx = 0;
5824 var nextOldFiber = null;
5825 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
5826 if (oldFiber.index > newIdx) {
5827 nextOldFiber = oldFiber;
5828 oldFiber = null;
5829 } else {
5830 nextOldFiber = oldFiber.sibling;
5831 }
5832 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
5833 if (newFiber === null) {
5834 // TODO: This breaks on empty slots like null children. That's
5835 // unfortunate because it triggers the slow path all the time. We need
5836 // a better way to communicate whether this was a miss or null,
5837 // boolean, undefined, etc.
5838 if (oldFiber === null) {
5839 oldFiber = nextOldFiber;
5840 }
5841 break;
5842 }
5843 if (shouldTrackSideEffects) {
5844 if (oldFiber && newFiber.alternate === null) {
5845 // We matched the slot, but we didn't reuse the existing fiber, so we
5846 // need to delete the existing child.
5847 deleteChild(returnFiber, oldFiber);
5848 }
5849 }
5850 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5851 if (previousNewFiber === null) {
5852 // TODO: Move out of the loop. This only happens for the first run.
5853 resultingFirstChild = newFiber;
5854 } else {
5855 // TODO: Defer siblings if we're not at the right index for this slot.
5856 // I.e. if we had null values before, then we want to defer this
5857 // for each null value. However, we also don't want to call updateSlot
5858 // with the previous one.
5859 previousNewFiber.sibling = newFiber;
5860 }
5861 previousNewFiber = newFiber;
5862 oldFiber = nextOldFiber;
5863 }
5864
5865 if (newIdx === newChildren.length) {
5866 // We've reached the end of the new children. We can delete the rest.
5867 deleteRemainingChildren(returnFiber, oldFiber);
5868 return resultingFirstChild;
5869 }
5870
5871 if (oldFiber === null) {
5872 // If we don't have any more existing children we can choose a fast path
5873 // since the rest will all be insertions.
5874 for (; newIdx < newChildren.length; newIdx++) {
5875 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
5876 if (!_newFiber) {
5877 continue;
5878 }
5879 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
5880 if (previousNewFiber === null) {
5881 // TODO: Move out of the loop. This only happens for the first run.
5882 resultingFirstChild = _newFiber;
5883 } else {
5884 previousNewFiber.sibling = _newFiber;
5885 }
5886 previousNewFiber = _newFiber;
5887 }
5888 return resultingFirstChild;
5889 }
5890
5891 // Add all children to a key map for quick lookups.
5892 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
5893
5894 // Keep scanning and use the map to restore deleted items as moves.
5895 for (; newIdx < newChildren.length; newIdx++) {
5896 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
5897 if (_newFiber2) {
5898 if (shouldTrackSideEffects) {
5899 if (_newFiber2.alternate !== null) {
5900 // The new fiber is a work in progress, but if there exists a
5901 // current, that means that we reused the fiber. We need to delete
5902 // it from the child list so that we don't add it to the deletion
5903 // list.
5904 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
5905 }
5906 }
5907 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
5908 if (previousNewFiber === null) {
5909 resultingFirstChild = _newFiber2;
5910 } else {
5911 previousNewFiber.sibling = _newFiber2;
5912 }
5913 previousNewFiber = _newFiber2;
5914 }
5915 }
5916
5917 if (shouldTrackSideEffects) {
5918 // Any existing children that weren't consumed above were deleted. We need
5919 // to add them to the deletion list.
5920 existingChildren.forEach(function (child) {
5921 return deleteChild(returnFiber, child);
5922 });
5923 }
5924
5925 return resultingFirstChild;
5926 }
5927
5928 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
5929 // This is the same implementation as reconcileChildrenArray(),
5930 // but using the iterator instead.
5931
5932 var iteratorFn = getIteratorFn(newChildrenIterable);
5933 !(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;
5934
5935 {
5936 // We don't support rendering Generators because it's a mutation.
5937 // See https://github.com/facebook/react/issues/12995
5938 if (typeof Symbol === 'function' &&
5939 // $FlowFixMe Flow doesn't know about toStringTag
5940 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
5941 !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;
5942 didWarnAboutGenerators = true;
5943 }
5944
5945 // Warn about using Maps as children
5946 if (newChildrenIterable.entries === iteratorFn) {
5947 !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;
5948 didWarnAboutMaps = true;
5949 }
5950
5951 // First, validate keys.
5952 // We'll get a different iterator later for the main pass.
5953 var _newChildren = iteratorFn.call(newChildrenIterable);
5954 if (_newChildren) {
5955 var knownKeys = null;
5956 var _step = _newChildren.next();
5957 for (; !_step.done; _step = _newChildren.next()) {
5958 var child = _step.value;
5959 knownKeys = warnOnInvalidKey(child, knownKeys);
5960 }
5961 }
5962 }
5963
5964 var newChildren = iteratorFn.call(newChildrenIterable);
5965 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
5966
5967 var resultingFirstChild = null;
5968 var previousNewFiber = null;
5969
5970 var oldFiber = currentFirstChild;
5971 var lastPlacedIndex = 0;
5972 var newIdx = 0;
5973 var nextOldFiber = null;
5974
5975 var step = newChildren.next();
5976 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
5977 if (oldFiber.index > newIdx) {
5978 nextOldFiber = oldFiber;
5979 oldFiber = null;
5980 } else {
5981 nextOldFiber = oldFiber.sibling;
5982 }
5983 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
5984 if (newFiber === null) {
5985 // TODO: This breaks on empty slots like null children. That's
5986 // unfortunate because it triggers the slow path all the time. We need
5987 // a better way to communicate whether this was a miss or null,
5988 // boolean, undefined, etc.
5989 if (!oldFiber) {
5990 oldFiber = nextOldFiber;
5991 }
5992 break;
5993 }
5994 if (shouldTrackSideEffects) {
5995 if (oldFiber && newFiber.alternate === null) {
5996 // We matched the slot, but we didn't reuse the existing fiber, so we
5997 // need to delete the existing child.
5998 deleteChild(returnFiber, oldFiber);
5999 }
6000 }
6001 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
6002 if (previousNewFiber === null) {
6003 // TODO: Move out of the loop. This only happens for the first run.
6004 resultingFirstChild = newFiber;
6005 } else {
6006 // TODO: Defer siblings if we're not at the right index for this slot.
6007 // I.e. if we had null values before, then we want to defer this
6008 // for each null value. However, we also don't want to call updateSlot
6009 // with the previous one.
6010 previousNewFiber.sibling = newFiber;
6011 }
6012 previousNewFiber = newFiber;
6013 oldFiber = nextOldFiber;
6014 }
6015
6016 if (step.done) {
6017 // We've reached the end of the new children. We can delete the rest.
6018 deleteRemainingChildren(returnFiber, oldFiber);
6019 return resultingFirstChild;
6020 }
6021
6022 if (oldFiber === null) {
6023 // If we don't have any more existing children we can choose a fast path
6024 // since the rest will all be insertions.
6025 for (; !step.done; newIdx++, step = newChildren.next()) {
6026 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
6027 if (_newFiber3 === null) {
6028 continue;
6029 }
6030 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
6031 if (previousNewFiber === null) {
6032 // TODO: Move out of the loop. This only happens for the first run.
6033 resultingFirstChild = _newFiber3;
6034 } else {
6035 previousNewFiber.sibling = _newFiber3;
6036 }
6037 previousNewFiber = _newFiber3;
6038 }
6039 return resultingFirstChild;
6040 }
6041
6042 // Add all children to a key map for quick lookups.
6043 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
6044
6045 // Keep scanning and use the map to restore deleted items as moves.
6046 for (; !step.done; newIdx++, step = newChildren.next()) {
6047 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
6048 if (_newFiber4 !== null) {
6049 if (shouldTrackSideEffects) {
6050 if (_newFiber4.alternate !== null) {
6051 // The new fiber is a work in progress, but if there exists a
6052 // current, that means that we reused the fiber. We need to delete
6053 // it from the child list so that we don't add it to the deletion
6054 // list.
6055 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
6056 }
6057 }
6058 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
6059 if (previousNewFiber === null) {
6060 resultingFirstChild = _newFiber4;
6061 } else {
6062 previousNewFiber.sibling = _newFiber4;
6063 }
6064 previousNewFiber = _newFiber4;
6065 }
6066 }
6067
6068 if (shouldTrackSideEffects) {
6069 // Any existing children that weren't consumed above were deleted. We need
6070 // to add them to the deletion list.
6071 existingChildren.forEach(function (child) {
6072 return deleteChild(returnFiber, child);
6073 });
6074 }
6075
6076 return resultingFirstChild;
6077 }
6078
6079 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
6080 // There's no need to check for keys on text nodes since we don't have a
6081 // way to define them.
6082 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
6083 // We already have an existing node so let's just update it and delete
6084 // the rest.
6085 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
6086 var existing = useFiber(currentFirstChild, textContent, expirationTime);
6087 existing.return = returnFiber;
6088 return existing;
6089 }
6090 // The existing first child is not a text node so we need to create one
6091 // and delete the existing ones.
6092 deleteRemainingChildren(returnFiber, currentFirstChild);
6093 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
6094 created.return = returnFiber;
6095 return created;
6096 }
6097
6098 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
6099 var key = element.key;
6100 var child = currentFirstChild;
6101 while (child !== null) {
6102 // TODO: If key === null and child.key === null, then this only applies to
6103 // the first item in the list.
6104 if (child.key === key) {
6105 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type) {
6106 deleteRemainingChildren(returnFiber, child.sibling);
6107 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
6108 existing.ref = coerceRef(returnFiber, child, element);
6109 existing.return = returnFiber;
6110 {
6111 existing._debugSource = element._source;
6112 existing._debugOwner = element._owner;
6113 }
6114 return existing;
6115 } else {
6116 deleteRemainingChildren(returnFiber, child);
6117 break;
6118 }
6119 } else {
6120 deleteChild(returnFiber, child);
6121 }
6122 child = child.sibling;
6123 }
6124
6125 if (element.type === REACT_FRAGMENT_TYPE) {
6126 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
6127 created.return = returnFiber;
6128 return created;
6129 } else {
6130 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
6131 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
6132 _created4.return = returnFiber;
6133 return _created4;
6134 }
6135 }
6136
6137 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
6138 var key = portal.key;
6139 var child = currentFirstChild;
6140 while (child !== null) {
6141 // TODO: If key === null and child.key === null, then this only applies to
6142 // the first item in the list.
6143 if (child.key === key) {
6144 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
6145 deleteRemainingChildren(returnFiber, child.sibling);
6146 var existing = useFiber(child, portal.children || [], expirationTime);
6147 existing.return = returnFiber;
6148 return existing;
6149 } else {
6150 deleteRemainingChildren(returnFiber, child);
6151 break;
6152 }
6153 } else {
6154 deleteChild(returnFiber, child);
6155 }
6156 child = child.sibling;
6157 }
6158
6159 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
6160 created.return = returnFiber;
6161 return created;
6162 }
6163
6164 // This API will tag the children with the side-effect of the reconciliation
6165 // itself. They will be added to the side-effect list as we pass through the
6166 // children and the parent.
6167 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
6168 // This function is not recursive.
6169 // If the top level item is an array, we treat it as a set of children,
6170 // not as a fragment. Nested arrays on the other hand will be treated as
6171 // fragment nodes. Recursion happens at the normal flow.
6172
6173 // Handle top level unkeyed fragments as if they were arrays.
6174 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
6175 // We treat the ambiguous cases above the same.
6176 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
6177 if (isUnkeyedTopLevelFragment) {
6178 newChild = newChild.props.children;
6179 }
6180
6181 // Handle object types
6182 var isObject = typeof newChild === 'object' && newChild !== null;
6183
6184 if (isObject) {
6185 switch (newChild.$$typeof) {
6186 case REACT_ELEMENT_TYPE:
6187 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
6188 case REACT_PORTAL_TYPE:
6189 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
6190 }
6191 }
6192
6193 if (typeof newChild === 'string' || typeof newChild === 'number') {
6194 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
6195 }
6196
6197 if (isArray(newChild)) {
6198 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
6199 }
6200
6201 if (getIteratorFn(newChild)) {
6202 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
6203 }
6204
6205 if (isObject) {
6206 throwOnInvalidObjectType(returnFiber, newChild);
6207 }
6208
6209 {
6210 if (typeof newChild === 'function') {
6211 warnOnFunctionType();
6212 }
6213 }
6214 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
6215 // If the new child is undefined, and the return fiber is a composite
6216 // component, throw an error. If Fiber return types are disabled,
6217 // we already threw above.
6218 switch (returnFiber.tag) {
6219 case ClassComponent:
6220 {
6221 {
6222 var instance = returnFiber.stateNode;
6223 if (instance.render._isMockFunction) {
6224 // We allow auto-mocks to proceed as if they're returning null.
6225 break;
6226 }
6227 }
6228 }
6229 // Intentionally fall through to the next case, which handles both
6230 // functions and classes
6231 // eslint-disable-next-lined no-fallthrough
6232 case FunctionComponent:
6233 {
6234 var Component = returnFiber.type;
6235 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');
6236 }
6237 }
6238 }
6239
6240 // Remaining cases are all treated as empty.
6241 return deleteRemainingChildren(returnFiber, currentFirstChild);
6242 }
6243
6244 return reconcileChildFibers;
6245}
6246
6247var reconcileChildFibers = ChildReconciler(true);
6248var mountChildFibers = ChildReconciler(false);
6249
6250function cloneChildFibers(current$$1, workInProgress) {
6251 !(current$$1 === null || workInProgress.child === current$$1.child) ? invariant(false, 'Resuming work not yet implemented.') : void 0;
6252
6253 if (workInProgress.child === null) {
6254 return;
6255 }
6256
6257 var currentChild = workInProgress.child;
6258 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
6259 workInProgress.child = newChild;
6260
6261 newChild.return = workInProgress;
6262 while (currentChild.sibling !== null) {
6263 currentChild = currentChild.sibling;
6264 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
6265 newChild.return = workInProgress;
6266 }
6267 newChild.sibling = null;
6268}
6269
6270// The deepest Fiber on the stack involved in a hydration context.
6271// This may have been an insertion or a hydration.
6272var hydrationParentFiber = null;
6273var nextHydratableInstance = null;
6274var isHydrating = false;
6275
6276function enterHydrationState(fiber) {
6277 if (!supportsHydration) {
6278 return false;
6279 }
6280
6281 var parentInstance = fiber.stateNode.containerInfo;
6282 nextHydratableInstance = getFirstHydratableChild(parentInstance);
6283 hydrationParentFiber = fiber;
6284 isHydrating = true;
6285 return true;
6286}
6287
6288function deleteHydratableInstance(returnFiber, instance) {
6289 {
6290 switch (returnFiber.tag) {
6291 case HostRoot:
6292 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
6293 break;
6294 case HostComponent:
6295 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
6296 break;
6297 }
6298 }
6299
6300 var childToDelete = createFiberFromHostInstanceForDeletion();
6301 childToDelete.stateNode = instance;
6302 childToDelete.return = returnFiber;
6303 childToDelete.effectTag = Deletion;
6304
6305 // This might seem like it belongs on progressedFirstDeletion. However,
6306 // these children are not part of the reconciliation list of children.
6307 // Even if we abort and rereconcile the children, that will try to hydrate
6308 // again and the nodes are still in the host tree so these will be
6309 // recreated.
6310 if (returnFiber.lastEffect !== null) {
6311 returnFiber.lastEffect.nextEffect = childToDelete;
6312 returnFiber.lastEffect = childToDelete;
6313 } else {
6314 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
6315 }
6316}
6317
6318function insertNonHydratedInstance(returnFiber, fiber) {
6319 fiber.effectTag |= Placement;
6320 {
6321 switch (returnFiber.tag) {
6322 case HostRoot:
6323 {
6324 var parentContainer = returnFiber.stateNode.containerInfo;
6325 switch (fiber.tag) {
6326 case HostComponent:
6327 var type = fiber.type;
6328 var props = fiber.pendingProps;
6329 didNotFindHydratableContainerInstance(parentContainer, type, props);
6330 break;
6331 case HostText:
6332 var text = fiber.pendingProps;
6333 didNotFindHydratableContainerTextInstance(parentContainer, text);
6334 break;
6335 }
6336 break;
6337 }
6338 case HostComponent:
6339 {
6340 var parentType = returnFiber.type;
6341 var parentProps = returnFiber.memoizedProps;
6342 var parentInstance = returnFiber.stateNode;
6343 switch (fiber.tag) {
6344 case HostComponent:
6345 var _type = fiber.type;
6346 var _props = fiber.pendingProps;
6347 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
6348 break;
6349 case HostText:
6350 var _text = fiber.pendingProps;
6351 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
6352 break;
6353 }
6354 break;
6355 }
6356 default:
6357 return;
6358 }
6359 }
6360}
6361
6362function tryHydrate(fiber, nextInstance) {
6363 switch (fiber.tag) {
6364 case HostComponent:
6365 {
6366 var type = fiber.type;
6367 var props = fiber.pendingProps;
6368 var instance = canHydrateInstance(nextInstance, type, props);
6369 if (instance !== null) {
6370 fiber.stateNode = instance;
6371 return true;
6372 }
6373 return false;
6374 }
6375 case HostText:
6376 {
6377 var text = fiber.pendingProps;
6378 var textInstance = canHydrateTextInstance(nextInstance, text);
6379 if (textInstance !== null) {
6380 fiber.stateNode = textInstance;
6381 return true;
6382 }
6383 return false;
6384 }
6385 default:
6386 return false;
6387 }
6388}
6389
6390function tryToClaimNextHydratableInstance(fiber) {
6391 if (!isHydrating) {
6392 return;
6393 }
6394 var nextInstance = nextHydratableInstance;
6395 if (!nextInstance) {
6396 // Nothing to hydrate. Make it an insertion.
6397 insertNonHydratedInstance(hydrationParentFiber, fiber);
6398 isHydrating = false;
6399 hydrationParentFiber = fiber;
6400 return;
6401 }
6402 var firstAttemptedInstance = nextInstance;
6403 if (!tryHydrate(fiber, nextInstance)) {
6404 // If we can't hydrate this instance let's try the next one.
6405 // We use this as a heuristic. It's based on intuition and not data so it
6406 // might be flawed or unnecessary.
6407 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
6408 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
6409 // Nothing to hydrate. Make it an insertion.
6410 insertNonHydratedInstance(hydrationParentFiber, fiber);
6411 isHydrating = false;
6412 hydrationParentFiber = fiber;
6413 return;
6414 }
6415 // We matched the next one, we'll now assume that the first one was
6416 // superfluous and we'll delete it. Since we can't eagerly delete it
6417 // we'll have to schedule a deletion. To do that, this node needs a dummy
6418 // fiber associated with it.
6419 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
6420 }
6421 hydrationParentFiber = fiber;
6422 nextHydratableInstance = getFirstHydratableChild(nextInstance);
6423}
6424
6425function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
6426 if (!supportsHydration) {
6427 invariant(false, 'Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6428 }
6429
6430 var instance = fiber.stateNode;
6431 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber);
6432 // TODO: Type this specific to this type of component.
6433 fiber.updateQueue = updatePayload;
6434 // If the update payload indicates that there is a change or if there
6435 // is a new ref we mark this as an update.
6436 if (updatePayload !== null) {
6437 return true;
6438 }
6439 return false;
6440}
6441
6442function prepareToHydrateHostTextInstance(fiber) {
6443 if (!supportsHydration) {
6444 invariant(false, 'Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6445 }
6446
6447 var textInstance = fiber.stateNode;
6448 var textContent = fiber.memoizedProps;
6449 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
6450 {
6451 if (shouldUpdate) {
6452 // We assume that prepareToHydrateHostTextInstance is called in a context where the
6453 // hydration parent is the parent host component of this host text.
6454 var returnFiber = hydrationParentFiber;
6455 if (returnFiber !== null) {
6456 switch (returnFiber.tag) {
6457 case HostRoot:
6458 {
6459 var parentContainer = returnFiber.stateNode.containerInfo;
6460 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
6461 break;
6462 }
6463 case HostComponent:
6464 {
6465 var parentType = returnFiber.type;
6466 var parentProps = returnFiber.memoizedProps;
6467 var parentInstance = returnFiber.stateNode;
6468 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
6469 break;
6470 }
6471 }
6472 }
6473 }
6474 }
6475 return shouldUpdate;
6476}
6477
6478function popToNextHostParent(fiber) {
6479 var parent = fiber.return;
6480 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot) {
6481 parent = parent.return;
6482 }
6483 hydrationParentFiber = parent;
6484}
6485
6486function popHydrationState(fiber) {
6487 if (!supportsHydration) {
6488 return false;
6489 }
6490 if (fiber !== hydrationParentFiber) {
6491 // We're deeper than the current hydration context, inside an inserted
6492 // tree.
6493 return false;
6494 }
6495 if (!isHydrating) {
6496 // If we're not currently hydrating but we're in a hydration context, then
6497 // we were an insertion and now need to pop up reenter hydration of our
6498 // siblings.
6499 popToNextHostParent(fiber);
6500 isHydrating = true;
6501 return false;
6502 }
6503
6504 var type = fiber.type;
6505
6506 // If we have any remaining hydratable nodes, we need to delete them now.
6507 // We only do this deeper than head and body since they tend to have random
6508 // other nodes in them. We also ignore components with pure text content in
6509 // side of them.
6510 // TODO: Better heuristic.
6511 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
6512 var nextInstance = nextHydratableInstance;
6513 while (nextInstance) {
6514 deleteHydratableInstance(fiber, nextInstance);
6515 nextInstance = getNextHydratableSibling(nextInstance);
6516 }
6517 }
6518
6519 popToNextHostParent(fiber);
6520 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
6521 return true;
6522}
6523
6524function resetHydrationState() {
6525 if (!supportsHydration) {
6526 return;
6527 }
6528
6529 hydrationParentFiber = null;
6530 nextHydratableInstance = null;
6531 isHydrating = false;
6532}
6533
6534var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
6535
6536var didWarnAboutBadClass = void 0;
6537var didWarnAboutContextTypeOnFunctionComponent = void 0;
6538var didWarnAboutGetDerivedStateOnFunctionComponent = void 0;
6539var didWarnAboutFunctionRefs = void 0;
6540var didWarnAboutReassigningProps = void 0;
6541
6542{
6543 didWarnAboutBadClass = {};
6544 didWarnAboutContextTypeOnFunctionComponent = {};
6545 didWarnAboutGetDerivedStateOnFunctionComponent = {};
6546 didWarnAboutFunctionRefs = {};
6547 didWarnAboutReassigningProps = false;
6548}
6549
6550function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6551 if (current$$1 === null) {
6552 // If this is a fresh new component that hasn't been rendered yet, we
6553 // won't update its child set by applying minimal side-effects. Instead,
6554 // we will add them all to the child before it gets rendered. That means
6555 // we can optimize this reconciliation pass by not tracking side-effects.
6556 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6557 } else {
6558 // If the current child is the same as the work in progress, it means that
6559 // we haven't yet started any work on these children. Therefore, we use
6560 // the clone algorithm to create a copy of all the current children.
6561
6562 // If we had any progressed work already, that is invalid at this point so
6563 // let's throw it out.
6564 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
6565 }
6566}
6567
6568function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6569 // This function is fork of reconcileChildren. It's used in cases where we
6570 // want to reconcile without matching against the existing set. This has the
6571 // effect of all current children being unmounted; even if the type and key
6572 // are the same, the old child is unmounted and a new child is created.
6573 //
6574 // To do this, we're going to go through the reconcile algorithm twice. In
6575 // the first pass, we schedule a deletion for all the current children by
6576 // passing null.
6577 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
6578 // In the second pass, we mount the new children. The trick here is that we
6579 // pass null in place of where we usually pass the current child set. This has
6580 // the effect of remounting all children regardless of whether their their
6581 // identity matches.
6582 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6583}
6584
6585function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6586 {
6587 if (workInProgress.type !== workInProgress.elementType) {
6588 // Lazy component props can't be validated in createElement
6589 // because they're only guaranteed to be resolved here.
6590 var innerPropTypes = Component.propTypes;
6591 if (innerPropTypes) {
6592 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6593 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6594 }
6595 }
6596 }
6597
6598 var render = Component.render;
6599 var ref = workInProgress.ref;
6600
6601 // The rest is a fork of updateFunctionComponent
6602 var nextChildren = void 0;
6603 prepareToReadContext(workInProgress, renderExpirationTime);
6604 prepareToUseHooks(current$$1, workInProgress, renderExpirationTime);
6605 {
6606 ReactCurrentOwner$2.current = workInProgress;
6607 setCurrentPhase('render');
6608 nextChildren = render(nextProps, ref);
6609 setCurrentPhase(null);
6610 }
6611 nextChildren = finishHooks(render, nextProps, nextChildren, ref);
6612
6613 // React DevTools reads this flag.
6614 workInProgress.effectTag |= PerformedWork;
6615 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6616 return workInProgress.child;
6617}
6618
6619function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6620 if (current$$1 === null) {
6621 var type = Component.type;
6622 if (isSimpleFunctionComponent(type) && Component.compare === null &&
6623 // SimpleMemoComponent codepath doesn't resolve outer props either.
6624 Component.defaultProps === undefined) {
6625 // If this is a plain function component without default props,
6626 // and with only the default shallow comparison, we upgrade it
6627 // to a SimpleMemoComponent to allow fast path updates.
6628 workInProgress.tag = SimpleMemoComponent;
6629 workInProgress.type = type;
6630 {
6631 validateFunctionComponentInDev(workInProgress, type);
6632 }
6633 return updateSimpleMemoComponent(current$$1, workInProgress, type, nextProps, updateExpirationTime, renderExpirationTime);
6634 }
6635 {
6636 var innerPropTypes = type.propTypes;
6637 if (innerPropTypes) {
6638 // Inner memo component props aren't currently validated in createElement.
6639 // We could move it there, but we'd still need this for lazy code path.
6640 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6641 'prop', getComponentName(type), getCurrentFiberStackInDev);
6642 }
6643 }
6644 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
6645 child.ref = workInProgress.ref;
6646 child.return = workInProgress;
6647 workInProgress.child = child;
6648 return child;
6649 }
6650 {
6651 var _type = Component.type;
6652 var _innerPropTypes = _type.propTypes;
6653 if (_innerPropTypes) {
6654 // Inner memo component props aren't currently validated in createElement.
6655 // We could move it there, but we'd still need this for lazy code path.
6656 checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
6657 'prop', getComponentName(_type), getCurrentFiberStackInDev);
6658 }
6659 }
6660 var currentChild = current$$1.child; // This is always exactly one child
6661 if (updateExpirationTime < renderExpirationTime) {
6662 // This will be the props with resolved defaultProps,
6663 // unlike current.memoizedProps which will be the unresolved ones.
6664 var prevProps = currentChild.memoizedProps;
6665 // Default to shallow comparison
6666 var compare = Component.compare;
6667 compare = compare !== null ? compare : shallowEqual;
6668 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6669 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6670 }
6671 }
6672 // React DevTools reads this flag.
6673 workInProgress.effectTag |= PerformedWork;
6674 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
6675 newChild.ref = workInProgress.ref;
6676 newChild.return = workInProgress;
6677 workInProgress.child = newChild;
6678 return newChild;
6679}
6680
6681function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6682 {
6683 if (workInProgress.type !== workInProgress.elementType) {
6684 // Lazy component props can't be validated in createElement
6685 // because they're only guaranteed to be resolved here.
6686 var outerMemoType = workInProgress.elementType;
6687 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
6688 // We warn when you define propTypes on lazy()
6689 // so let's just skip over it to find memo() outer wrapper.
6690 // Inner props for memo are validated later.
6691 outerMemoType = refineResolvedLazyComponent(outerMemoType);
6692 }
6693 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
6694 if (outerPropTypes) {
6695 checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
6696 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
6697 }
6698 // Inner propTypes will be validated in the function component path.
6699 }
6700 }
6701 if (current$$1 !== null && updateExpirationTime < renderExpirationTime) {
6702 var prevProps = current$$1.memoizedProps;
6703 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6704 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6705 }
6706 }
6707 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6708}
6709
6710function updateFragment(current$$1, workInProgress, renderExpirationTime) {
6711 var nextChildren = workInProgress.pendingProps;
6712 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6713 return workInProgress.child;
6714}
6715
6716function updateMode(current$$1, workInProgress, renderExpirationTime) {
6717 var nextChildren = workInProgress.pendingProps.children;
6718 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6719 return workInProgress.child;
6720}
6721
6722function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
6723 if (enableProfilerTimer) {
6724 workInProgress.effectTag |= Update;
6725 }
6726 var nextProps = workInProgress.pendingProps;
6727 var nextChildren = nextProps.children;
6728 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6729 return workInProgress.child;
6730}
6731
6732function markRef(current$$1, workInProgress) {
6733 var ref = workInProgress.ref;
6734 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
6735 // Schedule a Ref effect
6736 workInProgress.effectTag |= Ref;
6737 }
6738}
6739
6740function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6741 {
6742 if (workInProgress.type !== workInProgress.elementType) {
6743 // Lazy component props can't be validated in createElement
6744 // because they're only guaranteed to be resolved here.
6745 var innerPropTypes = Component.propTypes;
6746 if (innerPropTypes) {
6747 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6748 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6749 }
6750 }
6751 }
6752
6753 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
6754 var context = getMaskedContext(workInProgress, unmaskedContext);
6755
6756 var nextChildren = void 0;
6757 prepareToReadContext(workInProgress, renderExpirationTime);
6758 prepareToUseHooks(current$$1, workInProgress, renderExpirationTime);
6759 {
6760 ReactCurrentOwner$2.current = workInProgress;
6761 setCurrentPhase('render');
6762 nextChildren = Component(nextProps, context);
6763 setCurrentPhase(null);
6764 }
6765 nextChildren = finishHooks(Component, nextProps, nextChildren, context);
6766
6767 // React DevTools reads this flag.
6768 workInProgress.effectTag |= PerformedWork;
6769 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6770 return workInProgress.child;
6771}
6772
6773function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6774 {
6775 if (workInProgress.type !== workInProgress.elementType) {
6776 // Lazy component props can't be validated in createElement
6777 // because they're only guaranteed to be resolved here.
6778 var innerPropTypes = Component.propTypes;
6779 if (innerPropTypes) {
6780 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6781 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6782 }
6783 }
6784 }
6785
6786 // Push context providers early to prevent context stack mismatches.
6787 // During mounting we don't know the child context yet as the instance doesn't exist.
6788 // We will invalidate the child context in finishClassComponent() right after rendering.
6789 var hasContext = void 0;
6790 if (isContextProvider(Component)) {
6791 hasContext = true;
6792 pushContextProvider(workInProgress);
6793 } else {
6794 hasContext = false;
6795 }
6796 prepareToReadContext(workInProgress, renderExpirationTime);
6797
6798 var instance = workInProgress.stateNode;
6799 var shouldUpdate = void 0;
6800 if (instance === null) {
6801 if (current$$1 !== null) {
6802 // An class component without an instance only mounts if it suspended
6803 // inside a non- concurrent tree, in an inconsistent state. We want to
6804 // tree it like a new mount, even though an empty version of it already
6805 // committed. Disconnect the alternate pointers.
6806 current$$1.alternate = null;
6807 workInProgress.alternate = null;
6808 // Since this is conceptually a new fiber, schedule a Placement effect
6809 workInProgress.effectTag |= Placement;
6810 }
6811 // In the initial pass we might need to construct the instance.
6812 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6813 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6814 shouldUpdate = true;
6815 } else if (current$$1 === null) {
6816 // In a resume, we'll already have an instance we can reuse.
6817 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6818 } else {
6819 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6820 }
6821 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
6822 {
6823 var inst = workInProgress.stateNode;
6824 if (inst.props !== nextProps) {
6825 !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;
6826 didWarnAboutReassigningProps = true;
6827 }
6828 }
6829 return nextUnitOfWork;
6830}
6831
6832function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
6833 // Refs should update even if shouldComponentUpdate returns false
6834 markRef(current$$1, workInProgress);
6835
6836 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
6837
6838 if (!shouldUpdate && !didCaptureError) {
6839 // Context providers should defer to sCU for rendering
6840 if (hasContext) {
6841 invalidateContextProvider(workInProgress, Component, false);
6842 }
6843
6844 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6845 }
6846
6847 var instance = workInProgress.stateNode;
6848
6849 // Rerender
6850 ReactCurrentOwner$2.current = workInProgress;
6851 var nextChildren = void 0;
6852 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
6853 // If we captured an error, but getDerivedStateFrom catch is not defined,
6854 // unmount all the children. componentDidCatch will schedule an update to
6855 // re-render a fallback. This is temporary until we migrate everyone to
6856 // the new API.
6857 // TODO: Warn in a future release.
6858 nextChildren = null;
6859
6860 if (enableProfilerTimer) {
6861 stopProfilerTimerIfRunning(workInProgress);
6862 }
6863 } else {
6864 {
6865 setCurrentPhase('render');
6866 nextChildren = instance.render();
6867 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6868 instance.render();
6869 }
6870 setCurrentPhase(null);
6871 }
6872 }
6873
6874 // React DevTools reads this flag.
6875 workInProgress.effectTag |= PerformedWork;
6876 if (current$$1 !== null && didCaptureError) {
6877 // If we're recovering from an error, reconcile without reusing any of
6878 // the existing children. Conceptually, the normal children and the children
6879 // that are shown on error are two different sets, so we shouldn't reuse
6880 // normal children even if their identities match.
6881 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
6882 } else {
6883 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6884 }
6885
6886 // Memoize state using the values we just used to render.
6887 // TODO: Restructure so we never read values from the instance.
6888 workInProgress.memoizedState = instance.state;
6889
6890 // The context might have changed so we need to recalculate it.
6891 if (hasContext) {
6892 invalidateContextProvider(workInProgress, Component, true);
6893 }
6894
6895 return workInProgress.child;
6896}
6897
6898function pushHostRootContext(workInProgress) {
6899 var root = workInProgress.stateNode;
6900 if (root.pendingContext) {
6901 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
6902 } else if (root.context) {
6903 // Should always be set
6904 pushTopLevelContextObject(workInProgress, root.context, false);
6905 }
6906 pushHostContainer(workInProgress, root.containerInfo);
6907}
6908
6909function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
6910 pushHostRootContext(workInProgress);
6911 var updateQueue = workInProgress.updateQueue;
6912 !(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;
6913 var nextProps = workInProgress.pendingProps;
6914 var prevState = workInProgress.memoizedState;
6915 var prevChildren = prevState !== null ? prevState.element : null;
6916 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
6917 var nextState = workInProgress.memoizedState;
6918 // Caution: React DevTools currently depends on this property
6919 // being called "element".
6920 var nextChildren = nextState.element;
6921 if (nextChildren === prevChildren) {
6922 // If the state is the same as before, that's a bailout because we had
6923 // no work that expires at this time.
6924 resetHydrationState();
6925 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6926 }
6927 var root = workInProgress.stateNode;
6928 if ((current$$1 === null || current$$1.child === null) && root.hydrate && enterHydrationState(workInProgress)) {
6929 // If we don't have any current children this might be the first pass.
6930 // We always try to hydrate. If this isn't a hydration pass there won't
6931 // be any children to hydrate which is effectively the same thing as
6932 // not hydrating.
6933
6934 // This is a bit of a hack. We track the host root as a placement to
6935 // know that we're currently in a mounting state. That way isMounted
6936 // works as expected. We must reset this before committing.
6937 // TODO: Delete this when we delete isMounted and findDOMNode.
6938 workInProgress.effectTag |= Placement;
6939
6940 // Ensure that children mount into this root without tracking
6941 // side-effects. This ensures that we don't store Placement effects on
6942 // nodes that will be hydrated.
6943 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6944 } else {
6945 // Otherwise reset hydration state in case we aborted and resumed another
6946 // root.
6947 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6948 resetHydrationState();
6949 }
6950 return workInProgress.child;
6951}
6952
6953function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
6954 pushHostContext(workInProgress);
6955
6956 if (current$$1 === null) {
6957 tryToClaimNextHydratableInstance(workInProgress);
6958 }
6959
6960 var type = workInProgress.type;
6961 var nextProps = workInProgress.pendingProps;
6962 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
6963
6964 var nextChildren = nextProps.children;
6965 var isDirectTextChild = shouldSetTextContent(type, nextProps);
6966
6967 if (isDirectTextChild) {
6968 // We special case a direct text child of a host node. This is a common
6969 // case. We won't handle it as a reified child. We will instead handle
6970 // this in the host environment that also have access to this prop. That
6971 // avoids allocating another HostText fiber and traversing it.
6972 nextChildren = null;
6973 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
6974 // If we're switching from a direct text child to a normal child, or to
6975 // empty, we need to schedule the text content to be reset.
6976 workInProgress.effectTag |= ContentReset;
6977 }
6978
6979 markRef(current$$1, workInProgress);
6980
6981 // Check the host config to see if the children are offscreen/hidden.
6982 if (renderExpirationTime !== Never && workInProgress.mode & ConcurrentMode && shouldDeprioritizeSubtree(type, nextProps)) {
6983 // Schedule this fiber to re-render at offscreen priority. Then bailout.
6984 workInProgress.expirationTime = Never;
6985 return null;
6986 }
6987
6988 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6989 return workInProgress.child;
6990}
6991
6992function updateHostText(current$$1, workInProgress) {
6993 if (current$$1 === null) {
6994 tryToClaimNextHydratableInstance(workInProgress);
6995 }
6996 // Nothing to do here. This is terminal. We'll do the completion step
6997 // immediately after.
6998 return null;
6999}
7000
7001function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
7002 if (_current !== null) {
7003 // An lazy component only mounts if it suspended inside a non-
7004 // concurrent tree, in an inconsistent state. We want to treat it like
7005 // a new mount, even though an empty version of it already committed.
7006 // Disconnect the alternate pointers.
7007 _current.alternate = null;
7008 workInProgress.alternate = null;
7009 // Since this is conceptually a new fiber, schedule a Placement effect
7010 workInProgress.effectTag |= Placement;
7011 }
7012
7013 var props = workInProgress.pendingProps;
7014 // We can't start a User Timing measurement with correct label yet.
7015 // Cancel and resume right after we know the tag.
7016 cancelWorkTimer(workInProgress);
7017 var Component = readLazyComponentType(elementType);
7018 // Store the unwrapped component in the type.
7019 workInProgress.type = Component;
7020 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
7021 startWorkTimer(workInProgress);
7022 var resolvedProps = resolveDefaultProps(Component, props);
7023 var child = void 0;
7024 switch (resolvedTag) {
7025 case FunctionComponent:
7026 {
7027 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7028 break;
7029 }
7030 case ClassComponent:
7031 {
7032 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7033 break;
7034 }
7035 case ForwardRef:
7036 {
7037 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7038 break;
7039 }
7040 case MemoComponent:
7041 {
7042 {
7043 if (workInProgress.type !== workInProgress.elementType) {
7044 var outerPropTypes = Component.propTypes;
7045 if (outerPropTypes) {
7046 checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
7047 'prop', getComponentName(Component), getCurrentFiberStackInDev);
7048 }
7049 }
7050 }
7051 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
7052 updateExpirationTime, renderExpirationTime);
7053 break;
7054 }
7055 default:
7056 {
7057 var hint = '';
7058 {
7059 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
7060 hint = ' Did you wrap a component in React.lazy() more than once?';
7061 }
7062 }
7063 // This message intentionally doesn't mention ForwardRef or MemoComponent
7064 // because the fact that it's a separate type of work is an
7065 // implementation detail.
7066 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);
7067 }
7068 }
7069 return child;
7070}
7071
7072function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
7073 if (_current !== null) {
7074 // An incomplete component only mounts if it suspended inside a non-
7075 // concurrent tree, in an inconsistent state. We want to treat it like
7076 // a new mount, even though an empty version of it already committed.
7077 // Disconnect the alternate pointers.
7078 _current.alternate = null;
7079 workInProgress.alternate = null;
7080 // Since this is conceptually a new fiber, schedule a Placement effect
7081 workInProgress.effectTag |= Placement;
7082 }
7083
7084 // Promote the fiber to a class and try rendering again.
7085 workInProgress.tag = ClassComponent;
7086
7087 // The rest of this function is a fork of `updateClassComponent`
7088
7089 // Push context providers early to prevent context stack mismatches.
7090 // During mounting we don't know the child context yet as the instance doesn't exist.
7091 // We will invalidate the child context in finishClassComponent() right after rendering.
7092 var hasContext = void 0;
7093 if (isContextProvider(Component)) {
7094 hasContext = true;
7095 pushContextProvider(workInProgress);
7096 } else {
7097 hasContext = false;
7098 }
7099 prepareToReadContext(workInProgress, renderExpirationTime);
7100
7101 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7102 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7103
7104 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7105}
7106
7107function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
7108 if (_current !== null) {
7109 // An indeterminate component only mounts if it suspended inside a non-
7110 // concurrent tree, in an inconsistent state. We want to treat it like
7111 // a new mount, even though an empty version of it already committed.
7112 // Disconnect the alternate pointers.
7113 _current.alternate = null;
7114 workInProgress.alternate = null;
7115 // Since this is conceptually a new fiber, schedule a Placement effect
7116 workInProgress.effectTag |= Placement;
7117 }
7118
7119 var props = workInProgress.pendingProps;
7120 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
7121 var context = getMaskedContext(workInProgress, unmaskedContext);
7122
7123 prepareToReadContext(workInProgress, renderExpirationTime);
7124 prepareToUseHooks(null, workInProgress, renderExpirationTime);
7125
7126 var value = void 0;
7127
7128 {
7129 if (Component.prototype && typeof Component.prototype.render === 'function') {
7130 var componentName = getComponentName(Component) || 'Unknown';
7131
7132 if (!didWarnAboutBadClass[componentName]) {
7133 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);
7134 didWarnAboutBadClass[componentName] = true;
7135 }
7136 }
7137
7138 if (workInProgress.mode & StrictMode) {
7139 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
7140 }
7141
7142 ReactCurrentOwner$2.current = workInProgress;
7143 value = Component(props, context);
7144 }
7145 // React DevTools reads this flag.
7146 workInProgress.effectTag |= PerformedWork;
7147
7148 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
7149 // Proceed under the assumption that this is a class instance
7150 workInProgress.tag = ClassComponent;
7151
7152 // Throw out any hooks that were used.
7153 resetHooks();
7154
7155 // Push context providers early to prevent context stack mismatches.
7156 // During mounting we don't know the child context yet as the instance doesn't exist.
7157 // We will invalidate the child context in finishClassComponent() right after rendering.
7158 var hasContext = false;
7159 if (isContextProvider(Component)) {
7160 hasContext = true;
7161 pushContextProvider(workInProgress);
7162 } else {
7163 hasContext = false;
7164 }
7165
7166 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
7167
7168 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
7169 if (typeof getDerivedStateFromProps === 'function') {
7170 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
7171 }
7172
7173 adoptClassInstance(workInProgress, value);
7174 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
7175 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7176 } else {
7177 // Proceed under the assumption that this is a function component
7178 workInProgress.tag = FunctionComponent;
7179 value = finishHooks(Component, props, value, context);
7180 reconcileChildren(null, workInProgress, value, renderExpirationTime);
7181 {
7182 validateFunctionComponentInDev(workInProgress, Component);
7183 }
7184 return workInProgress.child;
7185 }
7186}
7187
7188function validateFunctionComponentInDev(workInProgress, Component) {
7189 if (Component) {
7190 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
7191 }
7192 if (workInProgress.ref !== null) {
7193 var info = '';
7194 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
7195 if (ownerName) {
7196 info += '\n\nCheck the render method of `' + ownerName + '`.';
7197 }
7198
7199 var warningKey = ownerName || workInProgress._debugID || '';
7200 var debugSource = workInProgress._debugSource;
7201 if (debugSource) {
7202 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
7203 }
7204 if (!didWarnAboutFunctionRefs[warningKey]) {
7205 didWarnAboutFunctionRefs[warningKey] = true;
7206 warning$1(false, 'Function components cannot be given refs. ' + 'Attempts to access this ref will fail.%s', info);
7207 }
7208 }
7209
7210 if (typeof Component.getDerivedStateFromProps === 'function') {
7211 var componentName = getComponentName(Component) || 'Unknown';
7212
7213 if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) {
7214 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', componentName);
7215 didWarnAboutGetDerivedStateOnFunctionComponent[componentName] = true;
7216 }
7217 }
7218
7219 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
7220 var _componentName = getComponentName(Component) || 'Unknown';
7221
7222 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName]) {
7223 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName);
7224 didWarnAboutContextTypeOnFunctionComponent[_componentName] = true;
7225 }
7226 }
7227}
7228
7229function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7230 var mode = workInProgress.mode;
7231 var nextProps = workInProgress.pendingProps;
7232
7233 // We should attempt to render the primary children unless this boundary
7234 // already suspended during this render (`alreadyCaptured` is true).
7235 var nextState = workInProgress.memoizedState;
7236
7237 var nextDidTimeout = void 0;
7238 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7239 // This is the first attempt.
7240 nextState = null;
7241 nextDidTimeout = false;
7242 } else {
7243 // Something in this boundary's subtree already suspended. Switch to
7244 // rendering the fallback children.
7245 nextState = {
7246 timedOutAt: nextState !== null ? nextState.timedOutAt : NoWork
7247 };
7248 nextDidTimeout = true;
7249 workInProgress.effectTag &= ~DidCapture;
7250 }
7251
7252 // This next part is a bit confusing. If the children timeout, we switch to
7253 // showing the fallback children in place of the "primary" children.
7254 // However, we don't want to delete the primary children because then their
7255 // state will be lost (both the React state and the host state, e.g.
7256 // uncontrolled form inputs). Instead we keep them mounted and hide them.
7257 // Both the fallback children AND the primary children are rendered at the
7258 // same time. Once the primary children are un-suspended, we can delete
7259 // the fallback children — don't need to preserve their state.
7260 //
7261 // The two sets of children are siblings in the host environment, but
7262 // semantically, for purposes of reconciliation, they are two separate sets.
7263 // So we store them using two fragment fibers.
7264 //
7265 // However, we want to avoid allocating extra fibers for every placeholder.
7266 // They're only necessary when the children time out, because that's the
7267 // only time when both sets are mounted.
7268 //
7269 // So, the extra fragment fibers are only used if the children time out.
7270 // Otherwise, we render the primary children directly. This requires some
7271 // custom reconciliation logic to preserve the state of the primary
7272 // children. It's essentially a very basic form of re-parenting.
7273
7274 // `child` points to the child fiber. In the normal case, this is the first
7275 // fiber of the primary children set. In the timed-out case, it's a
7276 // a fragment fiber containing the primary children.
7277 var child = void 0;
7278 // `next` points to the next fiber React should render. In the normal case,
7279 // it's the same as `child`: the first fiber of the primary children set.
7280 // In the timed-out case, it's a fragment fiber containing the *fallback*
7281 // children -- we skip over the primary children entirely.
7282 var next = void 0;
7283 if (current$$1 === null) {
7284 // This is the initial mount. This branch is pretty simple because there's
7285 // no previous state that needs to be preserved.
7286 if (nextDidTimeout) {
7287 // Mount separate fragments for primary and fallback children.
7288 var nextFallbackChildren = nextProps.fallback;
7289 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
7290
7291 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7292 // Outside of concurrent mode, we commit the effects from the
7293 var progressedState = workInProgress.memoizedState;
7294 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
7295 primaryChildFragment.child = progressedPrimaryChild;
7296 }
7297
7298 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
7299 primaryChildFragment.sibling = fallbackChildFragment;
7300 child = primaryChildFragment;
7301 // Skip the primary children, and continue working on the
7302 // fallback children.
7303 next = fallbackChildFragment;
7304 child.return = next.return = workInProgress;
7305 } else {
7306 // Mount the primary children without an intermediate fragment fiber.
7307 var nextPrimaryChildren = nextProps.children;
7308 child = next = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
7309 }
7310 } else {
7311 // This is an update. This branch is more complicated because we need to
7312 // ensure the state of the primary children is preserved.
7313 var prevState = current$$1.memoizedState;
7314 var prevDidTimeout = prevState !== null;
7315 if (prevDidTimeout) {
7316 // The current tree already timed out. That means each child set is
7317 var currentPrimaryChildFragment = current$$1.child;
7318 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
7319 if (nextDidTimeout) {
7320 // Still timed out. Reuse the current primary children by cloning
7321 // its fragment. We're going to skip over these entirely.
7322 var _nextFallbackChildren = nextProps.fallback;
7323 var _primaryChildFragment = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
7324
7325 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7326 // Outside of concurrent mode, we commit the effects from the
7327 var _progressedState = workInProgress.memoizedState;
7328 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
7329 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
7330 _primaryChildFragment.child = _progressedPrimaryChild;
7331 }
7332 }
7333
7334 // Because primaryChildFragment is a new fiber that we're inserting as the
7335 // parent of a new tree, we need to set its treeBaseDuration.
7336 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7337 // treeBaseDuration is the sum of all the child tree base durations.
7338 var treeBaseDuration = 0;
7339 var hiddenChild = _primaryChildFragment.child;
7340 while (hiddenChild !== null) {
7341 treeBaseDuration += hiddenChild.treeBaseDuration;
7342 hiddenChild = hiddenChild.sibling;
7343 }
7344 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
7345 }
7346
7347 // Clone the fallback child fragment, too. These we'll continue
7348 // working on.
7349 var _fallbackChildFragment = _primaryChildFragment.sibling = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren, currentFallbackChildFragment.expirationTime);
7350 child = _primaryChildFragment;
7351 _primaryChildFragment.childExpirationTime = NoWork;
7352 // Skip the primary children, and continue working on the
7353 // fallback children.
7354 next = _fallbackChildFragment;
7355 child.return = next.return = workInProgress;
7356 } else {
7357 // No longer suspended. Switch back to showing the primary children,
7358 // and remove the intermediate fragment fiber.
7359 var _nextPrimaryChildren = nextProps.children;
7360 var currentPrimaryChild = currentPrimaryChildFragment.child;
7361 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime);
7362
7363 // If this render doesn't suspend, we need to delete the fallback
7364 // children. Wait until the complete phase, after we've confirmed the
7365 // fallback is no longer needed.
7366 // TODO: Would it be better to store the fallback fragment on
7367 // the stateNode?
7368
7369 // Continue rendering the children, like we normally do.
7370 child = next = primaryChild;
7371 }
7372 } else {
7373 // The current tree has not already timed out. That means the primary
7374 // children are not wrapped in a fragment fiber.
7375 var _currentPrimaryChild = current$$1.child;
7376 if (nextDidTimeout) {
7377 // Timed out. Wrap the children in a fragment fiber to keep them
7378 // separate from the fallback children.
7379 var _nextFallbackChildren2 = nextProps.fallback;
7380 var _primaryChildFragment2 = createFiberFromFragment(
7381 // It shouldn't matter what the pending props are because we aren't
7382 // going to render this fragment.
7383 null, mode, NoWork, null);
7384 _primaryChildFragment2.child = _currentPrimaryChild;
7385
7386 // Even though we're creating a new fiber, there are no new children,
7387 // because we're reusing an already mounted tree. So we don't need to
7388 // schedule a placement.
7389 // primaryChildFragment.effectTag |= Placement;
7390
7391 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7392 // Outside of concurrent mode, we commit the effects from the
7393 var _progressedState2 = workInProgress.memoizedState;
7394 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
7395 _primaryChildFragment2.child = _progressedPrimaryChild2;
7396 }
7397
7398 // Because primaryChildFragment is a new fiber that we're inserting as the
7399 // parent of a new tree, we need to set its treeBaseDuration.
7400 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7401 // treeBaseDuration is the sum of all the child tree base durations.
7402 var _treeBaseDuration = 0;
7403 var _hiddenChild = _primaryChildFragment2.child;
7404 while (_hiddenChild !== null) {
7405 _treeBaseDuration += _hiddenChild.treeBaseDuration;
7406 _hiddenChild = _hiddenChild.sibling;
7407 }
7408 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
7409 }
7410
7411 // Create a fragment from the fallback children, too.
7412 var _fallbackChildFragment2 = _primaryChildFragment2.sibling = createFiberFromFragment(_nextFallbackChildren2, mode, renderExpirationTime, null);
7413 _fallbackChildFragment2.effectTag |= Placement;
7414 child = _primaryChildFragment2;
7415 _primaryChildFragment2.childExpirationTime = NoWork;
7416 // Skip the primary children, and continue working on the
7417 // fallback children.
7418 next = _fallbackChildFragment2;
7419 child.return = next.return = workInProgress;
7420 } else {
7421 // Still haven't timed out. Continue rendering the children, like we
7422 // normally do.
7423 var _nextPrimaryChildren2 = nextProps.children;
7424 next = child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
7425 }
7426 }
7427 workInProgress.stateNode = current$$1.stateNode;
7428 }
7429
7430 workInProgress.memoizedState = nextState;
7431 workInProgress.child = child;
7432 return next;
7433}
7434
7435function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
7436 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7437 var nextChildren = workInProgress.pendingProps;
7438 if (current$$1 === null) {
7439 // Portals are special because we don't append the children during mount
7440 // but at commit. Therefore we need to track insertions which the normal
7441 // flow doesn't do during mount. This doesn't happen at the root because
7442 // the root always starts with a "current" with a null child.
7443 // TODO: Consider unifying this with how the root works.
7444 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7445 } else {
7446 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7447 }
7448 return workInProgress.child;
7449}
7450
7451function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
7452 var providerType = workInProgress.type;
7453 var context = providerType._context;
7454
7455 var newProps = workInProgress.pendingProps;
7456 var oldProps = workInProgress.memoizedProps;
7457
7458 var newValue = newProps.value;
7459
7460 {
7461 var providerPropTypes = workInProgress.type.propTypes;
7462
7463 if (providerPropTypes) {
7464 checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
7465 }
7466 }
7467
7468 pushProvider(workInProgress, newValue);
7469
7470 if (oldProps !== null) {
7471 var oldValue = oldProps.value;
7472 var changedBits = calculateChangedBits(context, newValue, oldValue);
7473 if (changedBits === 0) {
7474 // No change. Bailout early if children are the same.
7475 if (oldProps.children === newProps.children && !hasContextChanged()) {
7476 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7477 }
7478 } else {
7479 // The context value changed. Search for matching consumers and schedule
7480 // them to update.
7481 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
7482 }
7483 }
7484
7485 var newChildren = newProps.children;
7486 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7487 return workInProgress.child;
7488}
7489
7490var hasWarnedAboutUsingContextAsConsumer = false;
7491
7492function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
7493 var context = workInProgress.type;
7494 // The logic below for Context differs depending on PROD or DEV mode. In
7495 // DEV mode, we create a separate object for Context.Consumer that acts
7496 // like a proxy to Context. This proxy object adds unnecessary code in PROD
7497 // so we use the old behaviour (Context.Consumer references Context) to
7498 // reduce size and overhead. The separate object references context via
7499 // a property called "_context", which also gives us the ability to check
7500 // in DEV mode if this property exists or not and warn if it does not.
7501 {
7502 if (context._context === undefined) {
7503 // This may be because it's a Context (rather than a Consumer).
7504 // Or it may be because it's older React where they're the same thing.
7505 // We only want to warn if we're sure it's a new React.
7506 if (context !== context.Consumer) {
7507 if (!hasWarnedAboutUsingContextAsConsumer) {
7508 hasWarnedAboutUsingContextAsConsumer = true;
7509 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?');
7510 }
7511 }
7512 } else {
7513 context = context._context;
7514 }
7515 }
7516 var newProps = workInProgress.pendingProps;
7517 var render = newProps.children;
7518
7519 {
7520 !(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;
7521 }
7522
7523 prepareToReadContext(workInProgress, renderExpirationTime);
7524 var newValue = readContext(context, newProps.unstable_observedBits);
7525 var newChildren = void 0;
7526 {
7527 ReactCurrentOwner$2.current = workInProgress;
7528 setCurrentPhase('render');
7529 newChildren = render(newValue);
7530 setCurrentPhase(null);
7531 }
7532
7533 // React DevTools reads this flag.
7534 workInProgress.effectTag |= PerformedWork;
7535 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7536 return workInProgress.child;
7537}
7538
7539function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
7540 cancelWorkTimer(workInProgress);
7541
7542 if (current$$1 !== null) {
7543 // Reuse previous context list
7544 workInProgress.firstContextDependency = current$$1.firstContextDependency;
7545 }
7546
7547 if (enableProfilerTimer) {
7548 // Don't update "base" render times for bailouts.
7549 stopProfilerTimerIfRunning(workInProgress);
7550 }
7551
7552 // Check if the children have any pending work.
7553 var childExpirationTime = workInProgress.childExpirationTime;
7554 if (childExpirationTime < renderExpirationTime) {
7555 // The children don't have any work either. We can skip them.
7556 // TODO: Once we add back resuming, we should check if the children are
7557 // a work-in-progress set. If so, we need to transfer their effects.
7558 return null;
7559 } else {
7560 // This fiber doesn't have work, but its subtree does. Clone the child
7561 // fibers and continue.
7562 cloneChildFibers(current$$1, workInProgress);
7563 return workInProgress.child;
7564 }
7565}
7566
7567function beginWork(current$$1, workInProgress, renderExpirationTime) {
7568 var updateExpirationTime = workInProgress.expirationTime;
7569
7570 if (current$$1 !== null) {
7571 var oldProps = current$$1.memoizedProps;
7572 var newProps = workInProgress.pendingProps;
7573 if (oldProps === newProps && !hasContextChanged() && updateExpirationTime < renderExpirationTime) {
7574 // This fiber does not have any pending work. Bailout without entering
7575 // the begin phase. There's still some bookkeeping we that needs to be done
7576 // in this optimized path, mostly pushing stuff onto the stack.
7577 switch (workInProgress.tag) {
7578 case HostRoot:
7579 pushHostRootContext(workInProgress);
7580 resetHydrationState();
7581 break;
7582 case HostComponent:
7583 pushHostContext(workInProgress);
7584 break;
7585 case ClassComponent:
7586 {
7587 var Component = workInProgress.type;
7588 if (isContextProvider(Component)) {
7589 pushContextProvider(workInProgress);
7590 }
7591 break;
7592 }
7593 case HostPortal:
7594 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7595 break;
7596 case ContextProvider:
7597 {
7598 var newValue = workInProgress.memoizedProps.value;
7599 pushProvider(workInProgress, newValue);
7600 break;
7601 }
7602 case Profiler:
7603 if (enableProfilerTimer) {
7604 workInProgress.effectTag |= Update;
7605 }
7606 break;
7607 case SuspenseComponent:
7608 {
7609 var state = workInProgress.memoizedState;
7610 var didTimeout = state !== null;
7611 if (didTimeout) {
7612 // If this boundary is currently timed out, we need to decide
7613 // whether to retry the primary children, or to skip over it and
7614 // go straight to the fallback. Check the priority of the primary
7615 var primaryChildFragment = workInProgress.child;
7616 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
7617 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
7618 // The primary children have pending work. Use the normal path
7619 // to attempt to render the primary children again.
7620 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7621 } else {
7622 // The primary children do not have pending work with sufficient
7623 // priority. Bailout.
7624 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7625 if (child !== null) {
7626 // The fallback children have pending work. Skip over the
7627 // primary children and work on the fallback.
7628 return child.sibling;
7629 } else {
7630 return null;
7631 }
7632 }
7633 }
7634 break;
7635 }
7636 }
7637 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7638 }
7639 }
7640
7641 // Before entering the begin phase, clear the expiration time.
7642 workInProgress.expirationTime = NoWork;
7643
7644 switch (workInProgress.tag) {
7645 case IndeterminateComponent:
7646 {
7647 var elementType = workInProgress.elementType;
7648 return mountIndeterminateComponent(current$$1, workInProgress, elementType, renderExpirationTime);
7649 }
7650 case LazyComponent:
7651 {
7652 var _elementType = workInProgress.elementType;
7653 return mountLazyComponent(current$$1, workInProgress, _elementType, updateExpirationTime, renderExpirationTime);
7654 }
7655 case FunctionComponent:
7656 {
7657 var _Component = workInProgress.type;
7658 var unresolvedProps = workInProgress.pendingProps;
7659 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
7660 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
7661 }
7662 case ClassComponent:
7663 {
7664 var _Component2 = workInProgress.type;
7665 var _unresolvedProps = workInProgress.pendingProps;
7666 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
7667 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
7668 }
7669 case HostRoot:
7670 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
7671 case HostComponent:
7672 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
7673 case HostText:
7674 return updateHostText(current$$1, workInProgress);
7675 case SuspenseComponent:
7676 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7677 case HostPortal:
7678 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
7679 case ForwardRef:
7680 {
7681 var type = workInProgress.type;
7682 var _unresolvedProps2 = workInProgress.pendingProps;
7683 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
7684 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
7685 }
7686 case Fragment:
7687 return updateFragment(current$$1, workInProgress, renderExpirationTime);
7688 case Mode:
7689 return updateMode(current$$1, workInProgress, renderExpirationTime);
7690 case Profiler:
7691 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
7692 case ContextProvider:
7693 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
7694 case ContextConsumer:
7695 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
7696 case MemoComponent:
7697 {
7698 var _type2 = workInProgress.type;
7699 var _unresolvedProps3 = workInProgress.pendingProps;
7700 // Resolve outer props first, then resolve inner props.
7701 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
7702 {
7703 if (workInProgress.type !== workInProgress.elementType) {
7704 var outerPropTypes = _type2.propTypes;
7705 if (outerPropTypes) {
7706 checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
7707 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
7708 }
7709 }
7710 }
7711 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
7712 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
7713 }
7714 case SimpleMemoComponent:
7715 {
7716 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
7717 }
7718 case IncompleteClassComponent:
7719 {
7720 var _Component3 = workInProgress.type;
7721 var _unresolvedProps4 = workInProgress.pendingProps;
7722 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
7723 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
7724 }
7725 default:
7726 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
7727 }
7728}
7729
7730function markUpdate(workInProgress) {
7731 // Tag the fiber with an update effect. This turns a Placement into
7732 // a PlacementAndUpdate.
7733 workInProgress.effectTag |= Update;
7734}
7735
7736function markRef$1(workInProgress) {
7737 workInProgress.effectTag |= Ref;
7738}
7739
7740var appendAllChildren = void 0;
7741var updateHostContainer = void 0;
7742var updateHostComponent$1 = void 0;
7743var updateHostText$1 = void 0;
7744if (supportsMutation) {
7745 // Mutation mode
7746
7747 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
7748 // We only have the top Fiber that was created but we need recurse down its
7749 // children to find all the terminal nodes.
7750 var node = workInProgress.child;
7751 while (node !== null) {
7752 if (node.tag === HostComponent || node.tag === HostText) {
7753 appendInitialChild(parent, node.stateNode);
7754 } else if (node.tag === HostPortal) {
7755 // If we have a portal child, then we don't want to traverse
7756 // down its children. Instead, we'll get insertions from each child in
7757 // the portal directly.
7758 } else if (node.child !== null) {
7759 node.child.return = node;
7760 node = node.child;
7761 continue;
7762 }
7763 if (node === workInProgress) {
7764 return;
7765 }
7766 while (node.sibling === null) {
7767 if (node.return === null || node.return === workInProgress) {
7768 return;
7769 }
7770 node = node.return;
7771 }
7772 node.sibling.return = node.return;
7773 node = node.sibling;
7774 }
7775 };
7776
7777 updateHostContainer = function (workInProgress) {
7778 // Noop
7779 };
7780 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
7781 // If we have an alternate, that means this is an update and we need to
7782 // schedule a side-effect to do the updates.
7783 var oldProps = current.memoizedProps;
7784 if (oldProps === newProps) {
7785 // In mutation mode, this is sufficient for a bailout because
7786 // we won't touch this node even if children changed.
7787 return;
7788 }
7789
7790 // If we get updated because one of our children updated, we don't
7791 // have newProps so we'll have to reuse them.
7792 // TODO: Split the update API as separate for the props vs. children.
7793 // Even better would be if children weren't special cased at all tho.
7794 var instance = workInProgress.stateNode;
7795 var currentHostContext = getHostContext();
7796 // TODO: Experiencing an error where oldProps is null. Suggests a host
7797 // component is hitting the resume path. Figure out why. Possibly
7798 // related to `hidden`.
7799 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
7800 // TODO: Type this specific to this type of component.
7801 workInProgress.updateQueue = updatePayload;
7802 // If the update payload indicates that there is a change or if there
7803 // is a new ref we mark this as an update. All the work is done in commitWork.
7804 if (updatePayload) {
7805 markUpdate(workInProgress);
7806 }
7807 };
7808 updateHostText$1 = function (current, workInProgress, oldText, newText) {
7809 // If the text differs, mark it as an update. All the work in done in commitWork.
7810 if (oldText !== newText) {
7811 markUpdate(workInProgress);
7812 }
7813 };
7814} else if (supportsPersistence) {
7815 // Persistent host tree mode
7816
7817 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
7818 // We only have the top Fiber that was created but we need recurse down its
7819 // children to find all the terminal nodes.
7820 var node = workInProgress.child;
7821 while (node !== null) {
7822 // eslint-disable-next-line no-labels
7823 branches: if (node.tag === HostComponent) {
7824 var instance = node.stateNode;
7825 if (needsVisibilityToggle) {
7826 var props = node.memoizedProps;
7827 var type = node.type;
7828 if (isHidden) {
7829 // This child is inside a timed out tree. Hide it.
7830 instance = cloneHiddenInstance(instance, type, props, node);
7831 } else {
7832 // This child was previously inside a timed out tree. If it was not
7833 // updated during this render, it may need to be unhidden. Clone
7834 // again to be sure.
7835 instance = cloneUnhiddenInstance(instance, type, props, node);
7836 }
7837 node.stateNode = instance;
7838 }
7839 appendInitialChild(parent, instance);
7840 } else if (node.tag === HostText) {
7841 var _instance = node.stateNode;
7842 if (needsVisibilityToggle) {
7843 var text = node.memoizedProps;
7844 var rootContainerInstance = getRootHostContainer();
7845 var currentHostContext = getHostContext();
7846 if (isHidden) {
7847 _instance = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
7848 } else {
7849 _instance = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
7850 }
7851 node.stateNode = _instance;
7852 }
7853 appendInitialChild(parent, _instance);
7854 } else if (node.tag === HostPortal) {
7855 // If we have a portal child, then we don't want to traverse
7856 // down its children. Instead, we'll get insertions from each child in
7857 // the portal directly.
7858 } else if (node.tag === SuspenseComponent) {
7859 var current = node.alternate;
7860 if (current !== null) {
7861 var oldState = current.memoizedState;
7862 var newState = node.memoizedState;
7863 var oldIsHidden = oldState !== null;
7864 var newIsHidden = newState !== null;
7865 if (oldIsHidden !== newIsHidden) {
7866 // The placeholder either just timed out or switched back to the normal
7867 // children after having previously timed out. Toggle the visibility of
7868 // the direct host children.
7869 var primaryChildParent = newIsHidden ? node.child : node;
7870 if (primaryChildParent !== null) {
7871 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
7872 }
7873 // eslint-disable-next-line no-labels
7874 break branches;
7875 }
7876 }
7877 if (node.child !== null) {
7878 // Continue traversing like normal
7879 node.child.return = node;
7880 node = node.child;
7881 continue;
7882 }
7883 } else if (node.child !== null) {
7884 node.child.return = node;
7885 node = node.child;
7886 continue;
7887 }
7888 // $FlowFixMe This is correct but Flow is confused by the labeled break.
7889 node = node;
7890 if (node === workInProgress) {
7891 return;
7892 }
7893 while (node.sibling === null) {
7894 if (node.return === null || node.return === workInProgress) {
7895 return;
7896 }
7897 node = node.return;
7898 }
7899 node.sibling.return = node.return;
7900 node = node.sibling;
7901 }
7902 };
7903
7904 // An unfortunate fork of appendAllChildren because we have two different parent types.
7905 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
7906 // We only have the top Fiber that was created but we need recurse down its
7907 // children to find all the terminal nodes.
7908 var node = workInProgress.child;
7909 while (node !== null) {
7910 // eslint-disable-next-line no-labels
7911 branches: if (node.tag === HostComponent) {
7912 var instance = node.stateNode;
7913 if (needsVisibilityToggle) {
7914 var props = node.memoizedProps;
7915 var type = node.type;
7916 if (isHidden) {
7917 // This child is inside a timed out tree. Hide it.
7918 instance = cloneHiddenInstance(instance, type, props, node);
7919 } else {
7920 // This child was previously inside a timed out tree. If it was not
7921 // updated during this render, it may need to be unhidden. Clone
7922 // again to be sure.
7923 instance = cloneUnhiddenInstance(instance, type, props, node);
7924 }
7925 node.stateNode = instance;
7926 }
7927 appendChildToContainerChildSet(containerChildSet, instance);
7928 } else if (node.tag === HostText) {
7929 var _instance2 = node.stateNode;
7930 if (needsVisibilityToggle) {
7931 var text = node.memoizedProps;
7932 var rootContainerInstance = getRootHostContainer();
7933 var currentHostContext = getHostContext();
7934 if (isHidden) {
7935 _instance2 = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
7936 } else {
7937 _instance2 = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
7938 }
7939 node.stateNode = _instance2;
7940 }
7941 appendChildToContainerChildSet(containerChildSet, _instance2);
7942 } else if (node.tag === HostPortal) {
7943 // If we have a portal child, then we don't want to traverse
7944 // down its children. Instead, we'll get insertions from each child in
7945 // the portal directly.
7946 } else if (node.tag === SuspenseComponent) {
7947 var current = node.alternate;
7948 if (current !== null) {
7949 var oldState = current.memoizedState;
7950 var newState = node.memoizedState;
7951 var oldIsHidden = oldState !== null;
7952 var newIsHidden = newState !== null;
7953 if (oldIsHidden !== newIsHidden) {
7954 // The placeholder either just timed out or switched back to the normal
7955 // children after having previously timed out. Toggle the visibility of
7956 // the direct host children.
7957 var primaryChildParent = newIsHidden ? node.child : node;
7958 if (primaryChildParent !== null) {
7959 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
7960 }
7961 // eslint-disable-next-line no-labels
7962 break branches;
7963 }
7964 }
7965 if (node.child !== null) {
7966 // Continue traversing like normal
7967 node.child.return = node;
7968 node = node.child;
7969 continue;
7970 }
7971 } else if (node.child !== null) {
7972 node.child.return = node;
7973 node = node.child;
7974 continue;
7975 }
7976 // $FlowFixMe This is correct but Flow is confused by the labeled break.
7977 node = node;
7978 if (node === workInProgress) {
7979 return;
7980 }
7981 while (node.sibling === null) {
7982 if (node.return === null || node.return === workInProgress) {
7983 return;
7984 }
7985 node = node.return;
7986 }
7987 node.sibling.return = node.return;
7988 node = node.sibling;
7989 }
7990 };
7991 updateHostContainer = function (workInProgress) {
7992 var portalOrRoot = workInProgress.stateNode;
7993 var childrenUnchanged = workInProgress.firstEffect === null;
7994 if (childrenUnchanged) {
7995 // No changes, just reuse the existing instance.
7996 } else {
7997 var container = portalOrRoot.containerInfo;
7998 var newChildSet = createContainerChildSet(container);
7999 // If children might have changed, we have to add them all to the set.
8000 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
8001 portalOrRoot.pendingChildren = newChildSet;
8002 // Schedule an update on the container to swap out the container.
8003 markUpdate(workInProgress);
8004 finalizeContainerChildren(container, newChildSet);
8005 }
8006 };
8007 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8008 var currentInstance = current.stateNode;
8009 var oldProps = current.memoizedProps;
8010 // If there are no effects associated with this node, then none of our children had any updates.
8011 // This guarantees that we can reuse all of them.
8012 var childrenUnchanged = workInProgress.firstEffect === null;
8013 if (childrenUnchanged && oldProps === newProps) {
8014 // No changes, just reuse the existing instance.
8015 // Note that this might release a previous clone.
8016 workInProgress.stateNode = currentInstance;
8017 return;
8018 }
8019 var recyclableInstance = workInProgress.stateNode;
8020 var currentHostContext = getHostContext();
8021 var updatePayload = null;
8022 if (oldProps !== newProps) {
8023 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8024 }
8025 if (childrenUnchanged && updatePayload === null) {
8026 // No changes, just reuse the existing instance.
8027 // Note that this might release a previous clone.
8028 workInProgress.stateNode = currentInstance;
8029 return;
8030 }
8031 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
8032 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
8033 markUpdate(workInProgress);
8034 }
8035 workInProgress.stateNode = newInstance;
8036 if (childrenUnchanged) {
8037 // If there are no other effects in this tree, we need to flag this node as having one.
8038 // Even though we're not going to use it for anything.
8039 // Otherwise parents won't know that there are new children to propagate upwards.
8040 markUpdate(workInProgress);
8041 } else {
8042 // If children might have changed, we have to add them all to the set.
8043 appendAllChildren(newInstance, workInProgress, false, false);
8044 }
8045 };
8046 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8047 if (oldText !== newText) {
8048 // If the text content differs, we'll create a new text instance for it.
8049 var rootContainerInstance = getRootHostContainer();
8050 var currentHostContext = getHostContext();
8051 workInProgress.stateNode = createTextInstance(newText, rootContainerInstance, currentHostContext, workInProgress);
8052 // We'll have to mark it as having an effect, even though we won't use the effect for anything.
8053 // This lets the parents know that at least one of their children has changed.
8054 markUpdate(workInProgress);
8055 }
8056 };
8057} else {
8058 // No host operations
8059 updateHostContainer = function (workInProgress) {
8060 // Noop
8061 };
8062 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8063 // Noop
8064 };
8065 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8066 // Noop
8067 };
8068}
8069
8070function completeWork(current, workInProgress, renderExpirationTime) {
8071 var newProps = workInProgress.pendingProps;
8072
8073 switch (workInProgress.tag) {
8074 case IndeterminateComponent:
8075 break;
8076 case LazyComponent:
8077 break;
8078 case SimpleMemoComponent:
8079 case FunctionComponent:
8080 break;
8081 case ClassComponent:
8082 {
8083 var Component = workInProgress.type;
8084 if (isContextProvider(Component)) {
8085 popContext(workInProgress);
8086 }
8087 break;
8088 }
8089 case HostRoot:
8090 {
8091 popHostContainer(workInProgress);
8092 popTopLevelContextObject(workInProgress);
8093 var fiberRoot = workInProgress.stateNode;
8094 if (fiberRoot.pendingContext) {
8095 fiberRoot.context = fiberRoot.pendingContext;
8096 fiberRoot.pendingContext = null;
8097 }
8098 if (current === null || current.child === null) {
8099 // If we hydrated, pop so that we can delete any remaining children
8100 // that weren't hydrated.
8101 popHydrationState(workInProgress);
8102 // This resets the hacky state to fix isMounted before committing.
8103 // TODO: Delete this when we delete isMounted and findDOMNode.
8104 workInProgress.effectTag &= ~Placement;
8105 }
8106 updateHostContainer(workInProgress);
8107 break;
8108 }
8109 case HostComponent:
8110 {
8111 popHostContext(workInProgress);
8112 var rootContainerInstance = getRootHostContainer();
8113 var type = workInProgress.type;
8114 if (current !== null && workInProgress.stateNode != null) {
8115 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
8116
8117 if (current.ref !== workInProgress.ref) {
8118 markRef$1(workInProgress);
8119 }
8120 } else {
8121 if (!newProps) {
8122 !(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;
8123 // This can happen when we abort work.
8124 break;
8125 }
8126
8127 var currentHostContext = getHostContext();
8128 // TODO: Move createInstance to beginWork and keep it on a context
8129 // "stack" as the parent. Then append children as we go in beginWork
8130 // or completeWork depending on we want to add then top->down or
8131 // bottom->up. Top->down is faster in IE11.
8132 var wasHydrated = popHydrationState(workInProgress);
8133 if (wasHydrated) {
8134 // TODO: Move this and createInstance step into the beginPhase
8135 // to consolidate.
8136 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
8137 // If changes to the hydrated node needs to be applied at the
8138 // commit-phase we mark this as such.
8139 markUpdate(workInProgress);
8140 }
8141 } else {
8142 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
8143
8144 appendAllChildren(instance, workInProgress, false, false);
8145
8146 // Certain renderers require commit-time effects for initial mount.
8147 // (eg DOM renderer supports auto-focus for certain elements).
8148 // Make sure such renderers get scheduled for later work.
8149 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
8150 markUpdate(workInProgress);
8151 }
8152 workInProgress.stateNode = instance;
8153 }
8154
8155 if (workInProgress.ref !== null) {
8156 // If there is a ref on a host node we need to schedule a callback
8157 markRef$1(workInProgress);
8158 }
8159 }
8160 break;
8161 }
8162 case HostText:
8163 {
8164 var newText = newProps;
8165 if (current && workInProgress.stateNode != null) {
8166 var oldText = current.memoizedProps;
8167 // If we have an alternate, that means this is an update and we need
8168 // to schedule a side-effect to do the updates.
8169 updateHostText$1(current, workInProgress, oldText, newText);
8170 } else {
8171 if (typeof newText !== 'string') {
8172 !(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;
8173 // This can happen when we abort work.
8174 }
8175 var _rootContainerInstance = getRootHostContainer();
8176 var _currentHostContext = getHostContext();
8177 var _wasHydrated = popHydrationState(workInProgress);
8178 if (_wasHydrated) {
8179 if (prepareToHydrateHostTextInstance(workInProgress)) {
8180 markUpdate(workInProgress);
8181 }
8182 } else {
8183 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
8184 }
8185 }
8186 break;
8187 }
8188 case ForwardRef:
8189 break;
8190 case SuspenseComponent:
8191 {
8192 var nextState = workInProgress.memoizedState;
8193 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
8194 // Something suspended. Re-render with the fallback children.
8195 workInProgress.expirationTime = renderExpirationTime;
8196 // Do not reset the effect list.
8197 return workInProgress;
8198 }
8199
8200 var nextDidTimeout = nextState !== null;
8201 var prevDidTimeout = current !== null && current.memoizedState !== null;
8202
8203 if (current !== null && !nextDidTimeout && prevDidTimeout) {
8204 // We just switched from the fallback to the normal children. Delete
8205 // the fallback.
8206 // TODO: Would it be better to store the fallback fragment on
8207 var currentFallbackChild = current.child.sibling;
8208 if (currentFallbackChild !== null) {
8209 // Deletions go at the beginning of the return fiber's effect list
8210 var first = workInProgress.firstEffect;
8211 if (first !== null) {
8212 workInProgress.firstEffect = currentFallbackChild;
8213 currentFallbackChild.nextEffect = first;
8214 } else {
8215 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
8216 currentFallbackChild.nextEffect = null;
8217 }
8218 currentFallbackChild.effectTag = Deletion;
8219 }
8220 }
8221
8222 // The children either timed out after previously being visible, or
8223 // were restored after previously being hidden. Schedule an effect
8224 // to update their visiblity.
8225 if (
8226 //
8227 nextDidTimeout !== prevDidTimeout ||
8228 // Outside concurrent mode, the primary children commit in an
8229 // inconsistent state, even if they are hidden. So if they are hidden,
8230 // we need to schedule an effect to re-hide them, just in case.
8231 (workInProgress.effectTag & ConcurrentMode) === NoContext && nextDidTimeout) {
8232 workInProgress.effectTag |= Update;
8233 }
8234 break;
8235 }
8236 case Fragment:
8237 break;
8238 case Mode:
8239 break;
8240 case Profiler:
8241 break;
8242 case HostPortal:
8243 popHostContainer(workInProgress);
8244 updateHostContainer(workInProgress);
8245 break;
8246 case ContextProvider:
8247 // Pop provider fiber
8248 popProvider(workInProgress);
8249 break;
8250 case ContextConsumer:
8251 break;
8252 case MemoComponent:
8253 break;
8254 case IncompleteClassComponent:
8255 {
8256 // Same as class component case. I put it down here so that the tags are
8257 // sequential to ensure this switch is compiled to a jump table.
8258 var _Component = workInProgress.type;
8259 if (isContextProvider(_Component)) {
8260 popContext(workInProgress);
8261 }
8262 break;
8263 }
8264 default:
8265 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
8266 }
8267
8268 return null;
8269}
8270
8271function shouldCaptureSuspense(workInProgress) {
8272 // In order to capture, the Suspense component must have a fallback prop.
8273 if (workInProgress.memoizedProps.fallback === undefined) {
8274 return false;
8275 }
8276 // If it was the primary children that just suspended, capture and render the
8277 // fallback. Otherwise, don't capture and bubble to the next boundary.
8278 var nextState = workInProgress.memoizedState;
8279 return nextState === null;
8280}
8281
8282// This module is forked in different environments.
8283// By default, return `true` to log errors to the console.
8284// Forks can return `false` if this isn't desirable.
8285function showErrorDialog(capturedError) {
8286 return true;
8287}
8288
8289function logCapturedError(capturedError) {
8290 var logError = showErrorDialog(capturedError);
8291
8292 // Allow injected showErrorDialog() to prevent default console.error logging.
8293 // This enables renderers like ReactNative to better manage redbox behavior.
8294 if (logError === false) {
8295 return;
8296 }
8297
8298 var error = capturedError.error;
8299 {
8300 var componentName = capturedError.componentName,
8301 componentStack = capturedError.componentStack,
8302 errorBoundaryName = capturedError.errorBoundaryName,
8303 errorBoundaryFound = capturedError.errorBoundaryFound,
8304 willRetry = capturedError.willRetry;
8305
8306 // Browsers support silencing uncaught errors by calling
8307 // `preventDefault()` in window `error` handler.
8308 // We record this information as an expando on the error.
8309
8310 if (error != null && error._suppressLogging) {
8311 if (errorBoundaryFound && willRetry) {
8312 // The error is recoverable and was silenced.
8313 // Ignore it and don't print the stack addendum.
8314 // This is handy for testing error boundaries without noise.
8315 return;
8316 }
8317 // The error is fatal. Since the silencing might have
8318 // been accidental, we'll surface it anyway.
8319 // However, the browser would have silenced the original error
8320 // so we'll print it first, and then print the stack addendum.
8321 console.error(error);
8322 // For a more detailed description of this block, see:
8323 // https://github.com/facebook/react/pull/13384
8324 }
8325
8326 var componentNameMessage = componentName ? 'The above error occurred in the <' + componentName + '> component:' : 'The above error occurred in one of your React components:';
8327
8328 var errorBoundaryMessage = void 0;
8329 // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
8330 if (errorBoundaryFound && errorBoundaryName) {
8331 if (willRetry) {
8332 errorBoundaryMessage = 'React will try to recreate this component tree from scratch ' + ('using the error boundary you provided, ' + errorBoundaryName + '.');
8333 } else {
8334 errorBoundaryMessage = 'This error was initially handled by the error boundary ' + errorBoundaryName + '.\n' + 'Recreating the tree from scratch failed so React will unmount the tree.';
8335 }
8336 } else {
8337 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.';
8338 }
8339 var combinedMessage = '' + componentNameMessage + componentStack + '\n\n' + ('' + errorBoundaryMessage);
8340
8341 // In development, we provide our own message with just the component stack.
8342 // We don't include the original error message and JS stack because the browser
8343 // has already printed it. Even if the application swallows the error, it is still
8344 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
8345 console.error(combinedMessage);
8346 }
8347}
8348
8349var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
8350{
8351 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
8352}
8353
8354var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
8355
8356function logError(boundary, errorInfo) {
8357 var source = errorInfo.source;
8358 var stack = errorInfo.stack;
8359 if (stack === null && source !== null) {
8360 stack = getStackByFiberInDevAndProd(source);
8361 }
8362
8363 var capturedError = {
8364 componentName: source !== null ? getComponentName(source.type) : null,
8365 componentStack: stack !== null ? stack : '',
8366 error: errorInfo.value,
8367 errorBoundary: null,
8368 errorBoundaryName: null,
8369 errorBoundaryFound: false,
8370 willRetry: false
8371 };
8372
8373 if (boundary !== null && boundary.tag === ClassComponent) {
8374 capturedError.errorBoundary = boundary.stateNode;
8375 capturedError.errorBoundaryName = getComponentName(boundary.type);
8376 capturedError.errorBoundaryFound = true;
8377 capturedError.willRetry = true;
8378 }
8379
8380 try {
8381 logCapturedError(capturedError);
8382 } catch (e) {
8383 // This method must not throw, or React internal state will get messed up.
8384 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
8385 // we want to report this error outside of the normal stack as a last resort.
8386 // https://github.com/facebook/react/issues/13188
8387 setTimeout(function () {
8388 throw e;
8389 });
8390 }
8391}
8392
8393var callComponentWillUnmountWithTimer = function (current$$1, instance) {
8394 startPhaseTimer(current$$1, 'componentWillUnmount');
8395 instance.props = current$$1.memoizedProps;
8396 instance.state = current$$1.memoizedState;
8397 instance.componentWillUnmount();
8398 stopPhaseTimer();
8399};
8400
8401// Capture errors so they don't interrupt unmounting.
8402function safelyCallComponentWillUnmount(current$$1, instance) {
8403 {
8404 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
8405 if (hasCaughtError()) {
8406 var unmountError = clearCaughtError();
8407 captureCommitPhaseError(current$$1, unmountError);
8408 }
8409 }
8410}
8411
8412function safelyDetachRef(current$$1) {
8413 var ref = current$$1.ref;
8414 if (ref !== null) {
8415 if (typeof ref === 'function') {
8416 {
8417 invokeGuardedCallback(null, ref, null, null);
8418 if (hasCaughtError()) {
8419 var refError = clearCaughtError();
8420 captureCommitPhaseError(current$$1, refError);
8421 }
8422 }
8423 } else {
8424 ref.current = null;
8425 }
8426 }
8427}
8428
8429function safelyCallDestroy(current$$1, destroy) {
8430 {
8431 invokeGuardedCallback(null, destroy, null);
8432 if (hasCaughtError()) {
8433 var error = clearCaughtError();
8434 captureCommitPhaseError(current$$1, error);
8435 }
8436 }
8437}
8438
8439function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
8440 switch (finishedWork.tag) {
8441 case FunctionComponent:
8442 case ForwardRef:
8443 case SimpleMemoComponent:
8444 {
8445 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
8446 return;
8447 }
8448 case ClassComponent:
8449 {
8450 if (finishedWork.effectTag & Snapshot) {
8451 if (current$$1 !== null) {
8452 var prevProps = current$$1.memoizedProps;
8453 var prevState = current$$1.memoizedState;
8454 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
8455 var instance = finishedWork.stateNode;
8456 // We could update instance props and state here,
8457 // but instead we rely on them being set during last render.
8458 // TODO: revisit this when we implement resuming.
8459 {
8460 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
8461 !(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;
8462 !(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;
8463 }
8464 }
8465 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
8466 {
8467 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
8468 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
8469 didWarnSet.add(finishedWork.type);
8470 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
8471 }
8472 }
8473 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
8474 stopPhaseTimer();
8475 }
8476 }
8477 return;
8478 }
8479 case HostRoot:
8480 case HostComponent:
8481 case HostText:
8482 case HostPortal:
8483 case IncompleteClassComponent:
8484 // Nothing to do for these component types
8485 return;
8486 default:
8487 {
8488 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.');
8489 }
8490 }
8491}
8492
8493function commitHookEffectList(unmountTag, mountTag, finishedWork) {
8494 if (!enableHooks) {
8495 return;
8496 }
8497 var updateQueue = finishedWork.updateQueue;
8498 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
8499 if (lastEffect !== null) {
8500 var firstEffect = lastEffect.next;
8501 var effect = firstEffect;
8502 do {
8503 if ((effect.tag & unmountTag) !== NoEffect$1) {
8504 // Unmount
8505 var destroy = effect.destroy;
8506 effect.destroy = null;
8507 if (destroy !== null) {
8508 destroy();
8509 }
8510 }
8511 if ((effect.tag & mountTag) !== NoEffect$1) {
8512 // Mount
8513 var create = effect.create;
8514 var _destroy = create();
8515 if (typeof _destroy !== 'function') {
8516 {
8517 if (_destroy !== null && _destroy !== undefined) {
8518 warningWithoutStack$1(false, 'useEffect function must return a cleanup function or ' + 'nothing.%s%s', typeof _destroy.then === 'function' ? '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, you may write an async function separately ' + 'and then call it from inside the effect:\n\n' + 'async function fetchComment(commentId) {\n' + ' // You can await here\n' + '}\n\n' + 'useEffect(() => {\n' + ' fetchComment(commentId);\n' + '}, [commentId]);\n\n' + 'In the future, React will provide a more idiomatic solution for data fetching ' + "that doesn't involve writing effects manually." : '', getStackByFiberInDevAndProd(finishedWork));
8519 }
8520 }
8521 _destroy = null;
8522 }
8523 effect.destroy = _destroy;
8524 }
8525 effect = effect.next;
8526 } while (effect !== firstEffect);
8527 }
8528}
8529
8530function commitPassiveHookEffects(finishedWork) {
8531 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
8532 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
8533}
8534
8535function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
8536 switch (finishedWork.tag) {
8537 case FunctionComponent:
8538 case ForwardRef:
8539 case SimpleMemoComponent:
8540 {
8541 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
8542 break;
8543 }
8544 case ClassComponent:
8545 {
8546 var instance = finishedWork.stateNode;
8547 if (finishedWork.effectTag & Update) {
8548 if (current$$1 === null) {
8549 startPhaseTimer(finishedWork, 'componentDidMount');
8550 // We could update instance props and state here,
8551 // but instead we rely on them being set during last render.
8552 // TODO: revisit this when we implement resuming.
8553 {
8554 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
8555 !(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;
8556 !(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;
8557 }
8558 }
8559 instance.componentDidMount();
8560 stopPhaseTimer();
8561 } else {
8562 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
8563 var prevState = current$$1.memoizedState;
8564 startPhaseTimer(finishedWork, 'componentDidUpdate');
8565 // We could update instance props and state here,
8566 // but instead we rely on them being set during last render.
8567 // TODO: revisit this when we implement resuming.
8568 {
8569 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
8570 !(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;
8571 !(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;
8572 }
8573 }
8574 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
8575 stopPhaseTimer();
8576 }
8577 }
8578 var updateQueue = finishedWork.updateQueue;
8579 if (updateQueue !== null) {
8580 {
8581 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
8582 !(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;
8583 !(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;
8584 }
8585 }
8586 // We could update instance props and state here,
8587 // but instead we rely on them being set during last render.
8588 // TODO: revisit this when we implement resuming.
8589 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
8590 }
8591 return;
8592 }
8593 case HostRoot:
8594 {
8595 var _updateQueue = finishedWork.updateQueue;
8596 if (_updateQueue !== null) {
8597 var _instance = null;
8598 if (finishedWork.child !== null) {
8599 switch (finishedWork.child.tag) {
8600 case HostComponent:
8601 _instance = getPublicInstance(finishedWork.child.stateNode);
8602 break;
8603 case ClassComponent:
8604 _instance = finishedWork.child.stateNode;
8605 break;
8606 }
8607 }
8608 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
8609 }
8610 return;
8611 }
8612 case HostComponent:
8613 {
8614 var _instance2 = finishedWork.stateNode;
8615
8616 // Renderers may schedule work to be done after host components are mounted
8617 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
8618 // These effects should only be committed when components are first mounted,
8619 // aka when there is no current/alternate.
8620 if (current$$1 === null && finishedWork.effectTag & Update) {
8621 var type = finishedWork.type;
8622 var props = finishedWork.memoizedProps;
8623
8624 }
8625
8626 return;
8627 }
8628 case HostText:
8629 {
8630 // We have no life-cycles associated with text.
8631 return;
8632 }
8633 case HostPortal:
8634 {
8635 // We have no life-cycles associated with portals.
8636 return;
8637 }
8638 case Profiler:
8639 {
8640 if (enableProfilerTimer) {
8641 var onRender = finishedWork.memoizedProps.onRender;
8642
8643 if (enableSchedulerTracing) {
8644 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
8645 } else {
8646 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
8647 }
8648 }
8649 return;
8650 }
8651 case SuspenseComponent:
8652 break;
8653 case IncompleteClassComponent:
8654 break;
8655 default:
8656 {
8657 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.');
8658 }
8659 }
8660}
8661
8662function hideOrUnhideAllChildren(finishedWork, isHidden) {
8663 if (supportsMutation) {
8664 // We only have the top Fiber that was inserted but we need recurse down its
8665 var node = finishedWork;
8666 while (true) {
8667 if (node.tag === HostComponent) {
8668 var instance = node.stateNode;
8669 if (isHidden) {
8670 hideInstance(instance);
8671 } else {
8672 unhideInstance(node.stateNode, node.memoizedProps);
8673 }
8674 } else if (node.tag === HostText) {
8675 var _instance3 = node.stateNode;
8676 if (isHidden) {
8677 hideTextInstance(_instance3);
8678 } else {
8679 unhideTextInstance(_instance3, node.memoizedProps);
8680 }
8681 } else if (node.tag === SuspenseComponent && node.memoizedState !== null) {
8682 // Found a nested Suspense component that timed out. Skip over the
8683 var fallbackChildFragment = node.child.sibling;
8684 fallbackChildFragment.return = node;
8685 node = fallbackChildFragment;
8686 continue;
8687 } else if (node.child !== null) {
8688 node.child.return = node;
8689 node = node.child;
8690 continue;
8691 }
8692 if (node === finishedWork) {
8693 return;
8694 }
8695 while (node.sibling === null) {
8696 if (node.return === null || node.return === finishedWork) {
8697 return;
8698 }
8699 node = node.return;
8700 }
8701 node.sibling.return = node.return;
8702 node = node.sibling;
8703 }
8704 }
8705}
8706
8707function commitAttachRef(finishedWork) {
8708 var ref = finishedWork.ref;
8709 if (ref !== null) {
8710 var instance = finishedWork.stateNode;
8711 var instanceToUse = void 0;
8712 switch (finishedWork.tag) {
8713 case HostComponent:
8714 instanceToUse = getPublicInstance(instance);
8715 break;
8716 default:
8717 instanceToUse = instance;
8718 }
8719 if (typeof ref === 'function') {
8720 ref(instanceToUse);
8721 } else {
8722 {
8723 if (!ref.hasOwnProperty('current')) {
8724 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
8725 }
8726 }
8727
8728 ref.current = instanceToUse;
8729 }
8730 }
8731}
8732
8733function commitDetachRef(current$$1) {
8734 var currentRef = current$$1.ref;
8735 if (currentRef !== null) {
8736 if (typeof currentRef === 'function') {
8737 currentRef(null);
8738 } else {
8739 currentRef.current = null;
8740 }
8741 }
8742}
8743
8744// User-originating errors (lifecycles and refs) should not interrupt
8745// deletion, so don't let them throw. Host-originating errors should
8746// interrupt deletion, so it's okay
8747function commitUnmount(current$$1) {
8748 onCommitUnmount(current$$1);
8749
8750 switch (current$$1.tag) {
8751 case FunctionComponent:
8752 case ForwardRef:
8753 case MemoComponent:
8754 case SimpleMemoComponent:
8755 {
8756 var updateQueue = current$$1.updateQueue;
8757 if (updateQueue !== null) {
8758 var lastEffect = updateQueue.lastEffect;
8759 if (lastEffect !== null) {
8760 var firstEffect = lastEffect.next;
8761 var effect = firstEffect;
8762 do {
8763 var destroy = effect.destroy;
8764 if (destroy !== null) {
8765 safelyCallDestroy(current$$1, destroy);
8766 }
8767 effect = effect.next;
8768 } while (effect !== firstEffect);
8769 }
8770 }
8771 break;
8772 }
8773 case ClassComponent:
8774 {
8775 safelyDetachRef(current$$1);
8776 var instance = current$$1.stateNode;
8777 if (typeof instance.componentWillUnmount === 'function') {
8778 safelyCallComponentWillUnmount(current$$1, instance);
8779 }
8780 return;
8781 }
8782 case HostComponent:
8783 {
8784 safelyDetachRef(current$$1);
8785 return;
8786 }
8787 case HostPortal:
8788 {
8789 // TODO: this is recursive.
8790 // We are also not using this parent because
8791 // the portal will get pushed immediately.
8792 if (supportsMutation) {
8793 unmountHostComponents(current$$1);
8794 } else if (supportsPersistence) {
8795 emptyPortalContainer(current$$1);
8796 }
8797 return;
8798 }
8799 }
8800}
8801
8802function commitNestedUnmounts(root) {
8803 // While we're inside a removed host node we don't want to call
8804 // removeChild on the inner nodes because they're removed by the top
8805 // call anyway. We also want to call componentWillUnmount on all
8806 // composites before this host node is removed from the tree. Therefore
8807 var node = root;
8808 while (true) {
8809 commitUnmount(node);
8810 // Visit children because they may contain more composite or host nodes.
8811 // Skip portals because commitUnmount() currently visits them recursively.
8812 if (node.child !== null && (
8813 // If we use mutation we drill down into portals using commitUnmount above.
8814 // If we don't use mutation we drill down into portals here instead.
8815 !supportsMutation || node.tag !== HostPortal)) {
8816 node.child.return = node;
8817 node = node.child;
8818 continue;
8819 }
8820 if (node === root) {
8821 return;
8822 }
8823 while (node.sibling === null) {
8824 if (node.return === null || node.return === root) {
8825 return;
8826 }
8827 node = node.return;
8828 }
8829 node.sibling.return = node.return;
8830 node = node.sibling;
8831 }
8832}
8833
8834function detachFiber(current$$1) {
8835 // Cut off the return pointers to disconnect it from the tree. Ideally, we
8836 // should clear the child pointer of the parent alternate to let this
8837 // get GC:ed but we don't know which for sure which parent is the current
8838 // one so we'll settle for GC:ing the subtree of this child. This child
8839 // itself will be GC:ed when the parent updates the next time.
8840 current$$1.return = null;
8841 current$$1.child = null;
8842 current$$1.memoizedState = null;
8843 current$$1.updateQueue = null;
8844 var alternate = current$$1.alternate;
8845 if (alternate !== null) {
8846 alternate.return = null;
8847 alternate.child = null;
8848 alternate.memoizedState = null;
8849 alternate.updateQueue = null;
8850 }
8851}
8852
8853function emptyPortalContainer(current$$1) {
8854 if (!supportsPersistence) {
8855 return;
8856 }
8857
8858 var portal = current$$1.stateNode;
8859 var containerInfo = portal.containerInfo;
8860
8861 var emptyChildSet = createContainerChildSet(containerInfo);
8862 replaceContainerChildren(containerInfo, emptyChildSet);
8863}
8864
8865function commitContainer(finishedWork) {
8866 if (!supportsPersistence) {
8867 return;
8868 }
8869
8870 switch (finishedWork.tag) {
8871 case ClassComponent:
8872 {
8873 return;
8874 }
8875 case HostComponent:
8876 {
8877 return;
8878 }
8879 case HostText:
8880 {
8881 return;
8882 }
8883 case HostRoot:
8884 case HostPortal:
8885 {
8886 var portalOrRoot = finishedWork.stateNode;
8887 var containerInfo = portalOrRoot.containerInfo,
8888 _pendingChildren = portalOrRoot.pendingChildren;
8889
8890 replaceContainerChildren(containerInfo, _pendingChildren);
8891 return;
8892 }
8893 default:
8894 {
8895 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.');
8896 }
8897 }
8898}
8899
8900function getHostParentFiber(fiber) {
8901 var parent = fiber.return;
8902 while (parent !== null) {
8903 if (isHostParent(parent)) {
8904 return parent;
8905 }
8906 parent = parent.return;
8907 }
8908 invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.');
8909}
8910
8911function isHostParent(fiber) {
8912 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
8913}
8914
8915function getHostSibling(fiber) {
8916 // We're going to search forward into the tree until we find a sibling host
8917 // node. Unfortunately, if multiple insertions are done in a row we have to
8918 // search past them. This leads to exponential search for the next sibling.
8919 var node = fiber;
8920 siblings: while (true) {
8921 // If we didn't find anything, let's try the next sibling.
8922 while (node.sibling === null) {
8923 if (node.return === null || isHostParent(node.return)) {
8924 // If we pop out of the root or hit the parent the fiber we are the
8925 // last sibling.
8926 return null;
8927 }
8928 node = node.return;
8929 }
8930 node.sibling.return = node.return;
8931 node = node.sibling;
8932 while (node.tag !== HostComponent && node.tag !== HostText) {
8933 // If it is not host node and, we might have a host node inside it.
8934 // Try to search down until we find one.
8935 if (node.effectTag & Placement) {
8936 // If we don't have a child, try the siblings instead.
8937 continue siblings;
8938 }
8939 // If we don't have a child, try the siblings instead.
8940 // We also skip portals because they are not part of this host tree.
8941 if (node.child === null || node.tag === HostPortal) {
8942 continue siblings;
8943 } else {
8944 node.child.return = node;
8945 node = node.child;
8946 }
8947 }
8948 // Check if this host node is stable or about to be placed.
8949 if (!(node.effectTag & Placement)) {
8950 // Found it!
8951 return node.stateNode;
8952 }
8953 }
8954}
8955
8956function commitPlacement(finishedWork) {
8957 if (!supportsMutation) {
8958 return;
8959 }
8960
8961 // Recursively insert all host nodes into the parent.
8962 var parentFiber = getHostParentFiber(finishedWork);
8963
8964 // Note: these two variables *must* always be updated together.
8965 var parent = void 0;
8966 var isContainer = void 0;
8967
8968 switch (parentFiber.tag) {
8969 case HostComponent:
8970 parent = parentFiber.stateNode;
8971 isContainer = false;
8972 break;
8973 case HostRoot:
8974 parent = parentFiber.stateNode.containerInfo;
8975 isContainer = true;
8976 break;
8977 case HostPortal:
8978 parent = parentFiber.stateNode.containerInfo;
8979 isContainer = true;
8980 break;
8981 default:
8982 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
8983 }
8984 if (parentFiber.effectTag & ContentReset) {
8985 // Reset the text content of the parent before doing any insertions
8986 parentFiber.effectTag &= ~ContentReset;
8987 }
8988
8989 var before = getHostSibling(finishedWork);
8990 // We only have the top Fiber that was inserted but we need recurse down its
8991 // children to find all the terminal nodes.
8992 var node = finishedWork;
8993 while (true) {
8994 if (node.tag === HostComponent || node.tag === HostText) {
8995 if (before) {
8996 if (isContainer) {
8997 insertInContainerBefore(parent, node.stateNode, before);
8998 } else {
8999 insertBefore(parent, node.stateNode, before);
9000 }
9001 } else {
9002 if (isContainer) {
9003 appendChildToContainer(parent, node.stateNode);
9004 } else {
9005 appendChild(parent, node.stateNode);
9006 }
9007 }
9008 } else if (node.tag === HostPortal) {
9009 // If the insertion itself is a portal, then we don't want to traverse
9010 // down its children. Instead, we'll get insertions from each child in
9011 // the portal directly.
9012 } else if (node.child !== null) {
9013 node.child.return = node;
9014 node = node.child;
9015 continue;
9016 }
9017 if (node === finishedWork) {
9018 return;
9019 }
9020 while (node.sibling === null) {
9021 if (node.return === null || node.return === finishedWork) {
9022 return;
9023 }
9024 node = node.return;
9025 }
9026 node.sibling.return = node.return;
9027 node = node.sibling;
9028 }
9029}
9030
9031function unmountHostComponents(current$$1) {
9032 // We only have the top Fiber that was deleted but we need recurse down its
9033 var node = current$$1;
9034
9035 // Each iteration, currentParent is populated with node's host parent if not
9036 // currentParentIsValid.
9037 var currentParentIsValid = false;
9038
9039 // Note: these two variables *must* always be updated together.
9040 var currentParent = void 0;
9041 var currentParentIsContainer = void 0;
9042
9043 while (true) {
9044 if (!currentParentIsValid) {
9045 var parent = node.return;
9046 findParent: while (true) {
9047 !(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;
9048 switch (parent.tag) {
9049 case HostComponent:
9050 currentParent = parent.stateNode;
9051 currentParentIsContainer = false;
9052 break findParent;
9053 case HostRoot:
9054 currentParent = parent.stateNode.containerInfo;
9055 currentParentIsContainer = true;
9056 break findParent;
9057 case HostPortal:
9058 currentParent = parent.stateNode.containerInfo;
9059 currentParentIsContainer = true;
9060 break findParent;
9061 }
9062 parent = parent.return;
9063 }
9064 currentParentIsValid = true;
9065 }
9066
9067 if (node.tag === HostComponent || node.tag === HostText) {
9068 commitNestedUnmounts(node);
9069 // After all the children have unmounted, it is now safe to remove the
9070 // node from the tree.
9071 if (currentParentIsContainer) {
9072 removeChildFromContainer(currentParent, node.stateNode);
9073 } else {
9074 removeChild(currentParent, node.stateNode);
9075 }
9076 // Don't visit children because we already visited them.
9077 } else if (node.tag === HostPortal) {
9078 // When we go into a portal, it becomes the parent to remove from.
9079 // We will reassign it back when we pop the portal on the way up.
9080 currentParent = node.stateNode.containerInfo;
9081 currentParentIsContainer = true;
9082 // Visit children because portals might contain host components.
9083 if (node.child !== null) {
9084 node.child.return = node;
9085 node = node.child;
9086 continue;
9087 }
9088 } else {
9089 commitUnmount(node);
9090 // Visit children because we may find more host components below.
9091 if (node.child !== null) {
9092 node.child.return = node;
9093 node = node.child;
9094 continue;
9095 }
9096 }
9097 if (node === current$$1) {
9098 return;
9099 }
9100 while (node.sibling === null) {
9101 if (node.return === null || node.return === current$$1) {
9102 return;
9103 }
9104 node = node.return;
9105 if (node.tag === HostPortal) {
9106 // When we go out of the portal, we need to restore the parent.
9107 // Since we don't keep a stack of them, we will search for it.
9108 currentParentIsValid = false;
9109 }
9110 }
9111 node.sibling.return = node.return;
9112 node = node.sibling;
9113 }
9114}
9115
9116function commitDeletion(current$$1) {
9117 if (supportsMutation) {
9118 // Recursively delete all host nodes from the parent.
9119 // Detach refs and call componentWillUnmount() on the whole subtree.
9120 unmountHostComponents(current$$1);
9121 } else {
9122 // Detach refs and call componentWillUnmount() on the whole subtree.
9123 commitNestedUnmounts(current$$1);
9124 }
9125 detachFiber(current$$1);
9126}
9127
9128function commitWork(current$$1, finishedWork) {
9129 if (!supportsMutation) {
9130 switch (finishedWork.tag) {
9131 case FunctionComponent:
9132 case ForwardRef:
9133 case MemoComponent:
9134 case SimpleMemoComponent:
9135 {
9136 // Note: We currently never use MountMutation, but useLayout uses
9137 // UnmountMutation.
9138 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
9139 return;
9140 }
9141 }
9142
9143 commitContainer(finishedWork);
9144 return;
9145 }
9146
9147 switch (finishedWork.tag) {
9148 case FunctionComponent:
9149 case ForwardRef:
9150 case MemoComponent:
9151 case SimpleMemoComponent:
9152 {
9153 // Note: We currently never use MountMutation, but useLayout uses
9154 // UnmountMutation.
9155 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
9156 return;
9157 }
9158 case ClassComponent:
9159 {
9160 return;
9161 }
9162 case HostComponent:
9163 {
9164 var instance = finishedWork.stateNode;
9165 if (instance != null) {
9166 // Commit the work prepared earlier.
9167 var newProps = finishedWork.memoizedProps;
9168 // For hydration we reuse the update path but we treat the oldProps
9169 // as the newProps. The updatePayload will contain the real change in
9170 // this case.
9171 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
9172 var type = finishedWork.type;
9173 // TODO: Type the updateQueue to be specific to host components.
9174 var updatePayload = finishedWork.updateQueue;
9175 finishedWork.updateQueue = null;
9176 if (updatePayload !== null) {
9177 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
9178 }
9179 }
9180 return;
9181 }
9182 case HostText:
9183 {
9184 !(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;
9185 var textInstance = finishedWork.stateNode;
9186 var newText = finishedWork.memoizedProps;
9187 // For hydration we reuse the update path but we treat the oldProps
9188 // as the newProps. The updatePayload will contain the real change in
9189 // this case.
9190 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
9191 commitTextUpdate(textInstance, oldText, newText);
9192 return;
9193 }
9194 case HostRoot:
9195 {
9196 return;
9197 }
9198 case Profiler:
9199 {
9200 return;
9201 }
9202 case SuspenseComponent:
9203 {
9204 var newState = finishedWork.memoizedState;
9205
9206 var newDidTimeout = void 0;
9207 var primaryChildParent = finishedWork;
9208 if (newState === null) {
9209 newDidTimeout = false;
9210 } else {
9211 newDidTimeout = true;
9212 primaryChildParent = finishedWork.child;
9213 if (newState.timedOutAt === NoWork) {
9214 // If the children had not already timed out, record the time.
9215 // This is used to compute the elapsed time during subsequent
9216 // attempts to render the children.
9217 newState.timedOutAt = requestCurrentTime();
9218 }
9219 }
9220
9221 if (primaryChildParent !== null) {
9222 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
9223 }
9224
9225 // If this boundary just timed out, then it will have a set of thenables.
9226 // For each thenable, attach a listener so that when it resolves, React
9227 // attempts to re-render the boundary in the primary (pre-timeout) state.
9228 var thenables = finishedWork.updateQueue;
9229 if (thenables !== null) {
9230 finishedWork.updateQueue = null;
9231 var retryCache = finishedWork.stateNode;
9232 if (retryCache === null) {
9233 retryCache = finishedWork.stateNode = new PossiblyWeakSet();
9234 }
9235 thenables.forEach(function (thenable) {
9236 // Memoize using the boundary fiber to prevent redundant listeners.
9237 var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable);
9238 if (enableSchedulerTracing) {
9239 retry = unstable_wrap(retry);
9240 }
9241 if (!retryCache.has(thenable)) {
9242 retryCache.add(thenable);
9243 thenable.then(retry, retry);
9244 }
9245 });
9246 }
9247
9248 return;
9249 }
9250 case IncompleteClassComponent:
9251 {
9252 return;
9253 }
9254 default:
9255 {
9256 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.');
9257 }
9258 }
9259}
9260
9261function commitResetTextContent(current$$1) {
9262 if (!supportsMutation) {
9263 return;
9264 }
9265 resetTextContent(current$$1.stateNode);
9266}
9267
9268var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
9269
9270function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
9271 var update = createUpdate(expirationTime);
9272 // Unmount the root by rendering null.
9273 update.tag = CaptureUpdate;
9274 // Caution: React DevTools currently depends on this property
9275 // being called "element".
9276 update.payload = { element: null };
9277 var error = errorInfo.value;
9278 update.callback = function () {
9279 onUncaughtError(error);
9280 logError(fiber, errorInfo);
9281 };
9282 return update;
9283}
9284
9285function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
9286 var update = createUpdate(expirationTime);
9287 update.tag = CaptureUpdate;
9288 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
9289 if (typeof getDerivedStateFromError === 'function') {
9290 var error = errorInfo.value;
9291 update.payload = function () {
9292 return getDerivedStateFromError(error);
9293 };
9294 }
9295
9296 var inst = fiber.stateNode;
9297 if (inst !== null && typeof inst.componentDidCatch === 'function') {
9298 update.callback = function callback() {
9299 if (typeof getDerivedStateFromError !== 'function') {
9300 // To preserve the preexisting retry behavior of error boundaries,
9301 // we keep track of which ones already failed during this batch.
9302 // This gets reset before we yield back to the browser.
9303 // TODO: Warn in strict mode if getDerivedStateFromError is
9304 // not defined.
9305 markLegacyErrorBoundaryAsFailed(this);
9306 }
9307 var error = errorInfo.value;
9308 var stack = errorInfo.stack;
9309 logError(fiber, errorInfo);
9310 this.componentDidCatch(error, {
9311 componentStack: stack !== null ? stack : ''
9312 });
9313 {
9314 if (typeof getDerivedStateFromError !== 'function') {
9315 // If componentDidCatch is the only error boundary method defined,
9316 // then it needs to call setState to recover from errors.
9317 // If no state update is scheduled then the boundary will swallow the error.
9318 !(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;
9319 }
9320 }
9321 };
9322 }
9323 return update;
9324}
9325
9326function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
9327 // The source fiber did not complete.
9328 sourceFiber.effectTag |= Incomplete;
9329 // Its effect list is no longer valid.
9330 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
9331
9332 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
9333 // This is a thenable.
9334 var thenable = value;
9335
9336 // Find the earliest timeout threshold of all the placeholders in the
9337 // ancestor path. We could avoid this traversal by storing the thresholds on
9338 // the stack, but we choose not to because we only hit this path if we're
9339 // IO-bound (i.e. if something suspends). Whereas the stack is used even in
9340 // the non-IO- bound case.
9341 var _workInProgress = returnFiber;
9342 var earliestTimeoutMs = -1;
9343 var startTimeMs = -1;
9344 do {
9345 if (_workInProgress.tag === SuspenseComponent) {
9346 var current$$1 = _workInProgress.alternate;
9347 if (current$$1 !== null) {
9348 var currentState = current$$1.memoizedState;
9349 if (currentState !== null) {
9350 // Reached a boundary that already timed out. Do not search
9351 // any further.
9352 var timedOutAt = currentState.timedOutAt;
9353 startTimeMs = expirationTimeToMs(timedOutAt);
9354 // Do not search any further.
9355 break;
9356 }
9357 }
9358 var timeoutPropMs = _workInProgress.pendingProps.maxDuration;
9359 if (typeof timeoutPropMs === 'number') {
9360 if (timeoutPropMs <= 0) {
9361 earliestTimeoutMs = 0;
9362 } else if (earliestTimeoutMs === -1 || timeoutPropMs < earliestTimeoutMs) {
9363 earliestTimeoutMs = timeoutPropMs;
9364 }
9365 }
9366 }
9367 _workInProgress = _workInProgress.return;
9368 } while (_workInProgress !== null);
9369
9370 // Schedule the nearest Suspense to re-render the timed out view.
9371 _workInProgress = returnFiber;
9372 do {
9373 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress)) {
9374 // Found the nearest boundary.
9375
9376 // Stash the promise on the boundary fiber. If the boundary times out, we'll
9377 var thenables = _workInProgress.updateQueue;
9378 if (thenables === null) {
9379 _workInProgress.updateQueue = new Set([thenable]);
9380 } else {
9381 thenables.add(thenable);
9382 }
9383
9384 // If the boundary is outside of concurrent mode, we should *not*
9385 // suspend the commit. Pretend as if the suspended component rendered
9386 // null and keep rendering. In the commit phase, we'll schedule a
9387 // subsequent synchronous update to re-render the Suspense.
9388 //
9389 // Note: It doesn't matter whether the component that suspended was
9390 // inside a concurrent mode tree. If the Suspense is outside of it, we
9391 // should *not* suspend the commit.
9392 if ((_workInProgress.mode & ConcurrentMode) === NoEffect) {
9393 _workInProgress.effectTag |= DidCapture;
9394
9395 // We're going to commit this fiber even though it didn't complete.
9396 // But we shouldn't call any lifecycle methods or callbacks. Remove
9397 // all lifecycle effect tags.
9398 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
9399
9400 if (sourceFiber.tag === ClassComponent) {
9401 var currentSourceFiber = sourceFiber.alternate;
9402 if (currentSourceFiber === null) {
9403 // This is a new mount. Change the tag so it's not mistaken for a
9404 // completed class component. For example, we should not call
9405 // componentWillUnmount if it is deleted.
9406 sourceFiber.tag = IncompleteClassComponent;
9407 } else {
9408 // When we try rendering again, we should not reuse the current fiber,
9409 // since it's known to be in an inconsistent state. Use a force updte to
9410 // prevent a bail out.
9411 var update = createUpdate(Sync);
9412 update.tag = ForceUpdate;
9413 enqueueUpdate(sourceFiber, update);
9414 }
9415 }
9416
9417 // The source fiber did not complete. Mark it with Sync priority to
9418 // indicate that it still has pending work.
9419 sourceFiber.expirationTime = Sync;
9420
9421 // Exit without suspending.
9422 return;
9423 }
9424
9425 // Confirmed that the boundary is in a concurrent mode tree. Continue
9426 // with the normal suspend path.
9427
9428 // Attach a listener to the promise to "ping" the root and retry. But
9429 // only if one does not already exist for the current render expiration
9430 // time (which acts like a "thread ID" here).
9431 var pingCache = root.pingCache;
9432 var threadIDs = void 0;
9433 if (pingCache === null) {
9434 pingCache = root.pingCache = new PossiblyWeakMap();
9435 threadIDs = new Set();
9436 pingCache.set(thenable, threadIDs);
9437 } else {
9438 threadIDs = pingCache.get(thenable);
9439 if (threadIDs === undefined) {
9440 threadIDs = new Set();
9441 pingCache.set(thenable, threadIDs);
9442 }
9443 }
9444 if (!threadIDs.has(renderExpirationTime)) {
9445 // Memoize using the thread ID to prevent redundant listeners.
9446 threadIDs.add(renderExpirationTime);
9447 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
9448 if (enableSchedulerTracing) {
9449 ping = unstable_wrap(ping);
9450 }
9451 thenable.then(ping, ping);
9452 }
9453
9454 var absoluteTimeoutMs = void 0;
9455 if (earliestTimeoutMs === -1) {
9456 // If no explicit threshold is given, default to an abitrarily large
9457 // value. The actual size doesn't matter because the threshold for the
9458 // whole tree will be clamped to the expiration time.
9459 absoluteTimeoutMs = maxSigned31BitInt;
9460 } else {
9461 if (startTimeMs === -1) {
9462 // This suspend happened outside of any already timed-out
9463 // placeholders. We don't know exactly when the update was
9464 // scheduled, but we can infer an approximate start time from the
9465 // expiration time. First, find the earliest uncommitted expiration
9466 // time in the tree, including work that is suspended. Then subtract
9467 // the offset used to compute an async update's expiration time.
9468 // This will cause high priority (interactive) work to expire
9469 // earlier than necessary, but we can account for this by adjusting
9470 // for the Just Noticeable Difference.
9471 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, renderExpirationTime);
9472 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
9473 startTimeMs = earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
9474 }
9475 absoluteTimeoutMs = startTimeMs + earliestTimeoutMs;
9476 }
9477
9478 // Mark the earliest timeout in the suspended fiber's ancestor path.
9479 // After completing the root, we'll take the largest of all the
9480 // suspended fiber's timeouts and use it to compute a timeout for the
9481 // whole tree.
9482 renderDidSuspend(root, absoluteTimeoutMs, renderExpirationTime);
9483
9484 _workInProgress.effectTag |= ShouldCapture;
9485 _workInProgress.expirationTime = renderExpirationTime;
9486 return;
9487 }
9488 // This boundary already captured during this render. Continue to the next
9489 // boundary.
9490 _workInProgress = _workInProgress.return;
9491 } while (_workInProgress !== null);
9492 // No boundary was found. Fallthrough to error mode.
9493 // TODO: Use invariant so the message is stripped in prod?
9494 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));
9495 }
9496
9497 // We didn't find a boundary that could handle this type of exception. Start
9498 // over and traverse parent path again, this time treating the exception
9499 // as an error.
9500 renderDidError();
9501 value = createCapturedValue(value, sourceFiber);
9502 var workInProgress = returnFiber;
9503 do {
9504 switch (workInProgress.tag) {
9505 case HostRoot:
9506 {
9507 var _errorInfo = value;
9508 workInProgress.effectTag |= ShouldCapture;
9509 workInProgress.expirationTime = renderExpirationTime;
9510 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
9511 enqueueCapturedUpdate(workInProgress, _update);
9512 return;
9513 }
9514 case ClassComponent:
9515 // Capture and retry
9516 var errorInfo = value;
9517 var ctor = workInProgress.type;
9518 var instance = workInProgress.stateNode;
9519 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
9520 workInProgress.effectTag |= ShouldCapture;
9521 workInProgress.expirationTime = renderExpirationTime;
9522 // Schedule the error boundary to re-render using updated state
9523 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
9524 enqueueCapturedUpdate(workInProgress, _update2);
9525 return;
9526 }
9527 break;
9528 default:
9529 break;
9530 }
9531 workInProgress = workInProgress.return;
9532 } while (workInProgress !== null);
9533}
9534
9535function unwindWork(workInProgress, renderExpirationTime) {
9536 switch (workInProgress.tag) {
9537 case ClassComponent:
9538 {
9539 var Component = workInProgress.type;
9540 if (isContextProvider(Component)) {
9541 popContext(workInProgress);
9542 }
9543 var effectTag = workInProgress.effectTag;
9544 if (effectTag & ShouldCapture) {
9545 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
9546 return workInProgress;
9547 }
9548 return null;
9549 }
9550 case HostRoot:
9551 {
9552 popHostContainer(workInProgress);
9553 popTopLevelContextObject(workInProgress);
9554 var _effectTag = workInProgress.effectTag;
9555 !((_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;
9556 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
9557 return workInProgress;
9558 }
9559 case HostComponent:
9560 {
9561 popHostContext(workInProgress);
9562 return null;
9563 }
9564 case SuspenseComponent:
9565 {
9566 var _effectTag2 = workInProgress.effectTag;
9567 if (_effectTag2 & ShouldCapture) {
9568 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture;
9569 // Captured a suspense effect. Re-render the boundary.
9570 return workInProgress;
9571 }
9572 return null;
9573 }
9574 case HostPortal:
9575 popHostContainer(workInProgress);
9576 return null;
9577 case ContextProvider:
9578 popProvider(workInProgress);
9579 return null;
9580 default:
9581 return null;
9582 }
9583}
9584
9585function unwindInterruptedWork(interruptedWork) {
9586 switch (interruptedWork.tag) {
9587 case ClassComponent:
9588 {
9589 var childContextTypes = interruptedWork.type.childContextTypes;
9590 if (childContextTypes !== null && childContextTypes !== undefined) {
9591 popContext(interruptedWork);
9592 }
9593 break;
9594 }
9595 case HostRoot:
9596 {
9597 popHostContainer(interruptedWork);
9598 popTopLevelContextObject(interruptedWork);
9599 break;
9600 }
9601 case HostComponent:
9602 {
9603 popHostContext(interruptedWork);
9604 break;
9605 }
9606 case HostPortal:
9607 popHostContainer(interruptedWork);
9608 break;
9609 case ContextProvider:
9610 popProvider(interruptedWork);
9611 break;
9612 default:
9613 break;
9614 }
9615}
9616
9617var Dispatcher = {
9618 readContext: readContext,
9619 useCallback: useCallback,
9620 useContext: useContext,
9621 useEffect: useEffect,
9622 useImperativeMethods: useImperativeMethods,
9623 useLayoutEffect: useLayoutEffect,
9624 useMemo: useMemo,
9625 useReducer: useReducer,
9626 useRef: useRef,
9627 useState: useState
9628};
9629var DispatcherWithoutHooks = {
9630 readContext: readContext
9631};
9632
9633var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
9634
9635
9636var didWarnAboutStateTransition = void 0;
9637var didWarnSetStateChildContext = void 0;
9638var warnAboutUpdateOnUnmounted = void 0;
9639var warnAboutInvalidUpdates = void 0;
9640
9641if (enableSchedulerTracing) {
9642 // Provide explicit error message when production+profiling bundle of e.g. react-dom
9643 // is used with production (non-profiling) bundle of scheduler/tracing
9644 !(__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;
9645}
9646
9647{
9648 didWarnAboutStateTransition = false;
9649 didWarnSetStateChildContext = false;
9650 var didWarnStateUpdateForUnmountedComponent = {};
9651
9652 warnAboutUpdateOnUnmounted = function (fiber, isClass) {
9653 // We show the whole stack but dedupe on the top component's name because
9654 // the problematic code almost always lies inside that component.
9655 var componentName = getComponentName(fiber.type) || 'ReactComponent';
9656 if (didWarnStateUpdateForUnmountedComponent[componentName]) {
9657 return;
9658 }
9659 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));
9660 didWarnStateUpdateForUnmountedComponent[componentName] = true;
9661 };
9662
9663 warnAboutInvalidUpdates = function (instance) {
9664 switch (phase) {
9665 case 'getChildContext':
9666 if (didWarnSetStateChildContext) {
9667 return;
9668 }
9669 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
9670 didWarnSetStateChildContext = true;
9671 break;
9672 case 'render':
9673 if (didWarnAboutStateTransition) {
9674 return;
9675 }
9676 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.');
9677 didWarnAboutStateTransition = true;
9678 break;
9679 }
9680 };
9681}
9682
9683// Represents the expiration time that incoming updates should use. (If this
9684// is NoWork, use the default strategy: async updates in async mode, sync
9685// updates in sync mode.)
9686var expirationContext = NoWork;
9687
9688var isWorking = false;
9689
9690// The next work in progress fiber that we're currently working on.
9691var nextUnitOfWork = null;
9692var nextRoot = null;
9693// The time at which we're currently rendering work.
9694var nextRenderExpirationTime = NoWork;
9695var nextLatestAbsoluteTimeoutMs = -1;
9696var nextRenderDidError = false;
9697
9698// The next fiber with an effect that we're currently committing.
9699var nextEffect = null;
9700
9701var isCommitting$1 = false;
9702var rootWithPendingPassiveEffects = null;
9703var passiveEffectCallbackHandle = null;
9704var passiveEffectCallback = null;
9705
9706var legacyErrorBoundariesThatAlreadyFailed = null;
9707
9708// Used for performance tracking.
9709var interruptedBy = null;
9710
9711var stashedWorkInProgressProperties = void 0;
9712var replayUnitOfWork = void 0;
9713var mayReplayFailedUnitOfWork = void 0;
9714var isReplayingFailedUnitOfWork = void 0;
9715var originalReplayError = void 0;
9716var rethrowOriginalError = void 0;
9717if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
9718 stashedWorkInProgressProperties = null;
9719 mayReplayFailedUnitOfWork = true;
9720 isReplayingFailedUnitOfWork = false;
9721 originalReplayError = null;
9722 replayUnitOfWork = function (failedUnitOfWork, thrownValue, isYieldy) {
9723 if (thrownValue !== null && typeof thrownValue === 'object' && typeof thrownValue.then === 'function') {
9724 // Don't replay promises. Treat everything else like an error.
9725 // TODO: Need to figure out a different strategy if/when we add
9726 // support for catching other types.
9727 return;
9728 }
9729
9730 // Restore the original state of the work-in-progress
9731 if (stashedWorkInProgressProperties === null) {
9732 // This should never happen. Don't throw because this code is DEV-only.
9733 warningWithoutStack$1(false, 'Could not replay rendering after an error. This is likely a bug in React. ' + 'Please file an issue.');
9734 return;
9735 }
9736 assignFiberPropertiesInDEV(failedUnitOfWork, stashedWorkInProgressProperties);
9737
9738 switch (failedUnitOfWork.tag) {
9739 case HostRoot:
9740 popHostContainer(failedUnitOfWork);
9741 popTopLevelContextObject(failedUnitOfWork);
9742 break;
9743 case HostComponent:
9744 popHostContext(failedUnitOfWork);
9745 break;
9746 case ClassComponent:
9747 {
9748 var Component = failedUnitOfWork.type;
9749 if (isContextProvider(Component)) {
9750 popContext(failedUnitOfWork);
9751 }
9752 break;
9753 }
9754 case HostPortal:
9755 popHostContainer(failedUnitOfWork);
9756 break;
9757 case ContextProvider:
9758 popProvider(failedUnitOfWork);
9759 break;
9760 }
9761 // Replay the begin phase.
9762 isReplayingFailedUnitOfWork = true;
9763 originalReplayError = thrownValue;
9764 invokeGuardedCallback(null, workLoop, null, isYieldy);
9765 isReplayingFailedUnitOfWork = false;
9766 originalReplayError = null;
9767 if (hasCaughtError()) {
9768 var replayError = clearCaughtError();
9769 if (replayError != null && thrownValue != null) {
9770 try {
9771 // Reading the expando property is intentionally
9772 // inside `try` because it might be a getter or Proxy.
9773 if (replayError._suppressLogging) {
9774 // Also suppress logging for the original error.
9775 thrownValue._suppressLogging = true;
9776 }
9777 } catch (inner) {
9778 // Ignore.
9779 }
9780 }
9781 } else {
9782 // If the begin phase did not fail the second time, set this pointer
9783 // back to the original value.
9784 nextUnitOfWork = failedUnitOfWork;
9785 }
9786 };
9787 rethrowOriginalError = function () {
9788 throw originalReplayError;
9789 };
9790}
9791
9792function resetStack() {
9793 if (nextUnitOfWork !== null) {
9794 var interruptedWork = nextUnitOfWork.return;
9795 while (interruptedWork !== null) {
9796 unwindInterruptedWork(interruptedWork);
9797 interruptedWork = interruptedWork.return;
9798 }
9799 }
9800
9801 {
9802 ReactStrictModeWarnings.discardPendingWarnings();
9803 checkThatStackIsEmpty();
9804 }
9805
9806 nextRoot = null;
9807 nextRenderExpirationTime = NoWork;
9808 nextLatestAbsoluteTimeoutMs = -1;
9809 nextRenderDidError = false;
9810 nextUnitOfWork = null;
9811}
9812
9813function commitAllHostEffects() {
9814 while (nextEffect !== null) {
9815 {
9816 setCurrentFiber(nextEffect);
9817 }
9818 recordEffect();
9819
9820 var effectTag = nextEffect.effectTag;
9821
9822 if (effectTag & ContentReset) {
9823 commitResetTextContent(nextEffect);
9824 }
9825
9826 if (effectTag & Ref) {
9827 var current$$1 = nextEffect.alternate;
9828 if (current$$1 !== null) {
9829 commitDetachRef(current$$1);
9830 }
9831 }
9832
9833 // The following switch statement is only concerned about placement,
9834 // updates, and deletions. To avoid needing to add a case for every
9835 // possible bitmap value, we remove the secondary effects from the
9836 // effect tag and switch on that value.
9837 var primaryEffectTag = effectTag & (Placement | Update | Deletion);
9838 switch (primaryEffectTag) {
9839 case Placement:
9840 {
9841 commitPlacement(nextEffect);
9842 // Clear the "placement" from effect tag so that we know that this is inserted, before
9843 // any life-cycles like componentDidMount gets called.
9844 // TODO: findDOMNode doesn't rely on this any more but isMounted
9845 // does and isMounted is deprecated anyway so we should be able
9846 // to kill this.
9847 nextEffect.effectTag &= ~Placement;
9848 break;
9849 }
9850 case PlacementAndUpdate:
9851 {
9852 // Placement
9853 commitPlacement(nextEffect);
9854 // Clear the "placement" from effect tag so that we know that this is inserted, before
9855 // any life-cycles like componentDidMount gets called.
9856 nextEffect.effectTag &= ~Placement;
9857
9858 // Update
9859 var _current = nextEffect.alternate;
9860 commitWork(_current, nextEffect);
9861 break;
9862 }
9863 case Update:
9864 {
9865 var _current2 = nextEffect.alternate;
9866 commitWork(_current2, nextEffect);
9867 break;
9868 }
9869 case Deletion:
9870 {
9871 commitDeletion(nextEffect);
9872 break;
9873 }
9874 }
9875 nextEffect = nextEffect.nextEffect;
9876 }
9877
9878 {
9879 resetCurrentFiber();
9880 }
9881}
9882
9883function commitBeforeMutationLifecycles() {
9884 while (nextEffect !== null) {
9885 {
9886 setCurrentFiber(nextEffect);
9887 }
9888
9889 var effectTag = nextEffect.effectTag;
9890 if (effectTag & Snapshot) {
9891 recordEffect();
9892 var current$$1 = nextEffect.alternate;
9893 commitBeforeMutationLifeCycles(current$$1, nextEffect);
9894 }
9895
9896 nextEffect = nextEffect.nextEffect;
9897 }
9898
9899 {
9900 resetCurrentFiber();
9901 }
9902}
9903
9904function commitAllLifeCycles(finishedRoot, committedExpirationTime) {
9905 {
9906 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
9907 ReactStrictModeWarnings.flushLegacyContextWarning();
9908
9909 if (warnAboutDeprecatedLifecycles) {
9910 ReactStrictModeWarnings.flushPendingDeprecationWarnings();
9911 }
9912 }
9913 while (nextEffect !== null) {
9914 var effectTag = nextEffect.effectTag;
9915
9916 if (effectTag & (Update | Callback)) {
9917 recordEffect();
9918 var current$$1 = nextEffect.alternate;
9919 commitLifeCycles(finishedRoot, current$$1, nextEffect, committedExpirationTime);
9920 }
9921
9922 if (effectTag & Ref) {
9923 recordEffect();
9924 commitAttachRef(nextEffect);
9925 }
9926
9927 if (enableHooks && effectTag & Passive) {
9928 rootWithPendingPassiveEffects = finishedRoot;
9929 }
9930
9931 nextEffect = nextEffect.nextEffect;
9932 }
9933}
9934
9935function commitPassiveEffects(root, firstEffect) {
9936 rootWithPendingPassiveEffects = null;
9937 passiveEffectCallbackHandle = null;
9938 passiveEffectCallback = null;
9939
9940 // Set this to true to prevent re-entrancy
9941 var previousIsRendering = isRendering;
9942 isRendering = true;
9943
9944 var effect = firstEffect;
9945 do {
9946 if (effect.effectTag & Passive) {
9947 var didError = false;
9948 var error = void 0;
9949 {
9950 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
9951 if (hasCaughtError()) {
9952 didError = true;
9953 error = clearCaughtError();
9954 }
9955 }
9956 if (didError) {
9957 captureCommitPhaseError(effect, error);
9958 }
9959 }
9960 effect = effect.nextEffect;
9961 } while (effect !== null);
9962
9963 isRendering = previousIsRendering;
9964
9965 // Check if work was scheduled by one of the effects
9966 var rootExpirationTime = root.expirationTime;
9967 if (rootExpirationTime !== NoWork) {
9968 requestWork(root, rootExpirationTime);
9969 }
9970}
9971
9972function isAlreadyFailedLegacyErrorBoundary(instance) {
9973 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
9974}
9975
9976function markLegacyErrorBoundaryAsFailed(instance) {
9977 if (legacyErrorBoundariesThatAlreadyFailed === null) {
9978 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
9979 } else {
9980 legacyErrorBoundariesThatAlreadyFailed.add(instance);
9981 }
9982}
9983
9984function flushPassiveEffects() {
9985 if (passiveEffectCallback !== null) {
9986 unstable_cancelCallback(passiveEffectCallbackHandle);
9987 // We call the scheduled callback instead of commitPassiveEffects directly
9988 // to ensure tracing works correctly.
9989 passiveEffectCallback();
9990 }
9991}
9992
9993function commitRoot(root, finishedWork) {
9994 isWorking = true;
9995 isCommitting$1 = true;
9996 startCommitTimer();
9997
9998 !(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;
9999 var committedExpirationTime = root.pendingCommitExpirationTime;
10000 !(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;
10001 root.pendingCommitExpirationTime = NoWork;
10002
10003 // Update the pending priority levels to account for the work that we are
10004 // about to commit. This needs to happen before calling the lifecycles, since
10005 // they may schedule additional updates.
10006 var updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
10007 var childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
10008 var earliestRemainingTimeBeforeCommit = childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit ? childExpirationTimeBeforeCommit : updateExpirationTimeBeforeCommit;
10009 markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
10010
10011 var prevInteractions = null;
10012 if (enableSchedulerTracing) {
10013 // Restore any pending interactions at this point,
10014 // So that cascading work triggered during the render phase will be accounted for.
10015 prevInteractions = __interactionsRef.current;
10016 __interactionsRef.current = root.memoizedInteractions;
10017 }
10018
10019 // Reset this to null before calling lifecycles
10020 ReactCurrentOwner$1.current = null;
10021
10022 var firstEffect = void 0;
10023 if (finishedWork.effectTag > PerformedWork) {
10024 // A fiber's effect list consists only of its children, not itself. So if
10025 // the root has an effect, we need to add it to the end of the list. The
10026 // resulting list is the set that would belong to the root's parent, if
10027 // it had one; that is, all the effects in the tree including the root.
10028 if (finishedWork.lastEffect !== null) {
10029 finishedWork.lastEffect.nextEffect = finishedWork;
10030 firstEffect = finishedWork.firstEffect;
10031 } else {
10032 firstEffect = finishedWork;
10033 }
10034 } else {
10035 // There is no effect on the root.
10036 firstEffect = finishedWork.firstEffect;
10037 }
10038
10039 prepareForCommit(root.containerInfo);
10040
10041 // Invoke instances of getSnapshotBeforeUpdate before mutation.
10042 nextEffect = firstEffect;
10043 startCommitSnapshotEffectsTimer();
10044 while (nextEffect !== null) {
10045 var didError = false;
10046 var error = void 0;
10047 {
10048 invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
10049 if (hasCaughtError()) {
10050 didError = true;
10051 error = clearCaughtError();
10052 }
10053 }
10054 if (didError) {
10055 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10056 captureCommitPhaseError(nextEffect, error);
10057 // Clean-up
10058 if (nextEffect !== null) {
10059 nextEffect = nextEffect.nextEffect;
10060 }
10061 }
10062 }
10063 stopCommitSnapshotEffectsTimer();
10064
10065 if (enableProfilerTimer) {
10066 // Mark the current commit time to be shared by all Profilers in this batch.
10067 // This enables them to be grouped later.
10068 recordCommitTime();
10069 }
10070
10071 // Commit all the side-effects within a tree. We'll do this in two passes.
10072 // The first pass performs all the host insertions, updates, deletions and
10073 // ref unmounts.
10074 nextEffect = firstEffect;
10075 startCommitHostEffectsTimer();
10076 while (nextEffect !== null) {
10077 var _didError = false;
10078 var _error = void 0;
10079 {
10080 invokeGuardedCallback(null, commitAllHostEffects, null);
10081 if (hasCaughtError()) {
10082 _didError = true;
10083 _error = clearCaughtError();
10084 }
10085 }
10086 if (_didError) {
10087 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10088 captureCommitPhaseError(nextEffect, _error);
10089 // Clean-up
10090 if (nextEffect !== null) {
10091 nextEffect = nextEffect.nextEffect;
10092 }
10093 }
10094 }
10095 stopCommitHostEffectsTimer();
10096
10097 resetAfterCommit(root.containerInfo);
10098
10099 // The work-in-progress tree is now the current tree. This must come after
10100 // the first pass of the commit phase, so that the previous tree is still
10101 // current during componentWillUnmount, but before the second pass, so that
10102 // the finished work is current during componentDidMount/Update.
10103 root.current = finishedWork;
10104
10105 // In the second pass we'll perform all life-cycles and ref callbacks.
10106 // Life-cycles happen as a separate pass so that all placements, updates,
10107 // and deletions in the entire tree have already been invoked.
10108 // This pass also triggers any renderer-specific initial effects.
10109 nextEffect = firstEffect;
10110 startCommitLifeCyclesTimer();
10111 while (nextEffect !== null) {
10112 var _didError2 = false;
10113 var _error2 = void 0;
10114 {
10115 invokeGuardedCallback(null, commitAllLifeCycles, null, root, committedExpirationTime);
10116 if (hasCaughtError()) {
10117 _didError2 = true;
10118 _error2 = clearCaughtError();
10119 }
10120 }
10121 if (_didError2) {
10122 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10123 captureCommitPhaseError(nextEffect, _error2);
10124 if (nextEffect !== null) {
10125 nextEffect = nextEffect.nextEffect;
10126 }
10127 }
10128 }
10129
10130 if (enableHooks && firstEffect !== null && rootWithPendingPassiveEffects !== null) {
10131 // This commit included a passive effect. These do not need to fire until
10132 // after the next paint. Schedule an callback to fire them in an async
10133 // event. To ensure serial execution, the callback will be flushed early if
10134 // we enter rootWithPendingPassiveEffects commit phase before then.
10135 var callback = commitPassiveEffects.bind(null, root, firstEffect);
10136 if (enableSchedulerTracing) {
10137 // TODO: Avoid this extra callback by mutating the tracing ref directly,
10138 // like we do at the beginning of commitRoot. I've opted not to do that
10139 // here because that code is still in flux.
10140 callback = unstable_wrap(callback);
10141 }
10142 passiveEffectCallbackHandle = unstable_scheduleCallback(callback);
10143 passiveEffectCallback = callback;
10144 }
10145
10146 isCommitting$1 = false;
10147 isWorking = false;
10148 stopCommitLifeCyclesTimer();
10149 stopCommitTimer();
10150 onCommitRoot(finishedWork.stateNode);
10151 if (true && ReactFiberInstrumentation_1.debugTool) {
10152 ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork);
10153 }
10154
10155 var updateExpirationTimeAfterCommit = finishedWork.expirationTime;
10156 var childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
10157 var earliestRemainingTimeAfterCommit = childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit ? childExpirationTimeAfterCommit : updateExpirationTimeAfterCommit;
10158 if (earliestRemainingTimeAfterCommit === NoWork) {
10159 // If there's no remaining work, we can clear the set of already failed
10160 // error boundaries.
10161 legacyErrorBoundariesThatAlreadyFailed = null;
10162 }
10163 onCommit(root, earliestRemainingTimeAfterCommit);
10164
10165 if (enableSchedulerTracing) {
10166 __interactionsRef.current = prevInteractions;
10167
10168 var subscriber = void 0;
10169
10170 try {
10171 subscriber = __subscriberRef.current;
10172 if (subscriber !== null && root.memoizedInteractions.size > 0) {
10173 var threadID = computeThreadID(committedExpirationTime, root.interactionThreadID);
10174 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
10175 }
10176 } catch (error) {
10177 // It's not safe for commitRoot() to throw.
10178 // Store the error for now and we'll re-throw in finishRendering().
10179 if (!hasUnhandledError) {
10180 hasUnhandledError = true;
10181 unhandledError = error;
10182 }
10183 } finally {
10184 // Clear completed interactions from the pending Map.
10185 // Unless the render was suspended or cascading work was scheduled,
10186 // In which case– leave pending interactions until the subsequent render.
10187 var pendingInteractionMap = root.pendingInteractionMap;
10188 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
10189 // Only decrement the pending interaction count if we're done.
10190 // If there's still work at the current priority,
10191 // That indicates that we are waiting for suspense data.
10192 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
10193 pendingInteractionMap.delete(scheduledExpirationTime);
10194
10195 scheduledInteractions.forEach(function (interaction) {
10196 interaction.__count--;
10197
10198 if (subscriber !== null && interaction.__count === 0) {
10199 try {
10200 subscriber.onInteractionScheduledWorkCompleted(interaction);
10201 } catch (error) {
10202 // It's not safe for commitRoot() to throw.
10203 // Store the error for now and we'll re-throw in finishRendering().
10204 if (!hasUnhandledError) {
10205 hasUnhandledError = true;
10206 unhandledError = error;
10207 }
10208 }
10209 }
10210 });
10211 }
10212 });
10213 }
10214 }
10215}
10216
10217function resetChildExpirationTime(workInProgress, renderTime) {
10218 if (renderTime !== Never && workInProgress.childExpirationTime === Never) {
10219 // The children of this component are hidden. Don't bubble their
10220 // expiration times.
10221 return;
10222 }
10223
10224 var newChildExpirationTime = NoWork;
10225
10226 // Bubble up the earliest expiration time.
10227 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
10228 // We're in profiling mode.
10229 // Let's use this same traversal to update the render durations.
10230 var actualDuration = workInProgress.actualDuration;
10231 var treeBaseDuration = workInProgress.selfBaseDuration;
10232
10233 // When a fiber is cloned, its actualDuration is reset to 0.
10234 // This value will only be updated if work is done on the fiber (i.e. it doesn't bailout).
10235 // When work is done, it should bubble to the parent's actualDuration.
10236 // If the fiber has not been cloned though, (meaning no work was done),
10237 // Then this value will reflect the amount of time spent working on a previous render.
10238 // In that case it should not bubble.
10239 // We determine whether it was cloned by comparing the child pointer.
10240 var shouldBubbleActualDurations = workInProgress.alternate === null || workInProgress.child !== workInProgress.alternate.child;
10241
10242 var child = workInProgress.child;
10243 while (child !== null) {
10244 var childUpdateExpirationTime = child.expirationTime;
10245 var childChildExpirationTime = child.childExpirationTime;
10246 if (childUpdateExpirationTime > newChildExpirationTime) {
10247 newChildExpirationTime = childUpdateExpirationTime;
10248 }
10249 if (childChildExpirationTime > newChildExpirationTime) {
10250 newChildExpirationTime = childChildExpirationTime;
10251 }
10252 if (shouldBubbleActualDurations) {
10253 actualDuration += child.actualDuration;
10254 }
10255 treeBaseDuration += child.treeBaseDuration;
10256 child = child.sibling;
10257 }
10258 workInProgress.actualDuration = actualDuration;
10259 workInProgress.treeBaseDuration = treeBaseDuration;
10260 } else {
10261 var _child = workInProgress.child;
10262 while (_child !== null) {
10263 var _childUpdateExpirationTime = _child.expirationTime;
10264 var _childChildExpirationTime = _child.childExpirationTime;
10265 if (_childUpdateExpirationTime > newChildExpirationTime) {
10266 newChildExpirationTime = _childUpdateExpirationTime;
10267 }
10268 if (_childChildExpirationTime > newChildExpirationTime) {
10269 newChildExpirationTime = _childChildExpirationTime;
10270 }
10271 _child = _child.sibling;
10272 }
10273 }
10274
10275 workInProgress.childExpirationTime = newChildExpirationTime;
10276}
10277
10278function completeUnitOfWork(workInProgress) {
10279 // Attempt to complete the current unit of work, then move to the
10280 // next sibling. If there are no more siblings, return to the
10281 // parent fiber.
10282 while (true) {
10283 // The current, flushed, state of this fiber is the alternate.
10284 // Ideally nothing should rely on this, but relying on it here
10285 // means that we don't need an additional field on the work in
10286 // progress.
10287 var current$$1 = workInProgress.alternate;
10288 {
10289 setCurrentFiber(workInProgress);
10290 }
10291
10292 var returnFiber = workInProgress.return;
10293 var siblingFiber = workInProgress.sibling;
10294
10295 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
10296 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10297 // Don't replay if it fails during completion phase.
10298 mayReplayFailedUnitOfWork = false;
10299 }
10300 // This fiber completed.
10301 // Remember we're completing this unit so we can find a boundary if it fails.
10302 nextUnitOfWork = workInProgress;
10303 if (enableProfilerTimer) {
10304 if (workInProgress.mode & ProfileMode) {
10305 startProfilerTimer(workInProgress);
10306 }
10307 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
10308 if (workInProgress.mode & ProfileMode) {
10309 // Update render duration assuming we didn't error.
10310 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
10311 }
10312 } else {
10313 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
10314 }
10315 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10316 // We're out of completion phase so replaying is fine now.
10317 mayReplayFailedUnitOfWork = true;
10318 }
10319 stopWorkTimer(workInProgress);
10320 resetChildExpirationTime(workInProgress, nextRenderExpirationTime);
10321 {
10322 resetCurrentFiber();
10323 }
10324
10325 if (nextUnitOfWork !== null) {
10326 // Completing this fiber spawned new work. Work on that next.
10327 return nextUnitOfWork;
10328 }
10329
10330 if (returnFiber !== null &&
10331 // Do not append effects to parents if a sibling failed to complete
10332 (returnFiber.effectTag & Incomplete) === NoEffect) {
10333 // Append all the effects of the subtree and this fiber onto the effect
10334 // list of the parent. The completion order of the children affects the
10335 // side-effect order.
10336 if (returnFiber.firstEffect === null) {
10337 returnFiber.firstEffect = workInProgress.firstEffect;
10338 }
10339 if (workInProgress.lastEffect !== null) {
10340 if (returnFiber.lastEffect !== null) {
10341 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
10342 }
10343 returnFiber.lastEffect = workInProgress.lastEffect;
10344 }
10345
10346 // If this fiber had side-effects, we append it AFTER the children's
10347 // side-effects. We can perform certain side-effects earlier if
10348 // needed, by doing multiple passes over the effect list. We don't want
10349 // to schedule our own side-effect on our own list because if end up
10350 // reusing children we'll schedule this effect onto itself since we're
10351 // at the end.
10352 var effectTag = workInProgress.effectTag;
10353 // Skip both NoWork and PerformedWork tags when creating the effect list.
10354 // PerformedWork effect is read by React DevTools but shouldn't be committed.
10355 if (effectTag > PerformedWork) {
10356 if (returnFiber.lastEffect !== null) {
10357 returnFiber.lastEffect.nextEffect = workInProgress;
10358 } else {
10359 returnFiber.firstEffect = workInProgress;
10360 }
10361 returnFiber.lastEffect = workInProgress;
10362 }
10363 }
10364
10365 if (true && ReactFiberInstrumentation_1.debugTool) {
10366 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
10367 }
10368
10369 if (siblingFiber !== null) {
10370 // If there is more work to do in this returnFiber, do that next.
10371 return siblingFiber;
10372 } else if (returnFiber !== null) {
10373 // If there's no more work in this returnFiber. Complete the returnFiber.
10374 workInProgress = returnFiber;
10375 continue;
10376 } else {
10377 // We've reached the root.
10378 return null;
10379 }
10380 } else {
10381 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
10382 // Record the render duration for the fiber that errored.
10383 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
10384
10385 // Include the time spent working on failed children before continuing.
10386 var actualDuration = workInProgress.actualDuration;
10387 var child = workInProgress.child;
10388 while (child !== null) {
10389 actualDuration += child.actualDuration;
10390 child = child.sibling;
10391 }
10392 workInProgress.actualDuration = actualDuration;
10393 }
10394
10395 // This fiber did not complete because something threw. Pop values off
10396 // the stack without entering the complete phase. If this is a boundary,
10397 // capture values if possible.
10398 var next = unwindWork(workInProgress, nextRenderExpirationTime);
10399 // Because this fiber did not complete, don't reset its expiration time.
10400 if (workInProgress.effectTag & DidCapture) {
10401 // Restarting an error boundary
10402 stopFailedWorkTimer(workInProgress);
10403 } else {
10404 stopWorkTimer(workInProgress);
10405 }
10406
10407 {
10408 resetCurrentFiber();
10409 }
10410
10411 if (next !== null) {
10412 stopWorkTimer(workInProgress);
10413 if (true && ReactFiberInstrumentation_1.debugTool) {
10414 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
10415 }
10416
10417 // If completing this work spawned new work, do that next. We'll come
10418 // back here again.
10419 // Since we're restarting, remove anything that is not a host effect
10420 // from the effect tag.
10421 next.effectTag &= HostEffectMask;
10422 return next;
10423 }
10424
10425 if (returnFiber !== null) {
10426 // Mark the parent fiber as incomplete and clear its effect list.
10427 returnFiber.firstEffect = returnFiber.lastEffect = null;
10428 returnFiber.effectTag |= Incomplete;
10429 }
10430
10431 if (true && ReactFiberInstrumentation_1.debugTool) {
10432 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
10433 }
10434
10435 if (siblingFiber !== null) {
10436 // If there is more work to do in this returnFiber, do that next.
10437 return siblingFiber;
10438 } else if (returnFiber !== null) {
10439 // If there's no more work in this returnFiber. Complete the returnFiber.
10440 workInProgress = returnFiber;
10441 continue;
10442 } else {
10443 return null;
10444 }
10445 }
10446 }
10447
10448 // Without this explicit null return Flow complains of invalid return type
10449 // TODO Remove the above while(true) loop
10450 // eslint-disable-next-line no-unreachable
10451 return null;
10452}
10453
10454function performUnitOfWork(workInProgress) {
10455 // The current, flushed, state of this fiber is the alternate.
10456 // Ideally nothing should rely on this, but relying on it here
10457 // means that we don't need an additional field on the work in
10458 // progress.
10459 var current$$1 = workInProgress.alternate;
10460
10461 // See if beginning this work spawns more work.
10462 startWorkTimer(workInProgress);
10463 {
10464 setCurrentFiber(workInProgress);
10465 }
10466
10467 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10468 stashedWorkInProgressProperties = assignFiberPropertiesInDEV(stashedWorkInProgressProperties, workInProgress);
10469 }
10470
10471 var next = void 0;
10472 if (enableProfilerTimer) {
10473 if (workInProgress.mode & ProfileMode) {
10474 startProfilerTimer(workInProgress);
10475 }
10476
10477 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
10478 workInProgress.memoizedProps = workInProgress.pendingProps;
10479
10480 if (workInProgress.mode & ProfileMode) {
10481 // Record the render duration assuming we didn't bailout (or error).
10482 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
10483 }
10484 } else {
10485 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
10486 workInProgress.memoizedProps = workInProgress.pendingProps;
10487 }
10488
10489 {
10490 resetCurrentFiber();
10491 if (isReplayingFailedUnitOfWork) {
10492 // Currently replaying a failed unit of work. This should be unreachable,
10493 // because the render phase is meant to be idempotent, and it should
10494 // have thrown again. Since it didn't, rethrow the original error, so
10495 // React's internal stack is not misaligned.
10496 rethrowOriginalError();
10497 }
10498 }
10499 if (true && ReactFiberInstrumentation_1.debugTool) {
10500 ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress);
10501 }
10502
10503 if (next === null) {
10504 // If this doesn't spawn new work, complete the current work.
10505 next = completeUnitOfWork(workInProgress);
10506 }
10507
10508 ReactCurrentOwner$1.current = null;
10509
10510 return next;
10511}
10512
10513function workLoop(isYieldy) {
10514 if (!isYieldy) {
10515 // Flush work without yielding
10516 while (nextUnitOfWork !== null) {
10517 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
10518 }
10519 } else {
10520 // Flush asynchronous work until there's a higher priority event
10521 while (nextUnitOfWork !== null && !shouldYieldToRenderer()) {
10522 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
10523 }
10524 }
10525}
10526
10527function renderRoot(root, isYieldy) {
10528 !!isWorking ? invariant(false, 'renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10529
10530 flushPassiveEffects();
10531
10532 isWorking = true;
10533 if (enableHooks) {
10534 ReactCurrentOwner$1.currentDispatcher = Dispatcher;
10535 } else {
10536 ReactCurrentOwner$1.currentDispatcher = DispatcherWithoutHooks;
10537 }
10538
10539 var expirationTime = root.nextExpirationTimeToWorkOn;
10540
10541 // Check if we're starting from a fresh stack, or if we're resuming from
10542 // previously yielded work.
10543 if (expirationTime !== nextRenderExpirationTime || root !== nextRoot || nextUnitOfWork === null) {
10544 // Reset the stack and start working from the root.
10545 resetStack();
10546 nextRoot = root;
10547 nextRenderExpirationTime = expirationTime;
10548 nextUnitOfWork = createWorkInProgress(nextRoot.current, null, nextRenderExpirationTime);
10549 root.pendingCommitExpirationTime = NoWork;
10550
10551 if (enableSchedulerTracing) {
10552 // Determine which interactions this batch of work currently includes,
10553 // So that we can accurately attribute time spent working on it,
10554 var interactions = new Set();
10555 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
10556 if (scheduledExpirationTime >= expirationTime) {
10557 scheduledInteractions.forEach(function (interaction) {
10558 return interactions.add(interaction);
10559 });
10560 }
10561 });
10562
10563 // Store the current set of interactions on the FiberRoot for a few reasons:
10564 // We can re-use it in hot functions like renderRoot() without having to recalculate it.
10565 // We will also use it in commitWork() to pass to any Profiler onRender() hooks.
10566 // This also provides DevTools with a way to access it when the onCommitRoot() hook is called.
10567 root.memoizedInteractions = interactions;
10568
10569 if (interactions.size > 0) {
10570 var subscriber = __subscriberRef.current;
10571 if (subscriber !== null) {
10572 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
10573 try {
10574 subscriber.onWorkStarted(interactions, threadID);
10575 } catch (error) {
10576 // Work thrown by an interaction tracing subscriber should be rethrown,
10577 // But only once it's safe (to avoid leaveing the scheduler in an invalid state).
10578 // Store the error for now and we'll re-throw in finishRendering().
10579 if (!hasUnhandledError) {
10580 hasUnhandledError = true;
10581 unhandledError = error;
10582 }
10583 }
10584 }
10585 }
10586 }
10587 }
10588
10589 var prevInteractions = null;
10590 if (enableSchedulerTracing) {
10591 // We're about to start new traced work.
10592 // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
10593 prevInteractions = __interactionsRef.current;
10594 __interactionsRef.current = root.memoizedInteractions;
10595 }
10596
10597 var didFatal = false;
10598
10599 startWorkLoopTimer(nextUnitOfWork);
10600
10601 do {
10602 try {
10603 workLoop(isYieldy);
10604 } catch (thrownValue) {
10605 resetContextDependences();
10606 resetHooks();
10607
10608 // Reset in case completion throws.
10609 // This is only used in DEV and when replaying is on.
10610 var mayReplay = void 0;
10611 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10612 mayReplay = mayReplayFailedUnitOfWork;
10613 mayReplayFailedUnitOfWork = true;
10614 }
10615
10616 if (nextUnitOfWork === null) {
10617 // This is a fatal error.
10618 didFatal = true;
10619 onUncaughtError(thrownValue);
10620 } else {
10621 if (enableProfilerTimer && nextUnitOfWork.mode & ProfileMode) {
10622 // Record the time spent rendering before an error was thrown.
10623 // This avoids inaccurate Profiler durations in the case of a suspended render.
10624 stopProfilerTimerIfRunningAndRecordDelta(nextUnitOfWork, true);
10625 }
10626
10627 {
10628 // Reset global debug state
10629 // We assume this is defined in DEV
10630 resetCurrentlyProcessingQueue();
10631 }
10632
10633 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10634 if (mayReplay) {
10635 var failedUnitOfWork = nextUnitOfWork;
10636 replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
10637 }
10638 }
10639
10640 // TODO: we already know this isn't true in some cases.
10641 // At least this shows a nicer error message until we figure out the cause.
10642 // https://github.com/facebook/react/issues/12449#issuecomment-386727431
10643 !(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;
10644
10645 var sourceFiber = nextUnitOfWork;
10646 var returnFiber = sourceFiber.return;
10647 if (returnFiber === null) {
10648 // This is the root. The root could capture its own errors. However,
10649 // we don't know if it errors before or after we pushed the host
10650 // context. This information is needed to avoid a stack mismatch.
10651 // Because we're not sure, treat this as a fatal error. We could track
10652 // which phase it fails in, but doesn't seem worth it. At least
10653 // for now.
10654 didFatal = true;
10655 onUncaughtError(thrownValue);
10656 } else {
10657 throwException(root, returnFiber, sourceFiber, thrownValue, nextRenderExpirationTime);
10658 nextUnitOfWork = completeUnitOfWork(sourceFiber);
10659 continue;
10660 }
10661 }
10662 }
10663 break;
10664 } while (true);
10665
10666 if (enableSchedulerTracing) {
10667 // Traced work is done for now; restore the previous interactions.
10668 __interactionsRef.current = prevInteractions;
10669 }
10670
10671 // We're done performing work. Time to clean up.
10672 isWorking = false;
10673 ReactCurrentOwner$1.currentDispatcher = null;
10674 resetContextDependences();
10675 resetHooks();
10676
10677 // Yield back to main thread.
10678 if (didFatal) {
10679 var _didCompleteRoot = false;
10680 stopWorkLoopTimer(interruptedBy, _didCompleteRoot);
10681 interruptedBy = null;
10682 // There was a fatal error.
10683 {
10684 resetStackAfterFatalErrorInDev();
10685 }
10686 // `nextRoot` points to the in-progress root. A non-null value indicates
10687 // that we're in the middle of an async render. Set it to null to indicate
10688 // there's no more work to be done in the current batch.
10689 nextRoot = null;
10690 onFatal(root);
10691 return;
10692 }
10693
10694 if (nextUnitOfWork !== null) {
10695 // There's still remaining async work in this tree, but we ran out of time
10696 // in the current frame. Yield back to the renderer. Unless we're
10697 // interrupted by a higher priority update, we'll continue later from where
10698 // we left off.
10699 var _didCompleteRoot2 = false;
10700 stopWorkLoopTimer(interruptedBy, _didCompleteRoot2);
10701 interruptedBy = null;
10702 onYield(root);
10703 return;
10704 }
10705
10706 // We completed the whole tree.
10707 var didCompleteRoot = true;
10708 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
10709 var rootWorkInProgress = root.current.alternate;
10710 !(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;
10711
10712 // `nextRoot` points to the in-progress root. A non-null value indicates
10713 // that we're in the middle of an async render. Set it to null to indicate
10714 // there's no more work to be done in the current batch.
10715 nextRoot = null;
10716 interruptedBy = null;
10717
10718 if (nextRenderDidError) {
10719 // There was an error
10720 if (hasLowerPriorityWork(root, expirationTime)) {
10721 // There's lower priority work. If so, it may have the effect of fixing
10722 // the exception that was just thrown. Exit without committing. This is
10723 // similar to a suspend, but without a timeout because we're not waiting
10724 // for a promise to resolve. React will restart at the lower
10725 // priority level.
10726 markSuspendedPriorityLevel(root, expirationTime);
10727 var suspendedExpirationTime = expirationTime;
10728 var rootExpirationTime = root.expirationTime;
10729 onSuspend(root, rootWorkInProgress, suspendedExpirationTime, rootExpirationTime, -1 // Indicates no timeout
10730 );
10731 return;
10732 } else if (
10733 // There's no lower priority work, but we're rendering asynchronously.
10734 // Synchronsouly attempt to render the same level one more time. This is
10735 // similar to a suspend, but without a timeout because we're not waiting
10736 // for a promise to resolve.
10737 !root.didError && isYieldy) {
10738 root.didError = true;
10739 var _suspendedExpirationTime = root.nextExpirationTimeToWorkOn = expirationTime;
10740 var _rootExpirationTime = root.expirationTime = Sync;
10741 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime, _rootExpirationTime, -1 // Indicates no timeout
10742 );
10743 return;
10744 }
10745 }
10746
10747 if (isYieldy && nextLatestAbsoluteTimeoutMs !== -1) {
10748 // The tree was suspended.
10749 var _suspendedExpirationTime2 = expirationTime;
10750 markSuspendedPriorityLevel(root, _suspendedExpirationTime2);
10751
10752 // Find the earliest uncommitted expiration time in the tree, including
10753 // work that is suspended. The timeout threshold cannot be longer than
10754 // the overall expiration.
10755 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, expirationTime);
10756 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
10757 if (earliestExpirationTimeMs < nextLatestAbsoluteTimeoutMs) {
10758 nextLatestAbsoluteTimeoutMs = earliestExpirationTimeMs;
10759 }
10760
10761 // Subtract the current time from the absolute timeout to get the number
10762 // of milliseconds until the timeout. In other words, convert an absolute
10763 // timestamp to a relative time. This is the value that is passed
10764 // to `setTimeout`.
10765 var currentTimeMs = expirationTimeToMs(requestCurrentTime());
10766 var msUntilTimeout = nextLatestAbsoluteTimeoutMs - currentTimeMs;
10767 msUntilTimeout = msUntilTimeout < 0 ? 0 : msUntilTimeout;
10768
10769 // TODO: Account for the Just Noticeable Difference
10770
10771 var _rootExpirationTime2 = root.expirationTime;
10772 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime2, _rootExpirationTime2, msUntilTimeout);
10773 return;
10774 }
10775
10776 // Ready to commit.
10777 onComplete(root, rootWorkInProgress, expirationTime);
10778}
10779
10780function captureCommitPhaseError(sourceFiber, value) {
10781 var expirationTime = Sync;
10782 var fiber = sourceFiber.return;
10783 while (fiber !== null) {
10784 switch (fiber.tag) {
10785 case ClassComponent:
10786 var ctor = fiber.type;
10787 var instance = fiber.stateNode;
10788 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
10789 var errorInfo = createCapturedValue(value, sourceFiber);
10790 var update = createClassErrorUpdate(fiber, errorInfo, expirationTime);
10791 enqueueUpdate(fiber, update);
10792 scheduleWork(fiber, expirationTime);
10793 return;
10794 }
10795 break;
10796 case HostRoot:
10797 {
10798 var _errorInfo = createCapturedValue(value, sourceFiber);
10799 var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime);
10800 enqueueUpdate(fiber, _update);
10801 scheduleWork(fiber, expirationTime);
10802 return;
10803 }
10804 }
10805 fiber = fiber.return;
10806 }
10807
10808 if (sourceFiber.tag === HostRoot) {
10809 // Error was thrown at the root. There is no parent, so the root
10810 // itself should capture it.
10811 var rootFiber = sourceFiber;
10812 var _errorInfo2 = createCapturedValue(value, rootFiber);
10813 var _update2 = createRootErrorUpdate(rootFiber, _errorInfo2, expirationTime);
10814 enqueueUpdate(rootFiber, _update2);
10815 scheduleWork(rootFiber, expirationTime);
10816 }
10817}
10818
10819function computeThreadID(expirationTime, interactionThreadID) {
10820 // Interaction threads are unique per root and expiration time.
10821 return expirationTime * 1000 + interactionThreadID;
10822}
10823
10824function computeExpirationForFiber(currentTime, fiber) {
10825 var expirationTime = void 0;
10826 if (expirationContext !== NoWork) {
10827 // An explicit expiration context was set;
10828 expirationTime = expirationContext;
10829 } else if (isWorking) {
10830 if (isCommitting$1) {
10831 // Updates that occur during the commit phase should have sync priority
10832 // by default.
10833 expirationTime = Sync;
10834 } else {
10835 // Updates during the render phase should expire at the same time as
10836 // the work that is being rendered.
10837 expirationTime = nextRenderExpirationTime;
10838 }
10839 } else {
10840 // No explicit expiration context was set, and we're not currently
10841 // performing work. Calculate a new expiration time.
10842 if (fiber.mode & ConcurrentMode) {
10843 if (isBatchingInteractiveUpdates) {
10844 // This is an interactive update
10845 expirationTime = computeInteractiveExpiration(currentTime);
10846 } else {
10847 // This is an async update
10848 expirationTime = computeAsyncExpiration(currentTime);
10849 }
10850 // If we're in the middle of rendering a tree, do not update at the same
10851 // expiration time that is already rendering.
10852 if (nextRoot !== null && expirationTime === nextRenderExpirationTime) {
10853 expirationTime -= 1;
10854 }
10855 } else {
10856 // This is a sync update
10857 expirationTime = Sync;
10858 }
10859 }
10860 return expirationTime;
10861}
10862
10863function renderDidSuspend(root, absoluteTimeoutMs, suspendedTime) {
10864 // Schedule the timeout.
10865 if (absoluteTimeoutMs >= 0 && nextLatestAbsoluteTimeoutMs < absoluteTimeoutMs) {
10866 nextLatestAbsoluteTimeoutMs = absoluteTimeoutMs;
10867 }
10868}
10869
10870function renderDidError() {
10871 nextRenderDidError = true;
10872}
10873
10874function pingSuspendedRoot(root, thenable, pingTime) {
10875 // A promise that previously suspended React from committing has resolved.
10876 // If React is still suspended, try again at the previous level (pingTime).
10877
10878 var pingCache = root.pingCache;
10879 if (pingCache !== null) {
10880 // The thenable resolved, so we no longer need to memoize, because it will
10881 // never be thrown again.
10882 pingCache.delete(thenable);
10883 }
10884
10885 if (nextRoot !== null && nextRenderExpirationTime === pingTime) {
10886 // Received a ping at the same priority level at which we're currently
10887 // rendering. Restart from the root.
10888 nextRoot = null;
10889 } else {
10890 // Confirm that the root is still suspended at this level. Otherwise exit.
10891 if (isPriorityLevelSuspended(root, pingTime)) {
10892 // Ping at the original level
10893 markPingedPriorityLevel(root, pingTime);
10894 var rootExpirationTime = root.expirationTime;
10895 if (rootExpirationTime !== NoWork) {
10896 requestWork(root, rootExpirationTime);
10897 }
10898 }
10899 }
10900}
10901
10902function retryTimedOutBoundary(boundaryFiber, thenable) {
10903 // The boundary fiber (a Suspense component) previously timed out and was
10904 // rendered in its fallback state. One of the promises that suspended it has
10905 // resolved, which means at least part of the tree was likely unblocked. Try
10906 var retryCache = boundaryFiber.stateNode;
10907 if (retryCache !== null) {
10908 // The thenable resolved, so we no longer need to memoize, because it will
10909 // never be thrown again.
10910 retryCache.delete(thenable);
10911 }
10912
10913 var currentTime = requestCurrentTime();
10914 var retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
10915 var root = scheduleWorkToRoot(boundaryFiber, retryTime);
10916 if (root !== null) {
10917 markPendingPriorityLevel(root, retryTime);
10918 var rootExpirationTime = root.expirationTime;
10919 if (rootExpirationTime !== NoWork) {
10920 requestWork(root, rootExpirationTime);
10921 }
10922 }
10923}
10924
10925function scheduleWorkToRoot(fiber, expirationTime) {
10926 recordScheduleUpdate();
10927
10928 {
10929 if (fiber.tag === ClassComponent) {
10930 var instance = fiber.stateNode;
10931 warnAboutInvalidUpdates(instance);
10932 }
10933 }
10934
10935 // Update the source fiber's expiration time
10936 if (fiber.expirationTime < expirationTime) {
10937 fiber.expirationTime = expirationTime;
10938 }
10939 var alternate = fiber.alternate;
10940 if (alternate !== null && alternate.expirationTime < expirationTime) {
10941 alternate.expirationTime = expirationTime;
10942 }
10943 // Walk the parent path to the root and update the child expiration time.
10944 var node = fiber.return;
10945 var root = null;
10946 if (node === null && fiber.tag === HostRoot) {
10947 root = fiber.stateNode;
10948 } else {
10949 while (node !== null) {
10950 alternate = node.alternate;
10951 if (node.childExpirationTime < expirationTime) {
10952 node.childExpirationTime = expirationTime;
10953 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
10954 alternate.childExpirationTime = expirationTime;
10955 }
10956 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
10957 alternate.childExpirationTime = expirationTime;
10958 }
10959 if (node.return === null && node.tag === HostRoot) {
10960 root = node.stateNode;
10961 break;
10962 }
10963 node = node.return;
10964 }
10965 }
10966
10967 if (enableSchedulerTracing) {
10968 if (root !== null) {
10969 var interactions = __interactionsRef.current;
10970 if (interactions.size > 0) {
10971 var pendingInteractionMap = root.pendingInteractionMap;
10972 var pendingInteractions = pendingInteractionMap.get(expirationTime);
10973 if (pendingInteractions != null) {
10974 interactions.forEach(function (interaction) {
10975 if (!pendingInteractions.has(interaction)) {
10976 // Update the pending async work count for previously unscheduled interaction.
10977 interaction.__count++;
10978 }
10979
10980 pendingInteractions.add(interaction);
10981 });
10982 } else {
10983 pendingInteractionMap.set(expirationTime, new Set(interactions));
10984
10985 // Update the pending async work count for the current interactions.
10986 interactions.forEach(function (interaction) {
10987 interaction.__count++;
10988 });
10989 }
10990
10991 var subscriber = __subscriberRef.current;
10992 if (subscriber !== null) {
10993 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
10994 subscriber.onWorkScheduled(interactions, threadID);
10995 }
10996 }
10997 }
10998 }
10999 return root;
11000}
11001
11002function scheduleWork(fiber, expirationTime) {
11003 var root = scheduleWorkToRoot(fiber, expirationTime);
11004 if (root === null) {
11005 {
11006 switch (fiber.tag) {
11007 case ClassComponent:
11008 warnAboutUpdateOnUnmounted(fiber, true);
11009 break;
11010 case FunctionComponent:
11011 case ForwardRef:
11012 case MemoComponent:
11013 case SimpleMemoComponent:
11014 warnAboutUpdateOnUnmounted(fiber, false);
11015 break;
11016 }
11017 }
11018 return;
11019 }
11020
11021 if (!isWorking && nextRenderExpirationTime !== NoWork && expirationTime > nextRenderExpirationTime) {
11022 // This is an interruption. (Used for performance tracking.)
11023 interruptedBy = fiber;
11024 resetStack();
11025 }
11026 markPendingPriorityLevel(root, expirationTime);
11027 if (
11028 // If we're in the render phase, we don't need to schedule this root
11029 // for an update, because we'll do it before we exit...
11030 !isWorking || isCommitting$1 ||
11031 // ...unless this is a different root than the one we're rendering.
11032 nextRoot !== root) {
11033 var rootExpirationTime = root.expirationTime;
11034 requestWork(root, rootExpirationTime);
11035 }
11036 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
11037 // Reset this back to zero so subsequent updates don't throw.
11038 nestedUpdateCount = 0;
11039 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.');
11040 }
11041}
11042
11043function syncUpdates(fn, a, b, c, d) {
11044 var previousExpirationContext = expirationContext;
11045 expirationContext = Sync;
11046 try {
11047 return fn(a, b, c, d);
11048 } finally {
11049 expirationContext = previousExpirationContext;
11050 }
11051}
11052
11053// TODO: Everything below this is written as if it has been lifted to the
11054// renderers. I'll do this in a follow-up.
11055
11056// Linked-list of roots
11057var firstScheduledRoot = null;
11058var lastScheduledRoot = null;
11059
11060var callbackExpirationTime = NoWork;
11061var callbackID = void 0;
11062var isRendering = false;
11063var nextFlushedRoot = null;
11064var nextFlushedExpirationTime = NoWork;
11065var hasUnhandledError = false;
11066var unhandledError = null;
11067
11068var isBatchingUpdates = false;
11069var isUnbatchingUpdates = false;
11070var isBatchingInteractiveUpdates = false;
11071
11072var completedBatches = null;
11073
11074var originalStartTimeMs = now();
11075var currentRendererTime = msToExpirationTime(originalStartTimeMs);
11076var currentSchedulerTime = currentRendererTime;
11077
11078// Use these to prevent an infinite loop of nested updates
11079var NESTED_UPDATE_LIMIT = 50;
11080var nestedUpdateCount = 0;
11081var lastCommittedRootDuringThisBatch = null;
11082
11083function recomputeCurrentRendererTime() {
11084 var currentTimeMs = now() - originalStartTimeMs;
11085 currentRendererTime = msToExpirationTime(currentTimeMs);
11086}
11087
11088function scheduleCallbackWithExpirationTime(root, expirationTime) {
11089 if (callbackExpirationTime !== NoWork) {
11090 // A callback is already scheduled. Check its expiration time (timeout).
11091 if (expirationTime < callbackExpirationTime) {
11092 // Existing callback has sufficient timeout. Exit.
11093 return;
11094 } else {
11095 if (callbackID !== null) {
11096 // Existing callback has insufficient timeout. Cancel and schedule a
11097 // new one.
11098 cancelDeferredCallback$$1(callbackID);
11099 }
11100 }
11101 // The request callback timer is already running. Don't start a new one.
11102 } else {
11103 startRequestCallbackTimer();
11104 }
11105
11106 callbackExpirationTime = expirationTime;
11107 var currentMs = now() - originalStartTimeMs;
11108 var expirationTimeMs = expirationTimeToMs(expirationTime);
11109 var timeout = expirationTimeMs - currentMs;
11110 callbackID = scheduleDeferredCallback$$1(performAsyncWork, { timeout: timeout });
11111}
11112
11113// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and
11114// onYield is called upon exiting. We use these in lieu of returning a tuple.
11115// I've also chosen not to inline them into renderRoot because these will
11116// eventually be lifted into the renderer.
11117function onFatal(root) {
11118 root.finishedWork = null;
11119}
11120
11121function onComplete(root, finishedWork, expirationTime) {
11122 root.pendingCommitExpirationTime = expirationTime;
11123 root.finishedWork = finishedWork;
11124}
11125
11126function onSuspend(root, finishedWork, suspendedExpirationTime, rootExpirationTime, msUntilTimeout) {
11127 root.expirationTime = rootExpirationTime;
11128 if (msUntilTimeout === 0 && !shouldYieldToRenderer()) {
11129 // Don't wait an additional tick. Commit the tree immediately.
11130 root.pendingCommitExpirationTime = suspendedExpirationTime;
11131 root.finishedWork = finishedWork;
11132 } else if (msUntilTimeout > 0) {
11133 // Wait `msUntilTimeout` milliseconds before committing.
11134 root.timeoutHandle = scheduleTimeout(onTimeout.bind(null, root, finishedWork, suspendedExpirationTime), msUntilTimeout);
11135 }
11136}
11137
11138function onYield(root) {
11139 root.finishedWork = null;
11140}
11141
11142function onTimeout(root, finishedWork, suspendedExpirationTime) {
11143 // The root timed out. Commit it.
11144 root.pendingCommitExpirationTime = suspendedExpirationTime;
11145 root.finishedWork = finishedWork;
11146 // Read the current time before entering the commit phase. We can be
11147 // certain this won't cause tearing related to batching of event updates
11148 // because we're at the top of a timer event.
11149 recomputeCurrentRendererTime();
11150 currentSchedulerTime = currentRendererTime;
11151 flushRoot(root, suspendedExpirationTime);
11152}
11153
11154function onCommit(root, expirationTime) {
11155 root.expirationTime = expirationTime;
11156 root.finishedWork = null;
11157}
11158
11159function requestCurrentTime() {
11160 // requestCurrentTime is called by the scheduler to compute an expiration
11161 // time.
11162 //
11163 // Expiration times are computed by adding to the current time (the start
11164 // time). However, if two updates are scheduled within the same event, we
11165 // should treat their start times as simultaneous, even if the actual clock
11166 // time has advanced between the first and second call.
11167
11168 // In other words, because expiration times determine how updates are batched,
11169 // we want all updates of like priority that occur within the same event to
11170 // receive the same expiration time. Otherwise we get tearing.
11171 //
11172 // We keep track of two separate times: the current "renderer" time and the
11173 // current "scheduler" time. The renderer time can be updated whenever; it
11174 // only exists to minimize the calls performance.now.
11175 //
11176 // But the scheduler time can only be updated if there's no pending work, or
11177 // if we know for certain that we're not in the middle of an event.
11178
11179 if (isRendering) {
11180 // We're already rendering. Return the most recently read time.
11181 return currentSchedulerTime;
11182 }
11183 // Check if there's pending work.
11184 findHighestPriorityRoot();
11185 if (nextFlushedExpirationTime === NoWork || nextFlushedExpirationTime === Never) {
11186 // If there's no pending work, or if the pending work is offscreen, we can
11187 // read the current time without risk of tearing.
11188 recomputeCurrentRendererTime();
11189 currentSchedulerTime = currentRendererTime;
11190 return currentSchedulerTime;
11191 }
11192 // There's already pending work. We might be in the middle of a browser
11193 // event. If we were to read the current time, it could cause multiple updates
11194 // within the same event to receive different expiration times, leading to
11195 // tearing. Return the last read time. During the next idle callback, the
11196 // time will be updated.
11197 return currentSchedulerTime;
11198}
11199
11200// requestWork is called by the scheduler whenever a root receives an update.
11201// It's up to the renderer to call renderRoot at some point in the future.
11202function requestWork(root, expirationTime) {
11203 addRootToSchedule(root, expirationTime);
11204 if (isRendering) {
11205 // Prevent reentrancy. Remaining work will be scheduled at the end of
11206 // the currently rendering batch.
11207 return;
11208 }
11209
11210 if (isBatchingUpdates) {
11211 // Flush work at the end of the batch.
11212 if (isUnbatchingUpdates) {
11213 // ...unless we're inside unbatchedUpdates, in which case we should
11214 // flush it now.
11215 nextFlushedRoot = root;
11216 nextFlushedExpirationTime = Sync;
11217 performWorkOnRoot(root, Sync, false);
11218 }
11219 return;
11220 }
11221
11222 // TODO: Get rid of Sync and use current time?
11223 if (expirationTime === Sync) {
11224 performSyncWork();
11225 } else {
11226 scheduleCallbackWithExpirationTime(root, expirationTime);
11227 }
11228}
11229
11230function addRootToSchedule(root, expirationTime) {
11231 // Add the root to the schedule.
11232 // Check if this root is already part of the schedule.
11233 if (root.nextScheduledRoot === null) {
11234 // This root is not already scheduled. Add it.
11235 root.expirationTime = expirationTime;
11236 if (lastScheduledRoot === null) {
11237 firstScheduledRoot = lastScheduledRoot = root;
11238 root.nextScheduledRoot = root;
11239 } else {
11240 lastScheduledRoot.nextScheduledRoot = root;
11241 lastScheduledRoot = root;
11242 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
11243 }
11244 } else {
11245 // This root is already scheduled, but its priority may have increased.
11246 var remainingExpirationTime = root.expirationTime;
11247 if (expirationTime > remainingExpirationTime) {
11248 // Update the priority.
11249 root.expirationTime = expirationTime;
11250 }
11251 }
11252}
11253
11254function findHighestPriorityRoot() {
11255 var highestPriorityWork = NoWork;
11256 var highestPriorityRoot = null;
11257 if (lastScheduledRoot !== null) {
11258 var previousScheduledRoot = lastScheduledRoot;
11259 var root = firstScheduledRoot;
11260 while (root !== null) {
11261 var remainingExpirationTime = root.expirationTime;
11262 if (remainingExpirationTime === NoWork) {
11263 // This root no longer has work. Remove it from the scheduler.
11264
11265 // TODO: This check is redudant, but Flow is confused by the branch
11266 // below where we set lastScheduledRoot to null, even though we break
11267 // from the loop right after.
11268 !(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;
11269 if (root === root.nextScheduledRoot) {
11270 // This is the only root in the list.
11271 root.nextScheduledRoot = null;
11272 firstScheduledRoot = lastScheduledRoot = null;
11273 break;
11274 } else if (root === firstScheduledRoot) {
11275 // This is the first root in the list.
11276 var next = root.nextScheduledRoot;
11277 firstScheduledRoot = next;
11278 lastScheduledRoot.nextScheduledRoot = next;
11279 root.nextScheduledRoot = null;
11280 } else if (root === lastScheduledRoot) {
11281 // This is the last root in the list.
11282 lastScheduledRoot = previousScheduledRoot;
11283 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
11284 root.nextScheduledRoot = null;
11285 break;
11286 } else {
11287 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
11288 root.nextScheduledRoot = null;
11289 }
11290 root = previousScheduledRoot.nextScheduledRoot;
11291 } else {
11292 if (remainingExpirationTime > highestPriorityWork) {
11293 // Update the priority, if it's higher
11294 highestPriorityWork = remainingExpirationTime;
11295 highestPriorityRoot = root;
11296 }
11297 if (root === lastScheduledRoot) {
11298 break;
11299 }
11300 if (highestPriorityWork === Sync) {
11301 // Sync is highest priority by definition so
11302 // we can stop searching.
11303 break;
11304 }
11305 previousScheduledRoot = root;
11306 root = root.nextScheduledRoot;
11307 }
11308 }
11309 }
11310
11311 nextFlushedRoot = highestPriorityRoot;
11312 nextFlushedExpirationTime = highestPriorityWork;
11313}
11314
11315// TODO: This wrapper exists because many of the older tests (the ones that use
11316// flushDeferredPri) rely on the number of times `shouldYield` is called. We
11317// should get rid of it.
11318var didYield = false;
11319function shouldYieldToRenderer() {
11320 if (didYield) {
11321 return true;
11322 }
11323 if (shouldYield$$1()) {
11324 didYield = true;
11325 return true;
11326 }
11327 return false;
11328}
11329
11330function performAsyncWork() {
11331 try {
11332 if (!shouldYieldToRenderer()) {
11333 // The callback timed out. That means at least one update has expired.
11334 // Iterate through the root schedule. If they contain expired work, set
11335 // the next render expiration time to the current time. This has the effect
11336 // of flushing all expired work in a single batch, instead of flushing each
11337 // level one at a time.
11338 if (firstScheduledRoot !== null) {
11339 recomputeCurrentRendererTime();
11340 var root = firstScheduledRoot;
11341 do {
11342 didExpireAtExpirationTime(root, currentRendererTime);
11343 // The root schedule is circular, so this is never null.
11344 root = root.nextScheduledRoot;
11345 } while (root !== firstScheduledRoot);
11346 }
11347 }
11348 performWork(NoWork, true);
11349 } finally {
11350 didYield = false;
11351 }
11352}
11353
11354function performSyncWork() {
11355 performWork(Sync, false);
11356}
11357
11358function performWork(minExpirationTime, isYieldy) {
11359 // Keep working on roots until there's no more work, or until there's a higher
11360 // priority event.
11361 findHighestPriorityRoot();
11362
11363 if (isYieldy) {
11364 recomputeCurrentRendererTime();
11365 currentSchedulerTime = currentRendererTime;
11366
11367 if (enableUserTimingAPI) {
11368 var didExpire = nextFlushedExpirationTime > currentRendererTime;
11369 var timeout = expirationTimeToMs(nextFlushedExpirationTime);
11370 stopRequestCallbackTimer(didExpire, timeout);
11371 }
11372
11373 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime && !(didYield && currentRendererTime > nextFlushedExpirationTime)) {
11374 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, currentRendererTime > nextFlushedExpirationTime);
11375 findHighestPriorityRoot();
11376 recomputeCurrentRendererTime();
11377 currentSchedulerTime = currentRendererTime;
11378 }
11379 } else {
11380 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime) {
11381 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
11382 findHighestPriorityRoot();
11383 }
11384 }
11385
11386 // We're done flushing work. Either we ran out of time in this callback,
11387 // or there's no more work left with sufficient priority.
11388
11389 // If we're inside a callback, set this to false since we just completed it.
11390 if (isYieldy) {
11391 callbackExpirationTime = NoWork;
11392 callbackID = null;
11393 }
11394 // If there's work left over, schedule a new callback.
11395 if (nextFlushedExpirationTime !== NoWork) {
11396 scheduleCallbackWithExpirationTime(nextFlushedRoot, nextFlushedExpirationTime);
11397 }
11398
11399 // Clean-up.
11400 finishRendering();
11401}
11402
11403function flushRoot(root, expirationTime) {
11404 !!isRendering ? invariant(false, 'work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method.') : void 0;
11405 // Perform work on root as if the given expiration time is the current time.
11406 // This has the effect of synchronously flushing all work up to and
11407 // including the given time.
11408 nextFlushedRoot = root;
11409 nextFlushedExpirationTime = expirationTime;
11410 performWorkOnRoot(root, expirationTime, false);
11411 // Flush any sync work that was scheduled by lifecycles
11412 performSyncWork();
11413}
11414
11415function finishRendering() {
11416 nestedUpdateCount = 0;
11417 lastCommittedRootDuringThisBatch = null;
11418
11419 if (completedBatches !== null) {
11420 var batches = completedBatches;
11421 completedBatches = null;
11422 for (var i = 0; i < batches.length; i++) {
11423 var batch = batches[i];
11424 try {
11425 batch._onComplete();
11426 } catch (error) {
11427 if (!hasUnhandledError) {
11428 hasUnhandledError = true;
11429 unhandledError = error;
11430 }
11431 }
11432 }
11433 }
11434
11435 if (hasUnhandledError) {
11436 var error = unhandledError;
11437 unhandledError = null;
11438 hasUnhandledError = false;
11439 throw error;
11440 }
11441}
11442
11443function performWorkOnRoot(root, expirationTime, isYieldy) {
11444 !!isRendering ? invariant(false, 'performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11445
11446 isRendering = true;
11447
11448 // Check if this is async work or sync/expired work.
11449 if (!isYieldy) {
11450 // Flush work without yielding.
11451 // TODO: Non-yieldy work does not necessarily imply expired work. A renderer
11452 // may want to perform some work without yielding, but also without
11453 // requiring the root to complete (by triggering placeholders).
11454
11455 var finishedWork = root.finishedWork;
11456 if (finishedWork !== null) {
11457 // This root is already complete. We can commit it.
11458 completeRoot(root, finishedWork, expirationTime);
11459 } else {
11460 root.finishedWork = null;
11461 // If this root previously suspended, clear its existing timeout, since
11462 // we're about to try rendering again.
11463 var timeoutHandle = root.timeoutHandle;
11464 if (timeoutHandle !== noTimeout) {
11465 root.timeoutHandle = noTimeout;
11466 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
11467 cancelTimeout(timeoutHandle);
11468 }
11469 renderRoot(root, isYieldy);
11470 finishedWork = root.finishedWork;
11471 if (finishedWork !== null) {
11472 // We've completed the root. Commit it.
11473 completeRoot(root, finishedWork, expirationTime);
11474 }
11475 }
11476 } else {
11477 // Flush async work.
11478 var _finishedWork = root.finishedWork;
11479 if (_finishedWork !== null) {
11480 // This root is already complete. We can commit it.
11481 completeRoot(root, _finishedWork, expirationTime);
11482 } else {
11483 root.finishedWork = null;
11484 // If this root previously suspended, clear its existing timeout, since
11485 // we're about to try rendering again.
11486 var _timeoutHandle = root.timeoutHandle;
11487 if (_timeoutHandle !== noTimeout) {
11488 root.timeoutHandle = noTimeout;
11489 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
11490 cancelTimeout(_timeoutHandle);
11491 }
11492 renderRoot(root, isYieldy);
11493 _finishedWork = root.finishedWork;
11494 if (_finishedWork !== null) {
11495 // We've completed the root. Check the if we should yield one more time
11496 // before committing.
11497 if (!shouldYieldToRenderer()) {
11498 // Still time left. Commit the root.
11499 completeRoot(root, _finishedWork, expirationTime);
11500 } else {
11501 // There's no time left. Mark this root as complete. We'll come
11502 // back and commit it later.
11503 root.finishedWork = _finishedWork;
11504 }
11505 }
11506 }
11507 }
11508
11509 isRendering = false;
11510}
11511
11512function completeRoot(root, finishedWork, expirationTime) {
11513 // Check if there's a batch that matches this expiration time.
11514 var firstBatch = root.firstBatch;
11515 if (firstBatch !== null && firstBatch._expirationTime >= expirationTime) {
11516 if (completedBatches === null) {
11517 completedBatches = [firstBatch];
11518 } else {
11519 completedBatches.push(firstBatch);
11520 }
11521 if (firstBatch._defer) {
11522 // This root is blocked from committing by a batch. Unschedule it until
11523 // we receive another update.
11524 root.finishedWork = finishedWork;
11525 root.expirationTime = NoWork;
11526 return;
11527 }
11528 }
11529
11530 // Commit the root.
11531 root.finishedWork = null;
11532
11533 // Check if this is a nested update (a sync update scheduled during the
11534 // commit phase).
11535 if (root === lastCommittedRootDuringThisBatch) {
11536 // If the next root is the same as the previous root, this is a nested
11537 // update. To prevent an infinite loop, increment the nested update count.
11538 nestedUpdateCount++;
11539 } else {
11540 // Reset whenever we switch roots.
11541 lastCommittedRootDuringThisBatch = root;
11542 nestedUpdateCount = 0;
11543 }
11544 commitRoot(root, finishedWork);
11545}
11546
11547function onUncaughtError(error) {
11548 !(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;
11549 // Unschedule this root so we don't work on it again until there's
11550 // another update.
11551 nextFlushedRoot.expirationTime = NoWork;
11552 if (!hasUnhandledError) {
11553 hasUnhandledError = true;
11554 unhandledError = error;
11555 }
11556}
11557
11558// TODO: Batching should be implemented at the renderer level, not within
11559// the reconciler.
11560function flushSync(fn, a) {
11561 !!isRendering ? invariant(false, 'flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.') : void 0;
11562 var previousIsBatchingUpdates = isBatchingUpdates;
11563 isBatchingUpdates = true;
11564 try {
11565 return syncUpdates(fn, a);
11566 } finally {
11567 isBatchingUpdates = previousIsBatchingUpdates;
11568 performSyncWork();
11569 }
11570}
11571
11572// 0 is PROD, 1 is DEV.
11573// Might add PROFILE later.
11574
11575
11576var didWarnAboutNestedUpdates = void 0;
11577{
11578 didWarnAboutNestedUpdates = false;
11579
11580}
11581
11582function getContextForSubtree(parentComponent) {
11583 if (!parentComponent) {
11584 return emptyContextObject;
11585 }
11586
11587 var fiber = get(parentComponent);
11588 var parentContext = findCurrentUnmaskedContext(fiber);
11589
11590 if (fiber.tag === ClassComponent) {
11591 var Component = fiber.type;
11592 if (isContextProvider(Component)) {
11593 return processChildContext(fiber, Component, parentContext);
11594 }
11595 }
11596
11597 return parentContext;
11598}
11599
11600function scheduleRootUpdate(current$$1, element, expirationTime, callback) {
11601 {
11602 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
11603 didWarnAboutNestedUpdates = true;
11604 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');
11605 }
11606 }
11607
11608 var update = createUpdate(expirationTime);
11609 // Caution: React DevTools currently depends on this property
11610 // being called "element".
11611 update.payload = { element: element };
11612
11613 callback = callback === undefined ? null : callback;
11614 if (callback !== null) {
11615 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
11616 update.callback = callback;
11617 }
11618
11619 flushPassiveEffects();
11620 enqueueUpdate(current$$1, update);
11621 scheduleWork(current$$1, expirationTime);
11622
11623 return expirationTime;
11624}
11625
11626function updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback) {
11627 // TODO: If this is a nested container, this won't be the root.
11628 var current$$1 = container.current;
11629
11630 {
11631 if (ReactFiberInstrumentation_1.debugTool) {
11632 if (current$$1.alternate === null) {
11633 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
11634 } else if (element === null) {
11635 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
11636 } else {
11637 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
11638 }
11639 }
11640 }
11641
11642 var context = getContextForSubtree(parentComponent);
11643 if (container.context === null) {
11644 container.context = context;
11645 } else {
11646 container.pendingContext = context;
11647 }
11648
11649 return scheduleRootUpdate(current$$1, element, expirationTime, callback);
11650}
11651
11652function createContainer(containerInfo, isConcurrent, hydrate) {
11653 return createFiberRoot(containerInfo, isConcurrent, hydrate);
11654}
11655
11656function updateContainer(element, container, parentComponent, callback) {
11657 var current$$1 = container.current;
11658 var currentTime = requestCurrentTime();
11659 var expirationTime = computeExpirationForFiber(currentTime, current$$1);
11660 return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback);
11661}
11662
11663function getPublicRootInstance(container) {
11664 var containerFiber = container.current;
11665 if (!containerFiber.child) {
11666 return null;
11667 }
11668 switch (containerFiber.child.tag) {
11669 case HostComponent:
11670 return getPublicInstance(containerFiber.child.stateNode);
11671 default:
11672 return containerFiber.child.stateNode;
11673 }
11674}
11675
11676
11677
11678var overrideProps = null;
11679
11680{
11681 var copyWithSetImpl = function (obj, path, idx, value) {
11682 if (idx >= path.length) {
11683 return value;
11684 }
11685 var key = path[idx];
11686 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
11687 // $FlowFixMe number or string is fine here
11688 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
11689 return updated;
11690 };
11691
11692 var copyWithSet = function (obj, path, value) {
11693 return copyWithSetImpl(obj, path, 0, value);
11694 };
11695
11696 // Support DevTools props for function components, forwardRef, memo, host components, etc.
11697 overrideProps = function (fiber, path, value) {
11698 flushPassiveEffects();
11699 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
11700 if (fiber.alternate) {
11701 fiber.alternate.pendingProps = fiber.pendingProps;
11702 }
11703 scheduleWork(fiber, Sync);
11704 };
11705}
11706
11707function injectIntoDevTools(devToolsConfig) {
11708 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
11709
11710 return injectInternals(_assign({}, devToolsConfig, {
11711 overrideProps: overrideProps,
11712 findHostInstanceByFiber: function (fiber) {
11713 var hostFiber = findCurrentHostFiber(fiber);
11714 if (hostFiber === null) {
11715 return null;
11716 }
11717 return hostFiber.stateNode;
11718 },
11719 findFiberByHostInstance: function (instance) {
11720 if (!findFiberByHostInstance) {
11721 // Might not be implemented by the renderer.
11722 return null;
11723 }
11724 return findFiberByHostInstance(instance);
11725 }
11726 }));
11727}
11728
11729// This file intentionally does *not* have the Flow annotation.
11730// Don't add it. See `./inline-typed.js` for an explanation.
11731
11732var getFiberCurrentPropsFromNode = null;
11733var getInstanceFromNode = null;
11734
11735
11736
11737
11738{
11739
11740}
11741
11742/**
11743 * Standard/simple iteration through an event's collected dispatches.
11744 */
11745
11746
11747/**
11748 * @see executeDispatchesInOrderStopAtTrueImpl
11749 */
11750
11751
11752/**
11753 * Execution of a "direct" dispatch - there must be at most one dispatch
11754 * accumulated on the event or it is considered an error. It doesn't really make
11755 * sense for an event with multiple dispatches (bubbled) to keep track of the
11756 * return values at each dispatch execution, but it does tend to make sense when
11757 * dealing with "direct" dispatches.
11758 *
11759 * @return {*} The return value of executing the single dispatch.
11760 */
11761
11762
11763/**
11764 * @param {SyntheticEvent} event
11765 * @return {boolean} True iff number of dispatches accumulated is greater than 0.
11766 */
11767
11768// Use to restore controlled state after a change event has fired.
11769
11770var restoreImpl = null;
11771var restoreTarget = null;
11772var restoreQueue = null;
11773
11774function restoreStateOfTarget(target) {
11775 // We perform this translation at the end of the event loop so that we
11776 // always receive the correct fiber here
11777 var internalInstance = getInstanceFromNode(target);
11778 if (!internalInstance) {
11779 // Unmounted
11780 return;
11781 }
11782 !(typeof restoreImpl === 'function') ? invariant(false, 'setRestoreImplementation() needs to be called to handle a target for controlled events. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11783 var props = getFiberCurrentPropsFromNode(internalInstance.stateNode);
11784 restoreImpl(internalInstance.stateNode, internalInstance.type, props);
11785}
11786
11787
11788
11789
11790
11791function needsStateRestore() {
11792 return restoreTarget !== null || restoreQueue !== null;
11793}
11794
11795function restoreStateIfNeeded() {
11796 if (!restoreTarget) {
11797 return;
11798 }
11799 var target = restoreTarget;
11800 var queuedTargets = restoreQueue;
11801 restoreTarget = null;
11802 restoreQueue = null;
11803
11804 restoreStateOfTarget(target);
11805 if (queuedTargets) {
11806 for (var i = 0; i < queuedTargets.length; i++) {
11807 restoreStateOfTarget(queuedTargets[i]);
11808 }
11809 }
11810}
11811
11812// Used as a way to call batchedUpdates when we don't have a reference to
11813// the renderer. Such as when we're dispatching events or if third party
11814// libraries need to call batchedUpdates. Eventually, this API will go away when
11815// everything is batched by default. We'll then have a similar API to opt-out of
11816// scheduled work and instead do synchronous work.
11817
11818// Defaults
11819var _batchedUpdatesImpl = function (fn, bookkeeping) {
11820 return fn(bookkeeping);
11821};
11822var _flushInteractiveUpdatesImpl = function () {};
11823
11824var isBatching = false;
11825function batchedUpdates$1(fn, bookkeeping) {
11826 if (isBatching) {
11827 // If we are currently inside another batch, we need to wait until it
11828 // fully completes before restoring state.
11829 return fn(bookkeeping);
11830 }
11831 isBatching = true;
11832 try {
11833 return _batchedUpdatesImpl(fn, bookkeeping);
11834 } finally {
11835 // Here we wait until all updates have propagated, which is important
11836 // when using controlled components within layers:
11837 // https://github.com/facebook/react/issues/1698
11838 // Then we restore state of any controlled component.
11839 isBatching = false;
11840 var controlledComponentsHavePendingUpdates = needsStateRestore();
11841 if (controlledComponentsHavePendingUpdates) {
11842 // If a controlled event was fired, we may need to restore the state of
11843 // the DOM node back to the controlled value. This is necessary when React
11844 // bails out of the update without touching the DOM.
11845 _flushInteractiveUpdatesImpl();
11846 restoreStateIfNeeded();
11847 }
11848 }
11849}
11850
11851// TODO: this is special because it gets imported during build.
11852
11853var ReactVersion = '16.7.0';
11854
11855var _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; }; }();
11856
11857function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11858
11859function _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; }
11860
11861var defaultTestOptions = {
11862 createNodeMock: function () {
11863 return null;
11864 }
11865};
11866
11867function toJSON(inst) {
11868 if (inst.isHidden) {
11869 // Omit timed out children from output entirely. This seems like the least
11870 // surprising behavior. We could perhaps add a separate API that includes
11871 // them, if it turns out people need it.
11872 return null;
11873 }
11874 switch (inst.tag) {
11875 case 'TEXT':
11876 return inst.text;
11877 case 'INSTANCE':
11878 {
11879 /* eslint-disable no-unused-vars */
11880 // We don't include the `children` prop in JSON.
11881 // Instead, we will include the actual rendered children.
11882 var _inst$props = inst.props,
11883 _children = _inst$props.children,
11884 _props = _objectWithoutProperties(_inst$props, ['children']);
11885 /* eslint-enable */
11886
11887
11888 var renderedChildren = null;
11889 if (inst.children && inst.children.length) {
11890 for (var i = 0; i < inst.children.length; i++) {
11891 var renderedChild = toJSON(inst.children[i]);
11892 if (renderedChild !== null) {
11893 if (renderedChildren === null) {
11894 renderedChildren = [renderedChild];
11895 } else {
11896 renderedChildren.push(renderedChild);
11897 }
11898 }
11899 }
11900 }
11901 var json = {
11902 type: inst.type,
11903 props: _props,
11904 children: renderedChildren
11905 };
11906 Object.defineProperty(json, '$$typeof', {
11907 value: Symbol.for('react.test.json')
11908 });
11909 return json;
11910 }
11911 default:
11912 throw new Error('Unexpected node type in toJSON: ' + inst.tag);
11913 }
11914}
11915
11916function childrenToTree(node) {
11917 if (!node) {
11918 return null;
11919 }
11920 var children = nodeAndSiblingsArray(node);
11921 if (children.length === 0) {
11922 return null;
11923 } else if (children.length === 1) {
11924 return toTree(children[0]);
11925 }
11926 return flatten(children.map(toTree));
11927}
11928
11929function nodeAndSiblingsArray(nodeWithSibling) {
11930 var array = [];
11931 var node = nodeWithSibling;
11932 while (node != null) {
11933 array.push(node);
11934 node = node.sibling;
11935 }
11936 return array;
11937}
11938
11939function flatten(arr) {
11940 var result = [];
11941 var stack = [{ i: 0, array: arr }];
11942 while (stack.length) {
11943 var n = stack.pop();
11944 while (n.i < n.array.length) {
11945 var el = n.array[n.i];
11946 n.i += 1;
11947 if (Array.isArray(el)) {
11948 stack.push(n);
11949 stack.push({ i: 0, array: el });
11950 break;
11951 }
11952 result.push(el);
11953 }
11954 }
11955 return result;
11956}
11957
11958function toTree(node) {
11959 if (node == null) {
11960 return null;
11961 }
11962 switch (node.tag) {
11963 case HostRoot:
11964 return childrenToTree(node.child);
11965 case HostPortal:
11966 return childrenToTree(node.child);
11967 case ClassComponent:
11968 return {
11969 nodeType: 'component',
11970 type: node.type,
11971 props: _assign({}, node.memoizedProps),
11972 instance: node.stateNode,
11973 rendered: childrenToTree(node.child)
11974 };
11975 case FunctionComponent:
11976 case SimpleMemoComponent:
11977 return {
11978 nodeType: 'component',
11979 type: node.type,
11980 props: _assign({}, node.memoizedProps),
11981 instance: null,
11982 rendered: childrenToTree(node.child)
11983 };
11984 case HostComponent:
11985 {
11986 return {
11987 nodeType: 'host',
11988 type: node.type,
11989 props: _assign({}, node.memoizedProps),
11990 instance: null, // TODO: use createNodeMock here somehow?
11991 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
11992 };
11993 }
11994 case HostText:
11995 return node.stateNode.text;
11996 case Fragment:
11997 case ContextProvider:
11998 case ContextConsumer:
11999 case Mode:
12000 case Profiler:
12001 case ForwardRef:
12002 case MemoComponent:
12003 case IncompleteClassComponent:
12004 return childrenToTree(node.child);
12005 default:
12006 invariant(false, 'toTree() does not yet know how to handle nodes with tag=%s', node.tag);
12007 }
12008}
12009
12010var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent,
12011// Normally skipped, but used when there's more than one root child.
12012HostRoot]);
12013
12014function getChildren(parent) {
12015 var children = [];
12016 var startingNode = parent;
12017 var node = startingNode;
12018 if (node.child === null) {
12019 return children;
12020 }
12021 node.child.return = node;
12022 node = node.child;
12023 outer: while (true) {
12024 var descend = false;
12025 if (validWrapperTypes.has(node.tag)) {
12026 children.push(wrapFiber(node));
12027 } else if (node.tag === HostText) {
12028 children.push('' + node.memoizedProps);
12029 } else {
12030 descend = true;
12031 }
12032 if (descend && node.child !== null) {
12033 node.child.return = node;
12034 node = node.child;
12035 continue;
12036 }
12037 while (node.sibling === null) {
12038 if (node.return === startingNode) {
12039 break outer;
12040 }
12041 node = node.return;
12042 }
12043 node.sibling.return = node.return;
12044 node = node.sibling;
12045 }
12046 return children;
12047}
12048
12049var ReactTestInstance = function () {
12050 ReactTestInstance.prototype._currentFiber = function _currentFiber() {
12051 // Throws if this component has been unmounted.
12052 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
12053 !(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;
12054 return fiber;
12055 };
12056
12057 function ReactTestInstance(fiber) {
12058 _classCallCheck(this, ReactTestInstance);
12059
12060 !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;
12061 this._fiber = fiber;
12062 }
12063
12064 // Custom search functions
12065 ReactTestInstance.prototype.find = function find(predicate) {
12066 return expectOne(this.findAll(predicate, { deep: false }), 'matching custom predicate: ' + predicate.toString());
12067 };
12068
12069 ReactTestInstance.prototype.findByType = function findByType(type) {
12070 return expectOne(this.findAllByType(type, { deep: false }), 'with node type: "' + (type.displayName || type.name) + '"');
12071 };
12072
12073 ReactTestInstance.prototype.findByProps = function findByProps(props) {
12074 return expectOne(this.findAllByProps(props, { deep: false }), 'with props: ' + JSON.stringify(props));
12075 };
12076
12077 ReactTestInstance.prototype.findAll = function findAll(predicate) {
12078 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12079
12080 return _findAll(this, predicate, options);
12081 };
12082
12083 ReactTestInstance.prototype.findAllByType = function findAllByType(type) {
12084 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12085
12086 return _findAll(this, function (node) {
12087 return node.type === type;
12088 }, options);
12089 };
12090
12091 ReactTestInstance.prototype.findAllByProps = function findAllByProps(props) {
12092 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12093
12094 return _findAll(this, function (node) {
12095 return node.props && propsMatch(node.props, props);
12096 }, options);
12097 };
12098
12099 _createClass(ReactTestInstance, [{
12100 key: 'instance',
12101 get: function () {
12102 if (this._fiber.tag === HostComponent) {
12103 return getPublicInstance(this._fiber.stateNode);
12104 } else {
12105 return this._fiber.stateNode;
12106 }
12107 }
12108 }, {
12109 key: 'type',
12110 get: function () {
12111 return this._fiber.type;
12112 }
12113 }, {
12114 key: 'props',
12115 get: function () {
12116 return this._currentFiber().memoizedProps;
12117 }
12118 }, {
12119 key: 'parent',
12120 get: function () {
12121 var parent = this._fiber.return;
12122 while (parent !== null) {
12123 if (validWrapperTypes.has(parent.tag)) {
12124 if (parent.tag === HostRoot) {
12125 // Special case: we only "materialize" instances for roots
12126 // if they have more than a single child. So we'll check that now.
12127 if (getChildren(parent).length < 2) {
12128 return null;
12129 }
12130 }
12131 return wrapFiber(parent);
12132 }
12133 parent = parent.return;
12134 }
12135 return null;
12136 }
12137 }, {
12138 key: 'children',
12139 get: function () {
12140 return getChildren(this._currentFiber());
12141 }
12142 }]);
12143
12144 return ReactTestInstance;
12145}();
12146
12147function _findAll(root, predicate, options) {
12148 var deep = options ? options.deep : true;
12149 var results = [];
12150
12151 if (predicate(root)) {
12152 results.push(root);
12153 if (!deep) {
12154 return results;
12155 }
12156 }
12157
12158 root.children.forEach(function (child) {
12159 if (typeof child === 'string') {
12160 return;
12161 }
12162 results.push.apply(results, _findAll(child, predicate, options));
12163 });
12164
12165 return results;
12166}
12167
12168function expectOne(all, message) {
12169 if (all.length === 1) {
12170 return all[0];
12171 }
12172
12173 var prefix = all.length === 0 ? 'No instances found ' : 'Expected 1 but found ' + all.length + ' instances ';
12174
12175 throw new Error(prefix + message);
12176}
12177
12178function propsMatch(props, filter) {
12179 for (var key in filter) {
12180 if (props[key] !== filter[key]) {
12181 return false;
12182 }
12183 }
12184 return true;
12185}
12186
12187var ReactTestRendererFiber = {
12188 create: function (element, options) {
12189 var createNodeMock = defaultTestOptions.createNodeMock;
12190 var isConcurrent = false;
12191 if (typeof options === 'object' && options !== null) {
12192 if (typeof options.createNodeMock === 'function') {
12193 createNodeMock = options.createNodeMock;
12194 }
12195 if (options.unstable_isConcurrent === true) {
12196 isConcurrent = true;
12197 }
12198 }
12199 var container = {
12200 children: [],
12201 createNodeMock: createNodeMock,
12202 tag: 'CONTAINER'
12203 };
12204 var root = createContainer(container, isConcurrent, false);
12205 !(root != null) ? invariant(false, 'something went wrong') : void 0;
12206 updateContainer(element, root, null, null);
12207
12208 var entry = {
12209 root: undefined, // makes flow happy
12210 // we define a 'getter' for 'root' below using 'Object.defineProperty'
12211 toJSON: function () {
12212 if (root == null || root.current == null || container == null) {
12213 return null;
12214 }
12215 if (container.children.length === 0) {
12216 return null;
12217 }
12218 if (container.children.length === 1) {
12219 return toJSON(container.children[0]);
12220 }
12221 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
12222 // Omit timed out children from output entirely, including the fact that we
12223 // temporarily wrap fallback and timed out children in an array.
12224 return toJSON(container.children[1]);
12225 }
12226 var renderedChildren = null;
12227 if (container.children && container.children.length) {
12228 for (var i = 0; i < container.children.length; i++) {
12229 var renderedChild = toJSON(container.children[i]);
12230 if (renderedChild !== null) {
12231 if (renderedChildren === null) {
12232 renderedChildren = [renderedChild];
12233 } else {
12234 renderedChildren.push(renderedChild);
12235 }
12236 }
12237 }
12238 }
12239 return renderedChildren;
12240 },
12241 toTree: function () {
12242 if (root == null || root.current == null) {
12243 return null;
12244 }
12245 return toTree(root.current);
12246 },
12247 update: function (newElement) {
12248 if (root == null || root.current == null) {
12249 return;
12250 }
12251 updateContainer(newElement, root, null, null);
12252 },
12253 unmount: function () {
12254 if (root == null || root.current == null) {
12255 return;
12256 }
12257 updateContainer(null, root, null, null);
12258 container = null;
12259 root = null;
12260 },
12261 getInstance: function () {
12262 if (root == null || root.current == null) {
12263 return null;
12264 }
12265 return getPublicRootInstance(root);
12266 },
12267
12268
12269 unstable_flushAll: flushAll,
12270 unstable_flushSync: function (fn) {
12271 clearYields();
12272 return flushSync(fn);
12273 },
12274
12275 unstable_flushNumberOfYields: flushNumberOfYields,
12276 unstable_clearYields: clearYields
12277 };
12278
12279 Object.defineProperty(entry, 'root', {
12280 configurable: true,
12281 enumerable: true,
12282 get: function () {
12283 if (root === null) {
12284 throw new Error("Can't access .root on unmounted test renderer");
12285 }
12286 var children = getChildren(root.current);
12287 if (children.length === 0) {
12288 throw new Error("Can't access .root on unmounted test renderer");
12289 } else if (children.length === 1) {
12290 // Normally, we skip the root and just give you the child.
12291 return children[0];
12292 } else {
12293 // However, we give you the root if there's more than one root child.
12294 // We could make this the behavior for all cases but it would be a breaking change.
12295 return wrapFiber(root.current);
12296 }
12297 }
12298 });
12299
12300 return entry;
12301 },
12302
12303
12304 unstable_yield: yieldValue,
12305 unstable_clearYields: clearYields,
12306
12307 /* eslint-disable camelcase */
12308 unstable_batchedUpdates: batchedUpdates$1,
12309 /* eslint-enable camelcase */
12310
12311 unstable_setNowImplementation: setNowImplementation
12312};
12313
12314var fiberToWrapper = new WeakMap();
12315function wrapFiber(fiber) {
12316 var wrapper = fiberToWrapper.get(fiber);
12317 if (wrapper === undefined && fiber.alternate !== null) {
12318 wrapper = fiberToWrapper.get(fiber.alternate);
12319 }
12320 if (wrapper === undefined) {
12321 wrapper = new ReactTestInstance(fiber);
12322 fiberToWrapper.set(fiber, wrapper);
12323 }
12324 return wrapper;
12325}
12326
12327// Enable ReactTestRenderer to be used to test DevTools integration.
12328injectIntoDevTools({
12329 findFiberByHostInstance: function () {
12330 throw new Error('TestRenderer does not support findFiberByHostInstance()');
12331 },
12332 bundleType: 1,
12333 version: ReactVersion,
12334 rendererPackageName: 'react-test-renderer'
12335});
12336
12337
12338
12339var ReactTestRenderer = Object.freeze({
12340 default: ReactTestRendererFiber
12341});
12342
12343var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
12344
12345// TODO: decide on the top-level export form.
12346// This is hacky but makes it work with both Rollup and Jest.
12347var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
12348
12349return reactTestRenderer;
12350
12351})));