UNPKG

497 kBJavaScriptView Raw
1/** @license React v16.8.3
2 * react-test-renderer.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
14 typeof define === 'function' && define.amd ? define(['react'], factory) :
15 (global.ReactTestRenderer = factory(global.React));
16}(this, (function (React) { 'use strict';
17
18/**
19 * Use invariant() to assert state which your program assumes to be true.
20 *
21 * Provide sprintf-style format (only %s is supported) and arguments
22 * to provide information about what broke and what you were
23 * expecting.
24 *
25 * The invariant message will be stripped in production, but the invariant
26 * will remain to ensure logic does not differ in production.
27 */
28
29var validateFormat = function () {};
30
31{
32 validateFormat = function (format) {
33 if (format === undefined) {
34 throw new Error('invariant requires an error message argument');
35 }
36 };
37}
38
39function invariant(condition, format, a, b, c, d, e, f) {
40 validateFormat(format);
41
42 if (!condition) {
43 var error = void 0;
44 if (format === undefined) {
45 error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
46 } else {
47 var args = [a, b, c, d, e, f];
48 var argIndex = 0;
49 error = new Error(format.replace(/%s/g, function () {
50 return args[argIndex++];
51 }));
52 error.name = 'Invariant Violation';
53 }
54
55 error.framesToPop = 1; // we don't care about invariant's own frame
56 throw error;
57 }
58}
59
60// Relying on the `invariant()` implementation lets us
61// preserve the format and params in the www builds.
62
63var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
64
65var _assign = ReactInternals.assign;
66
67/**
68 * Similar to invariant but only logs a warning if the condition is not met.
69 * This can be used to log issues in development environments in critical
70 * paths. Removing the logging code for production environments will keep the
71 * same logic and follow the same code paths.
72 */
73
74var warningWithoutStack = function () {};
75
76{
77 warningWithoutStack = function (condition, format) {
78 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
79 args[_key - 2] = arguments[_key];
80 }
81
82 if (format === undefined) {
83 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
84 }
85 if (args.length > 8) {
86 // Check before the condition to catch violations early.
87 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
88 }
89 if (condition) {
90 return;
91 }
92 if (typeof console !== 'undefined') {
93 var argsWithFormat = args.map(function (item) {
94 return '' + item;
95 });
96 argsWithFormat.unshift('Warning: ' + format);
97
98 // We intentionally don't use spread (or .apply) directly because it
99 // breaks IE9: https://github.com/facebook/react/issues/13610
100 Function.prototype.apply.call(console.error, console, argsWithFormat);
101 }
102 try {
103 // --- Welcome to debugging React ---
104 // This error was thrown as a convenience so that you can use this stack
105 // to find the callsite that caused this warning to fire.
106 var argIndex = 0;
107 var message = 'Warning: ' + format.replace(/%s/g, function () {
108 return args[argIndex++];
109 });
110 throw new Error(message);
111 } catch (x) {}
112 };
113}
114
115var warningWithoutStack$1 = warningWithoutStack;
116
117/**
118 * `ReactInstanceMap` maintains a mapping from a public facing stateful
119 * instance (key) and the internal representation (value). This allows public
120 * methods to accept the user facing instance as an argument and map them back
121 * to internal methods.
122 *
123 * Note that this module is currently shared and assumed to be stateless.
124 * If this becomes an actual Map, that will break.
125 */
126
127/**
128 * This API should be called `delete` but we'd have to make sure to always
129 * transform these to strings for IE support. When this transform is fully
130 * supported we can rename it.
131 */
132
133
134function get(key) {
135 return key._reactInternalFiber;
136}
137
138
139
140function set(key, value) {
141 key._reactInternalFiber = value;
142}
143
144var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
145
146// Prevent newer renderers from RTE when used with older react package versions.
147// Current owner and dispatcher used to share the same ref,
148// but PR #14548 split them out to better support the react-debug-tools package.
149if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
150 ReactSharedInternals.ReactCurrentDispatcher = {
151 current: null
152 };
153}
154
155// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
156// nor polyfill, then a plain number is used for performance.
157var hasSymbol = typeof Symbol === 'function' && Symbol.for;
158
159var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
160var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
161var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
162var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
163var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
164var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
165var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
166
167var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
168var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
169var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
170var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
171var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
172
173var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
174var FAUX_ITERATOR_SYMBOL = '@@iterator';
175
176function getIteratorFn(maybeIterable) {
177 if (maybeIterable === null || typeof maybeIterable !== 'object') {
178 return null;
179 }
180 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
181 if (typeof maybeIterator === 'function') {
182 return maybeIterator;
183 }
184 return null;
185}
186
187var Pending = 0;
188var Resolved = 1;
189var Rejected = 2;
190
191function refineResolvedLazyComponent(lazyComponent) {
192 return lazyComponent._status === Resolved ? lazyComponent._result : null;
193}
194
195function getWrappedName(outerType, innerType, wrapperName) {
196 var functionName = innerType.displayName || innerType.name || '';
197 return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
198}
199
200function getComponentName(type) {
201 if (type == null) {
202 // Host root, text node or just invalid type.
203 return null;
204 }
205 {
206 if (typeof type.tag === 'number') {
207 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
208 }
209 }
210 if (typeof type === 'function') {
211 return type.displayName || type.name || null;
212 }
213 if (typeof type === 'string') {
214 return type;
215 }
216 switch (type) {
217 case REACT_CONCURRENT_MODE_TYPE:
218 return 'ConcurrentMode';
219 case REACT_FRAGMENT_TYPE:
220 return 'Fragment';
221 case REACT_PORTAL_TYPE:
222 return 'Portal';
223 case REACT_PROFILER_TYPE:
224 return 'Profiler';
225 case REACT_STRICT_MODE_TYPE:
226 return 'StrictMode';
227 case REACT_SUSPENSE_TYPE:
228 return 'Suspense';
229 }
230 if (typeof type === 'object') {
231 switch (type.$$typeof) {
232 case REACT_CONTEXT_TYPE:
233 return 'Context.Consumer';
234 case REACT_PROVIDER_TYPE:
235 return 'Context.Provider';
236 case REACT_FORWARD_REF_TYPE:
237 return getWrappedName(type, type.render, 'ForwardRef');
238 case REACT_MEMO_TYPE:
239 return getComponentName(type.type);
240 case REACT_LAZY_TYPE:
241 {
242 var thenable = type;
243 var resolvedThenable = refineResolvedLazyComponent(thenable);
244 if (resolvedThenable) {
245 return getComponentName(resolvedThenable);
246 }
247 }
248 }
249 }
250 return null;
251}
252
253var FunctionComponent = 0;
254var ClassComponent = 1;
255var IndeterminateComponent = 2; // Before we know whether it is function or class
256var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
257var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
258var HostComponent = 5;
259var HostText = 6;
260var Fragment = 7;
261var Mode = 8;
262var ContextConsumer = 9;
263var ContextProvider = 10;
264var ForwardRef = 11;
265var Profiler = 12;
266var SuspenseComponent = 13;
267var MemoComponent = 14;
268var SimpleMemoComponent = 15;
269var LazyComponent = 16;
270var IncompleteClassComponent = 17;
271var DehydratedSuspenseComponent = 18;
272
273// Don't change these two values. They're used by React Dev Tools.
274var NoEffect = /* */0;
275var PerformedWork = /* */1;
276
277// You can change the rest (and add more).
278var Placement = /* */2;
279var Update = /* */4;
280var PlacementAndUpdate = /* */6;
281var Deletion = /* */8;
282var ContentReset = /* */16;
283var Callback = /* */32;
284var DidCapture = /* */64;
285var Ref = /* */128;
286var Snapshot = /* */256;
287var Passive = /* */512;
288
289// Passive & Update & Callback & Ref & Snapshot
290var LifecycleEffectMask = /* */932;
291
292// Union of all host effects
293var HostEffectMask = /* */1023;
294
295var Incomplete = /* */1024;
296var ShouldCapture = /* */2048;
297
298var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
299
300var MOUNTING = 1;
301var MOUNTED = 2;
302var UNMOUNTED = 3;
303
304function isFiberMountedImpl(fiber) {
305 var node = fiber;
306 if (!fiber.alternate) {
307 // If there is no alternate, this might be a new tree that isn't inserted
308 // yet. If it is, then it will have a pending insertion effect on it.
309 if ((node.effectTag & Placement) !== NoEffect) {
310 return MOUNTING;
311 }
312 while (node.return) {
313 node = node.return;
314 if ((node.effectTag & Placement) !== NoEffect) {
315 return MOUNTING;
316 }
317 }
318 } else {
319 while (node.return) {
320 node = node.return;
321 }
322 }
323 if (node.tag === HostRoot) {
324 // TODO: Check if this was a nested HostRoot when used with
325 // renderContainerIntoSubtree.
326 return MOUNTED;
327 }
328 // If we didn't hit the root, that means that we're in an disconnected tree
329 // that has been unmounted.
330 return UNMOUNTED;
331}
332
333function isFiberMounted(fiber) {
334 return isFiberMountedImpl(fiber) === MOUNTED;
335}
336
337function isMounted(component) {
338 {
339 var owner = ReactCurrentOwner.current;
340 if (owner !== null && owner.tag === ClassComponent) {
341 var ownerFiber = owner;
342 var instance = ownerFiber.stateNode;
343 !instance._warnedAboutRefsInRender ? warningWithoutStack$1(false, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber.type) || 'A component') : void 0;
344 instance._warnedAboutRefsInRender = true;
345 }
346 }
347
348 var fiber = get(component);
349 if (!fiber) {
350 return false;
351 }
352 return isFiberMountedImpl(fiber) === MOUNTED;
353}
354
355function assertIsMounted(fiber) {
356 !(isFiberMountedImpl(fiber) === MOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
357}
358
359function findCurrentFiberUsingSlowPath(fiber) {
360 var alternate = fiber.alternate;
361 if (!alternate) {
362 // If there is no alternate, then we only need to check if it is mounted.
363 var state = isFiberMountedImpl(fiber);
364 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
365 if (state === MOUNTING) {
366 return null;
367 }
368 return fiber;
369 }
370 // If we have two possible branches, we'll walk backwards up to the root
371 // to see what path the root points to. On the way we may hit one of the
372 // special cases and we'll deal with them.
373 var a = fiber;
374 var b = alternate;
375 while (true) {
376 var parentA = a.return;
377 var parentB = parentA ? parentA.alternate : null;
378 if (!parentA || !parentB) {
379 // We're at the root.
380 break;
381 }
382
383 // If both copies of the parent fiber point to the same child, we can
384 // assume that the child is current. This happens when we bailout on low
385 // priority: the bailed out fiber's child reuses the current child.
386 if (parentA.child === parentB.child) {
387 var child = parentA.child;
388 while (child) {
389 if (child === a) {
390 // We've determined that A is the current branch.
391 assertIsMounted(parentA);
392 return fiber;
393 }
394 if (child === b) {
395 // We've determined that B is the current branch.
396 assertIsMounted(parentA);
397 return alternate;
398 }
399 child = child.sibling;
400 }
401 // We should never have an alternate for any mounting node. So the only
402 // way this could possibly happen is if this was unmounted, if at all.
403 invariant(false, 'Unable to find node on an unmounted component.');
404 }
405
406 if (a.return !== b.return) {
407 // The return pointer of A and the return pointer of B point to different
408 // fibers. We assume that return pointers never criss-cross, so A must
409 // belong to the child set of A.return, and B must belong to the child
410 // set of B.return.
411 a = parentA;
412 b = parentB;
413 } else {
414 // The return pointers point to the same fiber. We'll have to use the
415 // default, slow path: scan the child sets of each parent alternate to see
416 // which child belongs to which set.
417 //
418 // Search parent A's child set
419 var didFindChild = false;
420 var _child = parentA.child;
421 while (_child) {
422 if (_child === a) {
423 didFindChild = true;
424 a = parentA;
425 b = parentB;
426 break;
427 }
428 if (_child === b) {
429 didFindChild = true;
430 b = parentA;
431 a = parentB;
432 break;
433 }
434 _child = _child.sibling;
435 }
436 if (!didFindChild) {
437 // Search parent B's child set
438 _child = parentB.child;
439 while (_child) {
440 if (_child === a) {
441 didFindChild = true;
442 a = parentB;
443 b = parentA;
444 break;
445 }
446 if (_child === b) {
447 didFindChild = true;
448 b = parentB;
449 a = parentA;
450 break;
451 }
452 _child = _child.sibling;
453 }
454 !didFindChild ? invariant(false, 'Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.') : void 0;
455 }
456 }
457
458 !(a.alternate === b) ? invariant(false, 'Return fibers should always be each others\' alternates. This error is likely caused by a bug in React. Please file an issue.') : void 0;
459 }
460 // If the root is not a host container, we're in a disconnected tree. I.e.
461 // unmounted.
462 !(a.tag === HostRoot) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
463 if (a.stateNode.current === a) {
464 // We've determined that A is the current branch.
465 return fiber;
466 }
467 // Otherwise B has to be current branch.
468 return alternate;
469}
470
471function findCurrentHostFiber(parent) {
472 var currentParent = findCurrentFiberUsingSlowPath(parent);
473 if (!currentParent) {
474 return null;
475 }
476
477 // Next we'll drill down this component to find the first HostComponent/Text.
478 var node = currentParent;
479 while (true) {
480 if (node.tag === HostComponent || node.tag === HostText) {
481 return node;
482 } else if (node.child) {
483 node.child.return = node;
484 node = node.child;
485 continue;
486 }
487 if (node === currentParent) {
488 return null;
489 }
490 while (!node.sibling) {
491 if (!node.return || node.return === currentParent) {
492 return null;
493 }
494 node = node.return;
495 }
496 node.sibling.return = node.return;
497 node = node.sibling;
498 }
499 // Flow needs the return null here, but ESLint complains about it.
500 // eslint-disable-next-line no-unreachable
501 return null;
502}
503
504/**
505 * Similar to invariant but only logs a warning if the condition is not met.
506 * This can be used to log issues in development environments in critical
507 * paths. Removing the logging code for production environments will keep the
508 * same logic and follow the same code paths.
509 */
510
511var warning = warningWithoutStack$1;
512
513{
514 warning = function (condition, format) {
515 if (condition) {
516 return;
517 }
518 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
519 var stack = ReactDebugCurrentFrame.getStackAddendum();
520 // eslint-disable-next-line react-internal/warning-and-invariant-args
521
522 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
523 args[_key - 2] = arguments[_key];
524 }
525
526 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
527 };
528}
529
530var warning$1 = warning;
531
532// Current virtual time
533var nowImplementation = function () {
534 return 0;
535};
536var scheduledCallback = null;
537var yieldedValues = [];
538
539var didStop = false;
540var expectedNumberOfYields = -1;
541
542function scheduleDeferredCallback$1(callback, options) {
543 scheduledCallback = callback;
544 var fakeCallbackId = 0;
545 return fakeCallbackId;
546}
547
548function cancelDeferredCallback$1(timeoutID) {
549 scheduledCallback = null;
550}
551
552function setNowImplementation(implementation) {
553 nowImplementation = implementation;
554}
555
556function shouldYield$1() {
557 if (expectedNumberOfYields !== -1 && yieldedValues.length >= expectedNumberOfYields) {
558 // We yielded at least as many values as expected. Stop rendering.
559 didStop = true;
560 return true;
561 }
562 // Keep rendering.
563 return false;
564}
565
566function flushAll() {
567 yieldedValues = [];
568 while (scheduledCallback !== null) {
569 var cb = scheduledCallback;
570 scheduledCallback = null;
571 cb();
572 }
573 var values = yieldedValues;
574 yieldedValues = [];
575 return values;
576}
577
578function flushNumberOfYields(count) {
579 expectedNumberOfYields = count;
580 didStop = false;
581 yieldedValues = [];
582 try {
583 while (scheduledCallback !== null && !didStop) {
584 var cb = scheduledCallback;
585 scheduledCallback = null;
586 cb();
587 }
588 return yieldedValues;
589 } finally {
590 expectedNumberOfYields = -1;
591 didStop = false;
592 yieldedValues = [];
593 }
594}
595
596function yieldValue(value) {
597 yieldedValues.push(value);
598}
599
600function clearYields() {
601 var values = yieldedValues;
602 yieldedValues = [];
603 return values;
604}
605
606// Renderers that don't support persistence
607// can re-export everything from this module.
608
609function shim() {
610 invariant(false, 'The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.');
611}
612
613// Persistence (when unsupported)
614var supportsPersistence = false;
615var cloneInstance = shim;
616var createContainerChildSet = shim;
617var appendChildToContainerChildSet = shim;
618var finalizeContainerChildren = shim;
619var replaceContainerChildren = shim;
620var cloneHiddenInstance = shim;
621var cloneUnhiddenInstance = shim;
622var createHiddenTextInstance = shim;
623
624// Renderers that don't support hydration
625// can re-export everything from this module.
626
627function shim$1() {
628 invariant(false, 'The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.');
629}
630
631// Hydration (when unsupported)
632
633var supportsHydration = false;
634var canHydrateInstance = shim$1;
635var canHydrateTextInstance = shim$1;
636var canHydrateSuspenseInstance = shim$1;
637var getNextHydratableSibling = shim$1;
638var getFirstHydratableChild = shim$1;
639var hydrateInstance = shim$1;
640var hydrateTextInstance = shim$1;
641var getNextHydratableInstanceAfterSuspenseInstance = shim$1;
642var clearSuspenseBoundary = shim$1;
643var clearSuspenseBoundaryFromContainer = shim$1;
644var didNotMatchHydratedContainerTextInstance = shim$1;
645var didNotMatchHydratedTextInstance = shim$1;
646var didNotHydrateContainerInstance = shim$1;
647var didNotHydrateInstance = shim$1;
648var didNotFindHydratableContainerInstance = shim$1;
649var didNotFindHydratableContainerTextInstance = shim$1;
650var didNotFindHydratableContainerSuspenseInstance = shim$1;
651var didNotFindHydratableInstance = shim$1;
652var didNotFindHydratableTextInstance = shim$1;
653var didNotFindHydratableSuspenseInstance = shim$1;
654
655var NO_CONTEXT = {};
656var UPDATE_SIGNAL = {};
657{
658 Object.freeze(NO_CONTEXT);
659 Object.freeze(UPDATE_SIGNAL);
660}
661
662function getPublicInstance(inst) {
663 switch (inst.tag) {
664 case 'INSTANCE':
665 var _createNodeMock = inst.rootContainerInstance.createNodeMock;
666 return _createNodeMock({
667 type: inst.type,
668 props: inst.props
669 });
670 default:
671 return inst;
672 }
673}
674
675function appendChild(parentInstance, child) {
676 {
677 !Array.isArray(parentInstance.children) ? warning$1(false, 'An invalid container has been provided. ' + 'This may indicate that another renderer is being used in addition to the test renderer. ' + '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' + 'This is not supported.') : void 0;
678 }
679 var index = parentInstance.children.indexOf(child);
680 if (index !== -1) {
681 parentInstance.children.splice(index, 1);
682 }
683 parentInstance.children.push(child);
684}
685
686function insertBefore(parentInstance, child, beforeChild) {
687 var index = parentInstance.children.indexOf(child);
688 if (index !== -1) {
689 parentInstance.children.splice(index, 1);
690 }
691 var beforeIndex = parentInstance.children.indexOf(beforeChild);
692 parentInstance.children.splice(beforeIndex, 0, child);
693}
694
695function removeChild(parentInstance, child) {
696 var index = parentInstance.children.indexOf(child);
697 parentInstance.children.splice(index, 1);
698}
699
700function getRootHostContext(rootContainerInstance) {
701 return NO_CONTEXT;
702}
703
704function getChildHostContext(parentHostContext, type, rootContainerInstance) {
705 return NO_CONTEXT;
706}
707
708function prepareForCommit(containerInfo) {
709 // noop
710}
711
712function resetAfterCommit(containerInfo) {
713 // noop
714}
715
716function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
717 return {
718 type: type,
719 props: props,
720 isHidden: false,
721 children: [],
722 rootContainerInstance: rootContainerInstance,
723 tag: 'INSTANCE'
724 };
725}
726
727function appendInitialChild(parentInstance, child) {
728 var index = parentInstance.children.indexOf(child);
729 if (index !== -1) {
730 parentInstance.children.splice(index, 1);
731 }
732 parentInstance.children.push(child);
733}
734
735function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
736 return false;
737}
738
739function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
740 return UPDATE_SIGNAL;
741}
742
743function shouldSetTextContent(type, props) {
744 return false;
745}
746
747function shouldDeprioritizeSubtree(type, props) {
748 return false;
749}
750
751function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
752 return {
753 text: text,
754 isHidden: false,
755 tag: 'TEXT'
756 };
757}
758
759var isPrimaryRenderer = false;
760// This approach enables `now` to be mocked by tests,
761// Even after the reconciler has initialized and read host config values.
762var now = function () {
763 return nowImplementation();
764};
765var scheduleDeferredCallback$$1 = scheduleDeferredCallback$1;
766var cancelDeferredCallback$$1 = cancelDeferredCallback$1;
767var shouldYield$$1 = shouldYield$1;
768
769var scheduleTimeout = setTimeout;
770var cancelTimeout = clearTimeout;
771var noTimeout = -1;
772var schedulePassiveEffects = scheduleDeferredCallback$$1;
773var cancelPassiveEffects = cancelDeferredCallback$$1;
774
775// -------------------
776// Mutation
777// -------------------
778
779var supportsMutation = true;
780
781function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
782 instance.type = type;
783 instance.props = newProps;
784}
785
786
787
788function commitTextUpdate(textInstance, oldText, newText) {
789 textInstance.text = newText;
790}
791
792function resetTextContent(testElement) {
793 // noop
794}
795
796var appendChildToContainer = appendChild;
797var insertInContainerBefore = insertBefore;
798var removeChildFromContainer = removeChild;
799
800function hideInstance(instance) {
801 instance.isHidden = true;
802}
803
804function hideTextInstance(textInstance) {
805 textInstance.isHidden = true;
806}
807
808function unhideInstance(instance, props) {
809 instance.isHidden = false;
810}
811
812function unhideTextInstance(textInstance, text) {
813 textInstance.isHidden = false;
814}
815
816/**
817 * Copyright (c) 2013-present, Facebook, Inc.
818 *
819 * This source code is licensed under the MIT license found in the
820 * LICENSE file in the root directory of this source tree.
821 */
822
823
824
825var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
826
827var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
828
829/**
830 * Copyright (c) 2013-present, Facebook, Inc.
831 *
832 * This source code is licensed under the MIT license found in the
833 * LICENSE file in the root directory of this source tree.
834 */
835
836
837
838var printWarning = function() {};
839
840{
841 var ReactPropTypesSecret = ReactPropTypesSecret_1;
842 var loggedTypeFailures = {};
843
844 printWarning = function(text) {
845 var message = 'Warning: ' + text;
846 if (typeof console !== 'undefined') {
847 console.error(message);
848 }
849 try {
850 // --- Welcome to debugging React ---
851 // This error was thrown as a convenience so that you can use this stack
852 // to find the callsite that caused this warning to fire.
853 throw new Error(message);
854 } catch (x) {}
855 };
856}
857
858/**
859 * Assert that the values match with the type specs.
860 * Error messages are memorized and will only be shown once.
861 *
862 * @param {object} typeSpecs Map of name to a ReactPropType
863 * @param {object} values Runtime values that need to be type-checked
864 * @param {string} location e.g. "prop", "context", "child context"
865 * @param {string} componentName Name of the component for error messages.
866 * @param {?Function} getStack Returns the component stack.
867 * @private
868 */
869function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
870 {
871 for (var typeSpecName in typeSpecs) {
872 if (typeSpecs.hasOwnProperty(typeSpecName)) {
873 var error;
874 // Prop type validation may throw. In case they do, we don't want to
875 // fail the render phase where it didn't fail before. So we log it.
876 // After these have been cleaned up, we'll let them throw.
877 try {
878 // This is intentionally an invariant that gets caught. It's the same
879 // behavior as without this statement except with a better message.
880 if (typeof typeSpecs[typeSpecName] !== 'function') {
881 var err = Error(
882 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
883 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
884 );
885 err.name = 'Invariant Violation';
886 throw err;
887 }
888 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
889 } catch (ex) {
890 error = ex;
891 }
892 if (error && !(error instanceof Error)) {
893 printWarning(
894 (componentName || 'React class') + ': type specification of ' +
895 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
896 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
897 'You may have forgotten to pass an argument to the type checker ' +
898 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
899 'shape all require an argument).'
900 );
901
902 }
903 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
904 // Only monitor this failure once because there tends to be a lot of the
905 // same error.
906 loggedTypeFailures[error.message] = true;
907
908 var stack = getStack ? getStack() : '';
909
910 printWarning(
911 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
912 );
913 }
914 }
915 }
916 }
917}
918
919var checkPropTypes_1 = checkPropTypes;
920
921var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
922
923var describeComponentFrame = function (name, source, ownerName) {
924 var sourceInfo = '';
925 if (source) {
926 var path = source.fileName;
927 var fileName = path.replace(BEFORE_SLASH_RE, '');
928 {
929 // In DEV, include code for a common special case:
930 // prefer "folder/index.js" instead of just "index.js".
931 if (/^index\./.test(fileName)) {
932 var match = path.match(BEFORE_SLASH_RE);
933 if (match) {
934 var pathBeforeSlash = match[1];
935 if (pathBeforeSlash) {
936 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
937 fileName = folderName + '/' + fileName;
938 }
939 }
940 }
941 }
942 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
943 } else if (ownerName) {
944 sourceInfo = ' (created by ' + ownerName + ')';
945 }
946 return '\n in ' + (name || 'Unknown') + sourceInfo;
947};
948
949var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
950
951function describeFiber(fiber) {
952 switch (fiber.tag) {
953 case HostRoot:
954 case HostPortal:
955 case HostText:
956 case Fragment:
957 case ContextProvider:
958 case ContextConsumer:
959 return '';
960 default:
961 var owner = fiber._debugOwner;
962 var source = fiber._debugSource;
963 var name = getComponentName(fiber.type);
964 var ownerName = null;
965 if (owner) {
966 ownerName = getComponentName(owner.type);
967 }
968 return describeComponentFrame(name, source, ownerName);
969 }
970}
971
972function getStackByFiberInDevAndProd(workInProgress) {
973 var info = '';
974 var node = workInProgress;
975 do {
976 info += describeFiber(node);
977 node = node.return;
978 } while (node);
979 return info;
980}
981
982var current = null;
983var phase = null;
984
985function getCurrentFiberOwnerNameInDevOrNull() {
986 {
987 if (current === null) {
988 return null;
989 }
990 var owner = current._debugOwner;
991 if (owner !== null && typeof owner !== 'undefined') {
992 return getComponentName(owner.type);
993 }
994 }
995 return null;
996}
997
998function getCurrentFiberStackInDev() {
999 {
1000 if (current === null) {
1001 return '';
1002 }
1003 // Safe because if current fiber exists, we are reconciling,
1004 // and it is guaranteed to be the work-in-progress version.
1005 return getStackByFiberInDevAndProd(current);
1006 }
1007 return '';
1008}
1009
1010function resetCurrentFiber() {
1011 {
1012 ReactDebugCurrentFrame.getCurrentStack = null;
1013 current = null;
1014 phase = null;
1015 }
1016}
1017
1018function setCurrentFiber(fiber) {
1019 {
1020 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1021 current = fiber;
1022 phase = null;
1023 }
1024}
1025
1026function setCurrentPhase(lifeCyclePhase) {
1027 {
1028 phase = lifeCyclePhase;
1029 }
1030}
1031
1032var debugRenderPhaseSideEffects = false;
1033var debugRenderPhaseSideEffectsForStrictMode = false;
1034var enableUserTimingAPI = true;
1035var warnAboutDeprecatedLifecycles = false;
1036var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
1037var enableProfilerTimer = false;
1038var enableSchedulerTracing = false;
1039var enableSuspenseServerRenderer = false;
1040
1041
1042
1043
1044
1045// Only used in www builds.
1046
1047// Prefix measurements so that it's possible to filter them.
1048// Longer prefixes are hard to read in DevTools.
1049var reactEmoji = '\u269B';
1050var warningEmoji = '\u26D4';
1051var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
1052
1053// Keep track of current fiber so that we know the path to unwind on pause.
1054// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1055var currentFiber = null;
1056// If we're in the middle of user code, which fiber and method is it?
1057// Reusing `currentFiber` would be confusing for this because user code fiber
1058// can change during commit phase too, but we don't need to unwind it (since
1059// lifecycles in the commit phase don't resemble a tree).
1060var currentPhase = null;
1061var currentPhaseFiber = null;
1062// Did lifecycle hook schedule an update? This is often a performance problem,
1063// so we will keep track of it, and include it in the report.
1064// Track commits caused by cascading updates.
1065var isCommitting = false;
1066var hasScheduledUpdateInCurrentCommit = false;
1067var hasScheduledUpdateInCurrentPhase = false;
1068var commitCountInCurrentWorkLoop = 0;
1069var effectCountInCurrentCommit = 0;
1070var isWaitingForCallback = false;
1071// During commits, we only show a measurement once per method name
1072// to avoid stretch the commit phase with measurement overhead.
1073var labelsInCurrentCommit = new Set();
1074
1075var formatMarkName = function (markName) {
1076 return reactEmoji + ' ' + markName;
1077};
1078
1079var formatLabel = function (label, warning) {
1080 var prefix = warning ? warningEmoji + ' ' : reactEmoji + ' ';
1081 var suffix = warning ? ' Warning: ' + warning : '';
1082 return '' + prefix + label + suffix;
1083};
1084
1085var beginMark = function (markName) {
1086 performance.mark(formatMarkName(markName));
1087};
1088
1089var clearMark = function (markName) {
1090 performance.clearMarks(formatMarkName(markName));
1091};
1092
1093var endMark = function (label, markName, warning) {
1094 var formattedMarkName = formatMarkName(markName);
1095 var formattedLabel = formatLabel(label, warning);
1096 try {
1097 performance.measure(formattedLabel, formattedMarkName);
1098 } catch (err) {}
1099 // If previous mark was missing for some reason, this will throw.
1100 // This could only happen if React crashed in an unexpected place earlier.
1101 // Don't pile on with more errors.
1102
1103 // Clear marks immediately to avoid growing buffer.
1104 performance.clearMarks(formattedMarkName);
1105 performance.clearMeasures(formattedLabel);
1106};
1107
1108var getFiberMarkName = function (label, debugID) {
1109 return label + ' (#' + debugID + ')';
1110};
1111
1112var getFiberLabel = function (componentName, isMounted, phase) {
1113 if (phase === null) {
1114 // These are composite component total time measurements.
1115 return componentName + ' [' + (isMounted ? 'update' : 'mount') + ']';
1116 } else {
1117 // Composite component methods.
1118 return componentName + '.' + phase;
1119 }
1120};
1121
1122var beginFiberMark = function (fiber, phase) {
1123 var componentName = getComponentName(fiber.type) || 'Unknown';
1124 var debugID = fiber._debugID;
1125 var isMounted = fiber.alternate !== null;
1126 var label = getFiberLabel(componentName, isMounted, phase);
1127
1128 if (isCommitting && labelsInCurrentCommit.has(label)) {
1129 // During the commit phase, we don't show duplicate labels because
1130 // there is a fixed overhead for every measurement, and we don't
1131 // want to stretch the commit phase beyond necessary.
1132 return false;
1133 }
1134 labelsInCurrentCommit.add(label);
1135
1136 var markName = getFiberMarkName(label, debugID);
1137 beginMark(markName);
1138 return true;
1139};
1140
1141var clearFiberMark = function (fiber, phase) {
1142 var componentName = getComponentName(fiber.type) || 'Unknown';
1143 var debugID = fiber._debugID;
1144 var isMounted = fiber.alternate !== null;
1145 var label = getFiberLabel(componentName, isMounted, phase);
1146 var markName = getFiberMarkName(label, debugID);
1147 clearMark(markName);
1148};
1149
1150var endFiberMark = function (fiber, phase, warning) {
1151 var componentName = getComponentName(fiber.type) || 'Unknown';
1152 var debugID = fiber._debugID;
1153 var isMounted = fiber.alternate !== null;
1154 var label = getFiberLabel(componentName, isMounted, phase);
1155 var markName = getFiberMarkName(label, debugID);
1156 endMark(label, markName, warning);
1157};
1158
1159var shouldIgnoreFiber = function (fiber) {
1160 // Host components should be skipped in the timeline.
1161 // We could check typeof fiber.type, but does this work with RN?
1162 switch (fiber.tag) {
1163 case HostRoot:
1164 case HostComponent:
1165 case HostText:
1166 case HostPortal:
1167 case Fragment:
1168 case ContextProvider:
1169 case ContextConsumer:
1170 case Mode:
1171 return true;
1172 default:
1173 return false;
1174 }
1175};
1176
1177var clearPendingPhaseMeasurement = function () {
1178 if (currentPhase !== null && currentPhaseFiber !== null) {
1179 clearFiberMark(currentPhaseFiber, currentPhase);
1180 }
1181 currentPhaseFiber = null;
1182 currentPhase = null;
1183 hasScheduledUpdateInCurrentPhase = false;
1184};
1185
1186var pauseTimers = function () {
1187 // Stops all currently active measurements so that they can be resumed
1188 // if we continue in a later deferred loop from the same unit of work.
1189 var fiber = currentFiber;
1190 while (fiber) {
1191 if (fiber._debugIsCurrentlyTiming) {
1192 endFiberMark(fiber, null, null);
1193 }
1194 fiber = fiber.return;
1195 }
1196};
1197
1198var resumeTimersRecursively = function (fiber) {
1199 if (fiber.return !== null) {
1200 resumeTimersRecursively(fiber.return);
1201 }
1202 if (fiber._debugIsCurrentlyTiming) {
1203 beginFiberMark(fiber, null);
1204 }
1205};
1206
1207var resumeTimers = function () {
1208 // Resumes all measurements that were active during the last deferred loop.
1209 if (currentFiber !== null) {
1210 resumeTimersRecursively(currentFiber);
1211 }
1212};
1213
1214function recordEffect() {
1215 if (enableUserTimingAPI) {
1216 effectCountInCurrentCommit++;
1217 }
1218}
1219
1220function recordScheduleUpdate() {
1221 if (enableUserTimingAPI) {
1222 if (isCommitting) {
1223 hasScheduledUpdateInCurrentCommit = true;
1224 }
1225 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1226 hasScheduledUpdateInCurrentPhase = true;
1227 }
1228 }
1229}
1230
1231function startRequestCallbackTimer() {
1232 if (enableUserTimingAPI) {
1233 if (supportsUserTiming && !isWaitingForCallback) {
1234 isWaitingForCallback = true;
1235 beginMark('(Waiting for async callback...)');
1236 }
1237 }
1238}
1239
1240function stopRequestCallbackTimer(didExpire, expirationTime) {
1241 if (enableUserTimingAPI) {
1242 if (supportsUserTiming) {
1243 isWaitingForCallback = false;
1244 var warning = didExpire ? 'React was blocked by main thread' : null;
1245 endMark('(Waiting for async callback... will force flush in ' + expirationTime + ' ms)', '(Waiting for async callback...)', warning);
1246 }
1247 }
1248}
1249
1250function startWorkTimer(fiber) {
1251 if (enableUserTimingAPI) {
1252 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1253 return;
1254 }
1255 // If we pause, this is the fiber to unwind from.
1256 currentFiber = fiber;
1257 if (!beginFiberMark(fiber, null)) {
1258 return;
1259 }
1260 fiber._debugIsCurrentlyTiming = true;
1261 }
1262}
1263
1264function cancelWorkTimer(fiber) {
1265 if (enableUserTimingAPI) {
1266 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1267 return;
1268 }
1269 // Remember we shouldn't complete measurement for this fiber.
1270 // Otherwise flamechart will be deep even for small updates.
1271 fiber._debugIsCurrentlyTiming = false;
1272 clearFiberMark(fiber, null);
1273 }
1274}
1275
1276function stopWorkTimer(fiber) {
1277 if (enableUserTimingAPI) {
1278 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1279 return;
1280 }
1281 // If we pause, its parent is the fiber to unwind from.
1282 currentFiber = fiber.return;
1283 if (!fiber._debugIsCurrentlyTiming) {
1284 return;
1285 }
1286 fiber._debugIsCurrentlyTiming = false;
1287 endFiberMark(fiber, null, null);
1288 }
1289}
1290
1291function stopFailedWorkTimer(fiber) {
1292 if (enableUserTimingAPI) {
1293 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1294 return;
1295 }
1296 // If we pause, its parent is the fiber to unwind from.
1297 currentFiber = fiber.return;
1298 if (!fiber._debugIsCurrentlyTiming) {
1299 return;
1300 }
1301 fiber._debugIsCurrentlyTiming = false;
1302 var warning = fiber.tag === SuspenseComponent || fiber.tag === DehydratedSuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1303 endFiberMark(fiber, null, warning);
1304 }
1305}
1306
1307function startPhaseTimer(fiber, phase) {
1308 if (enableUserTimingAPI) {
1309 if (!supportsUserTiming) {
1310 return;
1311 }
1312 clearPendingPhaseMeasurement();
1313 if (!beginFiberMark(fiber, phase)) {
1314 return;
1315 }
1316 currentPhaseFiber = fiber;
1317 currentPhase = phase;
1318 }
1319}
1320
1321function stopPhaseTimer() {
1322 if (enableUserTimingAPI) {
1323 if (!supportsUserTiming) {
1324 return;
1325 }
1326 if (currentPhase !== null && currentPhaseFiber !== null) {
1327 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1328 endFiberMark(currentPhaseFiber, currentPhase, warning);
1329 }
1330 currentPhase = null;
1331 currentPhaseFiber = null;
1332 }
1333}
1334
1335function startWorkLoopTimer(nextUnitOfWork) {
1336 if (enableUserTimingAPI) {
1337 currentFiber = nextUnitOfWork;
1338 if (!supportsUserTiming) {
1339 return;
1340 }
1341 commitCountInCurrentWorkLoop = 0;
1342 // This is top level call.
1343 // Any other measurements are performed within.
1344 beginMark('(React Tree Reconciliation)');
1345 // Resume any measurements that were in progress during the last loop.
1346 resumeTimers();
1347 }
1348}
1349
1350function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1351 if (enableUserTimingAPI) {
1352 if (!supportsUserTiming) {
1353 return;
1354 }
1355 var warning = null;
1356 if (interruptedBy !== null) {
1357 if (interruptedBy.tag === HostRoot) {
1358 warning = 'A top-level update interrupted the previous render';
1359 } else {
1360 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1361 warning = 'An update to ' + componentName + ' interrupted the previous render';
1362 }
1363 } else if (commitCountInCurrentWorkLoop > 1) {
1364 warning = 'There were cascading updates';
1365 }
1366 commitCountInCurrentWorkLoop = 0;
1367 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)';
1368 // Pause any measurements until the next loop.
1369 pauseTimers();
1370 endMark(label, '(React Tree Reconciliation)', warning);
1371 }
1372}
1373
1374function startCommitTimer() {
1375 if (enableUserTimingAPI) {
1376 if (!supportsUserTiming) {
1377 return;
1378 }
1379 isCommitting = true;
1380 hasScheduledUpdateInCurrentCommit = false;
1381 labelsInCurrentCommit.clear();
1382 beginMark('(Committing Changes)');
1383 }
1384}
1385
1386function stopCommitTimer() {
1387 if (enableUserTimingAPI) {
1388 if (!supportsUserTiming) {
1389 return;
1390 }
1391
1392 var warning = null;
1393 if (hasScheduledUpdateInCurrentCommit) {
1394 warning = 'Lifecycle hook scheduled a cascading update';
1395 } else if (commitCountInCurrentWorkLoop > 0) {
1396 warning = 'Caused by a cascading update in earlier commit';
1397 }
1398 hasScheduledUpdateInCurrentCommit = false;
1399 commitCountInCurrentWorkLoop++;
1400 isCommitting = false;
1401 labelsInCurrentCommit.clear();
1402
1403 endMark('(Committing Changes)', '(Committing Changes)', warning);
1404 }
1405}
1406
1407function startCommitSnapshotEffectsTimer() {
1408 if (enableUserTimingAPI) {
1409 if (!supportsUserTiming) {
1410 return;
1411 }
1412 effectCountInCurrentCommit = 0;
1413 beginMark('(Committing Snapshot Effects)');
1414 }
1415}
1416
1417function stopCommitSnapshotEffectsTimer() {
1418 if (enableUserTimingAPI) {
1419 if (!supportsUserTiming) {
1420 return;
1421 }
1422 var count = effectCountInCurrentCommit;
1423 effectCountInCurrentCommit = 0;
1424 endMark('(Committing Snapshot Effects: ' + count + ' Total)', '(Committing Snapshot Effects)', null);
1425 }
1426}
1427
1428function startCommitHostEffectsTimer() {
1429 if (enableUserTimingAPI) {
1430 if (!supportsUserTiming) {
1431 return;
1432 }
1433 effectCountInCurrentCommit = 0;
1434 beginMark('(Committing Host Effects)');
1435 }
1436}
1437
1438function stopCommitHostEffectsTimer() {
1439 if (enableUserTimingAPI) {
1440 if (!supportsUserTiming) {
1441 return;
1442 }
1443 var count = effectCountInCurrentCommit;
1444 effectCountInCurrentCommit = 0;
1445 endMark('(Committing Host Effects: ' + count + ' Total)', '(Committing Host Effects)', null);
1446 }
1447}
1448
1449function startCommitLifeCyclesTimer() {
1450 if (enableUserTimingAPI) {
1451 if (!supportsUserTiming) {
1452 return;
1453 }
1454 effectCountInCurrentCommit = 0;
1455 beginMark('(Calling Lifecycle Methods)');
1456 }
1457}
1458
1459function stopCommitLifeCyclesTimer() {
1460 if (enableUserTimingAPI) {
1461 if (!supportsUserTiming) {
1462 return;
1463 }
1464 var count = effectCountInCurrentCommit;
1465 effectCountInCurrentCommit = 0;
1466 endMark('(Calling Lifecycle Methods: ' + count + ' Total)', '(Calling Lifecycle Methods)', null);
1467 }
1468}
1469
1470var valueStack = [];
1471
1472var fiberStack = void 0;
1473
1474{
1475 fiberStack = [];
1476}
1477
1478var index = -1;
1479
1480function createCursor(defaultValue) {
1481 return {
1482 current: defaultValue
1483 };
1484}
1485
1486function pop(cursor, fiber) {
1487 if (index < 0) {
1488 {
1489 warningWithoutStack$1(false, 'Unexpected pop.');
1490 }
1491 return;
1492 }
1493
1494 {
1495 if (fiber !== fiberStack[index]) {
1496 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1497 }
1498 }
1499
1500 cursor.current = valueStack[index];
1501
1502 valueStack[index] = null;
1503
1504 {
1505 fiberStack[index] = null;
1506 }
1507
1508 index--;
1509}
1510
1511function push(cursor, value, fiber) {
1512 index++;
1513
1514 valueStack[index] = cursor.current;
1515
1516 {
1517 fiberStack[index] = fiber;
1518 }
1519
1520 cursor.current = value;
1521}
1522
1523function checkThatStackIsEmpty() {
1524 {
1525 if (index !== -1) {
1526 warningWithoutStack$1(false, 'Expected an empty stack. Something was not reset properly.');
1527 }
1528 }
1529}
1530
1531function resetStackAfterFatalErrorInDev() {
1532 {
1533 index = -1;
1534 valueStack.length = 0;
1535 fiberStack.length = 0;
1536 }
1537}
1538
1539var warnedAboutMissingGetChildContext = void 0;
1540
1541{
1542 warnedAboutMissingGetChildContext = {};
1543}
1544
1545var emptyContextObject = {};
1546{
1547 Object.freeze(emptyContextObject);
1548}
1549
1550// A cursor to the current merged context object on the stack.
1551var contextStackCursor = createCursor(emptyContextObject);
1552// A cursor to a boolean indicating whether the context has changed.
1553var didPerformWorkStackCursor = createCursor(false);
1554// Keep track of the previous context object that was on the stack.
1555// We use this to get access to the parent context after we have already
1556// pushed the next context provider, and now need to merge their contexts.
1557var previousContext = emptyContextObject;
1558
1559function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1560 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1561 // If the fiber is a context provider itself, when we read its context
1562 // we may have already pushed its own child context on the stack. A context
1563 // provider should not "see" its own child context. Therefore we read the
1564 // previous (parent) context instead for a context provider.
1565 return previousContext;
1566 }
1567 return contextStackCursor.current;
1568}
1569
1570function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1571 var instance = workInProgress.stateNode;
1572 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1573 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1574}
1575
1576function getMaskedContext(workInProgress, unmaskedContext) {
1577 var type = workInProgress.type;
1578 var contextTypes = type.contextTypes;
1579 if (!contextTypes) {
1580 return emptyContextObject;
1581 }
1582
1583 // Avoid recreating masked context unless unmasked context has changed.
1584 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1585 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1586 var instance = workInProgress.stateNode;
1587 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1588 return instance.__reactInternalMemoizedMaskedChildContext;
1589 }
1590
1591 var context = {};
1592 for (var key in contextTypes) {
1593 context[key] = unmaskedContext[key];
1594 }
1595
1596 {
1597 var name = getComponentName(type) || 'Unknown';
1598 checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1599 }
1600
1601 // Cache unmasked context so we can avoid recreating masked context unless necessary.
1602 // Context is created before the class component is instantiated so check for instance.
1603 if (instance) {
1604 cacheContext(workInProgress, unmaskedContext, context);
1605 }
1606
1607 return context;
1608}
1609
1610function hasContextChanged() {
1611 return didPerformWorkStackCursor.current;
1612}
1613
1614function isContextProvider(type) {
1615 var childContextTypes = type.childContextTypes;
1616 return childContextTypes !== null && childContextTypes !== undefined;
1617}
1618
1619function popContext(fiber) {
1620 pop(didPerformWorkStackCursor, fiber);
1621 pop(contextStackCursor, fiber);
1622}
1623
1624function popTopLevelContextObject(fiber) {
1625 pop(didPerformWorkStackCursor, fiber);
1626 pop(contextStackCursor, fiber);
1627}
1628
1629function pushTopLevelContextObject(fiber, context, didChange) {
1630 !(contextStackCursor.current === emptyContextObject) ? invariant(false, 'Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue.') : void 0;
1631
1632 push(contextStackCursor, context, fiber);
1633 push(didPerformWorkStackCursor, didChange, fiber);
1634}
1635
1636function processChildContext(fiber, type, parentContext) {
1637 var instance = fiber.stateNode;
1638 var childContextTypes = type.childContextTypes;
1639
1640 // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1641 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1642 if (typeof instance.getChildContext !== 'function') {
1643 {
1644 var componentName = getComponentName(type) || 'Unknown';
1645
1646 if (!warnedAboutMissingGetChildContext[componentName]) {
1647 warnedAboutMissingGetChildContext[componentName] = true;
1648 warningWithoutStack$1(false, '%s.childContextTypes is specified but there is no getChildContext() method ' + 'on the instance. You can either define getChildContext() on %s or remove ' + 'childContextTypes from it.', componentName, componentName);
1649 }
1650 }
1651 return parentContext;
1652 }
1653
1654 var childContext = void 0;
1655 {
1656 setCurrentPhase('getChildContext');
1657 }
1658 startPhaseTimer(fiber, 'getChildContext');
1659 childContext = instance.getChildContext();
1660 stopPhaseTimer();
1661 {
1662 setCurrentPhase(null);
1663 }
1664 for (var contextKey in childContext) {
1665 !(contextKey in childContextTypes) ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(type) || 'Unknown', contextKey) : void 0;
1666 }
1667 {
1668 var name = getComponentName(type) || 'Unknown';
1669 checkPropTypes_1(childContextTypes, childContext, 'child context', name,
1670 // In practice, there is one case in which we won't get a stack. It's when
1671 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1672 // context from the parent component instance. The stack will be missing
1673 // because it's outside of the reconciliation, and so the pointer has not
1674 // been set. This is rare and doesn't matter. We'll also remove that API.
1675 getCurrentFiberStackInDev);
1676 }
1677
1678 return _assign({}, parentContext, childContext);
1679}
1680
1681function pushContextProvider(workInProgress) {
1682 var instance = workInProgress.stateNode;
1683 // We push the context as early as possible to ensure stack integrity.
1684 // If the instance does not exist yet, we will push null at first,
1685 // and replace it on the stack later when invalidating the context.
1686 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject;
1687
1688 // Remember the parent context so we can merge with it later.
1689 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1690 previousContext = contextStackCursor.current;
1691 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1692 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1693
1694 return true;
1695}
1696
1697function invalidateContextProvider(workInProgress, type, didChange) {
1698 var instance = workInProgress.stateNode;
1699 !instance ? invariant(false, 'Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue.') : void 0;
1700
1701 if (didChange) {
1702 // Merge parent and own context.
1703 // Skip this if we're not updating due to sCU.
1704 // This avoids unnecessarily recomputing memoized values.
1705 var mergedContext = processChildContext(workInProgress, type, previousContext);
1706 instance.__reactInternalMemoizedMergedChildContext = mergedContext;
1707
1708 // Replace the old (or empty) context with the new one.
1709 // It is important to unwind the context in the reverse order.
1710 pop(didPerformWorkStackCursor, workInProgress);
1711 pop(contextStackCursor, workInProgress);
1712 // Now push the new context and mark that it has changed.
1713 push(contextStackCursor, mergedContext, workInProgress);
1714 push(didPerformWorkStackCursor, didChange, workInProgress);
1715 } else {
1716 pop(didPerformWorkStackCursor, workInProgress);
1717 push(didPerformWorkStackCursor, didChange, workInProgress);
1718 }
1719}
1720
1721function findCurrentUnmaskedContext(fiber) {
1722 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1723 // makes sense elsewhere
1724 !(isFiberMounted(fiber) && fiber.tag === ClassComponent) ? invariant(false, 'Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue.') : void 0;
1725
1726 var node = fiber;
1727 do {
1728 switch (node.tag) {
1729 case HostRoot:
1730 return node.stateNode.context;
1731 case ClassComponent:
1732 {
1733 var Component = node.type;
1734 if (isContextProvider(Component)) {
1735 return node.stateNode.__reactInternalMemoizedMergedChildContext;
1736 }
1737 break;
1738 }
1739 }
1740 node = node.return;
1741 } while (node !== null);
1742 invariant(false, 'Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.');
1743}
1744
1745var onCommitFiberRoot = null;
1746var onCommitFiberUnmount = null;
1747var hasLoggedError = false;
1748
1749function catchErrors(fn) {
1750 return function (arg) {
1751 try {
1752 return fn(arg);
1753 } catch (err) {
1754 if (true && !hasLoggedError) {
1755 hasLoggedError = true;
1756 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
1757 }
1758 }
1759 };
1760}
1761
1762var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
1763
1764function injectInternals(internals) {
1765 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
1766 // No DevTools
1767 return false;
1768 }
1769 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
1770 if (hook.isDisabled) {
1771 // This isn't a real property on the hook, but it can be set to opt out
1772 // of DevTools integration and associated warnings and logs.
1773 // https://github.com/facebook/react/issues/3877
1774 return true;
1775 }
1776 if (!hook.supportsFiber) {
1777 {
1778 warningWithoutStack$1(false, 'The installed version of React DevTools is too old and will not work ' + 'with the current version of React. Please update React DevTools. ' + 'https://fb.me/react-devtools');
1779 }
1780 // DevTools exists, even though it doesn't support Fiber.
1781 return true;
1782 }
1783 try {
1784 var rendererID = hook.inject(internals);
1785 // We have successfully injected, so now it is safe to set up hooks.
1786 onCommitFiberRoot = catchErrors(function (root) {
1787 return hook.onCommitFiberRoot(rendererID, root);
1788 });
1789 onCommitFiberUnmount = catchErrors(function (fiber) {
1790 return hook.onCommitFiberUnmount(rendererID, fiber);
1791 });
1792 } catch (err) {
1793 // Catch all errors because it is unsafe to throw during initialization.
1794 {
1795 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
1796 }
1797 }
1798 // DevTools exists
1799 return true;
1800}
1801
1802function onCommitRoot(root) {
1803 if (typeof onCommitFiberRoot === 'function') {
1804 onCommitFiberRoot(root);
1805 }
1806}
1807
1808function onCommitUnmount(fiber) {
1809 if (typeof onCommitFiberUnmount === 'function') {
1810 onCommitFiberUnmount(fiber);
1811 }
1812}
1813
1814// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
1815// Math.pow(2, 30) - 1
1816// 0b111111111111111111111111111111
1817var maxSigned31BitInt = 1073741823;
1818
1819var NoWork = 0;
1820var Never = 1;
1821var Sync = maxSigned31BitInt;
1822
1823var UNIT_SIZE = 10;
1824var MAGIC_NUMBER_OFFSET = maxSigned31BitInt - 1;
1825
1826// 1 unit of expiration time represents 10ms.
1827function msToExpirationTime(ms) {
1828 // Always add an offset so that we don't clash with the magic number for NoWork.
1829 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
1830}
1831
1832function expirationTimeToMs(expirationTime) {
1833 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
1834}
1835
1836function ceiling(num, precision) {
1837 return ((num / precision | 0) + 1) * precision;
1838}
1839
1840function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
1841 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
1842}
1843
1844var LOW_PRIORITY_EXPIRATION = 5000;
1845var LOW_PRIORITY_BATCH_SIZE = 250;
1846
1847function computeAsyncExpiration(currentTime) {
1848 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
1849}
1850
1851// We intentionally set a higher expiration time for interactive updates in
1852// dev than in production.
1853//
1854// If the main thread is being blocked so long that you hit the expiration,
1855// it's a problem that could be solved with better scheduling.
1856//
1857// People will be more likely to notice this and fix it with the long
1858// expiration time in development.
1859//
1860// In production we opt for better UX at the risk of masking scheduling
1861// problems, by expiring fast.
1862var HIGH_PRIORITY_EXPIRATION = 500;
1863var HIGH_PRIORITY_BATCH_SIZE = 100;
1864
1865function computeInteractiveExpiration(currentTime) {
1866 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
1867}
1868
1869var NoContext = 0;
1870var ConcurrentMode = 1;
1871var StrictMode = 2;
1872var ProfileMode = 4;
1873
1874var hasBadMapPolyfill = void 0;
1875
1876{
1877 hasBadMapPolyfill = false;
1878 try {
1879 var nonExtensibleObject = Object.preventExtensions({});
1880 var testMap = new Map([[nonExtensibleObject, null]]);
1881 var testSet = new Set([nonExtensibleObject]);
1882 // This is necessary for Rollup to not consider these unused.
1883 // https://github.com/rollup/rollup/issues/1771
1884 // TODO: we can remove these if Rollup fixes the bug.
1885 testMap.set(0, 0);
1886 testSet.add(0);
1887 } catch (e) {
1888 // TODO: Consider warning about bad polyfills
1889 hasBadMapPolyfill = true;
1890 }
1891}
1892
1893// A Fiber is work on a Component that needs to be done or was done. There can
1894// be more than one per component.
1895
1896
1897var debugCounter = void 0;
1898
1899{
1900 debugCounter = 1;
1901}
1902
1903function FiberNode(tag, pendingProps, key, mode) {
1904 // Instance
1905 this.tag = tag;
1906 this.key = key;
1907 this.elementType = null;
1908 this.type = null;
1909 this.stateNode = null;
1910
1911 // Fiber
1912 this.return = null;
1913 this.child = null;
1914 this.sibling = null;
1915 this.index = 0;
1916
1917 this.ref = null;
1918
1919 this.pendingProps = pendingProps;
1920 this.memoizedProps = null;
1921 this.updateQueue = null;
1922 this.memoizedState = null;
1923 this.contextDependencies = null;
1924
1925 this.mode = mode;
1926
1927 // Effects
1928 this.effectTag = NoEffect;
1929 this.nextEffect = null;
1930
1931 this.firstEffect = null;
1932 this.lastEffect = null;
1933
1934 this.expirationTime = NoWork;
1935 this.childExpirationTime = NoWork;
1936
1937 this.alternate = null;
1938
1939 if (enableProfilerTimer) {
1940 // Note: The following is done to avoid a v8 performance cliff.
1941 //
1942 // Initializing the fields below to smis and later updating them with
1943 // double values will cause Fibers to end up having separate shapes.
1944 // This behavior/bug has something to do with Object.preventExtension().
1945 // Fortunately this only impacts DEV builds.
1946 // Unfortunately it makes React unusably slow for some applications.
1947 // To work around this, initialize the fields below with doubles.
1948 //
1949 // Learn more about this here:
1950 // https://github.com/facebook/react/issues/14365
1951 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
1952 this.actualDuration = Number.NaN;
1953 this.actualStartTime = Number.NaN;
1954 this.selfBaseDuration = Number.NaN;
1955 this.treeBaseDuration = Number.NaN;
1956
1957 // It's okay to replace the initial doubles with smis after initialization.
1958 // This won't trigger the performance cliff mentioned above,
1959 // and it simplifies other profiler code (including DevTools).
1960 this.actualDuration = 0;
1961 this.actualStartTime = -1;
1962 this.selfBaseDuration = 0;
1963 this.treeBaseDuration = 0;
1964 }
1965
1966 {
1967 this._debugID = debugCounter++;
1968 this._debugSource = null;
1969 this._debugOwner = null;
1970 this._debugIsCurrentlyTiming = false;
1971 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
1972 Object.preventExtensions(this);
1973 }
1974 }
1975}
1976
1977// This is a constructor function, rather than a POJO constructor, still
1978// please ensure we do the following:
1979// 1) Nobody should add any instance methods on this. Instance methods can be
1980// more difficult to predict when they get optimized and they are almost
1981// never inlined properly in static compilers.
1982// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
1983// always know when it is a fiber.
1984// 3) We might want to experiment with using numeric keys since they are easier
1985// to optimize in a non-JIT environment.
1986// 4) We can easily go from a constructor to a createFiber object literal if that
1987// is faster.
1988// 5) It should be easy to port this to a C struct and keep a C implementation
1989// compatible.
1990var createFiber = function (tag, pendingProps, key, mode) {
1991 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
1992 return new FiberNode(tag, pendingProps, key, mode);
1993};
1994
1995function shouldConstruct(Component) {
1996 var prototype = Component.prototype;
1997 return !!(prototype && prototype.isReactComponent);
1998}
1999
2000function isSimpleFunctionComponent(type) {
2001 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
2002}
2003
2004function resolveLazyComponentTag(Component) {
2005 if (typeof Component === 'function') {
2006 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
2007 } else if (Component !== undefined && Component !== null) {
2008 var $$typeof = Component.$$typeof;
2009 if ($$typeof === REACT_FORWARD_REF_TYPE) {
2010 return ForwardRef;
2011 }
2012 if ($$typeof === REACT_MEMO_TYPE) {
2013 return MemoComponent;
2014 }
2015 }
2016 return IndeterminateComponent;
2017}
2018
2019// This is used to create an alternate fiber to do work on.
2020function createWorkInProgress(current, pendingProps, expirationTime) {
2021 var workInProgress = current.alternate;
2022 if (workInProgress === null) {
2023 // We use a double buffering pooling technique because we know that we'll
2024 // only ever need at most two versions of a tree. We pool the "other" unused
2025 // node that we're free to reuse. This is lazily created to avoid allocating
2026 // extra objects for things that are never updated. It also allow us to
2027 // reclaim the extra memory if needed.
2028 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
2029 workInProgress.elementType = current.elementType;
2030 workInProgress.type = current.type;
2031 workInProgress.stateNode = current.stateNode;
2032
2033 {
2034 // DEV-only fields
2035 workInProgress._debugID = current._debugID;
2036 workInProgress._debugSource = current._debugSource;
2037 workInProgress._debugOwner = current._debugOwner;
2038 }
2039
2040 workInProgress.alternate = current;
2041 current.alternate = workInProgress;
2042 } else {
2043 workInProgress.pendingProps = pendingProps;
2044
2045 // We already have an alternate.
2046 // Reset the effect tag.
2047 workInProgress.effectTag = NoEffect;
2048
2049 // The effect list is no longer valid.
2050 workInProgress.nextEffect = null;
2051 workInProgress.firstEffect = null;
2052 workInProgress.lastEffect = null;
2053
2054 if (enableProfilerTimer) {
2055 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
2056 // This prevents time from endlessly accumulating in new commits.
2057 // This has the downside of resetting values for different priority renders,
2058 // But works for yielding (the common case) and should support resuming.
2059 workInProgress.actualDuration = 0;
2060 workInProgress.actualStartTime = -1;
2061 }
2062 }
2063
2064 workInProgress.childExpirationTime = current.childExpirationTime;
2065 workInProgress.expirationTime = current.expirationTime;
2066
2067 workInProgress.child = current.child;
2068 workInProgress.memoizedProps = current.memoizedProps;
2069 workInProgress.memoizedState = current.memoizedState;
2070 workInProgress.updateQueue = current.updateQueue;
2071 workInProgress.contextDependencies = current.contextDependencies;
2072
2073 // These will be overridden during the parent's reconciliation
2074 workInProgress.sibling = current.sibling;
2075 workInProgress.index = current.index;
2076 workInProgress.ref = current.ref;
2077
2078 if (enableProfilerTimer) {
2079 workInProgress.selfBaseDuration = current.selfBaseDuration;
2080 workInProgress.treeBaseDuration = current.treeBaseDuration;
2081 }
2082
2083 return workInProgress;
2084}
2085
2086function createHostRootFiber(isConcurrent) {
2087 var mode = isConcurrent ? ConcurrentMode | StrictMode : NoContext;
2088
2089 if (enableProfilerTimer && isDevToolsPresent) {
2090 // Always collect profile timings when DevTools are present.
2091 // This enables DevTools to start capturing timing at any point–
2092 // Without some nodes in the tree having empty base times.
2093 mode |= ProfileMode;
2094 }
2095
2096 return createFiber(HostRoot, null, null, mode);
2097}
2098
2099function createFiberFromTypeAndProps(type, // React$ElementType
2100key, pendingProps, owner, mode, expirationTime) {
2101 var fiber = void 0;
2102
2103 var fiberTag = IndeterminateComponent;
2104 // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
2105 var resolvedType = type;
2106 if (typeof type === 'function') {
2107 if (shouldConstruct(type)) {
2108 fiberTag = ClassComponent;
2109 }
2110 } else if (typeof type === 'string') {
2111 fiberTag = HostComponent;
2112 } else {
2113 getTag: switch (type) {
2114 case REACT_FRAGMENT_TYPE:
2115 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
2116 case REACT_CONCURRENT_MODE_TYPE:
2117 return createFiberFromMode(pendingProps, mode | ConcurrentMode | StrictMode, expirationTime, key);
2118 case REACT_STRICT_MODE_TYPE:
2119 return createFiberFromMode(pendingProps, mode | StrictMode, expirationTime, key);
2120 case REACT_PROFILER_TYPE:
2121 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
2122 case REACT_SUSPENSE_TYPE:
2123 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
2124 default:
2125 {
2126 if (typeof type === 'object' && type !== null) {
2127 switch (type.$$typeof) {
2128 case REACT_PROVIDER_TYPE:
2129 fiberTag = ContextProvider;
2130 break getTag;
2131 case REACT_CONTEXT_TYPE:
2132 // This is a consumer
2133 fiberTag = ContextConsumer;
2134 break getTag;
2135 case REACT_FORWARD_REF_TYPE:
2136 fiberTag = ForwardRef;
2137 break getTag;
2138 case REACT_MEMO_TYPE:
2139 fiberTag = MemoComponent;
2140 break getTag;
2141 case REACT_LAZY_TYPE:
2142 fiberTag = LazyComponent;
2143 resolvedType = null;
2144 break getTag;
2145 }
2146 }
2147 var info = '';
2148 {
2149 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2150 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.';
2151 }
2152 var ownerName = owner ? getComponentName(owner.type) : null;
2153 if (ownerName) {
2154 info += '\n\nCheck the render method of `' + ownerName + '`.';
2155 }
2156 }
2157 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);
2158 }
2159 }
2160 }
2161
2162 fiber = createFiber(fiberTag, pendingProps, key, mode);
2163 fiber.elementType = type;
2164 fiber.type = resolvedType;
2165 fiber.expirationTime = expirationTime;
2166
2167 return fiber;
2168}
2169
2170function createFiberFromElement(element, mode, expirationTime) {
2171 var owner = null;
2172 {
2173 owner = element._owner;
2174 }
2175 var type = element.type;
2176 var key = element.key;
2177 var pendingProps = element.props;
2178 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
2179 {
2180 fiber._debugSource = element._source;
2181 fiber._debugOwner = element._owner;
2182 }
2183 return fiber;
2184}
2185
2186function createFiberFromFragment(elements, mode, expirationTime, key) {
2187 var fiber = createFiber(Fragment, elements, key, mode);
2188 fiber.expirationTime = expirationTime;
2189 return fiber;
2190}
2191
2192function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
2193 {
2194 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
2195 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
2196 }
2197 }
2198
2199 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode);
2200 // TODO: The Profiler fiber shouldn't have a type. It has a tag.
2201 fiber.elementType = REACT_PROFILER_TYPE;
2202 fiber.type = REACT_PROFILER_TYPE;
2203 fiber.expirationTime = expirationTime;
2204
2205 return fiber;
2206}
2207
2208function createFiberFromMode(pendingProps, mode, expirationTime, key) {
2209 var fiber = createFiber(Mode, pendingProps, key, mode);
2210
2211 // TODO: The Mode fiber shouldn't have a type. It has a tag.
2212 var type = (mode & ConcurrentMode) === NoContext ? REACT_STRICT_MODE_TYPE : REACT_CONCURRENT_MODE_TYPE;
2213 fiber.elementType = type;
2214 fiber.type = type;
2215
2216 fiber.expirationTime = expirationTime;
2217 return fiber;
2218}
2219
2220function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
2221 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode);
2222
2223 // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
2224 var type = REACT_SUSPENSE_TYPE;
2225 fiber.elementType = type;
2226 fiber.type = type;
2227
2228 fiber.expirationTime = expirationTime;
2229 return fiber;
2230}
2231
2232function createFiberFromText(content, mode, expirationTime) {
2233 var fiber = createFiber(HostText, content, null, mode);
2234 fiber.expirationTime = expirationTime;
2235 return fiber;
2236}
2237
2238function createFiberFromHostInstanceForDeletion() {
2239 var fiber = createFiber(HostComponent, null, null, NoContext);
2240 // TODO: These should not need a type.
2241 fiber.elementType = 'DELETED';
2242 fiber.type = 'DELETED';
2243 return fiber;
2244}
2245
2246function createFiberFromPortal(portal, mode, expirationTime) {
2247 var pendingProps = portal.children !== null ? portal.children : [];
2248 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
2249 fiber.expirationTime = expirationTime;
2250 fiber.stateNode = {
2251 containerInfo: portal.containerInfo,
2252 pendingChildren: null, // Used by persistent updates
2253 implementation: portal.implementation
2254 };
2255 return fiber;
2256}
2257
2258// Used for stashing WIP properties to replay failed work in DEV.
2259function assignFiberPropertiesInDEV(target, source) {
2260 if (target === null) {
2261 // This Fiber's initial properties will always be overwritten.
2262 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
2263 target = createFiber(IndeterminateComponent, null, null, NoContext);
2264 }
2265
2266 // This is intentionally written as a list of all properties.
2267 // We tried to use Object.assign() instead but this is called in
2268 // the hottest path, and Object.assign() was too slow:
2269 // https://github.com/facebook/react/issues/12502
2270 // This code is DEV-only so size is not a concern.
2271
2272 target.tag = source.tag;
2273 target.key = source.key;
2274 target.elementType = source.elementType;
2275 target.type = source.type;
2276 target.stateNode = source.stateNode;
2277 target.return = source.return;
2278 target.child = source.child;
2279 target.sibling = source.sibling;
2280 target.index = source.index;
2281 target.ref = source.ref;
2282 target.pendingProps = source.pendingProps;
2283 target.memoizedProps = source.memoizedProps;
2284 target.updateQueue = source.updateQueue;
2285 target.memoizedState = source.memoizedState;
2286 target.contextDependencies = source.contextDependencies;
2287 target.mode = source.mode;
2288 target.effectTag = source.effectTag;
2289 target.nextEffect = source.nextEffect;
2290 target.firstEffect = source.firstEffect;
2291 target.lastEffect = source.lastEffect;
2292 target.expirationTime = source.expirationTime;
2293 target.childExpirationTime = source.childExpirationTime;
2294 target.alternate = source.alternate;
2295 if (enableProfilerTimer) {
2296 target.actualDuration = source.actualDuration;
2297 target.actualStartTime = source.actualStartTime;
2298 target.selfBaseDuration = source.selfBaseDuration;
2299 target.treeBaseDuration = source.treeBaseDuration;
2300 }
2301 target._debugID = source._debugID;
2302 target._debugSource = source._debugSource;
2303 target._debugOwner = source._debugOwner;
2304 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
2305 return target;
2306}
2307
2308var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2309
2310var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing;
2311var __interactionsRef = _ReactInternals$Sched.__interactionsRef;
2312var __subscriberRef = _ReactInternals$Sched.__subscriberRef;
2313var unstable_clear = _ReactInternals$Sched.unstable_clear;
2314var unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent;
2315var unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID;
2316var unstable_subscribe = _ReactInternals$Sched.unstable_subscribe;
2317var unstable_trace = _ReactInternals$Sched.unstable_trace;
2318var unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe;
2319var unstable_wrap = _ReactInternals$Sched.unstable_wrap;
2320
2321// TODO: This should be lifted into the renderer.
2322
2323
2324// The following attributes are only used by interaction tracing builds.
2325// They enable interactions to be associated with their async work,
2326// And expose interaction metadata to the React DevTools Profiler plugin.
2327// Note that these attributes are only defined when the enableSchedulerTracing flag is enabled.
2328
2329
2330// Exported FiberRoot type includes all properties,
2331// To avoid requiring potentially error-prone :any casts throughout the project.
2332// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracing is true).
2333// The types are defined separately within this file to ensure they stay in sync.
2334// (We don't have to use an inline :any cast when enableSchedulerTracing is disabled.)
2335
2336
2337function createFiberRoot(containerInfo, isConcurrent, hydrate) {
2338 // Cyclic construction. This cheats the type system right now because
2339 // stateNode is any.
2340 var uninitializedFiber = createHostRootFiber(isConcurrent);
2341
2342 var root = void 0;
2343 if (enableSchedulerTracing) {
2344 root = {
2345 current: uninitializedFiber,
2346 containerInfo: containerInfo,
2347 pendingChildren: null,
2348
2349 earliestPendingTime: NoWork,
2350 latestPendingTime: NoWork,
2351 earliestSuspendedTime: NoWork,
2352 latestSuspendedTime: NoWork,
2353 latestPingedTime: NoWork,
2354
2355 pingCache: null,
2356
2357 didError: false,
2358
2359 pendingCommitExpirationTime: NoWork,
2360 finishedWork: null,
2361 timeoutHandle: noTimeout,
2362 context: null,
2363 pendingContext: null,
2364 hydrate: hydrate,
2365 nextExpirationTimeToWorkOn: NoWork,
2366 expirationTime: NoWork,
2367 firstBatch: null,
2368 nextScheduledRoot: null,
2369
2370 interactionThreadID: unstable_getThreadID(),
2371 memoizedInteractions: new Set(),
2372 pendingInteractionMap: new Map()
2373 };
2374 } else {
2375 root = {
2376 current: uninitializedFiber,
2377 containerInfo: containerInfo,
2378 pendingChildren: null,
2379
2380 pingCache: null,
2381
2382 earliestPendingTime: NoWork,
2383 latestPendingTime: NoWork,
2384 earliestSuspendedTime: NoWork,
2385 latestSuspendedTime: NoWork,
2386 latestPingedTime: NoWork,
2387
2388 didError: false,
2389
2390 pendingCommitExpirationTime: NoWork,
2391 finishedWork: null,
2392 timeoutHandle: noTimeout,
2393 context: null,
2394 pendingContext: null,
2395 hydrate: hydrate,
2396 nextExpirationTimeToWorkOn: NoWork,
2397 expirationTime: NoWork,
2398 firstBatch: null,
2399 nextScheduledRoot: null
2400 };
2401 }
2402
2403 uninitializedFiber.stateNode = root;
2404
2405 // The reason for the way the Flow types are structured in this file,
2406 // Is to avoid needing :any casts everywhere interaction tracing fields are used.
2407 // Unfortunately that requires an :any cast for non-interaction tracing capable builds.
2408 // $FlowFixMe Remove this :any cast and replace it with something better.
2409 return root;
2410}
2411
2412var ReactInternals$2 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2413
2414var _ReactInternals$Sched$1 = ReactInternals$2.Scheduler;
2415var unstable_cancelCallback = _ReactInternals$Sched$1.unstable_cancelCallback;
2416var unstable_now = _ReactInternals$Sched$1.unstable_now;
2417var unstable_scheduleCallback = _ReactInternals$Sched$1.unstable_scheduleCallback;
2418var unstable_shouldYield = _ReactInternals$Sched$1.unstable_shouldYield;
2419var unstable_getFirstCallbackNode = _ReactInternals$Sched$1.unstable_getFirstCallbackNode;
2420var unstable_runWithPriority = _ReactInternals$Sched$1.unstable_runWithPriority;
2421var unstable_next = _ReactInternals$Sched$1.unstable_next;
2422var unstable_continueExecution = _ReactInternals$Sched$1.unstable_continueExecution;
2423var unstable_pauseExecution = _ReactInternals$Sched$1.unstable_pauseExecution;
2424var unstable_getCurrentPriorityLevel = _ReactInternals$Sched$1.unstable_getCurrentPriorityLevel;
2425var unstable_ImmediatePriority = _ReactInternals$Sched$1.unstable_ImmediatePriority;
2426var unstable_UserBlockingPriority = _ReactInternals$Sched$1.unstable_UserBlockingPriority;
2427var unstable_NormalPriority = _ReactInternals$Sched$1.unstable_NormalPriority;
2428var unstable_LowPriority = _ReactInternals$Sched$1.unstable_LowPriority;
2429var unstable_IdlePriority = _ReactInternals$Sched$1.unstable_IdlePriority;
2430
2431var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
2432 var funcArgs = Array.prototype.slice.call(arguments, 3);
2433 try {
2434 func.apply(context, funcArgs);
2435 } catch (error) {
2436 this.onError(error);
2437 }
2438};
2439
2440{
2441 // In DEV mode, we swap out invokeGuardedCallback for a special version
2442 // that plays more nicely with the browser's DevTools. The idea is to preserve
2443 // "Pause on exceptions" behavior. Because React wraps all user-provided
2444 // functions in invokeGuardedCallback, and the production version of
2445 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
2446 // like caught exceptions, and the DevTools won't pause unless the developer
2447 // takes the extra step of enabling pause on caught exceptions. This is
2448 // unintuitive, though, because even though React has caught the error, from
2449 // the developer's perspective, the error is uncaught.
2450 //
2451 // To preserve the expected "Pause on exceptions" behavior, we don't use a
2452 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
2453 // DOM node, and call the user-provided callback from inside an event handler
2454 // for that fake event. If the callback throws, the error is "captured" using
2455 // a global event handler. But because the error happens in a different
2456 // event loop context, it does not interrupt the normal program flow.
2457 // Effectively, this gives us try-catch behavior without actually using
2458 // try-catch. Neat!
2459
2460 // Check that the browser supports the APIs we need to implement our special
2461 // DEV version of invokeGuardedCallback
2462 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
2463 var fakeNode = document.createElement('react');
2464
2465 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
2466 // If document doesn't exist we know for sure we will crash in this method
2467 // when we call document.createEvent(). However this can cause confusing
2468 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
2469 // So we preemptively throw with a better message instead.
2470 !(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;
2471 var evt = document.createEvent('Event');
2472
2473 // Keeps track of whether the user-provided callback threw an error. We
2474 // set this to true at the beginning, then set it to false right after
2475 // calling the function. If the function errors, `didError` will never be
2476 // set to false. This strategy works even if the browser is flaky and
2477 // fails to call our global error handler, because it doesn't rely on
2478 // the error event at all.
2479 var didError = true;
2480
2481 // Keeps track of the value of window.event so that we can reset it
2482 // during the callback to let user code access window.event in the
2483 // browsers that support it.
2484 var windowEvent = window.event;
2485
2486 // Keeps track of the descriptor of window.event to restore it after event
2487 // dispatching: https://github.com/facebook/react/issues/13688
2488 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
2489
2490 // Create an event handler for our fake event. We will synchronously
2491 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
2492 // call the user-provided callback.
2493 var funcArgs = Array.prototype.slice.call(arguments, 3);
2494 function callCallback() {
2495 // We immediately remove the callback from event listeners so that
2496 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
2497 // nested call would trigger the fake event handlers of any call higher
2498 // in the stack.
2499 fakeNode.removeEventListener(evtType, callCallback, false);
2500
2501 // We check for window.hasOwnProperty('event') to prevent the
2502 // window.event assignment in both IE <= 10 as they throw an error
2503 // "Member not found" in strict mode, and in Firefox which does not
2504 // support window.event.
2505 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
2506 window.event = windowEvent;
2507 }
2508
2509 func.apply(context, funcArgs);
2510 didError = false;
2511 }
2512
2513 // Create a global error event handler. We use this to capture the value
2514 // that was thrown. It's possible that this error handler will fire more
2515 // than once; for example, if non-React code also calls `dispatchEvent`
2516 // and a handler for that event throws. We should be resilient to most of
2517 // those cases. Even if our error event handler fires more than once, the
2518 // last error event is always used. If the callback actually does error,
2519 // we know that the last error event is the correct one, because it's not
2520 // possible for anything else to have happened in between our callback
2521 // erroring and the code that follows the `dispatchEvent` call below. If
2522 // the callback doesn't error, but the error event was fired, we know to
2523 // ignore it because `didError` will be false, as described above.
2524 var error = void 0;
2525 // Use this to track whether the error event is ever called.
2526 var didSetError = false;
2527 var isCrossOriginError = false;
2528
2529 function handleWindowError(event) {
2530 error = event.error;
2531 didSetError = true;
2532 if (error === null && event.colno === 0 && event.lineno === 0) {
2533 isCrossOriginError = true;
2534 }
2535 if (event.defaultPrevented) {
2536 // Some other error handler has prevented default.
2537 // Browsers silence the error report if this happens.
2538 // We'll remember this to later decide whether to log it or not.
2539 if (error != null && typeof error === 'object') {
2540 try {
2541 error._suppressLogging = true;
2542 } catch (inner) {
2543 // Ignore.
2544 }
2545 }
2546 }
2547 }
2548
2549 // Create a fake event type.
2550 var evtType = 'react-' + (name ? name : 'invokeguardedcallback');
2551
2552 // Attach our event handlers
2553 window.addEventListener('error', handleWindowError);
2554 fakeNode.addEventListener(evtType, callCallback, false);
2555
2556 // Synchronously dispatch our fake event. If the user-provided function
2557 // errors, it will trigger our global error handler.
2558 evt.initEvent(evtType, false, false);
2559 fakeNode.dispatchEvent(evt);
2560
2561 if (windowEventDescriptor) {
2562 Object.defineProperty(window, 'event', windowEventDescriptor);
2563 }
2564
2565 if (didError) {
2566 if (!didSetError) {
2567 // The callback errored, but the error event never fired.
2568 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.');
2569 } else if (isCrossOriginError) {
2570 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.');
2571 }
2572 this.onError(error);
2573 }
2574
2575 // Remove our event listeners
2576 window.removeEventListener('error', handleWindowError);
2577 };
2578
2579 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
2580 }
2581}
2582
2583var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
2584
2585// Used by Fiber to simulate a try-catch.
2586var hasError = false;
2587var caughtError = null;
2588
2589var reporter = {
2590 onError: function (error) {
2591 hasError = true;
2592 caughtError = error;
2593 }
2594};
2595
2596/**
2597 * Call a function while guarding against errors that happens within it.
2598 * Returns an error if it throws, otherwise null.
2599 *
2600 * In production, this is implemented using a try-catch. The reason we don't
2601 * use a try-catch directly is so that we can swap out a different
2602 * implementation in DEV mode.
2603 *
2604 * @param {String} name of the guard to use for logging or debugging
2605 * @param {Function} func The function to invoke
2606 * @param {*} context The context to use when calling the function
2607 * @param {...*} args Arguments for function
2608 */
2609function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
2610 hasError = false;
2611 caughtError = null;
2612 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
2613}
2614
2615/**
2616 * Same as invokeGuardedCallback, but instead of returning an error, it stores
2617 * it in a global so it can be rethrown by `rethrowCaughtError` later.
2618 * TODO: See if caughtError and rethrowError can be unified.
2619 *
2620 * @param {String} name of the guard to use for logging or debugging
2621 * @param {Function} func The function to invoke
2622 * @param {*} context The context to use when calling the function
2623 * @param {...*} args Arguments for function
2624 */
2625
2626
2627/**
2628 * During execution of guarded functions we will capture the first error which
2629 * we will rethrow to be handled by the top level error handler.
2630 */
2631
2632
2633function hasCaughtError() {
2634 return hasError;
2635}
2636
2637function clearCaughtError() {
2638 if (hasError) {
2639 var error = caughtError;
2640 hasError = false;
2641 caughtError = null;
2642 return error;
2643 } else {
2644 invariant(false, 'clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.');
2645 }
2646}
2647
2648/**
2649 * Forked from fbjs/warning:
2650 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2651 *
2652 * Only change is we use console.warn instead of console.error,
2653 * and do nothing when 'console' is not supported.
2654 * This really simplifies the code.
2655 * ---
2656 * Similar to invariant but only logs a warning if the condition is not met.
2657 * This can be used to log issues in development environments in critical
2658 * paths. Removing the logging code for production environments will keep the
2659 * same logic and follow the same code paths.
2660 */
2661
2662var lowPriorityWarning = function () {};
2663
2664{
2665 var printWarning$1 = function (format) {
2666 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2667 args[_key - 1] = arguments[_key];
2668 }
2669
2670 var argIndex = 0;
2671 var message = 'Warning: ' + format.replace(/%s/g, function () {
2672 return args[argIndex++];
2673 });
2674 if (typeof console !== 'undefined') {
2675 console.warn(message);
2676 }
2677 try {
2678 // --- Welcome to debugging React ---
2679 // This error was thrown as a convenience so that you can use this stack
2680 // to find the callsite that caused this warning to fire.
2681 throw new Error(message);
2682 } catch (x) {}
2683 };
2684
2685 lowPriorityWarning = function (condition, format) {
2686 if (format === undefined) {
2687 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
2688 }
2689 if (!condition) {
2690 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2691 args[_key2 - 2] = arguments[_key2];
2692 }
2693
2694 printWarning$1.apply(undefined, [format].concat(args));
2695 }
2696 };
2697}
2698
2699var lowPriorityWarning$1 = lowPriorityWarning;
2700
2701var ReactStrictModeWarnings = {
2702 discardPendingWarnings: function () {},
2703 flushPendingDeprecationWarnings: function () {},
2704 flushPendingUnsafeLifecycleWarnings: function () {},
2705 recordDeprecationWarnings: function (fiber, instance) {},
2706 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2707 recordLegacyContextWarning: function (fiber, instance) {},
2708 flushLegacyContextWarning: function () {}
2709};
2710
2711{
2712 var LIFECYCLE_SUGGESTIONS = {
2713 UNSAFE_componentWillMount: 'componentDidMount',
2714 UNSAFE_componentWillReceiveProps: 'static getDerivedStateFromProps',
2715 UNSAFE_componentWillUpdate: 'componentDidUpdate'
2716 };
2717
2718 var pendingComponentWillMountWarnings = [];
2719 var pendingComponentWillReceivePropsWarnings = [];
2720 var pendingComponentWillUpdateWarnings = [];
2721 var pendingUnsafeLifecycleWarnings = new Map();
2722 var pendingLegacyContextWarning = new Map();
2723
2724 // Tracks components we have already warned about.
2725 var didWarnAboutDeprecatedLifecycles = new Set();
2726 var didWarnAboutUnsafeLifecycles = new Set();
2727 var didWarnAboutLegacyContext = new Set();
2728
2729 var setToSortedString = function (set) {
2730 var array = [];
2731 set.forEach(function (value) {
2732 array.push(value);
2733 });
2734 return array.sort().join(', ');
2735 };
2736
2737 ReactStrictModeWarnings.discardPendingWarnings = function () {
2738 pendingComponentWillMountWarnings = [];
2739 pendingComponentWillReceivePropsWarnings = [];
2740 pendingComponentWillUpdateWarnings = [];
2741 pendingUnsafeLifecycleWarnings = new Map();
2742 pendingLegacyContextWarning = new Map();
2743 };
2744
2745 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2746 pendingUnsafeLifecycleWarnings.forEach(function (lifecycleWarningsMap, strictRoot) {
2747 var lifecyclesWarningMessages = [];
2748
2749 Object.keys(lifecycleWarningsMap).forEach(function (lifecycle) {
2750 var lifecycleWarnings = lifecycleWarningsMap[lifecycle];
2751 if (lifecycleWarnings.length > 0) {
2752 var componentNames = new Set();
2753 lifecycleWarnings.forEach(function (fiber) {
2754 componentNames.add(getComponentName(fiber.type) || 'Component');
2755 didWarnAboutUnsafeLifecycles.add(fiber.type);
2756 });
2757
2758 var formatted = lifecycle.replace('UNSAFE_', '');
2759 var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle];
2760 var sortedComponentNames = setToSortedString(componentNames);
2761
2762 lifecyclesWarningMessages.push(formatted + ': Please update the following components to use ' + (suggestion + ' instead: ' + sortedComponentNames));
2763 }
2764 });
2765
2766 if (lifecyclesWarningMessages.length > 0) {
2767 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2768
2769 warningWithoutStack$1(false, 'Unsafe lifecycle methods were found within a strict-mode tree:%s' + '\n\n%s' + '\n\nLearn more about this warning here:' + '\nhttps://fb.me/react-strict-mode-warnings', strictRootComponentStack, lifecyclesWarningMessages.join('\n\n'));
2770 }
2771 });
2772
2773 pendingUnsafeLifecycleWarnings = new Map();
2774 };
2775
2776 var findStrictRoot = function (fiber) {
2777 var maybeStrictRoot = null;
2778
2779 var node = fiber;
2780 while (node !== null) {
2781 if (node.mode & StrictMode) {
2782 maybeStrictRoot = node;
2783 }
2784 node = node.return;
2785 }
2786
2787 return maybeStrictRoot;
2788 };
2789
2790 ReactStrictModeWarnings.flushPendingDeprecationWarnings = function () {
2791 if (pendingComponentWillMountWarnings.length > 0) {
2792 var uniqueNames = new Set();
2793 pendingComponentWillMountWarnings.forEach(function (fiber) {
2794 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2795 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2796 });
2797
2798 var sortedNames = setToSortedString(uniqueNames);
2799
2800 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);
2801
2802 pendingComponentWillMountWarnings = [];
2803 }
2804
2805 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2806 var _uniqueNames = new Set();
2807 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2808 _uniqueNames.add(getComponentName(fiber.type) || 'Component');
2809 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2810 });
2811
2812 var _sortedNames = setToSortedString(_uniqueNames);
2813
2814 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);
2815
2816 pendingComponentWillReceivePropsWarnings = [];
2817 }
2818
2819 if (pendingComponentWillUpdateWarnings.length > 0) {
2820 var _uniqueNames2 = new Set();
2821 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2822 _uniqueNames2.add(getComponentName(fiber.type) || 'Component');
2823 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2824 });
2825
2826 var _sortedNames2 = setToSortedString(_uniqueNames2);
2827
2828 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);
2829
2830 pendingComponentWillUpdateWarnings = [];
2831 }
2832 };
2833
2834 ReactStrictModeWarnings.recordDeprecationWarnings = function (fiber, instance) {
2835 // Dedup strategy: Warn once per component.
2836 if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) {
2837 return;
2838 }
2839
2840 // Don't warn about react-lifecycles-compat polyfilled components.
2841 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
2842 pendingComponentWillMountWarnings.push(fiber);
2843 }
2844 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2845 pendingComponentWillReceivePropsWarnings.push(fiber);
2846 }
2847 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2848 pendingComponentWillUpdateWarnings.push(fiber);
2849 }
2850 };
2851
2852 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2853 var strictRoot = findStrictRoot(fiber);
2854 if (strictRoot === null) {
2855 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.');
2856 return;
2857 }
2858
2859 // Dedup strategy: Warn once per component.
2860 // This is difficult to track any other way since component names
2861 // are often vague and are likely to collide between 3rd party libraries.
2862 // An expand property is probably okay to use here since it's DEV-only,
2863 // and will only be set in the event of serious warnings.
2864 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2865 return;
2866 }
2867
2868 var warningsForRoot = void 0;
2869 if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) {
2870 warningsForRoot = {
2871 UNSAFE_componentWillMount: [],
2872 UNSAFE_componentWillReceiveProps: [],
2873 UNSAFE_componentWillUpdate: []
2874 };
2875
2876 pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot);
2877 } else {
2878 warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot);
2879 }
2880
2881 var unsafeLifecycles = [];
2882 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillMount === 'function') {
2883 unsafeLifecycles.push('UNSAFE_componentWillMount');
2884 }
2885 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2886 unsafeLifecycles.push('UNSAFE_componentWillReceiveProps');
2887 }
2888 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillUpdate === 'function') {
2889 unsafeLifecycles.push('UNSAFE_componentWillUpdate');
2890 }
2891
2892 if (unsafeLifecycles.length > 0) {
2893 unsafeLifecycles.forEach(function (lifecycle) {
2894 warningsForRoot[lifecycle].push(fiber);
2895 });
2896 }
2897 };
2898
2899 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2900 var strictRoot = findStrictRoot(fiber);
2901 if (strictRoot === null) {
2902 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.');
2903 return;
2904 }
2905
2906 // Dedup strategy: Warn once per component.
2907 if (didWarnAboutLegacyContext.has(fiber.type)) {
2908 return;
2909 }
2910
2911 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2912
2913 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2914 if (warningsForRoot === undefined) {
2915 warningsForRoot = [];
2916 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2917 }
2918 warningsForRoot.push(fiber);
2919 }
2920 };
2921
2922 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2923 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2924 var uniqueNames = new Set();
2925 fiberArray.forEach(function (fiber) {
2926 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2927 didWarnAboutLegacyContext.add(fiber.type);
2928 });
2929
2930 var sortedNames = setToSortedString(uniqueNames);
2931 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2932
2933 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);
2934 });
2935 };
2936}
2937
2938// This lets us hook into Fiber to debug what it's doing.
2939// See https://github.com/facebook/react/pull/8033.
2940// This is not part of the public API, not even for React DevTools.
2941// You may only inject a debugTool if you work on React Fiber itself.
2942var ReactFiberInstrumentation = {
2943 debugTool: null
2944};
2945
2946var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
2947
2948// TODO: Offscreen updates should never suspend. However, a promise that
2949// suspended inside an offscreen subtree should be able to ping at the priority
2950// of the outer render.
2951
2952function markPendingPriorityLevel(root, expirationTime) {
2953 // If there's a gap between completing a failed root and retrying it,
2954 // additional updates may be scheduled. Clear `didError`, in case the update
2955 // is sufficient to fix the error.
2956 root.didError = false;
2957
2958 // Update the latest and earliest pending times
2959 var earliestPendingTime = root.earliestPendingTime;
2960 if (earliestPendingTime === NoWork) {
2961 // No other pending updates.
2962 root.earliestPendingTime = root.latestPendingTime = expirationTime;
2963 } else {
2964 if (earliestPendingTime < expirationTime) {
2965 // This is the earliest pending update.
2966 root.earliestPendingTime = expirationTime;
2967 } else {
2968 var latestPendingTime = root.latestPendingTime;
2969 if (latestPendingTime > expirationTime) {
2970 // This is the latest pending update
2971 root.latestPendingTime = expirationTime;
2972 }
2973 }
2974 }
2975 findNextExpirationTimeToWorkOn(expirationTime, root);
2976}
2977
2978function markCommittedPriorityLevels(root, earliestRemainingTime) {
2979 root.didError = false;
2980
2981 if (earliestRemainingTime === NoWork) {
2982 // Fast path. There's no remaining work. Clear everything.
2983 root.earliestPendingTime = NoWork;
2984 root.latestPendingTime = NoWork;
2985 root.earliestSuspendedTime = NoWork;
2986 root.latestSuspendedTime = NoWork;
2987 root.latestPingedTime = NoWork;
2988 findNextExpirationTimeToWorkOn(NoWork, root);
2989 return;
2990 }
2991
2992 if (earliestRemainingTime < root.latestPingedTime) {
2993 root.latestPingedTime = NoWork;
2994 }
2995
2996 // Let's see if the previous latest known pending level was just flushed.
2997 var latestPendingTime = root.latestPendingTime;
2998 if (latestPendingTime !== NoWork) {
2999 if (latestPendingTime > earliestRemainingTime) {
3000 // We've flushed all the known pending levels.
3001 root.earliestPendingTime = root.latestPendingTime = NoWork;
3002 } else {
3003 var earliestPendingTime = root.earliestPendingTime;
3004 if (earliestPendingTime > earliestRemainingTime) {
3005 // We've flushed the earliest known pending level. Set this to the
3006 // latest pending time.
3007 root.earliestPendingTime = root.latestPendingTime;
3008 }
3009 }
3010 }
3011
3012 // Now let's handle the earliest remaining level in the whole tree. We need to
3013 // decide whether to treat it as a pending level or as suspended. Check
3014 // it falls within the range of known suspended levels.
3015
3016 var earliestSuspendedTime = root.earliestSuspendedTime;
3017 if (earliestSuspendedTime === NoWork) {
3018 // There's no suspended work. Treat the earliest remaining level as a
3019 // pending level.
3020 markPendingPriorityLevel(root, earliestRemainingTime);
3021 findNextExpirationTimeToWorkOn(NoWork, root);
3022 return;
3023 }
3024
3025 var latestSuspendedTime = root.latestSuspendedTime;
3026 if (earliestRemainingTime < latestSuspendedTime) {
3027 // The earliest remaining level is later than all the suspended work. That
3028 // means we've flushed all the suspended work.
3029 root.earliestSuspendedTime = NoWork;
3030 root.latestSuspendedTime = NoWork;
3031 root.latestPingedTime = NoWork;
3032
3033 // There's no suspended work. Treat the earliest remaining level as a
3034 // pending level.
3035 markPendingPriorityLevel(root, earliestRemainingTime);
3036 findNextExpirationTimeToWorkOn(NoWork, root);
3037 return;
3038 }
3039
3040 if (earliestRemainingTime > earliestSuspendedTime) {
3041 // The earliest remaining time is earlier than all the suspended work.
3042 // Treat it as a pending update.
3043 markPendingPriorityLevel(root, earliestRemainingTime);
3044 findNextExpirationTimeToWorkOn(NoWork, root);
3045 return;
3046 }
3047
3048 // The earliest remaining time falls within the range of known suspended
3049 // levels. We should treat this as suspended work.
3050 findNextExpirationTimeToWorkOn(NoWork, root);
3051}
3052
3053function hasLowerPriorityWork(root, erroredExpirationTime) {
3054 var latestPendingTime = root.latestPendingTime;
3055 var latestSuspendedTime = root.latestSuspendedTime;
3056 var latestPingedTime = root.latestPingedTime;
3057 return latestPendingTime !== NoWork && latestPendingTime < erroredExpirationTime || latestSuspendedTime !== NoWork && latestSuspendedTime < erroredExpirationTime || latestPingedTime !== NoWork && latestPingedTime < erroredExpirationTime;
3058}
3059
3060function isPriorityLevelSuspended(root, expirationTime) {
3061 var earliestSuspendedTime = root.earliestSuspendedTime;
3062 var latestSuspendedTime = root.latestSuspendedTime;
3063 return earliestSuspendedTime !== NoWork && expirationTime <= earliestSuspendedTime && expirationTime >= latestSuspendedTime;
3064}
3065
3066function markSuspendedPriorityLevel(root, suspendedTime) {
3067 root.didError = false;
3068 clearPing(root, suspendedTime);
3069
3070 // First, check the known pending levels and update them if needed.
3071 var earliestPendingTime = root.earliestPendingTime;
3072 var latestPendingTime = root.latestPendingTime;
3073 if (earliestPendingTime === suspendedTime) {
3074 if (latestPendingTime === suspendedTime) {
3075 // Both known pending levels were suspended. Clear them.
3076 root.earliestPendingTime = root.latestPendingTime = NoWork;
3077 } else {
3078 // The earliest pending level was suspended. Clear by setting it to the
3079 // latest pending level.
3080 root.earliestPendingTime = latestPendingTime;
3081 }
3082 } else if (latestPendingTime === suspendedTime) {
3083 // The latest pending level was suspended. Clear by setting it to the
3084 // latest pending level.
3085 root.latestPendingTime = earliestPendingTime;
3086 }
3087
3088 // Finally, update the known suspended levels.
3089 var earliestSuspendedTime = root.earliestSuspendedTime;
3090 var latestSuspendedTime = root.latestSuspendedTime;
3091 if (earliestSuspendedTime === NoWork) {
3092 // No other suspended levels.
3093 root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime;
3094 } else {
3095 if (earliestSuspendedTime < suspendedTime) {
3096 // This is the earliest suspended level.
3097 root.earliestSuspendedTime = suspendedTime;
3098 } else if (latestSuspendedTime > suspendedTime) {
3099 // This is the latest suspended level
3100 root.latestSuspendedTime = suspendedTime;
3101 }
3102 }
3103
3104 findNextExpirationTimeToWorkOn(suspendedTime, root);
3105}
3106
3107function markPingedPriorityLevel(root, pingedTime) {
3108 root.didError = false;
3109
3110 // TODO: When we add back resuming, we need to ensure the progressed work
3111 // is thrown out and not reused during the restarted render. One way to
3112 // invalidate the progressed work is to restart at expirationTime + 1.
3113 var latestPingedTime = root.latestPingedTime;
3114 if (latestPingedTime === NoWork || latestPingedTime > pingedTime) {
3115 root.latestPingedTime = pingedTime;
3116 }
3117 findNextExpirationTimeToWorkOn(pingedTime, root);
3118}
3119
3120function clearPing(root, completedTime) {
3121 var latestPingedTime = root.latestPingedTime;
3122 if (latestPingedTime >= completedTime) {
3123 root.latestPingedTime = NoWork;
3124 }
3125}
3126
3127function findEarliestOutstandingPriorityLevel(root, renderExpirationTime) {
3128 var earliestExpirationTime = renderExpirationTime;
3129
3130 var earliestPendingTime = root.earliestPendingTime;
3131 var earliestSuspendedTime = root.earliestSuspendedTime;
3132 if (earliestPendingTime > earliestExpirationTime) {
3133 earliestExpirationTime = earliestPendingTime;
3134 }
3135 if (earliestSuspendedTime > earliestExpirationTime) {
3136 earliestExpirationTime = earliestSuspendedTime;
3137 }
3138 return earliestExpirationTime;
3139}
3140
3141function didExpireAtExpirationTime(root, currentTime) {
3142 var expirationTime = root.expirationTime;
3143 if (expirationTime !== NoWork && currentTime <= expirationTime) {
3144 // The root has expired. Flush all work up to the current time.
3145 root.nextExpirationTimeToWorkOn = currentTime;
3146 }
3147}
3148
3149function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
3150 var earliestSuspendedTime = root.earliestSuspendedTime;
3151 var latestSuspendedTime = root.latestSuspendedTime;
3152 var earliestPendingTime = root.earliestPendingTime;
3153 var latestPingedTime = root.latestPingedTime;
3154
3155 // Work on the earliest pending time. Failing that, work on the latest
3156 // pinged time.
3157 var nextExpirationTimeToWorkOn = earliestPendingTime !== NoWork ? earliestPendingTime : latestPingedTime;
3158
3159 // If there is no pending or pinged work, check if there's suspended work
3160 // that's lower priority than what we just completed.
3161 if (nextExpirationTimeToWorkOn === NoWork && (completedExpirationTime === NoWork || latestSuspendedTime < completedExpirationTime)) {
3162 // The lowest priority suspended work is the work most likely to be
3163 // committed next. Let's start rendering it again, so that if it times out,
3164 // it's ready to commit.
3165 nextExpirationTimeToWorkOn = latestSuspendedTime;
3166 }
3167
3168 var expirationTime = nextExpirationTimeToWorkOn;
3169 if (expirationTime !== NoWork && earliestSuspendedTime > expirationTime) {
3170 // Expire using the earliest known expiration time.
3171 expirationTime = earliestSuspendedTime;
3172 }
3173
3174 root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn;
3175 root.expirationTime = expirationTime;
3176}
3177
3178/**
3179 * inlined Object.is polyfill to avoid requiring consumers ship their own
3180 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3181 */
3182function is(x, y) {
3183 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
3184 ;
3185}
3186
3187var hasOwnProperty = Object.prototype.hasOwnProperty;
3188
3189/**
3190 * Performs equality by iterating through keys on an object and returning false
3191 * when any key has values which are not strictly equal between the arguments.
3192 * Returns true when the values of all keys are strictly equal.
3193 */
3194function shallowEqual(objA, objB) {
3195 if (is(objA, objB)) {
3196 return true;
3197 }
3198
3199 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
3200 return false;
3201 }
3202
3203 var keysA = Object.keys(objA);
3204 var keysB = Object.keys(objB);
3205
3206 if (keysA.length !== keysB.length) {
3207 return false;
3208 }
3209
3210 // Test for A's keys different from B.
3211 for (var i = 0; i < keysA.length; i++) {
3212 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
3213 return false;
3214 }
3215 }
3216
3217 return true;
3218}
3219
3220function resolveDefaultProps(Component, baseProps) {
3221 if (Component && Component.defaultProps) {
3222 // Resolve default props. Taken from ReactElement
3223 var props = _assign({}, baseProps);
3224 var defaultProps = Component.defaultProps;
3225 for (var propName in defaultProps) {
3226 if (props[propName] === undefined) {
3227 props[propName] = defaultProps[propName];
3228 }
3229 }
3230 return props;
3231 }
3232 return baseProps;
3233}
3234
3235function readLazyComponentType(lazyComponent) {
3236 var status = lazyComponent._status;
3237 var result = lazyComponent._result;
3238 switch (status) {
3239 case Resolved:
3240 {
3241 var Component = result;
3242 return Component;
3243 }
3244 case Rejected:
3245 {
3246 var error = result;
3247 throw error;
3248 }
3249 case Pending:
3250 {
3251 var thenable = result;
3252 throw thenable;
3253 }
3254 default:
3255 {
3256 lazyComponent._status = Pending;
3257 var ctor = lazyComponent._ctor;
3258 var _thenable = ctor();
3259 _thenable.then(function (moduleObject) {
3260 if (lazyComponent._status === Pending) {
3261 var defaultExport = moduleObject.default;
3262 {
3263 if (defaultExport === undefined) {
3264 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);
3265 }
3266 }
3267 lazyComponent._status = Resolved;
3268 lazyComponent._result = defaultExport;
3269 }
3270 }, function (error) {
3271 if (lazyComponent._status === Pending) {
3272 lazyComponent._status = Rejected;
3273 lazyComponent._result = error;
3274 }
3275 });
3276 // Handle synchronous thenables.
3277 switch (lazyComponent._status) {
3278 case Resolved:
3279 return lazyComponent._result;
3280 case Rejected:
3281 throw lazyComponent._result;
3282 }
3283 lazyComponent._result = _thenable;
3284 throw _thenable;
3285 }
3286 }
3287}
3288
3289var fakeInternalInstance = {};
3290var isArray$1 = Array.isArray;
3291
3292// React.Component uses a shared frozen object by default.
3293// We'll use it to determine whether we need to initialize legacy refs.
3294var emptyRefsObject = new React.Component().refs;
3295
3296var didWarnAboutStateAssignmentForComponent = void 0;
3297var didWarnAboutUninitializedState = void 0;
3298var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0;
3299var didWarnAboutLegacyLifecyclesAndDerivedState = void 0;
3300var didWarnAboutUndefinedDerivedState = void 0;
3301var warnOnUndefinedDerivedState = void 0;
3302var warnOnInvalidCallback = void 0;
3303var didWarnAboutDirectlyAssigningPropsToState = void 0;
3304var didWarnAboutContextTypeAndContextTypes = void 0;
3305var didWarnAboutInvalidateContextType = void 0;
3306
3307{
3308 didWarnAboutStateAssignmentForComponent = new Set();
3309 didWarnAboutUninitializedState = new Set();
3310 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3311 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3312 didWarnAboutDirectlyAssigningPropsToState = new Set();
3313 didWarnAboutUndefinedDerivedState = new Set();
3314 didWarnAboutContextTypeAndContextTypes = new Set();
3315 didWarnAboutInvalidateContextType = new Set();
3316
3317 var didWarnOnInvalidCallback = new Set();
3318
3319 warnOnInvalidCallback = function (callback, callerName) {
3320 if (callback === null || typeof callback === 'function') {
3321 return;
3322 }
3323 var key = callerName + '_' + callback;
3324 if (!didWarnOnInvalidCallback.has(key)) {
3325 didWarnOnInvalidCallback.add(key);
3326 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
3327 }
3328 };
3329
3330 warnOnUndefinedDerivedState = function (type, partialState) {
3331 if (partialState === undefined) {
3332 var componentName = getComponentName(type) || 'Component';
3333 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
3334 didWarnAboutUndefinedDerivedState.add(componentName);
3335 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
3336 }
3337 }
3338 };
3339
3340 // This is so gross but it's at least non-critical and can be removed if
3341 // it causes problems. This is meant to give a nicer error message for
3342 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
3343 // ...)) which otherwise throws a "_processChildContext is not a function"
3344 // exception.
3345 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
3346 enumerable: false,
3347 value: function () {
3348 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).');
3349 }
3350 });
3351 Object.freeze(fakeInternalInstance);
3352}
3353
3354function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
3355 var prevState = workInProgress.memoizedState;
3356
3357 {
3358 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3359 // Invoke the function an extra time to help detect side-effects.
3360 getDerivedStateFromProps(nextProps, prevState);
3361 }
3362 }
3363
3364 var partialState = getDerivedStateFromProps(nextProps, prevState);
3365
3366 {
3367 warnOnUndefinedDerivedState(ctor, partialState);
3368 }
3369 // Merge the partial state and the previous state.
3370 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
3371 workInProgress.memoizedState = memoizedState;
3372
3373 // Once the update queue is empty, persist the derived state onto the
3374 // base state.
3375 var updateQueue = workInProgress.updateQueue;
3376 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
3377 updateQueue.baseState = memoizedState;
3378 }
3379}
3380
3381var classComponentUpdater = {
3382 isMounted: isMounted,
3383 enqueueSetState: function (inst, payload, callback) {
3384 var fiber = get(inst);
3385 var currentTime = requestCurrentTime();
3386 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3387
3388 var update = createUpdate(expirationTime);
3389 update.payload = payload;
3390 if (callback !== undefined && callback !== null) {
3391 {
3392 warnOnInvalidCallback(callback, 'setState');
3393 }
3394 update.callback = callback;
3395 }
3396
3397 flushPassiveEffects$1();
3398 enqueueUpdate(fiber, update);
3399 scheduleWork(fiber, expirationTime);
3400 },
3401 enqueueReplaceState: function (inst, payload, callback) {
3402 var fiber = get(inst);
3403 var currentTime = requestCurrentTime();
3404 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3405
3406 var update = createUpdate(expirationTime);
3407 update.tag = ReplaceState;
3408 update.payload = payload;
3409
3410 if (callback !== undefined && callback !== null) {
3411 {
3412 warnOnInvalidCallback(callback, 'replaceState');
3413 }
3414 update.callback = callback;
3415 }
3416
3417 flushPassiveEffects$1();
3418 enqueueUpdate(fiber, update);
3419 scheduleWork(fiber, expirationTime);
3420 },
3421 enqueueForceUpdate: function (inst, callback) {
3422 var fiber = get(inst);
3423 var currentTime = requestCurrentTime();
3424 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3425
3426 var update = createUpdate(expirationTime);
3427 update.tag = ForceUpdate;
3428
3429 if (callback !== undefined && callback !== null) {
3430 {
3431 warnOnInvalidCallback(callback, 'forceUpdate');
3432 }
3433 update.callback = callback;
3434 }
3435
3436 flushPassiveEffects$1();
3437 enqueueUpdate(fiber, update);
3438 scheduleWork(fiber, expirationTime);
3439 }
3440};
3441
3442function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
3443 var instance = workInProgress.stateNode;
3444 if (typeof instance.shouldComponentUpdate === 'function') {
3445 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
3446 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
3447 stopPhaseTimer();
3448
3449 {
3450 !(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;
3451 }
3452
3453 return shouldUpdate;
3454 }
3455
3456 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
3457 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
3458 }
3459
3460 return true;
3461}
3462
3463function checkClassInstance(workInProgress, ctor, newProps) {
3464 var instance = workInProgress.stateNode;
3465 {
3466 var name = getComponentName(ctor) || 'Component';
3467 var renderPresent = instance.render;
3468
3469 if (!renderPresent) {
3470 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
3471 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
3472 } else {
3473 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
3474 }
3475 }
3476
3477 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
3478 !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;
3479 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
3480 !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;
3481 var noInstancePropTypes = !instance.propTypes;
3482 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
3483 var noInstanceContextType = !instance.contextType;
3484 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
3485 var noInstanceContextTypes = !instance.contextTypes;
3486 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
3487
3488 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
3489 didWarnAboutContextTypeAndContextTypes.add(ctor);
3490 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
3491 }
3492
3493 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
3494 !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;
3495 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
3496 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');
3497 }
3498 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
3499 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
3500 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
3501 !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;
3502 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
3503 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
3504 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
3505 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
3506 var hasMutatedProps = instance.props !== newProps;
3507 !(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;
3508 var noInstanceDefaultProps = !instance.defaultProps;
3509 !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;
3510
3511 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
3512 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
3513 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
3514 }
3515
3516 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
3517 !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;
3518 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
3519 !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;
3520 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
3521 !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;
3522 var _state = instance.state;
3523 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
3524 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
3525 }
3526 if (typeof instance.getChildContext === 'function') {
3527 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
3528 }
3529 }
3530}
3531
3532function adoptClassInstance(workInProgress, instance) {
3533 instance.updater = classComponentUpdater;
3534 workInProgress.stateNode = instance;
3535 // The instance needs access to the fiber so that it can schedule updates
3536 set(instance, workInProgress);
3537 {
3538 instance._reactInternalInstance = fakeInternalInstance;
3539 }
3540}
3541
3542function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
3543 var isLegacyContextConsumer = false;
3544 var unmaskedContext = emptyContextObject;
3545 var context = null;
3546 var contextType = ctor.contextType;
3547 if (typeof contextType === 'object' && contextType !== null) {
3548 {
3549 if (contextType.$$typeof !== REACT_CONTEXT_TYPE && !didWarnAboutInvalidateContextType.has(ctor)) {
3550 didWarnAboutInvalidateContextType.add(ctor);
3551 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');
3552 }
3553 }
3554
3555 context = readContext(contextType);
3556 } else {
3557 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3558 var contextTypes = ctor.contextTypes;
3559 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
3560 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
3561 }
3562
3563 // Instantiate twice to help detect side-effects.
3564 {
3565 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3566 new ctor(props, context); // eslint-disable-line no-new
3567 }
3568 }
3569
3570 var instance = new ctor(props, context);
3571 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
3572 adoptClassInstance(workInProgress, instance);
3573
3574 {
3575 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
3576 var componentName = getComponentName(ctor) || 'Component';
3577 if (!didWarnAboutUninitializedState.has(componentName)) {
3578 didWarnAboutUninitializedState.add(componentName);
3579 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);
3580 }
3581 }
3582
3583 // If new component APIs are defined, "unsafe" lifecycles won't be called.
3584 // Warn about these lifecycles if they are present.
3585 // Don't warn about react-lifecycles-compat polyfilled methods though.
3586 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
3587 var foundWillMountName = null;
3588 var foundWillReceivePropsName = null;
3589 var foundWillUpdateName = null;
3590 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
3591 foundWillMountName = 'componentWillMount';
3592 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
3593 foundWillMountName = 'UNSAFE_componentWillMount';
3594 }
3595 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
3596 foundWillReceivePropsName = 'componentWillReceiveProps';
3597 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3598 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
3599 }
3600 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
3601 foundWillUpdateName = 'componentWillUpdate';
3602 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3603 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
3604 }
3605 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
3606 var _componentName = getComponentName(ctor) || 'Component';
3607 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
3608 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
3609 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
3610 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 : '');
3611 }
3612 }
3613 }
3614 }
3615
3616 // Cache unmasked context so we can avoid recreating masked context unless necessary.
3617 // ReactFiberContext usually updates this cache but can't for newly-created instances.
3618 if (isLegacyContextConsumer) {
3619 cacheContext(workInProgress, unmaskedContext, context);
3620 }
3621
3622 return instance;
3623}
3624
3625function callComponentWillMount(workInProgress, instance) {
3626 startPhaseTimer(workInProgress, 'componentWillMount');
3627 var oldState = instance.state;
3628
3629 if (typeof instance.componentWillMount === 'function') {
3630 instance.componentWillMount();
3631 }
3632 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3633 instance.UNSAFE_componentWillMount();
3634 }
3635
3636 stopPhaseTimer();
3637
3638 if (oldState !== instance.state) {
3639 {
3640 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');
3641 }
3642 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3643 }
3644}
3645
3646function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
3647 var oldState = instance.state;
3648 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
3649 if (typeof instance.componentWillReceiveProps === 'function') {
3650 instance.componentWillReceiveProps(newProps, nextContext);
3651 }
3652 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3653 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
3654 }
3655 stopPhaseTimer();
3656
3657 if (instance.state !== oldState) {
3658 {
3659 var componentName = getComponentName(workInProgress.type) || 'Component';
3660 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
3661 didWarnAboutStateAssignmentForComponent.add(componentName);
3662 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
3663 }
3664 }
3665 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3666 }
3667}
3668
3669// Invokes the mount life-cycles on a previously never rendered instance.
3670function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3671 {
3672 checkClassInstance(workInProgress, ctor, newProps);
3673 }
3674
3675 var instance = workInProgress.stateNode;
3676 instance.props = newProps;
3677 instance.state = workInProgress.memoizedState;
3678 instance.refs = emptyRefsObject;
3679
3680 var contextType = ctor.contextType;
3681 if (typeof contextType === 'object' && contextType !== null) {
3682 instance.context = readContext(contextType);
3683 } else {
3684 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3685 instance.context = getMaskedContext(workInProgress, unmaskedContext);
3686 }
3687
3688 {
3689 if (instance.state === newProps) {
3690 var componentName = getComponentName(ctor) || 'Component';
3691 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
3692 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
3693 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);
3694 }
3695 }
3696
3697 if (workInProgress.mode & StrictMode) {
3698 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
3699
3700 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
3701 }
3702
3703 if (warnAboutDeprecatedLifecycles) {
3704 ReactStrictModeWarnings.recordDeprecationWarnings(workInProgress, instance);
3705 }
3706 }
3707
3708 var updateQueue = workInProgress.updateQueue;
3709 if (updateQueue !== null) {
3710 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3711 instance.state = workInProgress.memoizedState;
3712 }
3713
3714 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3715 if (typeof getDerivedStateFromProps === 'function') {
3716 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3717 instance.state = workInProgress.memoizedState;
3718 }
3719
3720 // In order to support react-lifecycles-compat polyfilled components,
3721 // Unsafe lifecycles should not be invoked for components using the new APIs.
3722 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3723 callComponentWillMount(workInProgress, instance);
3724 // If we had additional state updates during this life-cycle, let's
3725 // process them now.
3726 updateQueue = workInProgress.updateQueue;
3727 if (updateQueue !== null) {
3728 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3729 instance.state = workInProgress.memoizedState;
3730 }
3731 }
3732
3733 if (typeof instance.componentDidMount === 'function') {
3734 workInProgress.effectTag |= Update;
3735 }
3736}
3737
3738function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3739 var instance = workInProgress.stateNode;
3740
3741 var oldProps = workInProgress.memoizedProps;
3742 instance.props = oldProps;
3743
3744 var oldContext = instance.context;
3745 var contextType = ctor.contextType;
3746 var nextContext = void 0;
3747 if (typeof contextType === 'object' && contextType !== null) {
3748 nextContext = readContext(contextType);
3749 } else {
3750 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3751 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
3752 }
3753
3754 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3755 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3756
3757 // Note: During these life-cycles, instance.props/instance.state are what
3758 // ever the previously attempted to render - not the "current". However,
3759 // during componentDidUpdate we pass the "current" props.
3760
3761 // In order to support react-lifecycles-compat polyfilled components,
3762 // Unsafe lifecycles should not be invoked for components using the new APIs.
3763 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3764 if (oldProps !== newProps || oldContext !== nextContext) {
3765 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3766 }
3767 }
3768
3769 resetHasForceUpdateBeforeProcessing();
3770
3771 var oldState = workInProgress.memoizedState;
3772 var newState = instance.state = oldState;
3773 var updateQueue = workInProgress.updateQueue;
3774 if (updateQueue !== null) {
3775 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3776 newState = workInProgress.memoizedState;
3777 }
3778 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3779 // If an update was already in progress, we should schedule an Update
3780 // effect even though we're bailing out, so that cWU/cDU are called.
3781 if (typeof instance.componentDidMount === 'function') {
3782 workInProgress.effectTag |= Update;
3783 }
3784 return false;
3785 }
3786
3787 if (typeof getDerivedStateFromProps === 'function') {
3788 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3789 newState = workInProgress.memoizedState;
3790 }
3791
3792 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3793
3794 if (shouldUpdate) {
3795 // In order to support react-lifecycles-compat polyfilled components,
3796 // Unsafe lifecycles should not be invoked for components using the new APIs.
3797 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3798 startPhaseTimer(workInProgress, 'componentWillMount');
3799 if (typeof instance.componentWillMount === 'function') {
3800 instance.componentWillMount();
3801 }
3802 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3803 instance.UNSAFE_componentWillMount();
3804 }
3805 stopPhaseTimer();
3806 }
3807 if (typeof instance.componentDidMount === 'function') {
3808 workInProgress.effectTag |= Update;
3809 }
3810 } else {
3811 // If an update was already in progress, we should schedule an Update
3812 // effect even though we're bailing out, so that cWU/cDU are called.
3813 if (typeof instance.componentDidMount === 'function') {
3814 workInProgress.effectTag |= Update;
3815 }
3816
3817 // If shouldComponentUpdate returned false, we should still update the
3818 // memoized state to indicate that this work can be reused.
3819 workInProgress.memoizedProps = newProps;
3820 workInProgress.memoizedState = newState;
3821 }
3822
3823 // Update the existing instance's state, props, and context pointers even
3824 // if shouldComponentUpdate returns false.
3825 instance.props = newProps;
3826 instance.state = newState;
3827 instance.context = nextContext;
3828
3829 return shouldUpdate;
3830}
3831
3832// Invokes the update life-cycles and returns false if it shouldn't rerender.
3833function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
3834 var instance = workInProgress.stateNode;
3835
3836 var oldProps = workInProgress.memoizedProps;
3837 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
3838
3839 var oldContext = instance.context;
3840 var contextType = ctor.contextType;
3841 var nextContext = void 0;
3842 if (typeof contextType === 'object' && contextType !== null) {
3843 nextContext = readContext(contextType);
3844 } else {
3845 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3846 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
3847 }
3848
3849 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3850 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3851
3852 // Note: During these life-cycles, instance.props/instance.state are what
3853 // ever the previously attempted to render - not the "current". However,
3854 // during componentDidUpdate we pass the "current" props.
3855
3856 // In order to support react-lifecycles-compat polyfilled components,
3857 // Unsafe lifecycles should not be invoked for components using the new APIs.
3858 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3859 if (oldProps !== newProps || oldContext !== nextContext) {
3860 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3861 }
3862 }
3863
3864 resetHasForceUpdateBeforeProcessing();
3865
3866 var oldState = workInProgress.memoizedState;
3867 var newState = instance.state = oldState;
3868 var updateQueue = workInProgress.updateQueue;
3869 if (updateQueue !== null) {
3870 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3871 newState = workInProgress.memoizedState;
3872 }
3873
3874 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3875 // If an update was already in progress, we should schedule an Update
3876 // effect even though we're bailing out, so that cWU/cDU are called.
3877 if (typeof instance.componentDidUpdate === 'function') {
3878 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3879 workInProgress.effectTag |= Update;
3880 }
3881 }
3882 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3883 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3884 workInProgress.effectTag |= Snapshot;
3885 }
3886 }
3887 return false;
3888 }
3889
3890 if (typeof getDerivedStateFromProps === 'function') {
3891 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3892 newState = workInProgress.memoizedState;
3893 }
3894
3895 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3896
3897 if (shouldUpdate) {
3898 // In order to support react-lifecycles-compat polyfilled components,
3899 // Unsafe lifecycles should not be invoked for components using the new APIs.
3900 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
3901 startPhaseTimer(workInProgress, 'componentWillUpdate');
3902 if (typeof instance.componentWillUpdate === 'function') {
3903 instance.componentWillUpdate(newProps, newState, nextContext);
3904 }
3905 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3906 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
3907 }
3908 stopPhaseTimer();
3909 }
3910 if (typeof instance.componentDidUpdate === 'function') {
3911 workInProgress.effectTag |= Update;
3912 }
3913 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3914 workInProgress.effectTag |= Snapshot;
3915 }
3916 } else {
3917 // If an update was already in progress, we should schedule an Update
3918 // effect even though we're bailing out, so that cWU/cDU are called.
3919 if (typeof instance.componentDidUpdate === 'function') {
3920 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3921 workInProgress.effectTag |= Update;
3922 }
3923 }
3924 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3925 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3926 workInProgress.effectTag |= Snapshot;
3927 }
3928 }
3929
3930 // If shouldComponentUpdate returned false, we should still update the
3931 // memoized props/state to indicate that this work can be reused.
3932 workInProgress.memoizedProps = newProps;
3933 workInProgress.memoizedState = newState;
3934 }
3935
3936 // Update the existing instance's state, props, and context pointers even
3937 // if shouldComponentUpdate returns false.
3938 instance.props = newProps;
3939 instance.state = newState;
3940 instance.context = nextContext;
3941
3942 return shouldUpdate;
3943}
3944
3945var didWarnAboutMaps = void 0;
3946var didWarnAboutGenerators = void 0;
3947var didWarnAboutStringRefInStrictMode = void 0;
3948var ownerHasKeyUseWarning = void 0;
3949var ownerHasFunctionTypeWarning = void 0;
3950var warnForMissingKey = function (child) {};
3951
3952{
3953 didWarnAboutMaps = false;
3954 didWarnAboutGenerators = false;
3955 didWarnAboutStringRefInStrictMode = {};
3956
3957 /**
3958 * Warn if there's no key explicitly set on dynamic arrays of children or
3959 * object keys are not valid. This allows us to keep track of children between
3960 * updates.
3961 */
3962 ownerHasKeyUseWarning = {};
3963 ownerHasFunctionTypeWarning = {};
3964
3965 warnForMissingKey = function (child) {
3966 if (child === null || typeof child !== 'object') {
3967 return;
3968 }
3969 if (!child._store || child._store.validated || child.key != null) {
3970 return;
3971 }
3972 !(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;
3973 child._store.validated = true;
3974
3975 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
3976 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
3977 return;
3978 }
3979 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
3980
3981 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
3982 };
3983}
3984
3985var isArray = Array.isArray;
3986
3987function coerceRef(returnFiber, current$$1, element) {
3988 var mixedRef = element.ref;
3989 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
3990 {
3991 if (returnFiber.mode & StrictMode) {
3992 var componentName = getComponentName(returnFiber.type) || 'Component';
3993 if (!didWarnAboutStringRefInStrictMode[componentName]) {
3994 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));
3995 didWarnAboutStringRefInStrictMode[componentName] = true;
3996 }
3997 }
3998 }
3999
4000 if (element._owner) {
4001 var owner = element._owner;
4002 var inst = void 0;
4003 if (owner) {
4004 var ownerFiber = owner;
4005 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Function components cannot have refs. Did you mean to use React.forwardRef()?') : void 0;
4006 inst = ownerFiber.stateNode;
4007 }
4008 !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;
4009 var stringRef = '' + mixedRef;
4010 // Check if previous string ref matches new string ref
4011 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
4012 return current$$1.ref;
4013 }
4014 var ref = function (value) {
4015 var refs = inst.refs;
4016 if (refs === emptyRefsObject) {
4017 // This is a lazy pooled frozen object, so we need to initialize.
4018 refs = inst.refs = {};
4019 }
4020 if (value === null) {
4021 delete refs[stringRef];
4022 } else {
4023 refs[stringRef] = value;
4024 }
4025 };
4026 ref._stringRef = stringRef;
4027 return ref;
4028 } else {
4029 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.') : void 0;
4030 !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;
4031 }
4032 }
4033 return mixedRef;
4034}
4035
4036function throwOnInvalidObjectType(returnFiber, newChild) {
4037 if (returnFiber.type !== 'textarea') {
4038 var addendum = '';
4039 {
4040 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
4041 }
4042 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);
4043 }
4044}
4045
4046function warnOnFunctionType() {
4047 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();
4048
4049 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
4050 return;
4051 }
4052 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
4053
4054 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.');
4055}
4056
4057// This wrapper function exists because I expect to clone the code in each path
4058// to be able to optimize each path individually by branching early. This needs
4059// a compiler or we can do it manually. Helpers that don't need this branching
4060// live outside of this function.
4061function ChildReconciler(shouldTrackSideEffects) {
4062 function deleteChild(returnFiber, childToDelete) {
4063 if (!shouldTrackSideEffects) {
4064 // Noop.
4065 return;
4066 }
4067 // Deletions are added in reversed order so we add it to the front.
4068 // At this point, the return fiber's effect list is empty except for
4069 // deletions, so we can just append the deletion to the list. The remaining
4070 // effects aren't added until the complete phase. Once we implement
4071 // resuming, this may not be true.
4072 var last = returnFiber.lastEffect;
4073 if (last !== null) {
4074 last.nextEffect = childToDelete;
4075 returnFiber.lastEffect = childToDelete;
4076 } else {
4077 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
4078 }
4079 childToDelete.nextEffect = null;
4080 childToDelete.effectTag = Deletion;
4081 }
4082
4083 function deleteRemainingChildren(returnFiber, currentFirstChild) {
4084 if (!shouldTrackSideEffects) {
4085 // Noop.
4086 return null;
4087 }
4088
4089 // TODO: For the shouldClone case, this could be micro-optimized a bit by
4090 // assuming that after the first child we've already added everything.
4091 var childToDelete = currentFirstChild;
4092 while (childToDelete !== null) {
4093 deleteChild(returnFiber, childToDelete);
4094 childToDelete = childToDelete.sibling;
4095 }
4096 return null;
4097 }
4098
4099 function mapRemainingChildren(returnFiber, currentFirstChild) {
4100 // Add the remaining children to a temporary map so that we can find them by
4101 // keys quickly. Implicit (null) keys get added to this set with their index
4102 var existingChildren = new Map();
4103
4104 var existingChild = currentFirstChild;
4105 while (existingChild !== null) {
4106 if (existingChild.key !== null) {
4107 existingChildren.set(existingChild.key, existingChild);
4108 } else {
4109 existingChildren.set(existingChild.index, existingChild);
4110 }
4111 existingChild = existingChild.sibling;
4112 }
4113 return existingChildren;
4114 }
4115
4116 function useFiber(fiber, pendingProps, expirationTime) {
4117 // We currently set sibling to null and index to 0 here because it is easy
4118 // to forget to do before returning it. E.g. for the single child case.
4119 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4120 clone.index = 0;
4121 clone.sibling = null;
4122 return clone;
4123 }
4124
4125 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4126 newFiber.index = newIndex;
4127 if (!shouldTrackSideEffects) {
4128 // Noop.
4129 return lastPlacedIndex;
4130 }
4131 var current$$1 = newFiber.alternate;
4132 if (current$$1 !== null) {
4133 var oldIndex = current$$1.index;
4134 if (oldIndex < lastPlacedIndex) {
4135 // This is a move.
4136 newFiber.effectTag = Placement;
4137 return lastPlacedIndex;
4138 } else {
4139 // This item can stay in place.
4140 return oldIndex;
4141 }
4142 } else {
4143 // This is an insertion.
4144 newFiber.effectTag = Placement;
4145 return lastPlacedIndex;
4146 }
4147 }
4148
4149 function placeSingleChild(newFiber) {
4150 // This is simpler for the single child case. We only need to do a
4151 // placement for inserting new children.
4152 if (shouldTrackSideEffects && newFiber.alternate === null) {
4153 newFiber.effectTag = Placement;
4154 }
4155 return newFiber;
4156 }
4157
4158 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4159 if (current$$1 === null || current$$1.tag !== HostText) {
4160 // Insert
4161 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4162 created.return = returnFiber;
4163 return created;
4164 } else {
4165 // Update
4166 var existing = useFiber(current$$1, textContent, expirationTime);
4167 existing.return = returnFiber;
4168 return existing;
4169 }
4170 }
4171
4172 function updateElement(returnFiber, current$$1, element, expirationTime) {
4173 if (current$$1 !== null && current$$1.elementType === element.type) {
4174 // Move based on index
4175 var existing = useFiber(current$$1, element.props, expirationTime);
4176 existing.ref = coerceRef(returnFiber, current$$1, element);
4177 existing.return = returnFiber;
4178 {
4179 existing._debugSource = element._source;
4180 existing._debugOwner = element._owner;
4181 }
4182 return existing;
4183 } else {
4184 // Insert
4185 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
4186 created.ref = coerceRef(returnFiber, current$$1, element);
4187 created.return = returnFiber;
4188 return created;
4189 }
4190 }
4191
4192 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
4193 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
4194 // Insert
4195 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4196 created.return = returnFiber;
4197 return created;
4198 } else {
4199 // Update
4200 var existing = useFiber(current$$1, portal.children || [], expirationTime);
4201 existing.return = returnFiber;
4202 return existing;
4203 }
4204 }
4205
4206 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
4207 if (current$$1 === null || current$$1.tag !== Fragment) {
4208 // Insert
4209 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
4210 created.return = returnFiber;
4211 return created;
4212 } else {
4213 // Update
4214 var existing = useFiber(current$$1, fragment, expirationTime);
4215 existing.return = returnFiber;
4216 return existing;
4217 }
4218 }
4219
4220 function createChild(returnFiber, newChild, expirationTime) {
4221 if (typeof newChild === 'string' || typeof newChild === 'number') {
4222 // Text nodes don't have keys. If the previous node is implicitly keyed
4223 // we can continue to replace it without aborting even if it is not a text
4224 // node.
4225 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
4226 created.return = returnFiber;
4227 return created;
4228 }
4229
4230 if (typeof newChild === 'object' && newChild !== null) {
4231 switch (newChild.$$typeof) {
4232 case REACT_ELEMENT_TYPE:
4233 {
4234 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
4235 _created.ref = coerceRef(returnFiber, null, newChild);
4236 _created.return = returnFiber;
4237 return _created;
4238 }
4239 case REACT_PORTAL_TYPE:
4240 {
4241 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
4242 _created2.return = returnFiber;
4243 return _created2;
4244 }
4245 }
4246
4247 if (isArray(newChild) || getIteratorFn(newChild)) {
4248 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
4249 _created3.return = returnFiber;
4250 return _created3;
4251 }
4252
4253 throwOnInvalidObjectType(returnFiber, newChild);
4254 }
4255
4256 {
4257 if (typeof newChild === 'function') {
4258 warnOnFunctionType();
4259 }
4260 }
4261
4262 return null;
4263 }
4264
4265 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
4266 // Update the fiber if the keys match, otherwise return null.
4267
4268 var key = oldFiber !== null ? oldFiber.key : null;
4269
4270 if (typeof newChild === 'string' || typeof newChild === 'number') {
4271 // Text nodes don't have keys. If the previous node is implicitly keyed
4272 // we can continue to replace it without aborting even if it is not a text
4273 // node.
4274 if (key !== null) {
4275 return null;
4276 }
4277 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
4278 }
4279
4280 if (typeof newChild === 'object' && newChild !== null) {
4281 switch (newChild.$$typeof) {
4282 case REACT_ELEMENT_TYPE:
4283 {
4284 if (newChild.key === key) {
4285 if (newChild.type === REACT_FRAGMENT_TYPE) {
4286 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
4287 }
4288 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
4289 } else {
4290 return null;
4291 }
4292 }
4293 case REACT_PORTAL_TYPE:
4294 {
4295 if (newChild.key === key) {
4296 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
4297 } else {
4298 return null;
4299 }
4300 }
4301 }
4302
4303 if (isArray(newChild) || getIteratorFn(newChild)) {
4304 if (key !== null) {
4305 return null;
4306 }
4307
4308 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
4309 }
4310
4311 throwOnInvalidObjectType(returnFiber, newChild);
4312 }
4313
4314 {
4315 if (typeof newChild === 'function') {
4316 warnOnFunctionType();
4317 }
4318 }
4319
4320 return null;
4321 }
4322
4323 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
4324 if (typeof newChild === 'string' || typeof newChild === 'number') {
4325 // Text nodes don't have keys, so we neither have to check the old nor
4326 // new node for the key. If both are text nodes, they match.
4327 var matchedFiber = existingChildren.get(newIdx) || null;
4328 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
4329 }
4330
4331 if (typeof newChild === 'object' && newChild !== null) {
4332 switch (newChild.$$typeof) {
4333 case REACT_ELEMENT_TYPE:
4334 {
4335 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4336 if (newChild.type === REACT_FRAGMENT_TYPE) {
4337 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
4338 }
4339 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
4340 }
4341 case REACT_PORTAL_TYPE:
4342 {
4343 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4344 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
4345 }
4346 }
4347
4348 if (isArray(newChild) || getIteratorFn(newChild)) {
4349 var _matchedFiber3 = existingChildren.get(newIdx) || null;
4350 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
4351 }
4352
4353 throwOnInvalidObjectType(returnFiber, newChild);
4354 }
4355
4356 {
4357 if (typeof newChild === 'function') {
4358 warnOnFunctionType();
4359 }
4360 }
4361
4362 return null;
4363 }
4364
4365 /**
4366 * Warns if there is a duplicate or missing key
4367 */
4368 function warnOnInvalidKey(child, knownKeys) {
4369 {
4370 if (typeof child !== 'object' || child === null) {
4371 return knownKeys;
4372 }
4373 switch (child.$$typeof) {
4374 case REACT_ELEMENT_TYPE:
4375 case REACT_PORTAL_TYPE:
4376 warnForMissingKey(child);
4377 var key = child.key;
4378 if (typeof key !== 'string') {
4379 break;
4380 }
4381 if (knownKeys === null) {
4382 knownKeys = new Set();
4383 knownKeys.add(key);
4384 break;
4385 }
4386 if (!knownKeys.has(key)) {
4387 knownKeys.add(key);
4388 break;
4389 }
4390 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);
4391 break;
4392 default:
4393 break;
4394 }
4395 }
4396 return knownKeys;
4397 }
4398
4399 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
4400 // This algorithm can't optimize by searching from both ends since we
4401 // don't have backpointers on fibers. I'm trying to see how far we can get
4402 // with that model. If it ends up not being worth the tradeoffs, we can
4403 // add it later.
4404
4405 // Even with a two ended optimization, we'd want to optimize for the case
4406 // where there are few changes and brute force the comparison instead of
4407 // going for the Map. It'd like to explore hitting that path first in
4408 // forward-only mode and only go for the Map once we notice that we need
4409 // lots of look ahead. This doesn't handle reversal as well as two ended
4410 // search but that's unusual. Besides, for the two ended optimization to
4411 // work on Iterables, we'd need to copy the whole set.
4412
4413 // In this first iteration, we'll just live with hitting the bad case
4414 // (adding everything to a Map) in for every insert/move.
4415
4416 // If you change this code, also update reconcileChildrenIterator() which
4417 // uses the same algorithm.
4418
4419 {
4420 // First, validate keys.
4421 var knownKeys = null;
4422 for (var i = 0; i < newChildren.length; i++) {
4423 var child = newChildren[i];
4424 knownKeys = warnOnInvalidKey(child, knownKeys);
4425 }
4426 }
4427
4428 var resultingFirstChild = null;
4429 var previousNewFiber = null;
4430
4431 var oldFiber = currentFirstChild;
4432 var lastPlacedIndex = 0;
4433 var newIdx = 0;
4434 var nextOldFiber = null;
4435 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
4436 if (oldFiber.index > newIdx) {
4437 nextOldFiber = oldFiber;
4438 oldFiber = null;
4439 } else {
4440 nextOldFiber = oldFiber.sibling;
4441 }
4442 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
4443 if (newFiber === null) {
4444 // TODO: This breaks on empty slots like null children. That's
4445 // unfortunate because it triggers the slow path all the time. We need
4446 // a better way to communicate whether this was a miss or null,
4447 // boolean, undefined, etc.
4448 if (oldFiber === null) {
4449 oldFiber = nextOldFiber;
4450 }
4451 break;
4452 }
4453 if (shouldTrackSideEffects) {
4454 if (oldFiber && newFiber.alternate === null) {
4455 // We matched the slot, but we didn't reuse the existing fiber, so we
4456 // need to delete the existing child.
4457 deleteChild(returnFiber, oldFiber);
4458 }
4459 }
4460 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4461 if (previousNewFiber === null) {
4462 // TODO: Move out of the loop. This only happens for the first run.
4463 resultingFirstChild = newFiber;
4464 } else {
4465 // TODO: Defer siblings if we're not at the right index for this slot.
4466 // I.e. if we had null values before, then we want to defer this
4467 // for each null value. However, we also don't want to call updateSlot
4468 // with the previous one.
4469 previousNewFiber.sibling = newFiber;
4470 }
4471 previousNewFiber = newFiber;
4472 oldFiber = nextOldFiber;
4473 }
4474
4475 if (newIdx === newChildren.length) {
4476 // We've reached the end of the new children. We can delete the rest.
4477 deleteRemainingChildren(returnFiber, oldFiber);
4478 return resultingFirstChild;
4479 }
4480
4481 if (oldFiber === null) {
4482 // If we don't have any more existing children we can choose a fast path
4483 // since the rest will all be insertions.
4484 for (; newIdx < newChildren.length; newIdx++) {
4485 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
4486 if (!_newFiber) {
4487 continue;
4488 }
4489 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
4490 if (previousNewFiber === null) {
4491 // TODO: Move out of the loop. This only happens for the first run.
4492 resultingFirstChild = _newFiber;
4493 } else {
4494 previousNewFiber.sibling = _newFiber;
4495 }
4496 previousNewFiber = _newFiber;
4497 }
4498 return resultingFirstChild;
4499 }
4500
4501 // Add all children to a key map for quick lookups.
4502 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4503
4504 // Keep scanning and use the map to restore deleted items as moves.
4505 for (; newIdx < newChildren.length; newIdx++) {
4506 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
4507 if (_newFiber2) {
4508 if (shouldTrackSideEffects) {
4509 if (_newFiber2.alternate !== null) {
4510 // The new fiber is a work in progress, but if there exists a
4511 // current, that means that we reused the fiber. We need to delete
4512 // it from the child list so that we don't add it to the deletion
4513 // list.
4514 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
4515 }
4516 }
4517 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
4518 if (previousNewFiber === null) {
4519 resultingFirstChild = _newFiber2;
4520 } else {
4521 previousNewFiber.sibling = _newFiber2;
4522 }
4523 previousNewFiber = _newFiber2;
4524 }
4525 }
4526
4527 if (shouldTrackSideEffects) {
4528 // Any existing children that weren't consumed above were deleted. We need
4529 // to add them to the deletion list.
4530 existingChildren.forEach(function (child) {
4531 return deleteChild(returnFiber, child);
4532 });
4533 }
4534
4535 return resultingFirstChild;
4536 }
4537
4538 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
4539 // This is the same implementation as reconcileChildrenArray(),
4540 // but using the iterator instead.
4541
4542 var iteratorFn = getIteratorFn(newChildrenIterable);
4543 !(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;
4544
4545 {
4546 // We don't support rendering Generators because it's a mutation.
4547 // See https://github.com/facebook/react/issues/12995
4548 if (typeof Symbol === 'function' &&
4549 // $FlowFixMe Flow doesn't know about toStringTag
4550 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
4551 !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;
4552 didWarnAboutGenerators = true;
4553 }
4554
4555 // Warn about using Maps as children
4556 if (newChildrenIterable.entries === iteratorFn) {
4557 !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;
4558 didWarnAboutMaps = true;
4559 }
4560
4561 // First, validate keys.
4562 // We'll get a different iterator later for the main pass.
4563 var _newChildren = iteratorFn.call(newChildrenIterable);
4564 if (_newChildren) {
4565 var knownKeys = null;
4566 var _step = _newChildren.next();
4567 for (; !_step.done; _step = _newChildren.next()) {
4568 var child = _step.value;
4569 knownKeys = warnOnInvalidKey(child, knownKeys);
4570 }
4571 }
4572 }
4573
4574 var newChildren = iteratorFn.call(newChildrenIterable);
4575 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
4576
4577 var resultingFirstChild = null;
4578 var previousNewFiber = null;
4579
4580 var oldFiber = currentFirstChild;
4581 var lastPlacedIndex = 0;
4582 var newIdx = 0;
4583 var nextOldFiber = null;
4584
4585 var step = newChildren.next();
4586 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
4587 if (oldFiber.index > newIdx) {
4588 nextOldFiber = oldFiber;
4589 oldFiber = null;
4590 } else {
4591 nextOldFiber = oldFiber.sibling;
4592 }
4593 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
4594 if (newFiber === null) {
4595 // TODO: This breaks on empty slots like null children. That's
4596 // unfortunate because it triggers the slow path all the time. We need
4597 // a better way to communicate whether this was a miss or null,
4598 // boolean, undefined, etc.
4599 if (!oldFiber) {
4600 oldFiber = nextOldFiber;
4601 }
4602 break;
4603 }
4604 if (shouldTrackSideEffects) {
4605 if (oldFiber && newFiber.alternate === null) {
4606 // We matched the slot, but we didn't reuse the existing fiber, so we
4607 // need to delete the existing child.
4608 deleteChild(returnFiber, oldFiber);
4609 }
4610 }
4611 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4612 if (previousNewFiber === null) {
4613 // TODO: Move out of the loop. This only happens for the first run.
4614 resultingFirstChild = newFiber;
4615 } else {
4616 // TODO: Defer siblings if we're not at the right index for this slot.
4617 // I.e. if we had null values before, then we want to defer this
4618 // for each null value. However, we also don't want to call updateSlot
4619 // with the previous one.
4620 previousNewFiber.sibling = newFiber;
4621 }
4622 previousNewFiber = newFiber;
4623 oldFiber = nextOldFiber;
4624 }
4625
4626 if (step.done) {
4627 // We've reached the end of the new children. We can delete the rest.
4628 deleteRemainingChildren(returnFiber, oldFiber);
4629 return resultingFirstChild;
4630 }
4631
4632 if (oldFiber === null) {
4633 // If we don't have any more existing children we can choose a fast path
4634 // since the rest will all be insertions.
4635 for (; !step.done; newIdx++, step = newChildren.next()) {
4636 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
4637 if (_newFiber3 === null) {
4638 continue;
4639 }
4640 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
4641 if (previousNewFiber === null) {
4642 // TODO: Move out of the loop. This only happens for the first run.
4643 resultingFirstChild = _newFiber3;
4644 } else {
4645 previousNewFiber.sibling = _newFiber3;
4646 }
4647 previousNewFiber = _newFiber3;
4648 }
4649 return resultingFirstChild;
4650 }
4651
4652 // Add all children to a key map for quick lookups.
4653 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4654
4655 // Keep scanning and use the map to restore deleted items as moves.
4656 for (; !step.done; newIdx++, step = newChildren.next()) {
4657 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
4658 if (_newFiber4 !== null) {
4659 if (shouldTrackSideEffects) {
4660 if (_newFiber4.alternate !== null) {
4661 // The new fiber is a work in progress, but if there exists a
4662 // current, that means that we reused the fiber. We need to delete
4663 // it from the child list so that we don't add it to the deletion
4664 // list.
4665 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
4666 }
4667 }
4668 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
4669 if (previousNewFiber === null) {
4670 resultingFirstChild = _newFiber4;
4671 } else {
4672 previousNewFiber.sibling = _newFiber4;
4673 }
4674 previousNewFiber = _newFiber4;
4675 }
4676 }
4677
4678 if (shouldTrackSideEffects) {
4679 // Any existing children that weren't consumed above were deleted. We need
4680 // to add them to the deletion list.
4681 existingChildren.forEach(function (child) {
4682 return deleteChild(returnFiber, child);
4683 });
4684 }
4685
4686 return resultingFirstChild;
4687 }
4688
4689 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
4690 // There's no need to check for keys on text nodes since we don't have a
4691 // way to define them.
4692 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
4693 // We already have an existing node so let's just update it and delete
4694 // the rest.
4695 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
4696 var existing = useFiber(currentFirstChild, textContent, expirationTime);
4697 existing.return = returnFiber;
4698 return existing;
4699 }
4700 // The existing first child is not a text node so we need to create one
4701 // and delete the existing ones.
4702 deleteRemainingChildren(returnFiber, currentFirstChild);
4703 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4704 created.return = returnFiber;
4705 return created;
4706 }
4707
4708 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
4709 var key = element.key;
4710 var child = currentFirstChild;
4711 while (child !== null) {
4712 // TODO: If key === null and child.key === null, then this only applies to
4713 // the first item in the list.
4714 if (child.key === key) {
4715 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type) {
4716 deleteRemainingChildren(returnFiber, child.sibling);
4717 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
4718 existing.ref = coerceRef(returnFiber, child, element);
4719 existing.return = returnFiber;
4720 {
4721 existing._debugSource = element._source;
4722 existing._debugOwner = element._owner;
4723 }
4724 return existing;
4725 } else {
4726 deleteRemainingChildren(returnFiber, child);
4727 break;
4728 }
4729 } else {
4730 deleteChild(returnFiber, child);
4731 }
4732 child = child.sibling;
4733 }
4734
4735 if (element.type === REACT_FRAGMENT_TYPE) {
4736 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
4737 created.return = returnFiber;
4738 return created;
4739 } else {
4740 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
4741 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
4742 _created4.return = returnFiber;
4743 return _created4;
4744 }
4745 }
4746
4747 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
4748 var key = portal.key;
4749 var child = currentFirstChild;
4750 while (child !== null) {
4751 // TODO: If key === null and child.key === null, then this only applies to
4752 // the first item in the list.
4753 if (child.key === key) {
4754 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
4755 deleteRemainingChildren(returnFiber, child.sibling);
4756 var existing = useFiber(child, portal.children || [], expirationTime);
4757 existing.return = returnFiber;
4758 return existing;
4759 } else {
4760 deleteRemainingChildren(returnFiber, child);
4761 break;
4762 }
4763 } else {
4764 deleteChild(returnFiber, child);
4765 }
4766 child = child.sibling;
4767 }
4768
4769 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4770 created.return = returnFiber;
4771 return created;
4772 }
4773
4774 // This API will tag the children with the side-effect of the reconciliation
4775 // itself. They will be added to the side-effect list as we pass through the
4776 // children and the parent.
4777 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
4778 // This function is not recursive.
4779 // If the top level item is an array, we treat it as a set of children,
4780 // not as a fragment. Nested arrays on the other hand will be treated as
4781 // fragment nodes. Recursion happens at the normal flow.
4782
4783 // Handle top level unkeyed fragments as if they were arrays.
4784 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
4785 // We treat the ambiguous cases above the same.
4786 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
4787 if (isUnkeyedTopLevelFragment) {
4788 newChild = newChild.props.children;
4789 }
4790
4791 // Handle object types
4792 var isObject = typeof newChild === 'object' && newChild !== null;
4793
4794 if (isObject) {
4795 switch (newChild.$$typeof) {
4796 case REACT_ELEMENT_TYPE:
4797 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
4798 case REACT_PORTAL_TYPE:
4799 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
4800 }
4801 }
4802
4803 if (typeof newChild === 'string' || typeof newChild === 'number') {
4804 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
4805 }
4806
4807 if (isArray(newChild)) {
4808 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
4809 }
4810
4811 if (getIteratorFn(newChild)) {
4812 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
4813 }
4814
4815 if (isObject) {
4816 throwOnInvalidObjectType(returnFiber, newChild);
4817 }
4818
4819 {
4820 if (typeof newChild === 'function') {
4821 warnOnFunctionType();
4822 }
4823 }
4824 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
4825 // If the new child is undefined, and the return fiber is a composite
4826 // component, throw an error. If Fiber return types are disabled,
4827 // we already threw above.
4828 switch (returnFiber.tag) {
4829 case ClassComponent:
4830 {
4831 {
4832 var instance = returnFiber.stateNode;
4833 if (instance.render._isMockFunction) {
4834 // We allow auto-mocks to proceed as if they're returning null.
4835 break;
4836 }
4837 }
4838 }
4839 // Intentionally fall through to the next case, which handles both
4840 // functions and classes
4841 // eslint-disable-next-lined no-fallthrough
4842 case FunctionComponent:
4843 {
4844 var Component = returnFiber.type;
4845 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');
4846 }
4847 }
4848 }
4849
4850 // Remaining cases are all treated as empty.
4851 return deleteRemainingChildren(returnFiber, currentFirstChild);
4852 }
4853
4854 return reconcileChildFibers;
4855}
4856
4857var reconcileChildFibers = ChildReconciler(true);
4858var mountChildFibers = ChildReconciler(false);
4859
4860function cloneChildFibers(current$$1, workInProgress) {
4861 !(current$$1 === null || workInProgress.child === current$$1.child) ? invariant(false, 'Resuming work not yet implemented.') : void 0;
4862
4863 if (workInProgress.child === null) {
4864 return;
4865 }
4866
4867 var currentChild = workInProgress.child;
4868 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4869 workInProgress.child = newChild;
4870
4871 newChild.return = workInProgress;
4872 while (currentChild.sibling !== null) {
4873 currentChild = currentChild.sibling;
4874 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4875 newChild.return = workInProgress;
4876 }
4877 newChild.sibling = null;
4878}
4879
4880var NO_CONTEXT$1 = {};
4881
4882var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
4883var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
4884var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
4885
4886function requiredContext(c) {
4887 !(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;
4888 return c;
4889}
4890
4891function getRootHostContainer() {
4892 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4893 return rootInstance;
4894}
4895
4896function pushHostContainer(fiber, nextRootInstance) {
4897 // Push current root instance onto the stack;
4898 // This allows us to reset root when portals are popped.
4899 push(rootInstanceStackCursor, nextRootInstance, fiber);
4900 // Track the context and the Fiber that provided it.
4901 // This enables us to pop only Fibers that provide unique contexts.
4902 push(contextFiberStackCursor, fiber, fiber);
4903
4904 // Finally, we need to push the host context to the stack.
4905 // However, we can't just call getRootHostContext() and push it because
4906 // we'd have a different number of entries on the stack depending on
4907 // whether getRootHostContext() throws somewhere in renderer code or not.
4908 // So we push an empty value first. This lets us safely unwind on errors.
4909 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
4910 var nextRootContext = getRootHostContext(nextRootInstance);
4911 // Now that we know this function doesn't throw, replace it.
4912 pop(contextStackCursor$1, fiber);
4913 push(contextStackCursor$1, nextRootContext, fiber);
4914}
4915
4916function popHostContainer(fiber) {
4917 pop(contextStackCursor$1, fiber);
4918 pop(contextFiberStackCursor, fiber);
4919 pop(rootInstanceStackCursor, fiber);
4920}
4921
4922function getHostContext() {
4923 var context = requiredContext(contextStackCursor$1.current);
4924 return context;
4925}
4926
4927function pushHostContext(fiber) {
4928 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4929 var context = requiredContext(contextStackCursor$1.current);
4930 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
4931
4932 // Don't push this Fiber's context unless it's unique.
4933 if (context === nextContext) {
4934 return;
4935 }
4936
4937 // Track the context and the Fiber that provided it.
4938 // This enables us to pop only Fibers that provide unique contexts.
4939 push(contextFiberStackCursor, fiber, fiber);
4940 push(contextStackCursor$1, nextContext, fiber);
4941}
4942
4943function popHostContext(fiber) {
4944 // Do not pop unless this Fiber provided the current context.
4945 // pushHostContext() only pushes Fibers that provide unique contexts.
4946 if (contextFiberStackCursor.current !== fiber) {
4947 return;
4948 }
4949
4950 pop(contextStackCursor$1, fiber);
4951 pop(contextFiberStackCursor, fiber);
4952}
4953
4954var NoEffect$1 = /* */0;
4955var UnmountSnapshot = /* */2;
4956var UnmountMutation = /* */4;
4957var MountMutation = /* */8;
4958var UnmountLayout = /* */16;
4959var MountLayout = /* */32;
4960var MountPassive = /* */64;
4961var UnmountPassive = /* */128;
4962
4963var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
4964
4965
4966var didWarnAboutMismatchedHooksForComponent = void 0;
4967{
4968 didWarnAboutMismatchedHooksForComponent = new Set();
4969}
4970
4971// These are set right before calling the component.
4972var renderExpirationTime = NoWork;
4973// The work-in-progress fiber. I've named it differently to distinguish it from
4974// the work-in-progress hook.
4975var currentlyRenderingFiber$1 = null;
4976
4977// Hooks are stored as a linked list on the fiber's memoizedState field. The
4978// current hook list is the list that belongs to the current fiber. The
4979// work-in-progress hook list is a new list that will be added to the
4980// work-in-progress fiber.
4981var firstCurrentHook = null;
4982var currentHook = null;
4983var nextCurrentHook = null;
4984var firstWorkInProgressHook = null;
4985var workInProgressHook = null;
4986var nextWorkInProgressHook = null;
4987
4988var remainingExpirationTime = NoWork;
4989var componentUpdateQueue = null;
4990var sideEffectTag = 0;
4991
4992// Updates scheduled during render will trigger an immediate re-render at the
4993// end of the current pass. We can't store these updates on the normal queue,
4994// because if the work is aborted, they should be discarded. Because this is
4995// a relatively rare case, we also don't want to add an additional field to
4996// either the hook or queue object types. So we store them in a lazily create
4997// map of queue -> render-phase updates, which are discarded once the component
4998// completes without re-rendering.
4999
5000// Whether an update was scheduled during the currently executing render pass.
5001var didScheduleRenderPhaseUpdate = false;
5002// Lazily created map of render-phase updates
5003var renderPhaseUpdates = null;
5004// Counter to prevent infinite loops.
5005var numberOfReRenders = 0;
5006var RE_RENDER_LIMIT = 25;
5007
5008// In DEV, this is the name of the currently executing primitive hook
5009var currentHookNameInDev = null;
5010
5011function warnOnHookMismatchInDev() {
5012 {
5013 var componentName = getComponentName(currentlyRenderingFiber$1.type);
5014 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
5015 didWarnAboutMismatchedHooksForComponent.add(componentName);
5016
5017 var secondColumnStart = 22;
5018
5019 var table = '';
5020 var prevHook = firstCurrentHook;
5021 var nextHook = firstWorkInProgressHook;
5022 var n = 1;
5023 while (prevHook !== null && nextHook !== null) {
5024 var oldHookName = prevHook._debugType;
5025 var newHookName = nextHook._debugType;
5026
5027 var row = n + '. ' + oldHookName;
5028
5029 // Extra space so second column lines up
5030 // lol @ IE not supporting String#repeat
5031 while (row.length < secondColumnStart) {
5032 row += ' ';
5033 }
5034
5035 row += newHookName + '\n';
5036
5037 table += row;
5038 prevHook = prevHook.next;
5039 nextHook = nextHook.next;
5040 n++;
5041 }
5042
5043 warning$1(false, 'React has detected a change in the order of Hooks called by %s. ' + 'This will lead to bugs and errors if not fixed. ' + 'For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n' + ' Previous render Next render\n' + ' -------------------------------\n' + '%s' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', componentName, table);
5044 }
5045 }
5046}
5047
5048function throwInvalidHookError() {
5049 invariant(false, 'Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)');
5050}
5051
5052function areHookInputsEqual(nextDeps, prevDeps) {
5053 if (prevDeps === null) {
5054 {
5055 warning$1(false, '%s received a final argument during this render, but not during ' + 'the previous render. Even though the final argument is optional, ' + 'its type cannot change between renders.', currentHookNameInDev);
5056 }
5057 return false;
5058 }
5059
5060 {
5061 // Don't bother comparing lengths in prod because these arrays should be
5062 // passed inline.
5063 if (nextDeps.length !== prevDeps.length) {
5064 warning$1(false, 'The final argument passed to %s changed size between renders. The ' + 'order and size of this array must remain constant.\n\n' + 'Previous: %s\n' + 'Incoming: %s', currentHookNameInDev, '[' + nextDeps.join(', ') + ']', '[' + prevDeps.join(', ') + ']');
5065 }
5066 }
5067 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
5068 if (is(nextDeps[i], prevDeps[i])) {
5069 continue;
5070 }
5071 return false;
5072 }
5073 return true;
5074}
5075
5076function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
5077 renderExpirationTime = nextRenderExpirationTime;
5078 currentlyRenderingFiber$1 = workInProgress;
5079 firstCurrentHook = nextCurrentHook = current !== null ? current.memoizedState : null;
5080
5081 // The following should have already been reset
5082 // currentHook = null;
5083 // workInProgressHook = null;
5084
5085 // remainingExpirationTime = NoWork;
5086 // componentUpdateQueue = null;
5087
5088 // didScheduleRenderPhaseUpdate = false;
5089 // renderPhaseUpdates = null;
5090 // numberOfReRenders = 0;
5091 // sideEffectTag = 0;
5092
5093 {
5094 ReactCurrentDispatcher$1.current = nextCurrentHook === null ? HooksDispatcherOnMountInDEV : HooksDispatcherOnUpdateInDEV;
5095 }
5096
5097 var children = Component(props, refOrContext);
5098
5099 if (didScheduleRenderPhaseUpdate) {
5100 do {
5101 didScheduleRenderPhaseUpdate = false;
5102 numberOfReRenders += 1;
5103
5104 // Start over from the beginning of the list
5105 firstCurrentHook = nextCurrentHook = current !== null ? current.memoizedState : null;
5106 nextWorkInProgressHook = firstWorkInProgressHook;
5107
5108 currentHook = null;
5109 workInProgressHook = null;
5110 componentUpdateQueue = null;
5111
5112 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
5113
5114 children = Component(props, refOrContext);
5115 } while (didScheduleRenderPhaseUpdate);
5116
5117 renderPhaseUpdates = null;
5118 numberOfReRenders = 0;
5119 }
5120
5121 {
5122 currentHookNameInDev = null;
5123 }
5124
5125 // We can assume the previous dispatcher is always this one, since we set it
5126 // at the beginning of the render phase and there's no re-entrancy.
5127 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5128
5129 var renderedWork = currentlyRenderingFiber$1;
5130
5131 renderedWork.memoizedState = firstWorkInProgressHook;
5132 renderedWork.expirationTime = remainingExpirationTime;
5133 renderedWork.updateQueue = componentUpdateQueue;
5134 renderedWork.effectTag |= sideEffectTag;
5135
5136 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
5137
5138 renderExpirationTime = NoWork;
5139 currentlyRenderingFiber$1 = null;
5140
5141 firstCurrentHook = null;
5142 currentHook = null;
5143 nextCurrentHook = null;
5144 firstWorkInProgressHook = null;
5145 workInProgressHook = null;
5146 nextWorkInProgressHook = null;
5147
5148 remainingExpirationTime = NoWork;
5149 componentUpdateQueue = null;
5150 sideEffectTag = 0;
5151
5152 // These were reset above
5153 // didScheduleRenderPhaseUpdate = false;
5154 // renderPhaseUpdates = null;
5155 // numberOfReRenders = 0;
5156
5157 !!didRenderTooFewHooks ? invariant(false, 'Rendered fewer hooks than expected. This may be caused by an accidental early return statement.') : void 0;
5158
5159 return children;
5160}
5161
5162function bailoutHooks(current, workInProgress, expirationTime) {
5163 workInProgress.updateQueue = current.updateQueue;
5164 workInProgress.effectTag &= ~(Passive | Update);
5165 if (current.expirationTime <= expirationTime) {
5166 current.expirationTime = NoWork;
5167 }
5168}
5169
5170function resetHooks() {
5171 // We can assume the previous dispatcher is always this one, since we set it
5172 // at the beginning of the render phase and there's no re-entrancy.
5173 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5174
5175 // This is used to reset the state of this module when a component throws.
5176 // It's also called inside mountIndeterminateComponent if we determine the
5177 // component is a module-style component.
5178 renderExpirationTime = NoWork;
5179 currentlyRenderingFiber$1 = null;
5180
5181 firstCurrentHook = null;
5182 currentHook = null;
5183 nextCurrentHook = null;
5184 firstWorkInProgressHook = null;
5185 workInProgressHook = null;
5186 nextWorkInProgressHook = null;
5187
5188 remainingExpirationTime = NoWork;
5189 componentUpdateQueue = null;
5190 sideEffectTag = 0;
5191
5192 {
5193 currentHookNameInDev = null;
5194 }
5195
5196 didScheduleRenderPhaseUpdate = false;
5197 renderPhaseUpdates = null;
5198 numberOfReRenders = 0;
5199}
5200
5201function mountWorkInProgressHook() {
5202 var hook = {
5203 memoizedState: null,
5204
5205 baseState: null,
5206 queue: null,
5207 baseUpdate: null,
5208
5209 next: null
5210 };
5211
5212 {
5213 hook._debugType = currentHookNameInDev;
5214 }
5215 if (workInProgressHook === null) {
5216 // This is the first hook in the list
5217 firstWorkInProgressHook = workInProgressHook = hook;
5218 } else {
5219 // Append to the end of the list
5220 workInProgressHook = workInProgressHook.next = hook;
5221 }
5222 return workInProgressHook;
5223}
5224
5225function updateWorkInProgressHook() {
5226 // This function is used both for updates and for re-renders triggered by a
5227 // render phase update. It assumes there is either a current hook we can
5228 // clone, or a work-in-progress hook from a previous render pass that we can
5229 // use as a base. When we reach the end of the base list, we must switch to
5230 // the dispatcher used for mounts.
5231 if (nextWorkInProgressHook !== null) {
5232 // There's already a work-in-progress. Reuse it.
5233 workInProgressHook = nextWorkInProgressHook;
5234 nextWorkInProgressHook = workInProgressHook.next;
5235
5236 currentHook = nextCurrentHook;
5237 nextCurrentHook = currentHook !== null ? currentHook.next : null;
5238 } else {
5239 // Clone from the current hook.
5240 !(nextCurrentHook !== null) ? invariant(false, 'Rendered more hooks than during the previous render.') : void 0;
5241 currentHook = nextCurrentHook;
5242
5243 var newHook = {
5244 memoizedState: currentHook.memoizedState,
5245
5246 baseState: currentHook.baseState,
5247 queue: currentHook.queue,
5248 baseUpdate: currentHook.baseUpdate,
5249
5250 next: null
5251 };
5252
5253 if (workInProgressHook === null) {
5254 // This is the first hook in the list.
5255 workInProgressHook = firstWorkInProgressHook = newHook;
5256 } else {
5257 // Append to the end of the list.
5258 workInProgressHook = workInProgressHook.next = newHook;
5259 }
5260 nextCurrentHook = currentHook.next;
5261
5262 {
5263 newHook._debugType = currentHookNameInDev;
5264 if (currentHookNameInDev !== currentHook._debugType) {
5265 warnOnHookMismatchInDev();
5266 }
5267 }
5268 }
5269 return workInProgressHook;
5270}
5271
5272function createFunctionComponentUpdateQueue() {
5273 return {
5274 lastEffect: null
5275 };
5276}
5277
5278function basicStateReducer(state, action) {
5279 return typeof action === 'function' ? action(state) : action;
5280}
5281
5282function mountContext(context, observedBits) {
5283 {
5284 mountWorkInProgressHook();
5285 }
5286 return readContext(context, observedBits);
5287}
5288
5289function updateContext(context, observedBits) {
5290 {
5291 updateWorkInProgressHook();
5292 }
5293 return readContext(context, observedBits);
5294}
5295
5296function mountReducer(reducer, initialArg, init) {
5297 var hook = mountWorkInProgressHook();
5298 var initialState = void 0;
5299 if (init !== undefined) {
5300 initialState = init(initialArg);
5301 } else {
5302 initialState = initialArg;
5303 }
5304 hook.memoizedState = hook.baseState = initialState;
5305 var queue = hook.queue = {
5306 last: null,
5307 dispatch: null,
5308 eagerReducer: reducer,
5309 eagerState: initialState
5310 };
5311 var dispatch = queue.dispatch = dispatchAction.bind(null,
5312 // Flow doesn't know this is non-null, but we do.
5313 currentlyRenderingFiber$1, queue);
5314 return [hook.memoizedState, dispatch];
5315}
5316
5317function updateReducer(reducer, initialArg, init) {
5318 var hook = updateWorkInProgressHook();
5319 var queue = hook.queue;
5320 !(queue !== null) ? invariant(false, 'Should have a queue. This is likely a bug in React. Please file an issue.') : void 0;
5321
5322 if (numberOfReRenders > 0) {
5323 // This is a re-render. Apply the new render phase updates to the previous
5324 var _dispatch = queue.dispatch;
5325 if (renderPhaseUpdates !== null) {
5326 // Render phase updates are stored in a map of queue -> linked list
5327 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5328 if (firstRenderPhaseUpdate !== undefined) {
5329 renderPhaseUpdates.delete(queue);
5330 var newState = hook.memoizedState;
5331 var update = firstRenderPhaseUpdate;
5332 do {
5333 // Process this render phase update. We don't have to check the
5334 // priority because it will always be the same as the current
5335 // render's.
5336 var _action = update.action;
5337 newState = reducer(newState, _action);
5338 update = update.next;
5339 } while (update !== null);
5340
5341 // Mark that the fiber performed work, but only if the new state is
5342 // different from the current state.
5343 if (!is(newState, hook.memoizedState)) {
5344 markWorkInProgressReceivedUpdate();
5345 }
5346
5347 hook.memoizedState = newState;
5348 // Don't persist the state accumlated from the render phase updates to
5349 // the base state unless the queue is empty.
5350 // TODO: Not sure if this is the desired semantics, but it's what we
5351 // do for gDSFP. I can't remember why.
5352 if (hook.baseUpdate === queue.last) {
5353 hook.baseState = newState;
5354 }
5355
5356 queue.eagerReducer = reducer;
5357 queue.eagerState = newState;
5358
5359 return [newState, _dispatch];
5360 }
5361 }
5362 return [hook.memoizedState, _dispatch];
5363 }
5364
5365 // The last update in the entire queue
5366 var last = queue.last;
5367 // The last update that is part of the base state.
5368 var baseUpdate = hook.baseUpdate;
5369 var baseState = hook.baseState;
5370
5371 // Find the first unprocessed update.
5372 var first = void 0;
5373 if (baseUpdate !== null) {
5374 if (last !== null) {
5375 // For the first update, the queue is a circular linked list where
5376 // `queue.last.next = queue.first`. Once the first update commits, and
5377 // the `baseUpdate` is no longer empty, we can unravel the list.
5378 last.next = null;
5379 }
5380 first = baseUpdate.next;
5381 } else {
5382 first = last !== null ? last.next : null;
5383 }
5384 if (first !== null) {
5385 var _newState = baseState;
5386 var newBaseState = null;
5387 var newBaseUpdate = null;
5388 var prevUpdate = baseUpdate;
5389 var _update = first;
5390 var didSkip = false;
5391 do {
5392 var updateExpirationTime = _update.expirationTime;
5393 if (updateExpirationTime < renderExpirationTime) {
5394 // Priority is insufficient. Skip this update. If this is the first
5395 // skipped update, the previous update/state is the new base
5396 // update/state.
5397 if (!didSkip) {
5398 didSkip = true;
5399 newBaseUpdate = prevUpdate;
5400 newBaseState = _newState;
5401 }
5402 // Update the remaining priority in the queue.
5403 if (updateExpirationTime > remainingExpirationTime) {
5404 remainingExpirationTime = updateExpirationTime;
5405 }
5406 } else {
5407 // Process this update.
5408 if (_update.eagerReducer === reducer) {
5409 // If this update was processed eagerly, and its reducer matches the
5410 // current reducer, we can use the eagerly computed state.
5411 _newState = _update.eagerState;
5412 } else {
5413 var _action2 = _update.action;
5414 _newState = reducer(_newState, _action2);
5415 }
5416 }
5417 prevUpdate = _update;
5418 _update = _update.next;
5419 } while (_update !== null && _update !== first);
5420
5421 if (!didSkip) {
5422 newBaseUpdate = prevUpdate;
5423 newBaseState = _newState;
5424 }
5425
5426 // Mark that the fiber performed work, but only if the new state is
5427 // different from the current state.
5428 if (!is(_newState, hook.memoizedState)) {
5429 markWorkInProgressReceivedUpdate();
5430 }
5431
5432 hook.memoizedState = _newState;
5433 hook.baseUpdate = newBaseUpdate;
5434 hook.baseState = newBaseState;
5435
5436 queue.eagerReducer = reducer;
5437 queue.eagerState = _newState;
5438 }
5439
5440 var dispatch = queue.dispatch;
5441 return [hook.memoizedState, dispatch];
5442}
5443
5444function mountState(initialState) {
5445 var hook = mountWorkInProgressHook();
5446 if (typeof initialState === 'function') {
5447 initialState = initialState();
5448 }
5449 hook.memoizedState = hook.baseState = initialState;
5450 var queue = hook.queue = {
5451 last: null,
5452 dispatch: null,
5453 eagerReducer: basicStateReducer,
5454 eagerState: initialState
5455 };
5456 var dispatch = queue.dispatch = dispatchAction.bind(null,
5457 // Flow doesn't know this is non-null, but we do.
5458 currentlyRenderingFiber$1, queue);
5459 return [hook.memoizedState, dispatch];
5460}
5461
5462function updateState(initialState) {
5463 return updateReducer(basicStateReducer, initialState);
5464}
5465
5466function pushEffect(tag, create, destroy, deps) {
5467 var effect = {
5468 tag: tag,
5469 create: create,
5470 destroy: destroy,
5471 deps: deps,
5472 // Circular
5473 next: null
5474 };
5475 if (componentUpdateQueue === null) {
5476 componentUpdateQueue = createFunctionComponentUpdateQueue();
5477 componentUpdateQueue.lastEffect = effect.next = effect;
5478 } else {
5479 var _lastEffect = componentUpdateQueue.lastEffect;
5480 if (_lastEffect === null) {
5481 componentUpdateQueue.lastEffect = effect.next = effect;
5482 } else {
5483 var firstEffect = _lastEffect.next;
5484 _lastEffect.next = effect;
5485 effect.next = firstEffect;
5486 componentUpdateQueue.lastEffect = effect;
5487 }
5488 }
5489 return effect;
5490}
5491
5492function mountRef(initialValue) {
5493 var hook = mountWorkInProgressHook();
5494 var ref = { current: initialValue };
5495 {
5496 Object.seal(ref);
5497 }
5498 hook.memoizedState = ref;
5499 return ref;
5500}
5501
5502function updateRef(initialValue) {
5503 var hook = updateWorkInProgressHook();
5504 return hook.memoizedState;
5505}
5506
5507function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5508 var hook = mountWorkInProgressHook();
5509 var nextDeps = deps === undefined ? null : deps;
5510 sideEffectTag |= fiberEffectTag;
5511 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
5512}
5513
5514function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5515 var hook = updateWorkInProgressHook();
5516 var nextDeps = deps === undefined ? null : deps;
5517 var destroy = undefined;
5518
5519 if (currentHook !== null) {
5520 var prevEffect = currentHook.memoizedState;
5521 destroy = prevEffect.destroy;
5522 if (nextDeps !== null) {
5523 var prevDeps = prevEffect.deps;
5524 if (areHookInputsEqual(nextDeps, prevDeps)) {
5525 pushEffect(NoEffect$1, create, destroy, nextDeps);
5526 return;
5527 }
5528 }
5529 }
5530
5531 sideEffectTag |= fiberEffectTag;
5532 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
5533}
5534
5535function mountEffect(create, deps) {
5536 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5537}
5538
5539function updateEffect(create, deps) {
5540 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5541}
5542
5543function mountLayoutEffect(create, deps) {
5544 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5545}
5546
5547function updateLayoutEffect(create, deps) {
5548 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5549}
5550
5551function imperativeHandleEffect(create, ref) {
5552 if (typeof ref === 'function') {
5553 var refCallback = ref;
5554 var _inst = create();
5555 refCallback(_inst);
5556 return function () {
5557 refCallback(null);
5558 };
5559 } else if (ref !== null && ref !== undefined) {
5560 var refObject = ref;
5561 {
5562 !refObject.hasOwnProperty('current') ? warning$1(false, 'Expected useImperativeHandle() first argument to either be a ' + 'ref callback or React.createRef() object. Instead received: %s.', 'an object with keys {' + Object.keys(refObject).join(', ') + '}') : void 0;
5563 }
5564 var _inst2 = create();
5565 refObject.current = _inst2;
5566 return function () {
5567 refObject.current = null;
5568 };
5569 }
5570}
5571
5572function mountImperativeHandle(ref, create, deps) {
5573 {
5574 !(typeof create === 'function') ? warning$1(false, 'Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null') : void 0;
5575 }
5576
5577 // TODO: If deps are provided, should we skip comparing the ref itself?
5578 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
5579
5580 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5581}
5582
5583function updateImperativeHandle(ref, create, deps) {
5584 {
5585 !(typeof create === 'function') ? warning$1(false, 'Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null') : void 0;
5586 }
5587
5588 // TODO: If deps are provided, should we skip comparing the ref itself?
5589 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
5590
5591 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5592}
5593
5594function mountDebugValue(value, formatterFn) {
5595 // This hook is normally a no-op.
5596 // The react-debug-hooks package injects its own implementation
5597 // so that e.g. DevTools can display custom hook values.
5598}
5599
5600var updateDebugValue = mountDebugValue;
5601
5602function mountCallback(callback, deps) {
5603 var hook = mountWorkInProgressHook();
5604 var nextDeps = deps === undefined ? null : deps;
5605 hook.memoizedState = [callback, nextDeps];
5606 return callback;
5607}
5608
5609function updateCallback(callback, deps) {
5610 var hook = updateWorkInProgressHook();
5611 var nextDeps = deps === undefined ? null : deps;
5612 var prevState = hook.memoizedState;
5613 if (prevState !== null) {
5614 if (nextDeps !== null) {
5615 var prevDeps = prevState[1];
5616 if (areHookInputsEqual(nextDeps, prevDeps)) {
5617 return prevState[0];
5618 }
5619 }
5620 }
5621 hook.memoizedState = [callback, nextDeps];
5622 return callback;
5623}
5624
5625function mountMemo(nextCreate, deps) {
5626 var hook = mountWorkInProgressHook();
5627 var nextDeps = deps === undefined ? null : deps;
5628 var nextValue = nextCreate();
5629 hook.memoizedState = [nextValue, nextDeps];
5630 return nextValue;
5631}
5632
5633function updateMemo(nextCreate, deps) {
5634 var hook = updateWorkInProgressHook();
5635 var nextDeps = deps === undefined ? null : deps;
5636 var prevState = hook.memoizedState;
5637 if (prevState !== null) {
5638 // Assume these are defined. If they're not, areHookInputsEqual will warn.
5639 if (nextDeps !== null) {
5640 var prevDeps = prevState[1];
5641 if (areHookInputsEqual(nextDeps, prevDeps)) {
5642 return prevState[0];
5643 }
5644 }
5645 }
5646 var nextValue = nextCreate();
5647 hook.memoizedState = [nextValue, nextDeps];
5648 return nextValue;
5649}
5650
5651// in a test-like environment, we want to warn if dispatchAction()
5652// is called outside of a batchedUpdates/TestUtils.act(...) call.
5653var shouldWarnForUnbatchedSetState = false;
5654
5655{
5656 // jest isn't a 'global', it's just exposed to tests via a wrapped function
5657 // further, this isn't a test file, so flow doesn't recognize the symbol. So...
5658 // $FlowExpectedError - because requirements don't give a damn about your type sigs.
5659 if ('undefined' !== typeof jest) {
5660 shouldWarnForUnbatchedSetState = true;
5661 }
5662}
5663
5664function dispatchAction(fiber, queue, action) {
5665 !(numberOfReRenders < RE_RENDER_LIMIT) ? invariant(false, 'Too many re-renders. React limits the number of renders to prevent an infinite loop.') : void 0;
5666
5667 {
5668 !(arguments.length <= 3) ? warning$1(false, "State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().') : void 0;
5669 }
5670
5671 var alternate = fiber.alternate;
5672 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
5673 // This is a render phase update. Stash it in a lazily-created map of
5674 // queue -> linked list of updates. After this render pass, we'll restart
5675 // and apply the stashed updates on top of the work-in-progress hook.
5676 didScheduleRenderPhaseUpdate = true;
5677 var update = {
5678 expirationTime: renderExpirationTime,
5679 action: action,
5680 eagerReducer: null,
5681 eagerState: null,
5682 next: null
5683 };
5684 if (renderPhaseUpdates === null) {
5685 renderPhaseUpdates = new Map();
5686 }
5687 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5688 if (firstRenderPhaseUpdate === undefined) {
5689 renderPhaseUpdates.set(queue, update);
5690 } else {
5691 // Append the update to the end of the list.
5692 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
5693 while (lastRenderPhaseUpdate.next !== null) {
5694 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
5695 }
5696 lastRenderPhaseUpdate.next = update;
5697 }
5698 } else {
5699 flushPassiveEffects$1();
5700
5701 var currentTime = requestCurrentTime();
5702 var _expirationTime = computeExpirationForFiber(currentTime, fiber);
5703
5704 var _update2 = {
5705 expirationTime: _expirationTime,
5706 action: action,
5707 eagerReducer: null,
5708 eagerState: null,
5709 next: null
5710 };
5711
5712 // Append the update to the end of the list.
5713 var _last = queue.last;
5714 if (_last === null) {
5715 // This is the first update. Create a circular list.
5716 _update2.next = _update2;
5717 } else {
5718 var first = _last.next;
5719 if (first !== null) {
5720 // Still circular.
5721 _update2.next = first;
5722 }
5723 _last.next = _update2;
5724 }
5725 queue.last = _update2;
5726
5727 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
5728 // The queue is currently empty, which means we can eagerly compute the
5729 // next state before entering the render phase. If the new state is the
5730 // same as the current state, we may be able to bail out entirely.
5731 var _eagerReducer = queue.eagerReducer;
5732 if (_eagerReducer !== null) {
5733 var prevDispatcher = void 0;
5734 {
5735 prevDispatcher = ReactCurrentDispatcher$1.current;
5736 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5737 }
5738 try {
5739 var currentState = queue.eagerState;
5740 var _eagerState = _eagerReducer(currentState, action);
5741 // Stash the eagerly computed state, and the reducer used to compute
5742 // it, on the update object. If the reducer hasn't changed by the
5743 // time we enter the render phase, then the eager state can be used
5744 // without calling the reducer again.
5745 _update2.eagerReducer = _eagerReducer;
5746 _update2.eagerState = _eagerState;
5747 if (is(_eagerState, currentState)) {
5748 // Fast path. We can bail out without scheduling React to re-render.
5749 // It's still possible that we'll need to rebase this update later,
5750 // if the component re-renders for a different reason and by that
5751 // time the reducer has changed.
5752 return;
5753 }
5754 } catch (error) {
5755 // Suppress the error. It will throw again in the render phase.
5756 } finally {
5757 {
5758 ReactCurrentDispatcher$1.current = prevDispatcher;
5759 }
5760 }
5761 }
5762 }
5763 {
5764 if (shouldWarnForUnbatchedSetState === true) {
5765 warnIfNotCurrentlyBatchingInDev(fiber);
5766 }
5767 }
5768 scheduleWork(fiber, _expirationTime);
5769 }
5770}
5771
5772var ContextOnlyDispatcher = {
5773 readContext: readContext,
5774
5775 useCallback: throwInvalidHookError,
5776 useContext: throwInvalidHookError,
5777 useEffect: throwInvalidHookError,
5778 useImperativeHandle: throwInvalidHookError,
5779 useLayoutEffect: throwInvalidHookError,
5780 useMemo: throwInvalidHookError,
5781 useReducer: throwInvalidHookError,
5782 useRef: throwInvalidHookError,
5783 useState: throwInvalidHookError,
5784 useDebugValue: throwInvalidHookError
5785};
5786
5787var HooksDispatcherOnMountInDEV = null;
5788var HooksDispatcherOnUpdateInDEV = null;
5789var InvalidNestedHooksDispatcherOnMountInDEV = null;
5790var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
5791
5792{
5793 var warnInvalidContextAccess = function () {
5794 warning$1(false, 'Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
5795 };
5796
5797 var warnInvalidHookAccess = function () {
5798 warning$1(false, 'Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' + 'You can only call Hooks at the top level of your React function. ' + 'For more information, see ' + 'https://fb.me/rules-of-hooks');
5799 };
5800
5801 HooksDispatcherOnMountInDEV = {
5802 readContext: function (context, observedBits) {
5803 return readContext(context, observedBits);
5804 },
5805 useCallback: function (callback, deps) {
5806 currentHookNameInDev = 'useCallback';
5807 return mountCallback(callback, deps);
5808 },
5809 useContext: function (context, observedBits) {
5810 currentHookNameInDev = 'useContext';
5811 return mountContext(context, observedBits);
5812 },
5813 useEffect: function (create, deps) {
5814 currentHookNameInDev = 'useEffect';
5815 return mountEffect(create, deps);
5816 },
5817 useImperativeHandle: function (ref, create, deps) {
5818 currentHookNameInDev = 'useImperativeHandle';
5819 return mountImperativeHandle(ref, create, deps);
5820 },
5821 useLayoutEffect: function (create, deps) {
5822 currentHookNameInDev = 'useLayoutEffect';
5823 return mountLayoutEffect(create, deps);
5824 },
5825 useMemo: function (create, deps) {
5826 currentHookNameInDev = 'useMemo';
5827 var prevDispatcher = ReactCurrentDispatcher$1.current;
5828 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5829 try {
5830 return mountMemo(create, deps);
5831 } finally {
5832 ReactCurrentDispatcher$1.current = prevDispatcher;
5833 }
5834 },
5835 useReducer: function (reducer, initialArg, init) {
5836 currentHookNameInDev = 'useReducer';
5837 var prevDispatcher = ReactCurrentDispatcher$1.current;
5838 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5839 try {
5840 return mountReducer(reducer, initialArg, init);
5841 } finally {
5842 ReactCurrentDispatcher$1.current = prevDispatcher;
5843 }
5844 },
5845 useRef: function (initialValue) {
5846 currentHookNameInDev = 'useRef';
5847 return mountRef(initialValue);
5848 },
5849 useState: function (initialState) {
5850 currentHookNameInDev = 'useState';
5851 var prevDispatcher = ReactCurrentDispatcher$1.current;
5852 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5853 try {
5854 return mountState(initialState);
5855 } finally {
5856 ReactCurrentDispatcher$1.current = prevDispatcher;
5857 }
5858 },
5859 useDebugValue: function (value, formatterFn) {
5860 currentHookNameInDev = 'useDebugValue';
5861 return mountDebugValue(value, formatterFn);
5862 }
5863 };
5864
5865 HooksDispatcherOnUpdateInDEV = {
5866 readContext: function (context, observedBits) {
5867 return readContext(context, observedBits);
5868 },
5869 useCallback: function (callback, deps) {
5870 currentHookNameInDev = 'useCallback';
5871 return updateCallback(callback, deps);
5872 },
5873 useContext: function (context, observedBits) {
5874 currentHookNameInDev = 'useContext';
5875 return updateContext(context, observedBits);
5876 },
5877 useEffect: function (create, deps) {
5878 currentHookNameInDev = 'useEffect';
5879 return updateEffect(create, deps);
5880 },
5881 useImperativeHandle: function (ref, create, deps) {
5882 currentHookNameInDev = 'useImperativeHandle';
5883 return updateImperativeHandle(ref, create, deps);
5884 },
5885 useLayoutEffect: function (create, deps) {
5886 currentHookNameInDev = 'useLayoutEffect';
5887 return updateLayoutEffect(create, deps);
5888 },
5889 useMemo: function (create, deps) {
5890 currentHookNameInDev = 'useMemo';
5891 var prevDispatcher = ReactCurrentDispatcher$1.current;
5892 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5893 try {
5894 return updateMemo(create, deps);
5895 } finally {
5896 ReactCurrentDispatcher$1.current = prevDispatcher;
5897 }
5898 },
5899 useReducer: function (reducer, initialArg, init) {
5900 currentHookNameInDev = 'useReducer';
5901 var prevDispatcher = ReactCurrentDispatcher$1.current;
5902 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5903 try {
5904 return updateReducer(reducer, initialArg, init);
5905 } finally {
5906 ReactCurrentDispatcher$1.current = prevDispatcher;
5907 }
5908 },
5909 useRef: function (initialValue) {
5910 currentHookNameInDev = 'useRef';
5911 return updateRef(initialValue);
5912 },
5913 useState: function (initialState) {
5914 currentHookNameInDev = 'useState';
5915 var prevDispatcher = ReactCurrentDispatcher$1.current;
5916 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5917 try {
5918 return updateState(initialState);
5919 } finally {
5920 ReactCurrentDispatcher$1.current = prevDispatcher;
5921 }
5922 },
5923 useDebugValue: function (value, formatterFn) {
5924 currentHookNameInDev = 'useDebugValue';
5925 return updateDebugValue(value, formatterFn);
5926 }
5927 };
5928
5929 InvalidNestedHooksDispatcherOnMountInDEV = {
5930 readContext: function (context, observedBits) {
5931 warnInvalidContextAccess();
5932 return readContext(context, observedBits);
5933 },
5934 useCallback: function (callback, deps) {
5935 currentHookNameInDev = 'useCallback';
5936 warnInvalidHookAccess();
5937 return mountCallback(callback, deps);
5938 },
5939 useContext: function (context, observedBits) {
5940 currentHookNameInDev = 'useContext';
5941 warnInvalidHookAccess();
5942 return mountContext(context, observedBits);
5943 },
5944 useEffect: function (create, deps) {
5945 currentHookNameInDev = 'useEffect';
5946 warnInvalidHookAccess();
5947 return mountEffect(create, deps);
5948 },
5949 useImperativeHandle: function (ref, create, deps) {
5950 currentHookNameInDev = 'useImperativeHandle';
5951 warnInvalidHookAccess();
5952 return mountImperativeHandle(ref, create, deps);
5953 },
5954 useLayoutEffect: function (create, deps) {
5955 currentHookNameInDev = 'useLayoutEffect';
5956 warnInvalidHookAccess();
5957 return mountLayoutEffect(create, deps);
5958 },
5959 useMemo: function (create, deps) {
5960 currentHookNameInDev = 'useMemo';
5961 warnInvalidHookAccess();
5962 var prevDispatcher = ReactCurrentDispatcher$1.current;
5963 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5964 try {
5965 return mountMemo(create, deps);
5966 } finally {
5967 ReactCurrentDispatcher$1.current = prevDispatcher;
5968 }
5969 },
5970 useReducer: function (reducer, initialArg, init) {
5971 currentHookNameInDev = 'useReducer';
5972 warnInvalidHookAccess();
5973 var prevDispatcher = ReactCurrentDispatcher$1.current;
5974 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5975 try {
5976 return mountReducer(reducer, initialArg, init);
5977 } finally {
5978 ReactCurrentDispatcher$1.current = prevDispatcher;
5979 }
5980 },
5981 useRef: function (initialValue) {
5982 currentHookNameInDev = 'useRef';
5983 warnInvalidHookAccess();
5984 return mountRef(initialValue);
5985 },
5986 useState: function (initialState) {
5987 currentHookNameInDev = 'useState';
5988 warnInvalidHookAccess();
5989 var prevDispatcher = ReactCurrentDispatcher$1.current;
5990 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5991 try {
5992 return mountState(initialState);
5993 } finally {
5994 ReactCurrentDispatcher$1.current = prevDispatcher;
5995 }
5996 },
5997 useDebugValue: function (value, formatterFn) {
5998 currentHookNameInDev = 'useDebugValue';
5999 warnInvalidHookAccess();
6000 return mountDebugValue(value, formatterFn);
6001 }
6002 };
6003
6004 InvalidNestedHooksDispatcherOnUpdateInDEV = {
6005 readContext: function (context, observedBits) {
6006 warnInvalidContextAccess();
6007 return readContext(context, observedBits);
6008 },
6009 useCallback: function (callback, deps) {
6010 currentHookNameInDev = 'useCallback';
6011 warnInvalidHookAccess();
6012 return updateCallback(callback, deps);
6013 },
6014 useContext: function (context, observedBits) {
6015 currentHookNameInDev = 'useContext';
6016 warnInvalidHookAccess();
6017 return updateContext(context, observedBits);
6018 },
6019 useEffect: function (create, deps) {
6020 currentHookNameInDev = 'useEffect';
6021 warnInvalidHookAccess();
6022 return updateEffect(create, deps);
6023 },
6024 useImperativeHandle: function (ref, create, deps) {
6025 currentHookNameInDev = 'useImperativeHandle';
6026 warnInvalidHookAccess();
6027 return updateImperativeHandle(ref, create, deps);
6028 },
6029 useLayoutEffect: function (create, deps) {
6030 currentHookNameInDev = 'useLayoutEffect';
6031 warnInvalidHookAccess();
6032 return updateLayoutEffect(create, deps);
6033 },
6034 useMemo: function (create, deps) {
6035 currentHookNameInDev = 'useMemo';
6036 warnInvalidHookAccess();
6037 var prevDispatcher = ReactCurrentDispatcher$1.current;
6038 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6039 try {
6040 return updateMemo(create, deps);
6041 } finally {
6042 ReactCurrentDispatcher$1.current = prevDispatcher;
6043 }
6044 },
6045 useReducer: function (reducer, initialArg, init) {
6046 currentHookNameInDev = 'useReducer';
6047 warnInvalidHookAccess();
6048 var prevDispatcher = ReactCurrentDispatcher$1.current;
6049 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6050 try {
6051 return updateReducer(reducer, initialArg, init);
6052 } finally {
6053 ReactCurrentDispatcher$1.current = prevDispatcher;
6054 }
6055 },
6056 useRef: function (initialValue) {
6057 currentHookNameInDev = 'useRef';
6058 warnInvalidHookAccess();
6059 return updateRef(initialValue);
6060 },
6061 useState: function (initialState) {
6062 currentHookNameInDev = 'useState';
6063 warnInvalidHookAccess();
6064 var prevDispatcher = ReactCurrentDispatcher$1.current;
6065 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6066 try {
6067 return updateState(initialState);
6068 } finally {
6069 ReactCurrentDispatcher$1.current = prevDispatcher;
6070 }
6071 },
6072 useDebugValue: function (value, formatterFn) {
6073 currentHookNameInDev = 'useDebugValue';
6074 warnInvalidHookAccess();
6075 return updateDebugValue(value, formatterFn);
6076 }
6077 };
6078}
6079
6080var commitTime = 0;
6081var profilerStartTime = -1;
6082
6083function getCommitTime() {
6084 return commitTime;
6085}
6086
6087function recordCommitTime() {
6088 if (!enableProfilerTimer) {
6089 return;
6090 }
6091 commitTime = now();
6092}
6093
6094function startProfilerTimer(fiber) {
6095 if (!enableProfilerTimer) {
6096 return;
6097 }
6098
6099 profilerStartTime = now();
6100
6101 if (fiber.actualStartTime < 0) {
6102 fiber.actualStartTime = now();
6103 }
6104}
6105
6106function stopProfilerTimerIfRunning(fiber) {
6107 if (!enableProfilerTimer) {
6108 return;
6109 }
6110 profilerStartTime = -1;
6111}
6112
6113function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
6114 if (!enableProfilerTimer) {
6115 return;
6116 }
6117
6118 if (profilerStartTime >= 0) {
6119 var elapsedTime = now() - profilerStartTime;
6120 fiber.actualDuration += elapsedTime;
6121 if (overrideBaseTime) {
6122 fiber.selfBaseDuration = elapsedTime;
6123 }
6124 profilerStartTime = -1;
6125 }
6126}
6127
6128// The deepest Fiber on the stack involved in a hydration context.
6129// This may have been an insertion or a hydration.
6130var hydrationParentFiber = null;
6131var nextHydratableInstance = null;
6132var isHydrating = false;
6133
6134function enterHydrationState(fiber) {
6135 if (!supportsHydration) {
6136 return false;
6137 }
6138
6139 var parentInstance = fiber.stateNode.containerInfo;
6140 nextHydratableInstance = getFirstHydratableChild(parentInstance);
6141 hydrationParentFiber = fiber;
6142 isHydrating = true;
6143 return true;
6144}
6145
6146function reenterHydrationStateFromDehydratedSuspenseInstance(fiber) {
6147 if (!supportsHydration) {
6148 return false;
6149 }
6150
6151 var suspenseInstance = fiber.stateNode;
6152 nextHydratableInstance = getNextHydratableSibling(suspenseInstance);
6153 popToNextHostParent(fiber);
6154 isHydrating = true;
6155 return true;
6156}
6157
6158function deleteHydratableInstance(returnFiber, instance) {
6159 {
6160 switch (returnFiber.tag) {
6161 case HostRoot:
6162 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
6163 break;
6164 case HostComponent:
6165 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
6166 break;
6167 }
6168 }
6169
6170 var childToDelete = createFiberFromHostInstanceForDeletion();
6171 childToDelete.stateNode = instance;
6172 childToDelete.return = returnFiber;
6173 childToDelete.effectTag = Deletion;
6174
6175 // This might seem like it belongs on progressedFirstDeletion. However,
6176 // these children are not part of the reconciliation list of children.
6177 // Even if we abort and rereconcile the children, that will try to hydrate
6178 // again and the nodes are still in the host tree so these will be
6179 // recreated.
6180 if (returnFiber.lastEffect !== null) {
6181 returnFiber.lastEffect.nextEffect = childToDelete;
6182 returnFiber.lastEffect = childToDelete;
6183 } else {
6184 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
6185 }
6186}
6187
6188function insertNonHydratedInstance(returnFiber, fiber) {
6189 fiber.effectTag |= Placement;
6190 {
6191 switch (returnFiber.tag) {
6192 case HostRoot:
6193 {
6194 var parentContainer = returnFiber.stateNode.containerInfo;
6195 switch (fiber.tag) {
6196 case HostComponent:
6197 var type = fiber.type;
6198 var props = fiber.pendingProps;
6199 didNotFindHydratableContainerInstance(parentContainer, type, props);
6200 break;
6201 case HostText:
6202 var text = fiber.pendingProps;
6203 didNotFindHydratableContainerTextInstance(parentContainer, text);
6204 break;
6205 case SuspenseComponent:
6206 didNotFindHydratableContainerSuspenseInstance(parentContainer);
6207 break;
6208 }
6209 break;
6210 }
6211 case HostComponent:
6212 {
6213 var parentType = returnFiber.type;
6214 var parentProps = returnFiber.memoizedProps;
6215 var parentInstance = returnFiber.stateNode;
6216 switch (fiber.tag) {
6217 case HostComponent:
6218 var _type = fiber.type;
6219 var _props = fiber.pendingProps;
6220 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
6221 break;
6222 case HostText:
6223 var _text = fiber.pendingProps;
6224 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
6225 break;
6226 case SuspenseComponent:
6227 didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance);
6228 break;
6229 }
6230 break;
6231 }
6232 default:
6233 return;
6234 }
6235 }
6236}
6237
6238function tryHydrate(fiber, nextInstance) {
6239 switch (fiber.tag) {
6240 case HostComponent:
6241 {
6242 var type = fiber.type;
6243 var props = fiber.pendingProps;
6244 var instance = canHydrateInstance(nextInstance, type, props);
6245 if (instance !== null) {
6246 fiber.stateNode = instance;
6247 return true;
6248 }
6249 return false;
6250 }
6251 case HostText:
6252 {
6253 var text = fiber.pendingProps;
6254 var textInstance = canHydrateTextInstance(nextInstance, text);
6255 if (textInstance !== null) {
6256 fiber.stateNode = textInstance;
6257 return true;
6258 }
6259 return false;
6260 }
6261 case SuspenseComponent:
6262 {
6263 if (enableSuspenseServerRenderer) {
6264 var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
6265 if (suspenseInstance !== null) {
6266 // Downgrade the tag to a dehydrated component until we've hydrated it.
6267 fiber.tag = DehydratedSuspenseComponent;
6268 fiber.stateNode = suspenseInstance;
6269 return true;
6270 }
6271 }
6272 return false;
6273 }
6274 default:
6275 return false;
6276 }
6277}
6278
6279function tryToClaimNextHydratableInstance(fiber) {
6280 if (!isHydrating) {
6281 return;
6282 }
6283 var nextInstance = nextHydratableInstance;
6284 if (!nextInstance) {
6285 // Nothing to hydrate. Make it an insertion.
6286 insertNonHydratedInstance(hydrationParentFiber, fiber);
6287 isHydrating = false;
6288 hydrationParentFiber = fiber;
6289 return;
6290 }
6291 var firstAttemptedInstance = nextInstance;
6292 if (!tryHydrate(fiber, nextInstance)) {
6293 // If we can't hydrate this instance let's try the next one.
6294 // We use this as a heuristic. It's based on intuition and not data so it
6295 // might be flawed or unnecessary.
6296 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
6297 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
6298 // Nothing to hydrate. Make it an insertion.
6299 insertNonHydratedInstance(hydrationParentFiber, fiber);
6300 isHydrating = false;
6301 hydrationParentFiber = fiber;
6302 return;
6303 }
6304 // We matched the next one, we'll now assume that the first one was
6305 // superfluous and we'll delete it. Since we can't eagerly delete it
6306 // we'll have to schedule a deletion. To do that, this node needs a dummy
6307 // fiber associated with it.
6308 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
6309 }
6310 hydrationParentFiber = fiber;
6311 nextHydratableInstance = getFirstHydratableChild(nextInstance);
6312}
6313
6314function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
6315 if (!supportsHydration) {
6316 invariant(false, 'Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6317 }
6318
6319 var instance = fiber.stateNode;
6320 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber);
6321 // TODO: Type this specific to this type of component.
6322 fiber.updateQueue = updatePayload;
6323 // If the update payload indicates that there is a change or if there
6324 // is a new ref we mark this as an update.
6325 if (updatePayload !== null) {
6326 return true;
6327 }
6328 return false;
6329}
6330
6331function prepareToHydrateHostTextInstance(fiber) {
6332 if (!supportsHydration) {
6333 invariant(false, 'Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6334 }
6335
6336 var textInstance = fiber.stateNode;
6337 var textContent = fiber.memoizedProps;
6338 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
6339 {
6340 if (shouldUpdate) {
6341 // We assume that prepareToHydrateHostTextInstance is called in a context where the
6342 // hydration parent is the parent host component of this host text.
6343 var returnFiber = hydrationParentFiber;
6344 if (returnFiber !== null) {
6345 switch (returnFiber.tag) {
6346 case HostRoot:
6347 {
6348 var parentContainer = returnFiber.stateNode.containerInfo;
6349 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
6350 break;
6351 }
6352 case HostComponent:
6353 {
6354 var parentType = returnFiber.type;
6355 var parentProps = returnFiber.memoizedProps;
6356 var parentInstance = returnFiber.stateNode;
6357 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
6358 break;
6359 }
6360 }
6361 }
6362 }
6363 }
6364 return shouldUpdate;
6365}
6366
6367function skipPastDehydratedSuspenseInstance(fiber) {
6368 if (!supportsHydration) {
6369 invariant(false, 'Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6370 }
6371 var suspenseInstance = fiber.stateNode;
6372 !suspenseInstance ? invariant(false, 'Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.') : void 0;
6373 nextHydratableInstance = getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
6374}
6375
6376function popToNextHostParent(fiber) {
6377 var parent = fiber.return;
6378 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== DehydratedSuspenseComponent) {
6379 parent = parent.return;
6380 }
6381 hydrationParentFiber = parent;
6382}
6383
6384function popHydrationState(fiber) {
6385 if (!supportsHydration) {
6386 return false;
6387 }
6388 if (fiber !== hydrationParentFiber) {
6389 // We're deeper than the current hydration context, inside an inserted
6390 // tree.
6391 return false;
6392 }
6393 if (!isHydrating) {
6394 // If we're not currently hydrating but we're in a hydration context, then
6395 // we were an insertion and now need to pop up reenter hydration of our
6396 // siblings.
6397 popToNextHostParent(fiber);
6398 isHydrating = true;
6399 return false;
6400 }
6401
6402 var type = fiber.type;
6403
6404 // If we have any remaining hydratable nodes, we need to delete them now.
6405 // We only do this deeper than head and body since they tend to have random
6406 // other nodes in them. We also ignore components with pure text content in
6407 // side of them.
6408 // TODO: Better heuristic.
6409 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
6410 var nextInstance = nextHydratableInstance;
6411 while (nextInstance) {
6412 deleteHydratableInstance(fiber, nextInstance);
6413 nextInstance = getNextHydratableSibling(nextInstance);
6414 }
6415 }
6416
6417 popToNextHostParent(fiber);
6418 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
6419 return true;
6420}
6421
6422function resetHydrationState() {
6423 if (!supportsHydration) {
6424 return;
6425 }
6426
6427 hydrationParentFiber = null;
6428 nextHydratableInstance = null;
6429 isHydrating = false;
6430}
6431
6432var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
6433
6434var didReceiveUpdate = false;
6435
6436var didWarnAboutBadClass = void 0;
6437var didWarnAboutContextTypeOnFunctionComponent = void 0;
6438var didWarnAboutGetDerivedStateOnFunctionComponent = void 0;
6439var didWarnAboutFunctionRefs = void 0;
6440var didWarnAboutReassigningProps = void 0;
6441
6442{
6443 didWarnAboutBadClass = {};
6444 didWarnAboutContextTypeOnFunctionComponent = {};
6445 didWarnAboutGetDerivedStateOnFunctionComponent = {};
6446 didWarnAboutFunctionRefs = {};
6447 didWarnAboutReassigningProps = false;
6448}
6449
6450function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6451 if (current$$1 === null) {
6452 // If this is a fresh new component that hasn't been rendered yet, we
6453 // won't update its child set by applying minimal side-effects. Instead,
6454 // we will add them all to the child before it gets rendered. That means
6455 // we can optimize this reconciliation pass by not tracking side-effects.
6456 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6457 } else {
6458 // If the current child is the same as the work in progress, it means that
6459 // we haven't yet started any work on these children. Therefore, we use
6460 // the clone algorithm to create a copy of all the current children.
6461
6462 // If we had any progressed work already, that is invalid at this point so
6463 // let's throw it out.
6464 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
6465 }
6466}
6467
6468function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6469 // This function is fork of reconcileChildren. It's used in cases where we
6470 // want to reconcile without matching against the existing set. This has the
6471 // effect of all current children being unmounted; even if the type and key
6472 // are the same, the old child is unmounted and a new child is created.
6473 //
6474 // To do this, we're going to go through the reconcile algorithm twice. In
6475 // the first pass, we schedule a deletion for all the current children by
6476 // passing null.
6477 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
6478 // In the second pass, we mount the new children. The trick here is that we
6479 // pass null in place of where we usually pass the current child set. This has
6480 // the effect of remounting all children regardless of whether their their
6481 // identity matches.
6482 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6483}
6484
6485function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6486 // TODO: current can be non-null here even if the component
6487 // hasn't yet mounted. This happens after the first render suspends.
6488 // We'll need to figure out if this is fine or can cause issues.
6489
6490 {
6491 if (workInProgress.type !== workInProgress.elementType) {
6492 // Lazy component props can't be validated in createElement
6493 // because they're only guaranteed to be resolved here.
6494 var innerPropTypes = Component.propTypes;
6495 if (innerPropTypes) {
6496 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6497 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6498 }
6499 }
6500 }
6501
6502 var render = Component.render;
6503 var ref = workInProgress.ref;
6504
6505 // The rest is a fork of updateFunctionComponent
6506 var nextChildren = void 0;
6507 prepareToReadContext(workInProgress, renderExpirationTime);
6508 {
6509 ReactCurrentOwner$2.current = workInProgress;
6510 setCurrentPhase('render');
6511 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6512 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6513 // Only double-render components with Hooks
6514 if (workInProgress.memoizedState !== null) {
6515 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6516 }
6517 }
6518 setCurrentPhase(null);
6519 }
6520
6521 if (current$$1 !== null && !didReceiveUpdate) {
6522 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6523 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6524 }
6525
6526 // React DevTools reads this flag.
6527 workInProgress.effectTag |= PerformedWork;
6528 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6529 return workInProgress.child;
6530}
6531
6532function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6533 if (current$$1 === null) {
6534 var type = Component.type;
6535 if (isSimpleFunctionComponent(type) && Component.compare === null &&
6536 // SimpleMemoComponent codepath doesn't resolve outer props either.
6537 Component.defaultProps === undefined) {
6538 // If this is a plain function component without default props,
6539 // and with only the default shallow comparison, we upgrade it
6540 // to a SimpleMemoComponent to allow fast path updates.
6541 workInProgress.tag = SimpleMemoComponent;
6542 workInProgress.type = type;
6543 {
6544 validateFunctionComponentInDev(workInProgress, type);
6545 }
6546 return updateSimpleMemoComponent(current$$1, workInProgress, type, nextProps, updateExpirationTime, renderExpirationTime);
6547 }
6548 {
6549 var innerPropTypes = type.propTypes;
6550 if (innerPropTypes) {
6551 // Inner memo component props aren't currently validated in createElement.
6552 // We could move it there, but we'd still need this for lazy code path.
6553 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6554 'prop', getComponentName(type), getCurrentFiberStackInDev);
6555 }
6556 }
6557 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
6558 child.ref = workInProgress.ref;
6559 child.return = workInProgress;
6560 workInProgress.child = child;
6561 return child;
6562 }
6563 {
6564 var _type = Component.type;
6565 var _innerPropTypes = _type.propTypes;
6566 if (_innerPropTypes) {
6567 // Inner memo component props aren't currently validated in createElement.
6568 // We could move it there, but we'd still need this for lazy code path.
6569 checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
6570 'prop', getComponentName(_type), getCurrentFiberStackInDev);
6571 }
6572 }
6573 var currentChild = current$$1.child; // This is always exactly one child
6574 if (updateExpirationTime < renderExpirationTime) {
6575 // This will be the props with resolved defaultProps,
6576 // unlike current.memoizedProps which will be the unresolved ones.
6577 var prevProps = currentChild.memoizedProps;
6578 // Default to shallow comparison
6579 var compare = Component.compare;
6580 compare = compare !== null ? compare : shallowEqual;
6581 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6582 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6583 }
6584 }
6585 // React DevTools reads this flag.
6586 workInProgress.effectTag |= PerformedWork;
6587 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
6588 newChild.ref = workInProgress.ref;
6589 newChild.return = workInProgress;
6590 workInProgress.child = newChild;
6591 return newChild;
6592}
6593
6594function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6595 // TODO: current can be non-null here even if the component
6596 // hasn't yet mounted. This happens when the inner render suspends.
6597 // We'll need to figure out if this is fine or can cause issues.
6598
6599 {
6600 if (workInProgress.type !== workInProgress.elementType) {
6601 // Lazy component props can't be validated in createElement
6602 // because they're only guaranteed to be resolved here.
6603 var outerMemoType = workInProgress.elementType;
6604 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
6605 // We warn when you define propTypes on lazy()
6606 // so let's just skip over it to find memo() outer wrapper.
6607 // Inner props for memo are validated later.
6608 outerMemoType = refineResolvedLazyComponent(outerMemoType);
6609 }
6610 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
6611 if (outerPropTypes) {
6612 checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
6613 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
6614 }
6615 // Inner propTypes will be validated in the function component path.
6616 }
6617 }
6618 if (current$$1 !== null) {
6619 var prevProps = current$$1.memoizedProps;
6620 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6621 didReceiveUpdate = false;
6622 if (updateExpirationTime < renderExpirationTime) {
6623 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6624 }
6625 }
6626 }
6627 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6628}
6629
6630function updateFragment(current$$1, workInProgress, renderExpirationTime) {
6631 var nextChildren = workInProgress.pendingProps;
6632 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6633 return workInProgress.child;
6634}
6635
6636function updateMode(current$$1, workInProgress, renderExpirationTime) {
6637 var nextChildren = workInProgress.pendingProps.children;
6638 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6639 return workInProgress.child;
6640}
6641
6642function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
6643 if (enableProfilerTimer) {
6644 workInProgress.effectTag |= Update;
6645 }
6646 var nextProps = workInProgress.pendingProps;
6647 var nextChildren = nextProps.children;
6648 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6649 return workInProgress.child;
6650}
6651
6652function markRef(current$$1, workInProgress) {
6653 var ref = workInProgress.ref;
6654 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
6655 // Schedule a Ref effect
6656 workInProgress.effectTag |= Ref;
6657 }
6658}
6659
6660function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6661 {
6662 if (workInProgress.type !== workInProgress.elementType) {
6663 // Lazy component props can't be validated in createElement
6664 // because they're only guaranteed to be resolved here.
6665 var innerPropTypes = Component.propTypes;
6666 if (innerPropTypes) {
6667 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6668 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6669 }
6670 }
6671 }
6672
6673 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
6674 var context = getMaskedContext(workInProgress, unmaskedContext);
6675
6676 var nextChildren = void 0;
6677 prepareToReadContext(workInProgress, renderExpirationTime);
6678 {
6679 ReactCurrentOwner$2.current = workInProgress;
6680 setCurrentPhase('render');
6681 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6682 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6683 // Only double-render components with Hooks
6684 if (workInProgress.memoizedState !== null) {
6685 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6686 }
6687 }
6688 setCurrentPhase(null);
6689 }
6690
6691 if (current$$1 !== null && !didReceiveUpdate) {
6692 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6693 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6694 }
6695
6696 // React DevTools reads this flag.
6697 workInProgress.effectTag |= PerformedWork;
6698 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6699 return workInProgress.child;
6700}
6701
6702function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6703 {
6704 if (workInProgress.type !== workInProgress.elementType) {
6705 // Lazy component props can't be validated in createElement
6706 // because they're only guaranteed to be resolved here.
6707 var innerPropTypes = Component.propTypes;
6708 if (innerPropTypes) {
6709 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
6710 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6711 }
6712 }
6713 }
6714
6715 // Push context providers early to prevent context stack mismatches.
6716 // During mounting we don't know the child context yet as the instance doesn't exist.
6717 // We will invalidate the child context in finishClassComponent() right after rendering.
6718 var hasContext = void 0;
6719 if (isContextProvider(Component)) {
6720 hasContext = true;
6721 pushContextProvider(workInProgress);
6722 } else {
6723 hasContext = false;
6724 }
6725 prepareToReadContext(workInProgress, renderExpirationTime);
6726
6727 var instance = workInProgress.stateNode;
6728 var shouldUpdate = void 0;
6729 if (instance === null) {
6730 if (current$$1 !== null) {
6731 // An class component without an instance only mounts if it suspended
6732 // inside a non- concurrent tree, in an inconsistent state. We want to
6733 // tree it like a new mount, even though an empty version of it already
6734 // committed. Disconnect the alternate pointers.
6735 current$$1.alternate = null;
6736 workInProgress.alternate = null;
6737 // Since this is conceptually a new fiber, schedule a Placement effect
6738 workInProgress.effectTag |= Placement;
6739 }
6740 // In the initial pass we might need to construct the instance.
6741 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6742 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6743 shouldUpdate = true;
6744 } else if (current$$1 === null) {
6745 // In a resume, we'll already have an instance we can reuse.
6746 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6747 } else {
6748 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6749 }
6750 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
6751 {
6752 var inst = workInProgress.stateNode;
6753 if (inst.props !== nextProps) {
6754 !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;
6755 didWarnAboutReassigningProps = true;
6756 }
6757 }
6758 return nextUnitOfWork;
6759}
6760
6761function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
6762 // Refs should update even if shouldComponentUpdate returns false
6763 markRef(current$$1, workInProgress);
6764
6765 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
6766
6767 if (!shouldUpdate && !didCaptureError) {
6768 // Context providers should defer to sCU for rendering
6769 if (hasContext) {
6770 invalidateContextProvider(workInProgress, Component, false);
6771 }
6772
6773 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6774 }
6775
6776 var instance = workInProgress.stateNode;
6777
6778 // Rerender
6779 ReactCurrentOwner$2.current = workInProgress;
6780 var nextChildren = void 0;
6781 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
6782 // If we captured an error, but getDerivedStateFrom catch is not defined,
6783 // unmount all the children. componentDidCatch will schedule an update to
6784 // re-render a fallback. This is temporary until we migrate everyone to
6785 // the new API.
6786 // TODO: Warn in a future release.
6787 nextChildren = null;
6788
6789 if (enableProfilerTimer) {
6790 stopProfilerTimerIfRunning(workInProgress);
6791 }
6792 } else {
6793 {
6794 setCurrentPhase('render');
6795 nextChildren = instance.render();
6796 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6797 instance.render();
6798 }
6799 setCurrentPhase(null);
6800 }
6801 }
6802
6803 // React DevTools reads this flag.
6804 workInProgress.effectTag |= PerformedWork;
6805 if (current$$1 !== null && didCaptureError) {
6806 // If we're recovering from an error, reconcile without reusing any of
6807 // the existing children. Conceptually, the normal children and the children
6808 // that are shown on error are two different sets, so we shouldn't reuse
6809 // normal children even if their identities match.
6810 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
6811 } else {
6812 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6813 }
6814
6815 // Memoize state using the values we just used to render.
6816 // TODO: Restructure so we never read values from the instance.
6817 workInProgress.memoizedState = instance.state;
6818
6819 // The context might have changed so we need to recalculate it.
6820 if (hasContext) {
6821 invalidateContextProvider(workInProgress, Component, true);
6822 }
6823
6824 return workInProgress.child;
6825}
6826
6827function pushHostRootContext(workInProgress) {
6828 var root = workInProgress.stateNode;
6829 if (root.pendingContext) {
6830 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
6831 } else if (root.context) {
6832 // Should always be set
6833 pushTopLevelContextObject(workInProgress, root.context, false);
6834 }
6835 pushHostContainer(workInProgress, root.containerInfo);
6836}
6837
6838function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
6839 pushHostRootContext(workInProgress);
6840 var updateQueue = workInProgress.updateQueue;
6841 !(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;
6842 var nextProps = workInProgress.pendingProps;
6843 var prevState = workInProgress.memoizedState;
6844 var prevChildren = prevState !== null ? prevState.element : null;
6845 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
6846 var nextState = workInProgress.memoizedState;
6847 // Caution: React DevTools currently depends on this property
6848 // being called "element".
6849 var nextChildren = nextState.element;
6850 if (nextChildren === prevChildren) {
6851 // If the state is the same as before, that's a bailout because we had
6852 // no work that expires at this time.
6853 resetHydrationState();
6854 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6855 }
6856 var root = workInProgress.stateNode;
6857 if ((current$$1 === null || current$$1.child === null) && root.hydrate && enterHydrationState(workInProgress)) {
6858 // If we don't have any current children this might be the first pass.
6859 // We always try to hydrate. If this isn't a hydration pass there won't
6860 // be any children to hydrate which is effectively the same thing as
6861 // not hydrating.
6862
6863 // This is a bit of a hack. We track the host root as a placement to
6864 // know that we're currently in a mounting state. That way isMounted
6865 // works as expected. We must reset this before committing.
6866 // TODO: Delete this when we delete isMounted and findDOMNode.
6867 workInProgress.effectTag |= Placement;
6868
6869 // Ensure that children mount into this root without tracking
6870 // side-effects. This ensures that we don't store Placement effects on
6871 // nodes that will be hydrated.
6872 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6873 } else {
6874 // Otherwise reset hydration state in case we aborted and resumed another
6875 // root.
6876 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6877 resetHydrationState();
6878 }
6879 return workInProgress.child;
6880}
6881
6882function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
6883 pushHostContext(workInProgress);
6884
6885 if (current$$1 === null) {
6886 tryToClaimNextHydratableInstance(workInProgress);
6887 }
6888
6889 var type = workInProgress.type;
6890 var nextProps = workInProgress.pendingProps;
6891 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
6892
6893 var nextChildren = nextProps.children;
6894 var isDirectTextChild = shouldSetTextContent(type, nextProps);
6895
6896 if (isDirectTextChild) {
6897 // We special case a direct text child of a host node. This is a common
6898 // case. We won't handle it as a reified child. We will instead handle
6899 // this in the host environment that also have access to this prop. That
6900 // avoids allocating another HostText fiber and traversing it.
6901 nextChildren = null;
6902 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
6903 // If we're switching from a direct text child to a normal child, or to
6904 // empty, we need to schedule the text content to be reset.
6905 workInProgress.effectTag |= ContentReset;
6906 }
6907
6908 markRef(current$$1, workInProgress);
6909
6910 // Check the host config to see if the children are offscreen/hidden.
6911 if (renderExpirationTime !== Never && workInProgress.mode & ConcurrentMode && shouldDeprioritizeSubtree(type, nextProps)) {
6912 // Schedule this fiber to re-render at offscreen priority. Then bailout.
6913 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
6914 return null;
6915 }
6916
6917 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6918 return workInProgress.child;
6919}
6920
6921function updateHostText(current$$1, workInProgress) {
6922 if (current$$1 === null) {
6923 tryToClaimNextHydratableInstance(workInProgress);
6924 }
6925 // Nothing to do here. This is terminal. We'll do the completion step
6926 // immediately after.
6927 return null;
6928}
6929
6930function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
6931 if (_current !== null) {
6932 // An lazy component only mounts if it suspended inside a non-
6933 // concurrent tree, in an inconsistent state. We want to treat it like
6934 // a new mount, even though an empty version of it already committed.
6935 // Disconnect the alternate pointers.
6936 _current.alternate = null;
6937 workInProgress.alternate = null;
6938 // Since this is conceptually a new fiber, schedule a Placement effect
6939 workInProgress.effectTag |= Placement;
6940 }
6941
6942 var props = workInProgress.pendingProps;
6943 // We can't start a User Timing measurement with correct label yet.
6944 // Cancel and resume right after we know the tag.
6945 cancelWorkTimer(workInProgress);
6946 var Component = readLazyComponentType(elementType);
6947 // Store the unwrapped component in the type.
6948 workInProgress.type = Component;
6949 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
6950 startWorkTimer(workInProgress);
6951 var resolvedProps = resolveDefaultProps(Component, props);
6952 var child = void 0;
6953 switch (resolvedTag) {
6954 case FunctionComponent:
6955 {
6956 {
6957 validateFunctionComponentInDev(workInProgress, Component);
6958 }
6959 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
6960 break;
6961 }
6962 case ClassComponent:
6963 {
6964 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
6965 break;
6966 }
6967 case ForwardRef:
6968 {
6969 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
6970 break;
6971 }
6972 case MemoComponent:
6973 {
6974 {
6975 if (workInProgress.type !== workInProgress.elementType) {
6976 var outerPropTypes = Component.propTypes;
6977 if (outerPropTypes) {
6978 checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
6979 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6980 }
6981 }
6982 }
6983 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
6984 updateExpirationTime, renderExpirationTime);
6985 break;
6986 }
6987 default:
6988 {
6989 var hint = '';
6990 {
6991 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
6992 hint = ' Did you wrap a component in React.lazy() more than once?';
6993 }
6994 }
6995 // This message intentionally doesn't mention ForwardRef or MemoComponent
6996 // because the fact that it's a separate type of work is an
6997 // implementation detail.
6998 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);
6999 }
7000 }
7001 return child;
7002}
7003
7004function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
7005 if (_current !== null) {
7006 // An incomplete component only mounts if it suspended inside a non-
7007 // concurrent tree, in an inconsistent state. We want to treat it like
7008 // a new mount, even though an empty version of it already committed.
7009 // Disconnect the alternate pointers.
7010 _current.alternate = null;
7011 workInProgress.alternate = null;
7012 // Since this is conceptually a new fiber, schedule a Placement effect
7013 workInProgress.effectTag |= Placement;
7014 }
7015
7016 // Promote the fiber to a class and try rendering again.
7017 workInProgress.tag = ClassComponent;
7018
7019 // The rest of this function is a fork of `updateClassComponent`
7020
7021 // Push context providers early to prevent context stack mismatches.
7022 // During mounting we don't know the child context yet as the instance doesn't exist.
7023 // We will invalidate the child context in finishClassComponent() right after rendering.
7024 var hasContext = void 0;
7025 if (isContextProvider(Component)) {
7026 hasContext = true;
7027 pushContextProvider(workInProgress);
7028 } else {
7029 hasContext = false;
7030 }
7031 prepareToReadContext(workInProgress, renderExpirationTime);
7032
7033 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7034 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7035
7036 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7037}
7038
7039function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
7040 if (_current !== null) {
7041 // An indeterminate component only mounts if it suspended inside a non-
7042 // concurrent tree, in an inconsistent state. We want to treat it like
7043 // a new mount, even though an empty version of it already committed.
7044 // Disconnect the alternate pointers.
7045 _current.alternate = null;
7046 workInProgress.alternate = null;
7047 // Since this is conceptually a new fiber, schedule a Placement effect
7048 workInProgress.effectTag |= Placement;
7049 }
7050
7051 var props = workInProgress.pendingProps;
7052 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
7053 var context = getMaskedContext(workInProgress, unmaskedContext);
7054
7055 prepareToReadContext(workInProgress, renderExpirationTime);
7056
7057 var value = void 0;
7058
7059 {
7060 if (Component.prototype && typeof Component.prototype.render === 'function') {
7061 var componentName = getComponentName(Component) || 'Unknown';
7062
7063 if (!didWarnAboutBadClass[componentName]) {
7064 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);
7065 didWarnAboutBadClass[componentName] = true;
7066 }
7067 }
7068
7069 if (workInProgress.mode & StrictMode) {
7070 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
7071 }
7072
7073 ReactCurrentOwner$2.current = workInProgress;
7074 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7075 }
7076 // React DevTools reads this flag.
7077 workInProgress.effectTag |= PerformedWork;
7078
7079 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
7080 // Proceed under the assumption that this is a class instance
7081 workInProgress.tag = ClassComponent;
7082
7083 // Throw out any hooks that were used.
7084 resetHooks();
7085
7086 // Push context providers early to prevent context stack mismatches.
7087 // During mounting we don't know the child context yet as the instance doesn't exist.
7088 // We will invalidate the child context in finishClassComponent() right after rendering.
7089 var hasContext = false;
7090 if (isContextProvider(Component)) {
7091 hasContext = true;
7092 pushContextProvider(workInProgress);
7093 } else {
7094 hasContext = false;
7095 }
7096
7097 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
7098
7099 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
7100 if (typeof getDerivedStateFromProps === 'function') {
7101 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
7102 }
7103
7104 adoptClassInstance(workInProgress, value);
7105 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
7106 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7107 } else {
7108 // Proceed under the assumption that this is a function component
7109 workInProgress.tag = FunctionComponent;
7110 {
7111 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
7112 // Only double-render components with Hooks
7113 if (workInProgress.memoizedState !== null) {
7114 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7115 }
7116 }
7117 }
7118 reconcileChildren(null, workInProgress, value, renderExpirationTime);
7119 {
7120 validateFunctionComponentInDev(workInProgress, Component);
7121 }
7122 return workInProgress.child;
7123 }
7124}
7125
7126function validateFunctionComponentInDev(workInProgress, Component) {
7127 if (Component) {
7128 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
7129 }
7130 if (workInProgress.ref !== null) {
7131 var info = '';
7132 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
7133 if (ownerName) {
7134 info += '\n\nCheck the render method of `' + ownerName + '`.';
7135 }
7136
7137 var warningKey = ownerName || workInProgress._debugID || '';
7138 var debugSource = workInProgress._debugSource;
7139 if (debugSource) {
7140 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
7141 }
7142 if (!didWarnAboutFunctionRefs[warningKey]) {
7143 didWarnAboutFunctionRefs[warningKey] = true;
7144 warning$1(false, 'Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
7145 }
7146 }
7147
7148 if (typeof Component.getDerivedStateFromProps === 'function') {
7149 var componentName = getComponentName(Component) || 'Unknown';
7150
7151 if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) {
7152 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', componentName);
7153 didWarnAboutGetDerivedStateOnFunctionComponent[componentName] = true;
7154 }
7155 }
7156
7157 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
7158 var _componentName = getComponentName(Component) || 'Unknown';
7159
7160 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName]) {
7161 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName);
7162 didWarnAboutContextTypeOnFunctionComponent[_componentName] = true;
7163 }
7164 }
7165}
7166
7167function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7168 var mode = workInProgress.mode;
7169 var nextProps = workInProgress.pendingProps;
7170
7171 // We should attempt to render the primary children unless this boundary
7172 // already suspended during this render (`alreadyCaptured` is true).
7173 var nextState = workInProgress.memoizedState;
7174
7175 var nextDidTimeout = void 0;
7176 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7177 // This is the first attempt.
7178 nextState = null;
7179 nextDidTimeout = false;
7180 } else {
7181 // Something in this boundary's subtree already suspended. Switch to
7182 // rendering the fallback children.
7183 nextState = {
7184 timedOutAt: nextState !== null ? nextState.timedOutAt : NoWork
7185 };
7186 nextDidTimeout = true;
7187 workInProgress.effectTag &= ~DidCapture;
7188 }
7189
7190 // This next part is a bit confusing. If the children timeout, we switch to
7191 // showing the fallback children in place of the "primary" children.
7192 // However, we don't want to delete the primary children because then their
7193 // state will be lost (both the React state and the host state, e.g.
7194 // uncontrolled form inputs). Instead we keep them mounted and hide them.
7195 // Both the fallback children AND the primary children are rendered at the
7196 // same time. Once the primary children are un-suspended, we can delete
7197 // the fallback children — don't need to preserve their state.
7198 //
7199 // The two sets of children are siblings in the host environment, but
7200 // semantically, for purposes of reconciliation, they are two separate sets.
7201 // So we store them using two fragment fibers.
7202 //
7203 // However, we want to avoid allocating extra fibers for every placeholder.
7204 // They're only necessary when the children time out, because that's the
7205 // only time when both sets are mounted.
7206 //
7207 // So, the extra fragment fibers are only used if the children time out.
7208 // Otherwise, we render the primary children directly. This requires some
7209 // custom reconciliation logic to preserve the state of the primary
7210 // children. It's essentially a very basic form of re-parenting.
7211
7212 // `child` points to the child fiber. In the normal case, this is the first
7213 // fiber of the primary children set. In the timed-out case, it's a
7214 // a fragment fiber containing the primary children.
7215 var child = void 0;
7216 // `next` points to the next fiber React should render. In the normal case,
7217 // it's the same as `child`: the first fiber of the primary children set.
7218 // In the timed-out case, it's a fragment fiber containing the *fallback*
7219 // children -- we skip over the primary children entirely.
7220 var next = void 0;
7221 if (current$$1 === null) {
7222 if (enableSuspenseServerRenderer) {
7223 // If we're currently hydrating, try to hydrate this boundary.
7224 // But only if this has a fallback.
7225 if (nextProps.fallback !== undefined) {
7226 tryToClaimNextHydratableInstance(workInProgress);
7227 // This could've changed the tag if this was a dehydrated suspense component.
7228 if (workInProgress.tag === DehydratedSuspenseComponent) {
7229 return updateDehydratedSuspenseComponent(null, workInProgress, renderExpirationTime);
7230 }
7231 }
7232 }
7233
7234 // This is the initial mount. This branch is pretty simple because there's
7235 // no previous state that needs to be preserved.
7236 if (nextDidTimeout) {
7237 // Mount separate fragments for primary and fallback children.
7238 var nextFallbackChildren = nextProps.fallback;
7239 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
7240
7241 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7242 // Outside of concurrent mode, we commit the effects from the
7243 var progressedState = workInProgress.memoizedState;
7244 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
7245 primaryChildFragment.child = progressedPrimaryChild;
7246 }
7247
7248 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
7249 primaryChildFragment.sibling = fallbackChildFragment;
7250 child = primaryChildFragment;
7251 // Skip the primary children, and continue working on the
7252 // fallback children.
7253 next = fallbackChildFragment;
7254 child.return = next.return = workInProgress;
7255 } else {
7256 // Mount the primary children without an intermediate fragment fiber.
7257 var nextPrimaryChildren = nextProps.children;
7258 child = next = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
7259 }
7260 } else {
7261 // This is an update. This branch is more complicated because we need to
7262 // ensure the state of the primary children is preserved.
7263 var prevState = current$$1.memoizedState;
7264 var prevDidTimeout = prevState !== null;
7265 if (prevDidTimeout) {
7266 // The current tree already timed out. That means each child set is
7267 var currentPrimaryChildFragment = current$$1.child;
7268 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
7269 if (nextDidTimeout) {
7270 // Still timed out. Reuse the current primary children by cloning
7271 // its fragment. We're going to skip over these entirely.
7272 var _nextFallbackChildren = nextProps.fallback;
7273 var _primaryChildFragment = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
7274
7275 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7276 // Outside of concurrent mode, we commit the effects from the
7277 var _progressedState = workInProgress.memoizedState;
7278 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
7279 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
7280 _primaryChildFragment.child = _progressedPrimaryChild;
7281 }
7282 }
7283
7284 // Because primaryChildFragment is a new fiber that we're inserting as the
7285 // parent of a new tree, we need to set its treeBaseDuration.
7286 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7287 // treeBaseDuration is the sum of all the child tree base durations.
7288 var treeBaseDuration = 0;
7289 var hiddenChild = _primaryChildFragment.child;
7290 while (hiddenChild !== null) {
7291 treeBaseDuration += hiddenChild.treeBaseDuration;
7292 hiddenChild = hiddenChild.sibling;
7293 }
7294 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
7295 }
7296
7297 // Clone the fallback child fragment, too. These we'll continue
7298 // working on.
7299 var _fallbackChildFragment = _primaryChildFragment.sibling = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren, currentFallbackChildFragment.expirationTime);
7300 child = _primaryChildFragment;
7301 _primaryChildFragment.childExpirationTime = NoWork;
7302 // Skip the primary children, and continue working on the
7303 // fallback children.
7304 next = _fallbackChildFragment;
7305 child.return = next.return = workInProgress;
7306 } else {
7307 // No longer suspended. Switch back to showing the primary children,
7308 // and remove the intermediate fragment fiber.
7309 var _nextPrimaryChildren = nextProps.children;
7310 var currentPrimaryChild = currentPrimaryChildFragment.child;
7311 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime);
7312
7313 // If this render doesn't suspend, we need to delete the fallback
7314 // children. Wait until the complete phase, after we've confirmed the
7315 // fallback is no longer needed.
7316 // TODO: Would it be better to store the fallback fragment on
7317 // the stateNode?
7318
7319 // Continue rendering the children, like we normally do.
7320 child = next = primaryChild;
7321 }
7322 } else {
7323 // The current tree has not already timed out. That means the primary
7324 // children are not wrapped in a fragment fiber.
7325 var _currentPrimaryChild = current$$1.child;
7326 if (nextDidTimeout) {
7327 // Timed out. Wrap the children in a fragment fiber to keep them
7328 // separate from the fallback children.
7329 var _nextFallbackChildren2 = nextProps.fallback;
7330 var _primaryChildFragment2 = createFiberFromFragment(
7331 // It shouldn't matter what the pending props are because we aren't
7332 // going to render this fragment.
7333 null, mode, NoWork, null);
7334 _primaryChildFragment2.child = _currentPrimaryChild;
7335
7336 // Even though we're creating a new fiber, there are no new children,
7337 // because we're reusing an already mounted tree. So we don't need to
7338 // schedule a placement.
7339 // primaryChildFragment.effectTag |= Placement;
7340
7341 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7342 // Outside of concurrent mode, we commit the effects from the
7343 var _progressedState2 = workInProgress.memoizedState;
7344 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
7345 _primaryChildFragment2.child = _progressedPrimaryChild2;
7346 }
7347
7348 // Because primaryChildFragment is a new fiber that we're inserting as the
7349 // parent of a new tree, we need to set its treeBaseDuration.
7350 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7351 // treeBaseDuration is the sum of all the child tree base durations.
7352 var _treeBaseDuration = 0;
7353 var _hiddenChild = _primaryChildFragment2.child;
7354 while (_hiddenChild !== null) {
7355 _treeBaseDuration += _hiddenChild.treeBaseDuration;
7356 _hiddenChild = _hiddenChild.sibling;
7357 }
7358 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
7359 }
7360
7361 // Create a fragment from the fallback children, too.
7362 var _fallbackChildFragment2 = _primaryChildFragment2.sibling = createFiberFromFragment(_nextFallbackChildren2, mode, renderExpirationTime, null);
7363 _fallbackChildFragment2.effectTag |= Placement;
7364 child = _primaryChildFragment2;
7365 _primaryChildFragment2.childExpirationTime = NoWork;
7366 // Skip the primary children, and continue working on the
7367 // fallback children.
7368 next = _fallbackChildFragment2;
7369 child.return = next.return = workInProgress;
7370 } else {
7371 // Still haven't timed out. Continue rendering the children, like we
7372 // normally do.
7373 var _nextPrimaryChildren2 = nextProps.children;
7374 next = child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
7375 }
7376 }
7377 workInProgress.stateNode = current$$1.stateNode;
7378 }
7379
7380 workInProgress.memoizedState = nextState;
7381 workInProgress.child = child;
7382 return next;
7383}
7384
7385function updateDehydratedSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7386 if (current$$1 === null) {
7387 // During the first pass, we'll bail out and not drill into the children.
7388 // Instead, we'll leave the content in place and try to hydrate it later.
7389 workInProgress.expirationTime = Never;
7390 return null;
7391 }
7392 // We use childExpirationTime to indicate that a child might depend on context, so if
7393 // any context has changed, we need to treat is as if the input might have changed.
7394 var hasContextChanged$$1 = current$$1.childExpirationTime >= renderExpirationTime;
7395 if (didReceiveUpdate || hasContextChanged$$1) {
7396 // This boundary has changed since the first render. This means that we are now unable to
7397 // hydrate it. We might still be able to hydrate it using an earlier expiration time but
7398 // during this render we can't. Instead, we're going to delete the whole subtree and
7399 // instead inject a new real Suspense boundary to take its place, which may render content
7400 // or fallback. The real Suspense boundary will suspend for a while so we have some time
7401 // to ensure it can produce real content, but all state and pending events will be lost.
7402
7403 // Detach from the current dehydrated boundary.
7404 current$$1.alternate = null;
7405 workInProgress.alternate = null;
7406
7407 // Insert a deletion in the effect list.
7408 var returnFiber = workInProgress.return;
7409 !(returnFiber !== null) ? invariant(false, 'Suspense boundaries are never on the root. This is probably a bug in React.') : void 0;
7410 var last = returnFiber.lastEffect;
7411 if (last !== null) {
7412 last.nextEffect = current$$1;
7413 returnFiber.lastEffect = current$$1;
7414 } else {
7415 returnFiber.firstEffect = returnFiber.lastEffect = current$$1;
7416 }
7417 current$$1.nextEffect = null;
7418 current$$1.effectTag = Deletion;
7419
7420 // Upgrade this work in progress to a real Suspense component.
7421 workInProgress.tag = SuspenseComponent;
7422 workInProgress.stateNode = null;
7423 workInProgress.memoizedState = null;
7424 // This is now an insertion.
7425 workInProgress.effectTag |= Placement;
7426 // Retry as a real Suspense component.
7427 return updateSuspenseComponent(null, workInProgress, renderExpirationTime);
7428 }
7429 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7430 // This is the first attempt.
7431 reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress);
7432 var nextProps = workInProgress.pendingProps;
7433 var nextChildren = nextProps.children;
7434 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7435 return workInProgress.child;
7436 } else {
7437 // Something suspended. Leave the existing children in place.
7438 // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far?
7439 workInProgress.child = null;
7440 return null;
7441 }
7442}
7443
7444function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
7445 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7446 var nextChildren = workInProgress.pendingProps;
7447 if (current$$1 === null) {
7448 // Portals are special because we don't append the children during mount
7449 // but at commit. Therefore we need to track insertions which the normal
7450 // flow doesn't do during mount. This doesn't happen at the root because
7451 // the root always starts with a "current" with a null child.
7452 // TODO: Consider unifying this with how the root works.
7453 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7454 } else {
7455 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7456 }
7457 return workInProgress.child;
7458}
7459
7460function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
7461 var providerType = workInProgress.type;
7462 var context = providerType._context;
7463
7464 var newProps = workInProgress.pendingProps;
7465 var oldProps = workInProgress.memoizedProps;
7466
7467 var newValue = newProps.value;
7468
7469 {
7470 var providerPropTypes = workInProgress.type.propTypes;
7471
7472 if (providerPropTypes) {
7473 checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
7474 }
7475 }
7476
7477 pushProvider(workInProgress, newValue);
7478
7479 if (oldProps !== null) {
7480 var oldValue = oldProps.value;
7481 var changedBits = calculateChangedBits(context, newValue, oldValue);
7482 if (changedBits === 0) {
7483 // No change. Bailout early if children are the same.
7484 if (oldProps.children === newProps.children && !hasContextChanged()) {
7485 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7486 }
7487 } else {
7488 // The context value changed. Search for matching consumers and schedule
7489 // them to update.
7490 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
7491 }
7492 }
7493
7494 var newChildren = newProps.children;
7495 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7496 return workInProgress.child;
7497}
7498
7499var hasWarnedAboutUsingContextAsConsumer = false;
7500
7501function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
7502 var context = workInProgress.type;
7503 // The logic below for Context differs depending on PROD or DEV mode. In
7504 // DEV mode, we create a separate object for Context.Consumer that acts
7505 // like a proxy to Context. This proxy object adds unnecessary code in PROD
7506 // so we use the old behaviour (Context.Consumer references Context) to
7507 // reduce size and overhead. The separate object references context via
7508 // a property called "_context", which also gives us the ability to check
7509 // in DEV mode if this property exists or not and warn if it does not.
7510 {
7511 if (context._context === undefined) {
7512 // This may be because it's a Context (rather than a Consumer).
7513 // Or it may be because it's older React where they're the same thing.
7514 // We only want to warn if we're sure it's a new React.
7515 if (context !== context.Consumer) {
7516 if (!hasWarnedAboutUsingContextAsConsumer) {
7517 hasWarnedAboutUsingContextAsConsumer = true;
7518 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?');
7519 }
7520 }
7521 } else {
7522 context = context._context;
7523 }
7524 }
7525 var newProps = workInProgress.pendingProps;
7526 var render = newProps.children;
7527
7528 {
7529 !(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;
7530 }
7531
7532 prepareToReadContext(workInProgress, renderExpirationTime);
7533 var newValue = readContext(context, newProps.unstable_observedBits);
7534 var newChildren = void 0;
7535 {
7536 ReactCurrentOwner$2.current = workInProgress;
7537 setCurrentPhase('render');
7538 newChildren = render(newValue);
7539 setCurrentPhase(null);
7540 }
7541
7542 // React DevTools reads this flag.
7543 workInProgress.effectTag |= PerformedWork;
7544 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7545 return workInProgress.child;
7546}
7547
7548function markWorkInProgressReceivedUpdate() {
7549 didReceiveUpdate = true;
7550}
7551
7552function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
7553 cancelWorkTimer(workInProgress);
7554
7555 if (current$$1 !== null) {
7556 // Reuse previous context list
7557 workInProgress.contextDependencies = current$$1.contextDependencies;
7558 }
7559
7560 if (enableProfilerTimer) {
7561 // Don't update "base" render times for bailouts.
7562 stopProfilerTimerIfRunning(workInProgress);
7563 }
7564
7565 // Check if the children have any pending work.
7566 var childExpirationTime = workInProgress.childExpirationTime;
7567 if (childExpirationTime < renderExpirationTime) {
7568 // The children don't have any work either. We can skip them.
7569 // TODO: Once we add back resuming, we should check if the children are
7570 // a work-in-progress set. If so, we need to transfer their effects.
7571 return null;
7572 } else {
7573 // This fiber doesn't have work, but its subtree does. Clone the child
7574 // fibers and continue.
7575 cloneChildFibers(current$$1, workInProgress);
7576 return workInProgress.child;
7577 }
7578}
7579
7580function beginWork(current$$1, workInProgress, renderExpirationTime) {
7581 var updateExpirationTime = workInProgress.expirationTime;
7582
7583 if (current$$1 !== null) {
7584 var oldProps = current$$1.memoizedProps;
7585 var newProps = workInProgress.pendingProps;
7586
7587 if (oldProps !== newProps || hasContextChanged()) {
7588 // If props or context changed, mark the fiber as having performed work.
7589 // This may be unset if the props are determined to be equal later (memo).
7590 didReceiveUpdate = true;
7591 } else if (updateExpirationTime < renderExpirationTime) {
7592 didReceiveUpdate = false;
7593 // This fiber does not have any pending work. Bailout without entering
7594 // the begin phase. There's still some bookkeeping we that needs to be done
7595 // in this optimized path, mostly pushing stuff onto the stack.
7596 switch (workInProgress.tag) {
7597 case HostRoot:
7598 pushHostRootContext(workInProgress);
7599 resetHydrationState();
7600 break;
7601 case HostComponent:
7602 pushHostContext(workInProgress);
7603 break;
7604 case ClassComponent:
7605 {
7606 var Component = workInProgress.type;
7607 if (isContextProvider(Component)) {
7608 pushContextProvider(workInProgress);
7609 }
7610 break;
7611 }
7612 case HostPortal:
7613 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7614 break;
7615 case ContextProvider:
7616 {
7617 var newValue = workInProgress.memoizedProps.value;
7618 pushProvider(workInProgress, newValue);
7619 break;
7620 }
7621 case Profiler:
7622 if (enableProfilerTimer) {
7623 workInProgress.effectTag |= Update;
7624 }
7625 break;
7626 case SuspenseComponent:
7627 {
7628 var state = workInProgress.memoizedState;
7629 var didTimeout = state !== null;
7630 if (didTimeout) {
7631 // If this boundary is currently timed out, we need to decide
7632 // whether to retry the primary children, or to skip over it and
7633 // go straight to the fallback. Check the priority of the primary
7634 var primaryChildFragment = workInProgress.child;
7635 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
7636 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
7637 // The primary children have pending work. Use the normal path
7638 // to attempt to render the primary children again.
7639 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7640 } else {
7641 // The primary children do not have pending work with sufficient
7642 // priority. Bailout.
7643 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7644 if (child !== null) {
7645 // The fallback children have pending work. Skip over the
7646 // primary children and work on the fallback.
7647 return child.sibling;
7648 } else {
7649 return null;
7650 }
7651 }
7652 }
7653 break;
7654 }
7655 case DehydratedSuspenseComponent:
7656 {
7657 if (enableSuspenseServerRenderer) {
7658 // We know that this component will suspend again because if it has
7659 // been unsuspended it has committed as a regular Suspense component.
7660 // If it needs to be retried, it should have work scheduled on it.
7661 workInProgress.effectTag |= DidCapture;
7662 break;
7663 }
7664 }
7665 }
7666 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7667 }
7668 } else {
7669 didReceiveUpdate = false;
7670 }
7671
7672 // Before entering the begin phase, clear the expiration time.
7673 workInProgress.expirationTime = NoWork;
7674
7675 switch (workInProgress.tag) {
7676 case IndeterminateComponent:
7677 {
7678 var elementType = workInProgress.elementType;
7679 return mountIndeterminateComponent(current$$1, workInProgress, elementType, renderExpirationTime);
7680 }
7681 case LazyComponent:
7682 {
7683 var _elementType = workInProgress.elementType;
7684 return mountLazyComponent(current$$1, workInProgress, _elementType, updateExpirationTime, renderExpirationTime);
7685 }
7686 case FunctionComponent:
7687 {
7688 var _Component = workInProgress.type;
7689 var unresolvedProps = workInProgress.pendingProps;
7690 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
7691 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
7692 }
7693 case ClassComponent:
7694 {
7695 var _Component2 = workInProgress.type;
7696 var _unresolvedProps = workInProgress.pendingProps;
7697 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
7698 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
7699 }
7700 case HostRoot:
7701 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
7702 case HostComponent:
7703 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
7704 case HostText:
7705 return updateHostText(current$$1, workInProgress);
7706 case SuspenseComponent:
7707 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7708 case HostPortal:
7709 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
7710 case ForwardRef:
7711 {
7712 var type = workInProgress.type;
7713 var _unresolvedProps2 = workInProgress.pendingProps;
7714 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
7715 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
7716 }
7717 case Fragment:
7718 return updateFragment(current$$1, workInProgress, renderExpirationTime);
7719 case Mode:
7720 return updateMode(current$$1, workInProgress, renderExpirationTime);
7721 case Profiler:
7722 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
7723 case ContextProvider:
7724 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
7725 case ContextConsumer:
7726 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
7727 case MemoComponent:
7728 {
7729 var _type2 = workInProgress.type;
7730 var _unresolvedProps3 = workInProgress.pendingProps;
7731 // Resolve outer props first, then resolve inner props.
7732 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
7733 {
7734 if (workInProgress.type !== workInProgress.elementType) {
7735 var outerPropTypes = _type2.propTypes;
7736 if (outerPropTypes) {
7737 checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
7738 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
7739 }
7740 }
7741 }
7742 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
7743 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
7744 }
7745 case SimpleMemoComponent:
7746 {
7747 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
7748 }
7749 case IncompleteClassComponent:
7750 {
7751 var _Component3 = workInProgress.type;
7752 var _unresolvedProps4 = workInProgress.pendingProps;
7753 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
7754 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
7755 }
7756 case DehydratedSuspenseComponent:
7757 {
7758 if (enableSuspenseServerRenderer) {
7759 return updateDehydratedSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7760 }
7761 break;
7762 }
7763 }
7764 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
7765}
7766
7767var valueCursor = createCursor(null);
7768
7769var rendererSigil = void 0;
7770{
7771 // Use this to detect multiple renderers using the same context
7772 rendererSigil = {};
7773}
7774
7775var currentlyRenderingFiber = null;
7776var lastContextDependency = null;
7777var lastContextWithAllBitsObserved = null;
7778
7779var isDisallowedContextReadInDEV = false;
7780
7781function resetContextDependences() {
7782 // This is called right before React yields execution, to ensure `readContext`
7783 // cannot be called outside the render phase.
7784 currentlyRenderingFiber = null;
7785 lastContextDependency = null;
7786 lastContextWithAllBitsObserved = null;
7787 {
7788 isDisallowedContextReadInDEV = false;
7789 }
7790}
7791
7792function enterDisallowedContextReadInDEV() {
7793 {
7794 isDisallowedContextReadInDEV = true;
7795 }
7796}
7797
7798function exitDisallowedContextReadInDEV() {
7799 {
7800 isDisallowedContextReadInDEV = false;
7801 }
7802}
7803
7804function pushProvider(providerFiber, nextValue) {
7805 var context = providerFiber.type._context;
7806
7807 if (isPrimaryRenderer) {
7808 push(valueCursor, context._currentValue, providerFiber);
7809
7810 context._currentValue = nextValue;
7811 {
7812 !(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;
7813 context._currentRenderer = rendererSigil;
7814 }
7815 } else {
7816 push(valueCursor, context._currentValue2, providerFiber);
7817
7818 context._currentValue2 = nextValue;
7819 {
7820 !(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;
7821 context._currentRenderer2 = rendererSigil;
7822 }
7823 }
7824}
7825
7826function popProvider(providerFiber) {
7827 var currentValue = valueCursor.current;
7828
7829 pop(valueCursor, providerFiber);
7830
7831 var context = providerFiber.type._context;
7832 if (isPrimaryRenderer) {
7833 context._currentValue = currentValue;
7834 } else {
7835 context._currentValue2 = currentValue;
7836 }
7837}
7838
7839function calculateChangedBits(context, newValue, oldValue) {
7840 if (is(oldValue, newValue)) {
7841 // No change
7842 return 0;
7843 } else {
7844 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : maxSigned31BitInt;
7845
7846 {
7847 !((changedBits & maxSigned31BitInt) === changedBits) ? warning$1(false, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits) : void 0;
7848 }
7849 return changedBits | 0;
7850 }
7851}
7852
7853function scheduleWorkOnParentPath(parent, renderExpirationTime) {
7854 // Update the child expiration time of all the ancestors, including
7855 // the alternates.
7856 var node = parent;
7857 while (node !== null) {
7858 var alternate = node.alternate;
7859 if (node.childExpirationTime < renderExpirationTime) {
7860 node.childExpirationTime = renderExpirationTime;
7861 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
7862 alternate.childExpirationTime = renderExpirationTime;
7863 }
7864 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
7865 alternate.childExpirationTime = renderExpirationTime;
7866 } else {
7867 // Neither alternate was updated, which means the rest of the
7868 // ancestor path already has sufficient priority.
7869 break;
7870 }
7871 node = node.return;
7872 }
7873}
7874
7875function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
7876 var fiber = workInProgress.child;
7877 if (fiber !== null) {
7878 // Set the return pointer of the child to the work-in-progress fiber.
7879 fiber.return = workInProgress;
7880 }
7881 while (fiber !== null) {
7882 var nextFiber = void 0;
7883
7884 // Visit this fiber.
7885 var list = fiber.contextDependencies;
7886 if (list !== null) {
7887 nextFiber = fiber.child;
7888
7889 var dependency = list.first;
7890 while (dependency !== null) {
7891 // Check if the context matches.
7892 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
7893 // Match! Schedule an update on this fiber.
7894
7895 if (fiber.tag === ClassComponent) {
7896 // Schedule a force update on the work-in-progress.
7897 var update = createUpdate(renderExpirationTime);
7898 update.tag = ForceUpdate;
7899 // TODO: Because we don't have a work-in-progress, this will add the
7900 // update to the current fiber, too, which means it will persist even if
7901 // this render is thrown away. Since it's a race condition, not sure it's
7902 // worth fixing.
7903 enqueueUpdate(fiber, update);
7904 }
7905
7906 if (fiber.expirationTime < renderExpirationTime) {
7907 fiber.expirationTime = renderExpirationTime;
7908 }
7909 var alternate = fiber.alternate;
7910 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
7911 alternate.expirationTime = renderExpirationTime;
7912 }
7913
7914 scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
7915
7916 // Mark the expiration time on the list, too.
7917 if (list.expirationTime < renderExpirationTime) {
7918 list.expirationTime = renderExpirationTime;
7919 }
7920
7921 // Since we already found a match, we can stop traversing the
7922 // dependency list.
7923 break;
7924 }
7925 dependency = dependency.next;
7926 }
7927 } else if (fiber.tag === ContextProvider) {
7928 // Don't scan deeper if this is a matching provider
7929 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
7930 } else if (enableSuspenseServerRenderer && fiber.tag === DehydratedSuspenseComponent) {
7931 // If a dehydrated suspense component is in this subtree, we don't know
7932 // if it will have any context consumers in it. The best we can do is
7933 // mark it as having updates on its children.
7934 if (fiber.expirationTime < renderExpirationTime) {
7935 fiber.expirationTime = renderExpirationTime;
7936 }
7937 var _alternate = fiber.alternate;
7938 if (_alternate !== null && _alternate.expirationTime < renderExpirationTime) {
7939 _alternate.expirationTime = renderExpirationTime;
7940 }
7941 // This is intentionally passing this fiber as the parent
7942 // because we want to schedule this fiber as having work
7943 // on its children. We'll use the childExpirationTime on
7944 // this fiber to indicate that a context has changed.
7945 scheduleWorkOnParentPath(fiber, renderExpirationTime);
7946 nextFiber = fiber.sibling;
7947 } else {
7948 // Traverse down.
7949 nextFiber = fiber.child;
7950 }
7951
7952 if (nextFiber !== null) {
7953 // Set the return pointer of the child to the work-in-progress fiber.
7954 nextFiber.return = fiber;
7955 } else {
7956 // No child. Traverse to next sibling.
7957 nextFiber = fiber;
7958 while (nextFiber !== null) {
7959 if (nextFiber === workInProgress) {
7960 // We're back to the root of this subtree. Exit.
7961 nextFiber = null;
7962 break;
7963 }
7964 var sibling = nextFiber.sibling;
7965 if (sibling !== null) {
7966 // Set the return pointer of the sibling to the work-in-progress fiber.
7967 sibling.return = nextFiber.return;
7968 nextFiber = sibling;
7969 break;
7970 }
7971 // No more siblings. Traverse up.
7972 nextFiber = nextFiber.return;
7973 }
7974 }
7975 fiber = nextFiber;
7976 }
7977}
7978
7979function prepareToReadContext(workInProgress, renderExpirationTime) {
7980 currentlyRenderingFiber = workInProgress;
7981 lastContextDependency = null;
7982 lastContextWithAllBitsObserved = null;
7983
7984 var currentDependencies = workInProgress.contextDependencies;
7985 if (currentDependencies !== null && currentDependencies.expirationTime >= renderExpirationTime) {
7986 // Context list has a pending update. Mark that this fiber performed work.
7987 markWorkInProgressReceivedUpdate();
7988 }
7989
7990 // Reset the work-in-progress list
7991 workInProgress.contextDependencies = null;
7992}
7993
7994function readContext(context, observedBits) {
7995 {
7996 // This warning would fire if you read context inside a Hook like useMemo.
7997 // Unlike the class check below, it's not enforced in production for perf.
7998 !!isDisallowedContextReadInDEV ? warning$1(false, 'Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().') : void 0;
7999 }
8000
8001 if (lastContextWithAllBitsObserved === context) {
8002 // Nothing to do. We already observe everything in this context.
8003 } else if (observedBits === false || observedBits === 0) {
8004 // Do not observe any updates.
8005 } else {
8006 var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types.
8007 if (typeof observedBits !== 'number' || observedBits === maxSigned31BitInt) {
8008 // Observe all updates.
8009 lastContextWithAllBitsObserved = context;
8010 resolvedObservedBits = maxSigned31BitInt;
8011 } else {
8012 resolvedObservedBits = observedBits;
8013 }
8014
8015 var contextItem = {
8016 context: context,
8017 observedBits: resolvedObservedBits,
8018 next: null
8019 };
8020
8021 if (lastContextDependency === null) {
8022 !(currentlyRenderingFiber !== null) ? invariant(false, 'Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo().') : void 0;
8023
8024 // This is the first dependency for this component. Create a new list.
8025 lastContextDependency = contextItem;
8026 currentlyRenderingFiber.contextDependencies = {
8027 first: contextItem,
8028 expirationTime: NoWork
8029 };
8030 } else {
8031 // Append a new context item.
8032 lastContextDependency = lastContextDependency.next = contextItem;
8033 }
8034 }
8035 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
8036}
8037
8038// UpdateQueue is a linked list of prioritized updates.
8039//
8040// Like fibers, update queues come in pairs: a current queue, which represents
8041// the visible state of the screen, and a work-in-progress queue, which can be
8042// mutated and processed asynchronously before it is committed — a form of
8043// double buffering. If a work-in-progress render is discarded before finishing,
8044// we create a new work-in-progress by cloning the current queue.
8045//
8046// Both queues share a persistent, singly-linked list structure. To schedule an
8047// update, we append it to the end of both queues. Each queue maintains a
8048// pointer to first update in the persistent list that hasn't been processed.
8049// The work-in-progress pointer always has a position equal to or greater than
8050// the current queue, since we always work on that one. The current queue's
8051// pointer is only updated during the commit phase, when we swap in the
8052// work-in-progress.
8053//
8054// For example:
8055//
8056// Current pointer: A - B - C - D - E - F
8057// Work-in-progress pointer: D - E - F
8058// ^
8059// The work-in-progress queue has
8060// processed more updates than current.
8061//
8062// The reason we append to both queues is because otherwise we might drop
8063// updates without ever processing them. For example, if we only add updates to
8064// the work-in-progress queue, some updates could be lost whenever a work-in
8065// -progress render restarts by cloning from current. Similarly, if we only add
8066// updates to the current queue, the updates will be lost whenever an already
8067// in-progress queue commits and swaps with the current queue. However, by
8068// adding to both queues, we guarantee that the update will be part of the next
8069// work-in-progress. (And because the work-in-progress queue becomes the
8070// current queue once it commits, there's no danger of applying the same
8071// update twice.)
8072//
8073// Prioritization
8074// --------------
8075//
8076// Updates are not sorted by priority, but by insertion; new updates are always
8077// appended to the end of the list.
8078//
8079// The priority is still important, though. When processing the update queue
8080// during the render phase, only the updates with sufficient priority are
8081// included in the result. If we skip an update because it has insufficient
8082// priority, it remains in the queue to be processed later, during a lower
8083// priority render. Crucially, all updates subsequent to a skipped update also
8084// remain in the queue *regardless of their priority*. That means high priority
8085// updates are sometimes processed twice, at two separate priorities. We also
8086// keep track of a base state, that represents the state before the first
8087// update in the queue is applied.
8088//
8089// For example:
8090//
8091// Given a base state of '', and the following queue of updates
8092//
8093// A1 - B2 - C1 - D2
8094//
8095// where the number indicates the priority, and the update is applied to the
8096// previous state by appending a letter, React will process these updates as
8097// two separate renders, one per distinct priority level:
8098//
8099// First render, at priority 1:
8100// Base state: ''
8101// Updates: [A1, C1]
8102// Result state: 'AC'
8103//
8104// Second render, at priority 2:
8105// Base state: 'A' <- The base state does not include C1,
8106// because B2 was skipped.
8107// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
8108// Result state: 'ABCD'
8109//
8110// Because we process updates in insertion order, and rebase high priority
8111// updates when preceding updates are skipped, the final result is deterministic
8112// regardless of priority. Intermediate state may vary according to system
8113// resources, but the final state is always the same.
8114
8115var UpdateState = 0;
8116var ReplaceState = 1;
8117var ForceUpdate = 2;
8118var CaptureUpdate = 3;
8119
8120// Global state that is reset at the beginning of calling `processUpdateQueue`.
8121// It should only be read right after calling `processUpdateQueue`, via
8122// `checkHasForceUpdateAfterProcessing`.
8123var hasForceUpdate = false;
8124
8125var didWarnUpdateInsideUpdate = void 0;
8126var currentlyProcessingQueue = void 0;
8127var resetCurrentlyProcessingQueue = void 0;
8128{
8129 didWarnUpdateInsideUpdate = false;
8130 currentlyProcessingQueue = null;
8131 resetCurrentlyProcessingQueue = function () {
8132 currentlyProcessingQueue = null;
8133 };
8134}
8135
8136function createUpdateQueue(baseState) {
8137 var queue = {
8138 baseState: baseState,
8139 firstUpdate: null,
8140 lastUpdate: null,
8141 firstCapturedUpdate: null,
8142 lastCapturedUpdate: null,
8143 firstEffect: null,
8144 lastEffect: null,
8145 firstCapturedEffect: null,
8146 lastCapturedEffect: null
8147 };
8148 return queue;
8149}
8150
8151function cloneUpdateQueue(currentQueue) {
8152 var queue = {
8153 baseState: currentQueue.baseState,
8154 firstUpdate: currentQueue.firstUpdate,
8155 lastUpdate: currentQueue.lastUpdate,
8156
8157 // TODO: With resuming, if we bail out and resuse the child tree, we should
8158 // keep these effects.
8159 firstCapturedUpdate: null,
8160 lastCapturedUpdate: null,
8161
8162 firstEffect: null,
8163 lastEffect: null,
8164
8165 firstCapturedEffect: null,
8166 lastCapturedEffect: null
8167 };
8168 return queue;
8169}
8170
8171function createUpdate(expirationTime) {
8172 return {
8173 expirationTime: expirationTime,
8174
8175 tag: UpdateState,
8176 payload: null,
8177 callback: null,
8178
8179 next: null,
8180 nextEffect: null
8181 };
8182}
8183
8184function appendUpdateToQueue(queue, update) {
8185 // Append the update to the end of the list.
8186 if (queue.lastUpdate === null) {
8187 // Queue is empty
8188 queue.firstUpdate = queue.lastUpdate = update;
8189 } else {
8190 queue.lastUpdate.next = update;
8191 queue.lastUpdate = update;
8192 }
8193}
8194
8195function enqueueUpdate(fiber, update) {
8196 // Update queues are created lazily.
8197 var alternate = fiber.alternate;
8198 var queue1 = void 0;
8199 var queue2 = void 0;
8200 if (alternate === null) {
8201 // There's only one fiber.
8202 queue1 = fiber.updateQueue;
8203 queue2 = null;
8204 if (queue1 === null) {
8205 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8206 }
8207 } else {
8208 // There are two owners.
8209 queue1 = fiber.updateQueue;
8210 queue2 = alternate.updateQueue;
8211 if (queue1 === null) {
8212 if (queue2 === null) {
8213 // Neither fiber has an update queue. Create new ones.
8214 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8215 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
8216 } else {
8217 // Only one fiber has an update queue. Clone to create a new one.
8218 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
8219 }
8220 } else {
8221 if (queue2 === null) {
8222 // Only one fiber has an update queue. Clone to create a new one.
8223 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
8224 } else {
8225 // Both owners have an update queue.
8226 }
8227 }
8228 }
8229 if (queue2 === null || queue1 === queue2) {
8230 // There's only a single queue.
8231 appendUpdateToQueue(queue1, update);
8232 } else {
8233 // There are two queues. We need to append the update to both queues,
8234 // while accounting for the persistent structure of the list — we don't
8235 // want the same update to be added multiple times.
8236 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
8237 // One of the queues is not empty. We must add the update to both queues.
8238 appendUpdateToQueue(queue1, update);
8239 appendUpdateToQueue(queue2, update);
8240 } else {
8241 // Both queues are non-empty. The last update is the same in both lists,
8242 // because of structural sharing. So, only append to one of the lists.
8243 appendUpdateToQueue(queue1, update);
8244 // But we still need to update the `lastUpdate` pointer of queue2.
8245 queue2.lastUpdate = update;
8246 }
8247 }
8248
8249 {
8250 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
8251 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.');
8252 didWarnUpdateInsideUpdate = true;
8253 }
8254 }
8255}
8256
8257function enqueueCapturedUpdate(workInProgress, update) {
8258 // Captured updates go into a separate list, and only on the work-in-
8259 // progress queue.
8260 var workInProgressQueue = workInProgress.updateQueue;
8261 if (workInProgressQueue === null) {
8262 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
8263 } else {
8264 // TODO: I put this here rather than createWorkInProgress so that we don't
8265 // clone the queue unnecessarily. There's probably a better way to
8266 // structure this.
8267 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
8268 }
8269
8270 // Append the update to the end of the list.
8271 if (workInProgressQueue.lastCapturedUpdate === null) {
8272 // This is the first render phase update
8273 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
8274 } else {
8275 workInProgressQueue.lastCapturedUpdate.next = update;
8276 workInProgressQueue.lastCapturedUpdate = update;
8277 }
8278}
8279
8280function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
8281 var current = workInProgress.alternate;
8282 if (current !== null) {
8283 // If the work-in-progress queue is equal to the current queue,
8284 // we need to clone it first.
8285 if (queue === current.updateQueue) {
8286 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
8287 }
8288 }
8289 return queue;
8290}
8291
8292function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
8293 switch (update.tag) {
8294 case ReplaceState:
8295 {
8296 var _payload = update.payload;
8297 if (typeof _payload === 'function') {
8298 // Updater function
8299 {
8300 enterDisallowedContextReadInDEV();
8301 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8302 _payload.call(instance, prevState, nextProps);
8303 }
8304 }
8305 var nextState = _payload.call(instance, prevState, nextProps);
8306 {
8307 exitDisallowedContextReadInDEV();
8308 }
8309 return nextState;
8310 }
8311 // State object
8312 return _payload;
8313 }
8314 case CaptureUpdate:
8315 {
8316 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
8317 }
8318 // Intentional fallthrough
8319 case UpdateState:
8320 {
8321 var _payload2 = update.payload;
8322 var partialState = void 0;
8323 if (typeof _payload2 === 'function') {
8324 // Updater function
8325 {
8326 enterDisallowedContextReadInDEV();
8327 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8328 _payload2.call(instance, prevState, nextProps);
8329 }
8330 }
8331 partialState = _payload2.call(instance, prevState, nextProps);
8332 {
8333 exitDisallowedContextReadInDEV();
8334 }
8335 } else {
8336 // Partial state object
8337 partialState = _payload2;
8338 }
8339 if (partialState === null || partialState === undefined) {
8340 // Null and undefined are treated as no-ops.
8341 return prevState;
8342 }
8343 // Merge the partial state and the previous state.
8344 return _assign({}, prevState, partialState);
8345 }
8346 case ForceUpdate:
8347 {
8348 hasForceUpdate = true;
8349 return prevState;
8350 }
8351 }
8352 return prevState;
8353}
8354
8355function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
8356 hasForceUpdate = false;
8357
8358 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
8359
8360 {
8361 currentlyProcessingQueue = queue;
8362 }
8363
8364 // These values may change as we process the queue.
8365 var newBaseState = queue.baseState;
8366 var newFirstUpdate = null;
8367 var newExpirationTime = NoWork;
8368
8369 // Iterate through the list of updates to compute the result.
8370 var update = queue.firstUpdate;
8371 var resultState = newBaseState;
8372 while (update !== null) {
8373 var updateExpirationTime = update.expirationTime;
8374 if (updateExpirationTime < renderExpirationTime) {
8375 // This update does not have sufficient priority. Skip it.
8376 if (newFirstUpdate === null) {
8377 // This is the first skipped update. It will be the first update in
8378 // the new list.
8379 newFirstUpdate = update;
8380 // Since this is the first update that was skipped, the current result
8381 // is the new base state.
8382 newBaseState = resultState;
8383 }
8384 // Since this update will remain in the list, update the remaining
8385 // expiration time.
8386 if (newExpirationTime < updateExpirationTime) {
8387 newExpirationTime = updateExpirationTime;
8388 }
8389 } else {
8390 // This update does have sufficient priority. Process it and compute
8391 // a new result.
8392 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8393 var _callback = update.callback;
8394 if (_callback !== null) {
8395 workInProgress.effectTag |= Callback;
8396 // Set this to null, in case it was mutated during an aborted render.
8397 update.nextEffect = null;
8398 if (queue.lastEffect === null) {
8399 queue.firstEffect = queue.lastEffect = update;
8400 } else {
8401 queue.lastEffect.nextEffect = update;
8402 queue.lastEffect = update;
8403 }
8404 }
8405 }
8406 // Continue to the next update.
8407 update = update.next;
8408 }
8409
8410 // Separately, iterate though the list of captured updates.
8411 var newFirstCapturedUpdate = null;
8412 update = queue.firstCapturedUpdate;
8413 while (update !== null) {
8414 var _updateExpirationTime = update.expirationTime;
8415 if (_updateExpirationTime < renderExpirationTime) {
8416 // This update does not have sufficient priority. Skip it.
8417 if (newFirstCapturedUpdate === null) {
8418 // This is the first skipped captured update. It will be the first
8419 // update in the new list.
8420 newFirstCapturedUpdate = update;
8421 // If this is the first update that was skipped, the current result is
8422 // the new base state.
8423 if (newFirstUpdate === null) {
8424 newBaseState = resultState;
8425 }
8426 }
8427 // Since this update will remain in the list, update the remaining
8428 // expiration time.
8429 if (newExpirationTime < _updateExpirationTime) {
8430 newExpirationTime = _updateExpirationTime;
8431 }
8432 } else {
8433 // This update does have sufficient priority. Process it and compute
8434 // a new result.
8435 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8436 var _callback2 = update.callback;
8437 if (_callback2 !== null) {
8438 workInProgress.effectTag |= Callback;
8439 // Set this to null, in case it was mutated during an aborted render.
8440 update.nextEffect = null;
8441 if (queue.lastCapturedEffect === null) {
8442 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
8443 } else {
8444 queue.lastCapturedEffect.nextEffect = update;
8445 queue.lastCapturedEffect = update;
8446 }
8447 }
8448 }
8449 update = update.next;
8450 }
8451
8452 if (newFirstUpdate === null) {
8453 queue.lastUpdate = null;
8454 }
8455 if (newFirstCapturedUpdate === null) {
8456 queue.lastCapturedUpdate = null;
8457 } else {
8458 workInProgress.effectTag |= Callback;
8459 }
8460 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
8461 // We processed every update, without skipping. That means the new base
8462 // state is the same as the result state.
8463 newBaseState = resultState;
8464 }
8465
8466 queue.baseState = newBaseState;
8467 queue.firstUpdate = newFirstUpdate;
8468 queue.firstCapturedUpdate = newFirstCapturedUpdate;
8469
8470 // Set the remaining expiration time to be whatever is remaining in the queue.
8471 // This should be fine because the only two other things that contribute to
8472 // expiration time are props and context. We're already in the middle of the
8473 // begin phase by the time we start processing the queue, so we've already
8474 // dealt with the props. Context in components that specify
8475 // shouldComponentUpdate is tricky; but we'll have to account for
8476 // that regardless.
8477 workInProgress.expirationTime = newExpirationTime;
8478 workInProgress.memoizedState = resultState;
8479
8480 {
8481 currentlyProcessingQueue = null;
8482 }
8483}
8484
8485function callCallback(callback, context) {
8486 !(typeof callback === 'function') ? invariant(false, 'Invalid argument passed as callback. Expected a function. Instead received: %s', callback) : void 0;
8487 callback.call(context);
8488}
8489
8490function resetHasForceUpdateBeforeProcessing() {
8491 hasForceUpdate = false;
8492}
8493
8494function checkHasForceUpdateAfterProcessing() {
8495 return hasForceUpdate;
8496}
8497
8498function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
8499 // If the finished render included captured updates, and there are still
8500 // lower priority updates left over, we need to keep the captured updates
8501 // in the queue so that they are rebased and not dropped once we process the
8502 // queue again at the lower priority.
8503 if (finishedQueue.firstCapturedUpdate !== null) {
8504 // Join the captured update list to the end of the normal list.
8505 if (finishedQueue.lastUpdate !== null) {
8506 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
8507 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
8508 }
8509 // Clear the list of captured updates.
8510 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
8511 }
8512
8513 // Commit the effects
8514 commitUpdateEffects(finishedQueue.firstEffect, instance);
8515 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
8516
8517 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
8518 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
8519}
8520
8521function commitUpdateEffects(effect, instance) {
8522 while (effect !== null) {
8523 var _callback3 = effect.callback;
8524 if (_callback3 !== null) {
8525 effect.callback = null;
8526 callCallback(_callback3, instance);
8527 }
8528 effect = effect.nextEffect;
8529 }
8530}
8531
8532function createCapturedValue(value, source) {
8533 // If the value is an error, call this function immediately after it is thrown
8534 // so the stack is accurate.
8535 return {
8536 value: value,
8537 source: source,
8538 stack: getStackByFiberInDevAndProd(source)
8539 };
8540}
8541
8542function markUpdate(workInProgress) {
8543 // Tag the fiber with an update effect. This turns a Placement into
8544 // a PlacementAndUpdate.
8545 workInProgress.effectTag |= Update;
8546}
8547
8548function markRef$1(workInProgress) {
8549 workInProgress.effectTag |= Ref;
8550}
8551
8552var appendAllChildren = void 0;
8553var updateHostContainer = void 0;
8554var updateHostComponent$1 = void 0;
8555var updateHostText$1 = void 0;
8556if (supportsMutation) {
8557 // Mutation mode
8558
8559 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8560 // We only have the top Fiber that was created but we need recurse down its
8561 // children to find all the terminal nodes.
8562 var node = workInProgress.child;
8563 while (node !== null) {
8564 if (node.tag === HostComponent || node.tag === HostText) {
8565 appendInitialChild(parent, node.stateNode);
8566 } else if (node.tag === HostPortal) {
8567 // If we have a portal child, then we don't want to traverse
8568 // down its children. Instead, we'll get insertions from each child in
8569 // the portal directly.
8570 } else if (node.child !== null) {
8571 node.child.return = node;
8572 node = node.child;
8573 continue;
8574 }
8575 if (node === workInProgress) {
8576 return;
8577 }
8578 while (node.sibling === null) {
8579 if (node.return === null || node.return === workInProgress) {
8580 return;
8581 }
8582 node = node.return;
8583 }
8584 node.sibling.return = node.return;
8585 node = node.sibling;
8586 }
8587 };
8588
8589 updateHostContainer = function (workInProgress) {
8590 // Noop
8591 };
8592 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8593 // If we have an alternate, that means this is an update and we need to
8594 // schedule a side-effect to do the updates.
8595 var oldProps = current.memoizedProps;
8596 if (oldProps === newProps) {
8597 // In mutation mode, this is sufficient for a bailout because
8598 // we won't touch this node even if children changed.
8599 return;
8600 }
8601
8602 // If we get updated because one of our children updated, we don't
8603 // have newProps so we'll have to reuse them.
8604 // TODO: Split the update API as separate for the props vs. children.
8605 // Even better would be if children weren't special cased at all tho.
8606 var instance = workInProgress.stateNode;
8607 var currentHostContext = getHostContext();
8608 // TODO: Experiencing an error where oldProps is null. Suggests a host
8609 // component is hitting the resume path. Figure out why. Possibly
8610 // related to `hidden`.
8611 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8612 // TODO: Type this specific to this type of component.
8613 workInProgress.updateQueue = updatePayload;
8614 // If the update payload indicates that there is a change or if there
8615 // is a new ref we mark this as an update. All the work is done in commitWork.
8616 if (updatePayload) {
8617 markUpdate(workInProgress);
8618 }
8619 };
8620 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8621 // If the text differs, mark it as an update. All the work in done in commitWork.
8622 if (oldText !== newText) {
8623 markUpdate(workInProgress);
8624 }
8625 };
8626} else if (supportsPersistence) {
8627 // Persistent host tree mode
8628
8629 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8630 // We only have the top Fiber that was created but we need recurse down its
8631 // children to find all the terminal nodes.
8632 var node = workInProgress.child;
8633 while (node !== null) {
8634 // eslint-disable-next-line no-labels
8635 branches: if (node.tag === HostComponent) {
8636 var instance = node.stateNode;
8637 if (needsVisibilityToggle) {
8638 var props = node.memoizedProps;
8639 var type = node.type;
8640 if (isHidden) {
8641 // This child is inside a timed out tree. Hide it.
8642 instance = cloneHiddenInstance(instance, type, props, node);
8643 } else {
8644 // This child was previously inside a timed out tree. If it was not
8645 // updated during this render, it may need to be unhidden. Clone
8646 // again to be sure.
8647 instance = cloneUnhiddenInstance(instance, type, props, node);
8648 }
8649 node.stateNode = instance;
8650 }
8651 appendInitialChild(parent, instance);
8652 } else if (node.tag === HostText) {
8653 var _instance = node.stateNode;
8654 if (needsVisibilityToggle) {
8655 var text = node.memoizedProps;
8656 var rootContainerInstance = getRootHostContainer();
8657 var currentHostContext = getHostContext();
8658 if (isHidden) {
8659 _instance = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8660 } else {
8661 _instance = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8662 }
8663 node.stateNode = _instance;
8664 }
8665 appendInitialChild(parent, _instance);
8666 } else if (node.tag === HostPortal) {
8667 // If we have a portal child, then we don't want to traverse
8668 // down its children. Instead, we'll get insertions from each child in
8669 // the portal directly.
8670 } else if (node.tag === SuspenseComponent) {
8671 var current = node.alternate;
8672 if (current !== null) {
8673 var oldState = current.memoizedState;
8674 var newState = node.memoizedState;
8675 var oldIsHidden = oldState !== null;
8676 var newIsHidden = newState !== null;
8677 if (oldIsHidden !== newIsHidden) {
8678 // The placeholder either just timed out or switched back to the normal
8679 // children after having previously timed out. Toggle the visibility of
8680 // the direct host children.
8681 var primaryChildParent = newIsHidden ? node.child : node;
8682 if (primaryChildParent !== null) {
8683 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
8684 }
8685 // eslint-disable-next-line no-labels
8686 break branches;
8687 }
8688 }
8689 if (node.child !== null) {
8690 // Continue traversing like normal
8691 node.child.return = node;
8692 node = node.child;
8693 continue;
8694 }
8695 } else if (node.child !== null) {
8696 node.child.return = node;
8697 node = node.child;
8698 continue;
8699 }
8700 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8701 node = node;
8702 if (node === workInProgress) {
8703 return;
8704 }
8705 while (node.sibling === null) {
8706 if (node.return === null || node.return === workInProgress) {
8707 return;
8708 }
8709 node = node.return;
8710 }
8711 node.sibling.return = node.return;
8712 node = node.sibling;
8713 }
8714 };
8715
8716 // An unfortunate fork of appendAllChildren because we have two different parent types.
8717 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
8718 // We only have the top Fiber that was created but we need recurse down its
8719 // children to find all the terminal nodes.
8720 var node = workInProgress.child;
8721 while (node !== null) {
8722 // eslint-disable-next-line no-labels
8723 branches: if (node.tag === HostComponent) {
8724 var instance = node.stateNode;
8725 if (needsVisibilityToggle) {
8726 var props = node.memoizedProps;
8727 var type = node.type;
8728 if (isHidden) {
8729 // This child is inside a timed out tree. Hide it.
8730 instance = cloneHiddenInstance(instance, type, props, node);
8731 } else {
8732 // This child was previously inside a timed out tree. If it was not
8733 // updated during this render, it may need to be unhidden. Clone
8734 // again to be sure.
8735 instance = cloneUnhiddenInstance(instance, type, props, node);
8736 }
8737 node.stateNode = instance;
8738 }
8739 appendChildToContainerChildSet(containerChildSet, instance);
8740 } else if (node.tag === HostText) {
8741 var _instance2 = node.stateNode;
8742 if (needsVisibilityToggle) {
8743 var text = node.memoizedProps;
8744 var rootContainerInstance = getRootHostContainer();
8745 var currentHostContext = getHostContext();
8746 if (isHidden) {
8747 _instance2 = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8748 } else {
8749 _instance2 = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8750 }
8751 node.stateNode = _instance2;
8752 }
8753 appendChildToContainerChildSet(containerChildSet, _instance2);
8754 } else if (node.tag === HostPortal) {
8755 // If we have a portal child, then we don't want to traverse
8756 // down its children. Instead, we'll get insertions from each child in
8757 // the portal directly.
8758 } else if (node.tag === SuspenseComponent) {
8759 var current = node.alternate;
8760 if (current !== null) {
8761 var oldState = current.memoizedState;
8762 var newState = node.memoizedState;
8763 var oldIsHidden = oldState !== null;
8764 var newIsHidden = newState !== null;
8765 if (oldIsHidden !== newIsHidden) {
8766 // The placeholder either just timed out or switched back to the normal
8767 // children after having previously timed out. Toggle the visibility of
8768 // the direct host children.
8769 var primaryChildParent = newIsHidden ? node.child : node;
8770 if (primaryChildParent !== null) {
8771 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
8772 }
8773 // eslint-disable-next-line no-labels
8774 break branches;
8775 }
8776 }
8777 if (node.child !== null) {
8778 // Continue traversing like normal
8779 node.child.return = node;
8780 node = node.child;
8781 continue;
8782 }
8783 } else if (node.child !== null) {
8784 node.child.return = node;
8785 node = node.child;
8786 continue;
8787 }
8788 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8789 node = node;
8790 if (node === workInProgress) {
8791 return;
8792 }
8793 while (node.sibling === null) {
8794 if (node.return === null || node.return === workInProgress) {
8795 return;
8796 }
8797 node = node.return;
8798 }
8799 node.sibling.return = node.return;
8800 node = node.sibling;
8801 }
8802 };
8803 updateHostContainer = function (workInProgress) {
8804 var portalOrRoot = workInProgress.stateNode;
8805 var childrenUnchanged = workInProgress.firstEffect === null;
8806 if (childrenUnchanged) {
8807 // No changes, just reuse the existing instance.
8808 } else {
8809 var container = portalOrRoot.containerInfo;
8810 var newChildSet = createContainerChildSet(container);
8811 // If children might have changed, we have to add them all to the set.
8812 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
8813 portalOrRoot.pendingChildren = newChildSet;
8814 // Schedule an update on the container to swap out the container.
8815 markUpdate(workInProgress);
8816 finalizeContainerChildren(container, newChildSet);
8817 }
8818 };
8819 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8820 var currentInstance = current.stateNode;
8821 var oldProps = current.memoizedProps;
8822 // If there are no effects associated with this node, then none of our children had any updates.
8823 // This guarantees that we can reuse all of them.
8824 var childrenUnchanged = workInProgress.firstEffect === null;
8825 if (childrenUnchanged && oldProps === newProps) {
8826 // No changes, just reuse the existing instance.
8827 // Note that this might release a previous clone.
8828 workInProgress.stateNode = currentInstance;
8829 return;
8830 }
8831 var recyclableInstance = workInProgress.stateNode;
8832 var currentHostContext = getHostContext();
8833 var updatePayload = null;
8834 if (oldProps !== newProps) {
8835 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8836 }
8837 if (childrenUnchanged && updatePayload === null) {
8838 // No changes, just reuse the existing instance.
8839 // Note that this might release a previous clone.
8840 workInProgress.stateNode = currentInstance;
8841 return;
8842 }
8843 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
8844 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
8845 markUpdate(workInProgress);
8846 }
8847 workInProgress.stateNode = newInstance;
8848 if (childrenUnchanged) {
8849 // If there are no other effects in this tree, we need to flag this node as having one.
8850 // Even though we're not going to use it for anything.
8851 // Otherwise parents won't know that there are new children to propagate upwards.
8852 markUpdate(workInProgress);
8853 } else {
8854 // If children might have changed, we have to add them all to the set.
8855 appendAllChildren(newInstance, workInProgress, false, false);
8856 }
8857 };
8858 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8859 if (oldText !== newText) {
8860 // If the text content differs, we'll create a new text instance for it.
8861 var rootContainerInstance = getRootHostContainer();
8862 var currentHostContext = getHostContext();
8863 workInProgress.stateNode = createTextInstance(newText, rootContainerInstance, currentHostContext, workInProgress);
8864 // We'll have to mark it as having an effect, even though we won't use the effect for anything.
8865 // This lets the parents know that at least one of their children has changed.
8866 markUpdate(workInProgress);
8867 }
8868 };
8869} else {
8870 // No host operations
8871 updateHostContainer = function (workInProgress) {
8872 // Noop
8873 };
8874 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8875 // Noop
8876 };
8877 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8878 // Noop
8879 };
8880}
8881
8882function completeWork(current, workInProgress, renderExpirationTime) {
8883 var newProps = workInProgress.pendingProps;
8884
8885 switch (workInProgress.tag) {
8886 case IndeterminateComponent:
8887 break;
8888 case LazyComponent:
8889 break;
8890 case SimpleMemoComponent:
8891 case FunctionComponent:
8892 break;
8893 case ClassComponent:
8894 {
8895 var Component = workInProgress.type;
8896 if (isContextProvider(Component)) {
8897 popContext(workInProgress);
8898 }
8899 break;
8900 }
8901 case HostRoot:
8902 {
8903 popHostContainer(workInProgress);
8904 popTopLevelContextObject(workInProgress);
8905 var fiberRoot = workInProgress.stateNode;
8906 if (fiberRoot.pendingContext) {
8907 fiberRoot.context = fiberRoot.pendingContext;
8908 fiberRoot.pendingContext = null;
8909 }
8910 if (current === null || current.child === null) {
8911 // If we hydrated, pop so that we can delete any remaining children
8912 // that weren't hydrated.
8913 popHydrationState(workInProgress);
8914 // This resets the hacky state to fix isMounted before committing.
8915 // TODO: Delete this when we delete isMounted and findDOMNode.
8916 workInProgress.effectTag &= ~Placement;
8917 }
8918 updateHostContainer(workInProgress);
8919 break;
8920 }
8921 case HostComponent:
8922 {
8923 popHostContext(workInProgress);
8924 var rootContainerInstance = getRootHostContainer();
8925 var type = workInProgress.type;
8926 if (current !== null && workInProgress.stateNode != null) {
8927 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
8928
8929 if (current.ref !== workInProgress.ref) {
8930 markRef$1(workInProgress);
8931 }
8932 } else {
8933 if (!newProps) {
8934 !(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;
8935 // This can happen when we abort work.
8936 break;
8937 }
8938
8939 var currentHostContext = getHostContext();
8940 // TODO: Move createInstance to beginWork and keep it on a context
8941 // "stack" as the parent. Then append children as we go in beginWork
8942 // or completeWork depending on we want to add then top->down or
8943 // bottom->up. Top->down is faster in IE11.
8944 var wasHydrated = popHydrationState(workInProgress);
8945 if (wasHydrated) {
8946 // TODO: Move this and createInstance step into the beginPhase
8947 // to consolidate.
8948 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
8949 // If changes to the hydrated node needs to be applied at the
8950 // commit-phase we mark this as such.
8951 markUpdate(workInProgress);
8952 }
8953 } else {
8954 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
8955
8956 appendAllChildren(instance, workInProgress, false, false);
8957
8958 // Certain renderers require commit-time effects for initial mount.
8959 // (eg DOM renderer supports auto-focus for certain elements).
8960 // Make sure such renderers get scheduled for later work.
8961 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
8962 markUpdate(workInProgress);
8963 }
8964 workInProgress.stateNode = instance;
8965 }
8966
8967 if (workInProgress.ref !== null) {
8968 // If there is a ref on a host node we need to schedule a callback
8969 markRef$1(workInProgress);
8970 }
8971 }
8972 break;
8973 }
8974 case HostText:
8975 {
8976 var newText = newProps;
8977 if (current && workInProgress.stateNode != null) {
8978 var oldText = current.memoizedProps;
8979 // If we have an alternate, that means this is an update and we need
8980 // to schedule a side-effect to do the updates.
8981 updateHostText$1(current, workInProgress, oldText, newText);
8982 } else {
8983 if (typeof newText !== 'string') {
8984 !(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;
8985 // This can happen when we abort work.
8986 }
8987 var _rootContainerInstance = getRootHostContainer();
8988 var _currentHostContext = getHostContext();
8989 var _wasHydrated = popHydrationState(workInProgress);
8990 if (_wasHydrated) {
8991 if (prepareToHydrateHostTextInstance(workInProgress)) {
8992 markUpdate(workInProgress);
8993 }
8994 } else {
8995 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
8996 }
8997 }
8998 break;
8999 }
9000 case ForwardRef:
9001 break;
9002 case SuspenseComponent:
9003 {
9004 var nextState = workInProgress.memoizedState;
9005 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
9006 // Something suspended. Re-render with the fallback children.
9007 workInProgress.expirationTime = renderExpirationTime;
9008 // Do not reset the effect list.
9009 return workInProgress;
9010 }
9011
9012 var nextDidTimeout = nextState !== null;
9013 var prevDidTimeout = current !== null && current.memoizedState !== null;
9014
9015 if (current !== null && !nextDidTimeout && prevDidTimeout) {
9016 // We just switched from the fallback to the normal children. Delete
9017 // the fallback.
9018 // TODO: Would it be better to store the fallback fragment on
9019 var currentFallbackChild = current.child.sibling;
9020 if (currentFallbackChild !== null) {
9021 // Deletions go at the beginning of the return fiber's effect list
9022 var first = workInProgress.firstEffect;
9023 if (first !== null) {
9024 workInProgress.firstEffect = currentFallbackChild;
9025 currentFallbackChild.nextEffect = first;
9026 } else {
9027 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
9028 currentFallbackChild.nextEffect = null;
9029 }
9030 currentFallbackChild.effectTag = Deletion;
9031 }
9032 }
9033
9034 if (nextDidTimeout || prevDidTimeout) {
9035 // If the children are hidden, or if they were previous hidden, schedule
9036 // an effect to toggle their visibility. This is also used to attach a
9037 // retry listener to the promise.
9038 workInProgress.effectTag |= Update;
9039 }
9040 break;
9041 }
9042 case Fragment:
9043 break;
9044 case Mode:
9045 break;
9046 case Profiler:
9047 break;
9048 case HostPortal:
9049 popHostContainer(workInProgress);
9050 updateHostContainer(workInProgress);
9051 break;
9052 case ContextProvider:
9053 // Pop provider fiber
9054 popProvider(workInProgress);
9055 break;
9056 case ContextConsumer:
9057 break;
9058 case MemoComponent:
9059 break;
9060 case IncompleteClassComponent:
9061 {
9062 // Same as class component case. I put it down here so that the tags are
9063 // sequential to ensure this switch is compiled to a jump table.
9064 var _Component = workInProgress.type;
9065 if (isContextProvider(_Component)) {
9066 popContext(workInProgress);
9067 }
9068 break;
9069 }
9070 case DehydratedSuspenseComponent:
9071 {
9072 if (enableSuspenseServerRenderer) {
9073 if (current === null) {
9074 var _wasHydrated2 = popHydrationState(workInProgress);
9075 !_wasHydrated2 ? invariant(false, 'A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React.') : void 0;
9076 skipPastDehydratedSuspenseInstance(workInProgress);
9077 } else if ((workInProgress.effectTag & DidCapture) === NoEffect) {
9078 // This boundary did not suspend so it's now hydrated.
9079 // To handle any future suspense cases, we're going to now upgrade it
9080 // to a Suspense component. We detach it from the existing current fiber.
9081 current.alternate = null;
9082 workInProgress.alternate = null;
9083 workInProgress.tag = SuspenseComponent;
9084 workInProgress.memoizedState = null;
9085 workInProgress.stateNode = null;
9086 }
9087 }
9088 break;
9089 }
9090 default:
9091 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
9092 }
9093
9094 return null;
9095}
9096
9097function shouldCaptureSuspense(workInProgress) {
9098 // In order to capture, the Suspense component must have a fallback prop.
9099 if (workInProgress.memoizedProps.fallback === undefined) {
9100 return false;
9101 }
9102 // If it was the primary children that just suspended, capture and render the
9103 // fallback. Otherwise, don't capture and bubble to the next boundary.
9104 var nextState = workInProgress.memoizedState;
9105 return nextState === null;
9106}
9107
9108// This module is forked in different environments.
9109// By default, return `true` to log errors to the console.
9110// Forks can return `false` if this isn't desirable.
9111function showErrorDialog(capturedError) {
9112 return true;
9113}
9114
9115function logCapturedError(capturedError) {
9116 var logError = showErrorDialog(capturedError);
9117
9118 // Allow injected showErrorDialog() to prevent default console.error logging.
9119 // This enables renderers like ReactNative to better manage redbox behavior.
9120 if (logError === false) {
9121 return;
9122 }
9123
9124 var error = capturedError.error;
9125 {
9126 var componentName = capturedError.componentName,
9127 componentStack = capturedError.componentStack,
9128 errorBoundaryName = capturedError.errorBoundaryName,
9129 errorBoundaryFound = capturedError.errorBoundaryFound,
9130 willRetry = capturedError.willRetry;
9131
9132 // Browsers support silencing uncaught errors by calling
9133 // `preventDefault()` in window `error` handler.
9134 // We record this information as an expando on the error.
9135
9136 if (error != null && error._suppressLogging) {
9137 if (errorBoundaryFound && willRetry) {
9138 // The error is recoverable and was silenced.
9139 // Ignore it and don't print the stack addendum.
9140 // This is handy for testing error boundaries without noise.
9141 return;
9142 }
9143 // The error is fatal. Since the silencing might have
9144 // been accidental, we'll surface it anyway.
9145 // However, the browser would have silenced the original error
9146 // so we'll print it first, and then print the stack addendum.
9147 console.error(error);
9148 // For a more detailed description of this block, see:
9149 // https://github.com/facebook/react/pull/13384
9150 }
9151
9152 var componentNameMessage = componentName ? 'The above error occurred in the <' + componentName + '> component:' : 'The above error occurred in one of your React components:';
9153
9154 var errorBoundaryMessage = void 0;
9155 // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
9156 if (errorBoundaryFound && errorBoundaryName) {
9157 if (willRetry) {
9158 errorBoundaryMessage = 'React will try to recreate this component tree from scratch ' + ('using the error boundary you provided, ' + errorBoundaryName + '.');
9159 } else {
9160 errorBoundaryMessage = 'This error was initially handled by the error boundary ' + errorBoundaryName + '.\n' + 'Recreating the tree from scratch failed so React will unmount the tree.';
9161 }
9162 } else {
9163 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.';
9164 }
9165 var combinedMessage = '' + componentNameMessage + componentStack + '\n\n' + ('' + errorBoundaryMessage);
9166
9167 // In development, we provide our own message with just the component stack.
9168 // We don't include the original error message and JS stack because the browser
9169 // has already printed it. Even if the application swallows the error, it is still
9170 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
9171 console.error(combinedMessage);
9172 }
9173}
9174
9175var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
9176{
9177 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
9178}
9179
9180var PossiblyWeakSet$1 = typeof WeakSet === 'function' ? WeakSet : Set;
9181
9182function logError(boundary, errorInfo) {
9183 var source = errorInfo.source;
9184 var stack = errorInfo.stack;
9185 if (stack === null && source !== null) {
9186 stack = getStackByFiberInDevAndProd(source);
9187 }
9188
9189 var capturedError = {
9190 componentName: source !== null ? getComponentName(source.type) : null,
9191 componentStack: stack !== null ? stack : '',
9192 error: errorInfo.value,
9193 errorBoundary: null,
9194 errorBoundaryName: null,
9195 errorBoundaryFound: false,
9196 willRetry: false
9197 };
9198
9199 if (boundary !== null && boundary.tag === ClassComponent) {
9200 capturedError.errorBoundary = boundary.stateNode;
9201 capturedError.errorBoundaryName = getComponentName(boundary.type);
9202 capturedError.errorBoundaryFound = true;
9203 capturedError.willRetry = true;
9204 }
9205
9206 try {
9207 logCapturedError(capturedError);
9208 } catch (e) {
9209 // This method must not throw, or React internal state will get messed up.
9210 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
9211 // we want to report this error outside of the normal stack as a last resort.
9212 // https://github.com/facebook/react/issues/13188
9213 setTimeout(function () {
9214 throw e;
9215 });
9216 }
9217}
9218
9219var callComponentWillUnmountWithTimer = function (current$$1, instance) {
9220 startPhaseTimer(current$$1, 'componentWillUnmount');
9221 instance.props = current$$1.memoizedProps;
9222 instance.state = current$$1.memoizedState;
9223 instance.componentWillUnmount();
9224 stopPhaseTimer();
9225};
9226
9227// Capture errors so they don't interrupt unmounting.
9228function safelyCallComponentWillUnmount(current$$1, instance) {
9229 {
9230 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
9231 if (hasCaughtError()) {
9232 var unmountError = clearCaughtError();
9233 captureCommitPhaseError(current$$1, unmountError);
9234 }
9235 }
9236}
9237
9238function safelyDetachRef(current$$1) {
9239 var ref = current$$1.ref;
9240 if (ref !== null) {
9241 if (typeof ref === 'function') {
9242 {
9243 invokeGuardedCallback(null, ref, null, null);
9244 if (hasCaughtError()) {
9245 var refError = clearCaughtError();
9246 captureCommitPhaseError(current$$1, refError);
9247 }
9248 }
9249 } else {
9250 ref.current = null;
9251 }
9252 }
9253}
9254
9255function safelyCallDestroy(current$$1, destroy) {
9256 {
9257 invokeGuardedCallback(null, destroy, null);
9258 if (hasCaughtError()) {
9259 var error = clearCaughtError();
9260 captureCommitPhaseError(current$$1, error);
9261 }
9262 }
9263}
9264
9265function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
9266 switch (finishedWork.tag) {
9267 case FunctionComponent:
9268 case ForwardRef:
9269 case SimpleMemoComponent:
9270 {
9271 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
9272 return;
9273 }
9274 case ClassComponent:
9275 {
9276 if (finishedWork.effectTag & Snapshot) {
9277 if (current$$1 !== null) {
9278 var prevProps = current$$1.memoizedProps;
9279 var prevState = current$$1.memoizedState;
9280 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
9281 var instance = finishedWork.stateNode;
9282 // We could update instance props and state here,
9283 // but instead we rely on them being set during last render.
9284 // TODO: revisit this when we implement resuming.
9285 {
9286 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9287 !(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;
9288 !(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;
9289 }
9290 }
9291 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
9292 {
9293 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
9294 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
9295 didWarnSet.add(finishedWork.type);
9296 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
9297 }
9298 }
9299 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
9300 stopPhaseTimer();
9301 }
9302 }
9303 return;
9304 }
9305 case HostRoot:
9306 case HostComponent:
9307 case HostText:
9308 case HostPortal:
9309 case IncompleteClassComponent:
9310 // Nothing to do for these component types
9311 return;
9312 default:
9313 {
9314 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.');
9315 }
9316 }
9317}
9318
9319function commitHookEffectList(unmountTag, mountTag, finishedWork) {
9320 var updateQueue = finishedWork.updateQueue;
9321 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
9322 if (lastEffect !== null) {
9323 var firstEffect = lastEffect.next;
9324 var effect = firstEffect;
9325 do {
9326 if ((effect.tag & unmountTag) !== NoEffect$1) {
9327 // Unmount
9328 var destroy = effect.destroy;
9329 effect.destroy = undefined;
9330 if (destroy !== undefined) {
9331 destroy();
9332 }
9333 }
9334 if ((effect.tag & mountTag) !== NoEffect$1) {
9335 // Mount
9336 var create = effect.create;
9337 effect.destroy = create();
9338
9339 {
9340 var _destroy = effect.destroy;
9341 if (_destroy !== undefined && typeof _destroy !== 'function') {
9342 var addendum = void 0;
9343 if (_destroy === null) {
9344 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
9345 } else if (typeof _destroy.then === 'function') {
9346 addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, you may write an async function separately ' + 'and then call it from inside the effect:\n\n' + 'async function fetchComment(commentId) {\n' + ' // You can await here\n' + '}\n\n' + 'useEffect(() => {\n' + ' fetchComment(commentId);\n' + '}, [commentId]);\n\n' + 'In the future, React will provide a more idiomatic solution for data fetching ' + "that doesn't involve writing effects manually.";
9347 } else {
9348 addendum = ' You returned: ' + _destroy;
9349 }
9350 warningWithoutStack$1(false, 'An Effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
9351 }
9352 }
9353 }
9354 effect = effect.next;
9355 } while (effect !== firstEffect);
9356 }
9357}
9358
9359function commitPassiveHookEffects(finishedWork) {
9360 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
9361 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
9362}
9363
9364function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
9365 switch (finishedWork.tag) {
9366 case FunctionComponent:
9367 case ForwardRef:
9368 case SimpleMemoComponent:
9369 {
9370 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
9371 break;
9372 }
9373 case ClassComponent:
9374 {
9375 var instance = finishedWork.stateNode;
9376 if (finishedWork.effectTag & Update) {
9377 if (current$$1 === null) {
9378 startPhaseTimer(finishedWork, 'componentDidMount');
9379 // We could update instance props and state here,
9380 // but instead we rely on them being set during last render.
9381 // TODO: revisit this when we implement resuming.
9382 {
9383 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9384 !(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;
9385 !(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;
9386 }
9387 }
9388 instance.componentDidMount();
9389 stopPhaseTimer();
9390 } else {
9391 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
9392 var prevState = current$$1.memoizedState;
9393 startPhaseTimer(finishedWork, 'componentDidUpdate');
9394 // We could update instance props and state here,
9395 // but instead we rely on them being set during last render.
9396 // TODO: revisit this when we implement resuming.
9397 {
9398 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9399 !(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;
9400 !(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;
9401 }
9402 }
9403 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
9404 stopPhaseTimer();
9405 }
9406 }
9407 var updateQueue = finishedWork.updateQueue;
9408 if (updateQueue !== null) {
9409 {
9410 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9411 !(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;
9412 !(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;
9413 }
9414 }
9415 // We could update instance props and state here,
9416 // but instead we rely on them being set during last render.
9417 // TODO: revisit this when we implement resuming.
9418 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
9419 }
9420 return;
9421 }
9422 case HostRoot:
9423 {
9424 var _updateQueue = finishedWork.updateQueue;
9425 if (_updateQueue !== null) {
9426 var _instance = null;
9427 if (finishedWork.child !== null) {
9428 switch (finishedWork.child.tag) {
9429 case HostComponent:
9430 _instance = getPublicInstance(finishedWork.child.stateNode);
9431 break;
9432 case ClassComponent:
9433 _instance = finishedWork.child.stateNode;
9434 break;
9435 }
9436 }
9437 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
9438 }
9439 return;
9440 }
9441 case HostComponent:
9442 {
9443 var _instance2 = finishedWork.stateNode;
9444
9445 // Renderers may schedule work to be done after host components are mounted
9446 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
9447 // These effects should only be committed when components are first mounted,
9448 // aka when there is no current/alternate.
9449 if (current$$1 === null && finishedWork.effectTag & Update) {
9450 var type = finishedWork.type;
9451 var props = finishedWork.memoizedProps;
9452
9453 }
9454
9455 return;
9456 }
9457 case HostText:
9458 {
9459 // We have no life-cycles associated with text.
9460 return;
9461 }
9462 case HostPortal:
9463 {
9464 // We have no life-cycles associated with portals.
9465 return;
9466 }
9467 case Profiler:
9468 {
9469 if (enableProfilerTimer) {
9470 var onRender = finishedWork.memoizedProps.onRender;
9471
9472 if (enableSchedulerTracing) {
9473 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
9474 } else {
9475 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
9476 }
9477 }
9478 return;
9479 }
9480 case SuspenseComponent:
9481 break;
9482 case IncompleteClassComponent:
9483 break;
9484 default:
9485 {
9486 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.');
9487 }
9488 }
9489}
9490
9491function hideOrUnhideAllChildren(finishedWork, isHidden) {
9492 if (supportsMutation) {
9493 // We only have the top Fiber that was inserted but we need to recurse down its
9494 var node = finishedWork;
9495 while (true) {
9496 if (node.tag === HostComponent) {
9497 var instance = node.stateNode;
9498 if (isHidden) {
9499 hideInstance(instance);
9500 } else {
9501 unhideInstance(node.stateNode, node.memoizedProps);
9502 }
9503 } else if (node.tag === HostText) {
9504 var _instance3 = node.stateNode;
9505 if (isHidden) {
9506 hideTextInstance(_instance3);
9507 } else {
9508 unhideTextInstance(_instance3, node.memoizedProps);
9509 }
9510 } else if (node.tag === SuspenseComponent && node.memoizedState !== null) {
9511 // Found a nested Suspense component that timed out. Skip over the
9512 var fallbackChildFragment = node.child.sibling;
9513 fallbackChildFragment.return = node;
9514 node = fallbackChildFragment;
9515 continue;
9516 } else if (node.child !== null) {
9517 node.child.return = node;
9518 node = node.child;
9519 continue;
9520 }
9521 if (node === finishedWork) {
9522 return;
9523 }
9524 while (node.sibling === null) {
9525 if (node.return === null || node.return === finishedWork) {
9526 return;
9527 }
9528 node = node.return;
9529 }
9530 node.sibling.return = node.return;
9531 node = node.sibling;
9532 }
9533 }
9534}
9535
9536function commitAttachRef(finishedWork) {
9537 var ref = finishedWork.ref;
9538 if (ref !== null) {
9539 var instance = finishedWork.stateNode;
9540 var instanceToUse = void 0;
9541 switch (finishedWork.tag) {
9542 case HostComponent:
9543 instanceToUse = getPublicInstance(instance);
9544 break;
9545 default:
9546 instanceToUse = instance;
9547 }
9548 if (typeof ref === 'function') {
9549 ref(instanceToUse);
9550 } else {
9551 {
9552 if (!ref.hasOwnProperty('current')) {
9553 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
9554 }
9555 }
9556
9557 ref.current = instanceToUse;
9558 }
9559 }
9560}
9561
9562function commitDetachRef(current$$1) {
9563 var currentRef = current$$1.ref;
9564 if (currentRef !== null) {
9565 if (typeof currentRef === 'function') {
9566 currentRef(null);
9567 } else {
9568 currentRef.current = null;
9569 }
9570 }
9571}
9572
9573// User-originating errors (lifecycles and refs) should not interrupt
9574// deletion, so don't let them throw. Host-originating errors should
9575// interrupt deletion, so it's okay
9576function commitUnmount(current$$1) {
9577 onCommitUnmount(current$$1);
9578
9579 switch (current$$1.tag) {
9580 case FunctionComponent:
9581 case ForwardRef:
9582 case MemoComponent:
9583 case SimpleMemoComponent:
9584 {
9585 var updateQueue = current$$1.updateQueue;
9586 if (updateQueue !== null) {
9587 var lastEffect = updateQueue.lastEffect;
9588 if (lastEffect !== null) {
9589 var firstEffect = lastEffect.next;
9590 var effect = firstEffect;
9591 do {
9592 var destroy = effect.destroy;
9593 if (destroy !== undefined) {
9594 safelyCallDestroy(current$$1, destroy);
9595 }
9596 effect = effect.next;
9597 } while (effect !== firstEffect);
9598 }
9599 }
9600 break;
9601 }
9602 case ClassComponent:
9603 {
9604 safelyDetachRef(current$$1);
9605 var instance = current$$1.stateNode;
9606 if (typeof instance.componentWillUnmount === 'function') {
9607 safelyCallComponentWillUnmount(current$$1, instance);
9608 }
9609 return;
9610 }
9611 case HostComponent:
9612 {
9613 safelyDetachRef(current$$1);
9614 return;
9615 }
9616 case HostPortal:
9617 {
9618 // TODO: this is recursive.
9619 // We are also not using this parent because
9620 // the portal will get pushed immediately.
9621 if (supportsMutation) {
9622 unmountHostComponents(current$$1);
9623 } else if (supportsPersistence) {
9624 emptyPortalContainer(current$$1);
9625 }
9626 return;
9627 }
9628 }
9629}
9630
9631function commitNestedUnmounts(root) {
9632 // While we're inside a removed host node we don't want to call
9633 // removeChild on the inner nodes because they're removed by the top
9634 // call anyway. We also want to call componentWillUnmount on all
9635 // composites before this host node is removed from the tree. Therefore
9636 var node = root;
9637 while (true) {
9638 commitUnmount(node);
9639 // Visit children because they may contain more composite or host nodes.
9640 // Skip portals because commitUnmount() currently visits them recursively.
9641 if (node.child !== null && (
9642 // If we use mutation we drill down into portals using commitUnmount above.
9643 // If we don't use mutation we drill down into portals here instead.
9644 !supportsMutation || node.tag !== HostPortal)) {
9645 node.child.return = node;
9646 node = node.child;
9647 continue;
9648 }
9649 if (node === root) {
9650 return;
9651 }
9652 while (node.sibling === null) {
9653 if (node.return === null || node.return === root) {
9654 return;
9655 }
9656 node = node.return;
9657 }
9658 node.sibling.return = node.return;
9659 node = node.sibling;
9660 }
9661}
9662
9663function detachFiber(current$$1) {
9664 // Cut off the return pointers to disconnect it from the tree. Ideally, we
9665 // should clear the child pointer of the parent alternate to let this
9666 // get GC:ed but we don't know which for sure which parent is the current
9667 // one so we'll settle for GC:ing the subtree of this child. This child
9668 // itself will be GC:ed when the parent updates the next time.
9669 current$$1.return = null;
9670 current$$1.child = null;
9671 current$$1.memoizedState = null;
9672 current$$1.updateQueue = null;
9673 var alternate = current$$1.alternate;
9674 if (alternate !== null) {
9675 alternate.return = null;
9676 alternate.child = null;
9677 alternate.memoizedState = null;
9678 alternate.updateQueue = null;
9679 }
9680}
9681
9682function emptyPortalContainer(current$$1) {
9683 if (!supportsPersistence) {
9684 return;
9685 }
9686
9687 var portal = current$$1.stateNode;
9688 var containerInfo = portal.containerInfo;
9689
9690 var emptyChildSet = createContainerChildSet(containerInfo);
9691 replaceContainerChildren(containerInfo, emptyChildSet);
9692}
9693
9694function commitContainer(finishedWork) {
9695 if (!supportsPersistence) {
9696 return;
9697 }
9698
9699 switch (finishedWork.tag) {
9700 case ClassComponent:
9701 {
9702 return;
9703 }
9704 case HostComponent:
9705 {
9706 return;
9707 }
9708 case HostText:
9709 {
9710 return;
9711 }
9712 case HostRoot:
9713 case HostPortal:
9714 {
9715 var portalOrRoot = finishedWork.stateNode;
9716 var containerInfo = portalOrRoot.containerInfo,
9717 _pendingChildren = portalOrRoot.pendingChildren;
9718
9719 replaceContainerChildren(containerInfo, _pendingChildren);
9720 return;
9721 }
9722 default:
9723 {
9724 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.');
9725 }
9726 }
9727}
9728
9729function getHostParentFiber(fiber) {
9730 var parent = fiber.return;
9731 while (parent !== null) {
9732 if (isHostParent(parent)) {
9733 return parent;
9734 }
9735 parent = parent.return;
9736 }
9737 invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.');
9738}
9739
9740function isHostParent(fiber) {
9741 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
9742}
9743
9744function getHostSibling(fiber) {
9745 // We're going to search forward into the tree until we find a sibling host
9746 // node. Unfortunately, if multiple insertions are done in a row we have to
9747 // search past them. This leads to exponential search for the next sibling.
9748 var node = fiber;
9749 siblings: while (true) {
9750 // If we didn't find anything, let's try the next sibling.
9751 while (node.sibling === null) {
9752 if (node.return === null || isHostParent(node.return)) {
9753 // If we pop out of the root or hit the parent the fiber we are the
9754 // last sibling.
9755 return null;
9756 }
9757 node = node.return;
9758 }
9759 node.sibling.return = node.return;
9760 node = node.sibling;
9761 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedSuspenseComponent) {
9762 // If it is not host node and, we might have a host node inside it.
9763 // Try to search down until we find one.
9764 if (node.effectTag & Placement) {
9765 // If we don't have a child, try the siblings instead.
9766 continue siblings;
9767 }
9768 // If we don't have a child, try the siblings instead.
9769 // We also skip portals because they are not part of this host tree.
9770 if (node.child === null || node.tag === HostPortal) {
9771 continue siblings;
9772 } else {
9773 node.child.return = node;
9774 node = node.child;
9775 }
9776 }
9777 // Check if this host node is stable or about to be placed.
9778 if (!(node.effectTag & Placement)) {
9779 // Found it!
9780 return node.stateNode;
9781 }
9782 }
9783}
9784
9785function commitPlacement(finishedWork) {
9786 if (!supportsMutation) {
9787 return;
9788 }
9789
9790 // Recursively insert all host nodes into the parent.
9791 var parentFiber = getHostParentFiber(finishedWork);
9792
9793 // Note: these two variables *must* always be updated together.
9794 var parent = void 0;
9795 var isContainer = void 0;
9796
9797 switch (parentFiber.tag) {
9798 case HostComponent:
9799 parent = parentFiber.stateNode;
9800 isContainer = false;
9801 break;
9802 case HostRoot:
9803 parent = parentFiber.stateNode.containerInfo;
9804 isContainer = true;
9805 break;
9806 case HostPortal:
9807 parent = parentFiber.stateNode.containerInfo;
9808 isContainer = true;
9809 break;
9810 default:
9811 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
9812 }
9813 if (parentFiber.effectTag & ContentReset) {
9814 // Reset the text content of the parent before doing any insertions
9815 parentFiber.effectTag &= ~ContentReset;
9816 }
9817
9818 var before = getHostSibling(finishedWork);
9819 // We only have the top Fiber that was inserted but we need to recurse down its
9820 // children to find all the terminal nodes.
9821 var node = finishedWork;
9822 while (true) {
9823 if (node.tag === HostComponent || node.tag === HostText) {
9824 if (before) {
9825 if (isContainer) {
9826 insertInContainerBefore(parent, node.stateNode, before);
9827 } else {
9828 insertBefore(parent, node.stateNode, before);
9829 }
9830 } else {
9831 if (isContainer) {
9832 appendChildToContainer(parent, node.stateNode);
9833 } else {
9834 appendChild(parent, node.stateNode);
9835 }
9836 }
9837 } else if (node.tag === HostPortal) {
9838 // If the insertion itself is a portal, then we don't want to traverse
9839 // down its children. Instead, we'll get insertions from each child in
9840 // the portal directly.
9841 } else if (node.child !== null) {
9842 node.child.return = node;
9843 node = node.child;
9844 continue;
9845 }
9846 if (node === finishedWork) {
9847 return;
9848 }
9849 while (node.sibling === null) {
9850 if (node.return === null || node.return === finishedWork) {
9851 return;
9852 }
9853 node = node.return;
9854 }
9855 node.sibling.return = node.return;
9856 node = node.sibling;
9857 }
9858}
9859
9860function unmountHostComponents(current$$1) {
9861 // We only have the top Fiber that was deleted but we need to recurse down its
9862 var node = current$$1;
9863
9864 // Each iteration, currentParent is populated with node's host parent if not
9865 // currentParentIsValid.
9866 var currentParentIsValid = false;
9867
9868 // Note: these two variables *must* always be updated together.
9869 var currentParent = void 0;
9870 var currentParentIsContainer = void 0;
9871
9872 while (true) {
9873 if (!currentParentIsValid) {
9874 var parent = node.return;
9875 findParent: while (true) {
9876 !(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;
9877 switch (parent.tag) {
9878 case HostComponent:
9879 currentParent = parent.stateNode;
9880 currentParentIsContainer = false;
9881 break findParent;
9882 case HostRoot:
9883 currentParent = parent.stateNode.containerInfo;
9884 currentParentIsContainer = true;
9885 break findParent;
9886 case HostPortal:
9887 currentParent = parent.stateNode.containerInfo;
9888 currentParentIsContainer = true;
9889 break findParent;
9890 }
9891 parent = parent.return;
9892 }
9893 currentParentIsValid = true;
9894 }
9895
9896 if (node.tag === HostComponent || node.tag === HostText) {
9897 commitNestedUnmounts(node);
9898 // After all the children have unmounted, it is now safe to remove the
9899 // node from the tree.
9900 if (currentParentIsContainer) {
9901 removeChildFromContainer(currentParent, node.stateNode);
9902 } else {
9903 removeChild(currentParent, node.stateNode);
9904 }
9905 // Don't visit children because we already visited them.
9906 } else if (enableSuspenseServerRenderer && node.tag === DehydratedSuspenseComponent) {
9907 // Delete the dehydrated suspense boundary and all of its content.
9908 if (currentParentIsContainer) {
9909 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);
9910 } else {
9911 clearSuspenseBoundary(currentParent, node.stateNode);
9912 }
9913 } else if (node.tag === HostPortal) {
9914 if (node.child !== null) {
9915 // When we go into a portal, it becomes the parent to remove from.
9916 // We will reassign it back when we pop the portal on the way up.
9917 currentParent = node.stateNode.containerInfo;
9918 currentParentIsContainer = true;
9919 // Visit children because portals might contain host components.
9920 node.child.return = node;
9921 node = node.child;
9922 continue;
9923 }
9924 } else {
9925 commitUnmount(node);
9926 // Visit children because we may find more host components below.
9927 if (node.child !== null) {
9928 node.child.return = node;
9929 node = node.child;
9930 continue;
9931 }
9932 }
9933 if (node === current$$1) {
9934 return;
9935 }
9936 while (node.sibling === null) {
9937 if (node.return === null || node.return === current$$1) {
9938 return;
9939 }
9940 node = node.return;
9941 if (node.tag === HostPortal) {
9942 // When we go out of the portal, we need to restore the parent.
9943 // Since we don't keep a stack of them, we will search for it.
9944 currentParentIsValid = false;
9945 }
9946 }
9947 node.sibling.return = node.return;
9948 node = node.sibling;
9949 }
9950}
9951
9952function commitDeletion(current$$1) {
9953 if (supportsMutation) {
9954 // Recursively delete all host nodes from the parent.
9955 // Detach refs and call componentWillUnmount() on the whole subtree.
9956 unmountHostComponents(current$$1);
9957 } else {
9958 // Detach refs and call componentWillUnmount() on the whole subtree.
9959 commitNestedUnmounts(current$$1);
9960 }
9961 detachFiber(current$$1);
9962}
9963
9964function commitWork(current$$1, finishedWork) {
9965 if (!supportsMutation) {
9966 switch (finishedWork.tag) {
9967 case FunctionComponent:
9968 case ForwardRef:
9969 case MemoComponent:
9970 case SimpleMemoComponent:
9971 {
9972 // Note: We currently never use MountMutation, but useLayout uses
9973 // UnmountMutation.
9974 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
9975 return;
9976 }
9977 }
9978
9979 commitContainer(finishedWork);
9980 return;
9981 }
9982
9983 switch (finishedWork.tag) {
9984 case FunctionComponent:
9985 case ForwardRef:
9986 case MemoComponent:
9987 case SimpleMemoComponent:
9988 {
9989 // Note: We currently never use MountMutation, but useLayout uses
9990 // UnmountMutation.
9991 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
9992 return;
9993 }
9994 case ClassComponent:
9995 {
9996 return;
9997 }
9998 case HostComponent:
9999 {
10000 var instance = finishedWork.stateNode;
10001 if (instance != null) {
10002 // Commit the work prepared earlier.
10003 var newProps = finishedWork.memoizedProps;
10004 // For hydration we reuse the update path but we treat the oldProps
10005 // as the newProps. The updatePayload will contain the real change in
10006 // this case.
10007 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
10008 var type = finishedWork.type;
10009 // TODO: Type the updateQueue to be specific to host components.
10010 var updatePayload = finishedWork.updateQueue;
10011 finishedWork.updateQueue = null;
10012 if (updatePayload !== null) {
10013 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
10014 }
10015 }
10016 return;
10017 }
10018 case HostText:
10019 {
10020 !(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;
10021 var textInstance = finishedWork.stateNode;
10022 var newText = finishedWork.memoizedProps;
10023 // For hydration we reuse the update path but we treat the oldProps
10024 // as the newProps. The updatePayload will contain the real change in
10025 // this case.
10026 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
10027 commitTextUpdate(textInstance, oldText, newText);
10028 return;
10029 }
10030 case HostRoot:
10031 {
10032 return;
10033 }
10034 case Profiler:
10035 {
10036 return;
10037 }
10038 case SuspenseComponent:
10039 {
10040 var newState = finishedWork.memoizedState;
10041
10042 var newDidTimeout = void 0;
10043 var primaryChildParent = finishedWork;
10044 if (newState === null) {
10045 newDidTimeout = false;
10046 } else {
10047 newDidTimeout = true;
10048 primaryChildParent = finishedWork.child;
10049 if (newState.timedOutAt === NoWork) {
10050 // If the children had not already timed out, record the time.
10051 // This is used to compute the elapsed time during subsequent
10052 // attempts to render the children.
10053 newState.timedOutAt = requestCurrentTime();
10054 }
10055 }
10056
10057 if (primaryChildParent !== null) {
10058 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
10059 }
10060
10061 // If this boundary just timed out, then it will have a set of thenables.
10062 // For each thenable, attach a listener so that when it resolves, React
10063 // attempts to re-render the boundary in the primary (pre-timeout) state.
10064 var thenables = finishedWork.updateQueue;
10065 if (thenables !== null) {
10066 finishedWork.updateQueue = null;
10067 var retryCache = finishedWork.stateNode;
10068 if (retryCache === null) {
10069 retryCache = finishedWork.stateNode = new PossiblyWeakSet$1();
10070 }
10071 thenables.forEach(function (thenable) {
10072 // Memoize using the boundary fiber to prevent redundant listeners.
10073 var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable);
10074 if (enableSchedulerTracing) {
10075 retry = unstable_wrap(retry);
10076 }
10077 if (!retryCache.has(thenable)) {
10078 retryCache.add(thenable);
10079 thenable.then(retry, retry);
10080 }
10081 });
10082 }
10083
10084 return;
10085 }
10086 case IncompleteClassComponent:
10087 {
10088 return;
10089 }
10090 default:
10091 {
10092 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.');
10093 }
10094 }
10095}
10096
10097function commitResetTextContent(current$$1) {
10098 if (!supportsMutation) {
10099 return;
10100 }
10101 resetTextContent(current$$1.stateNode);
10102}
10103
10104var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
10105var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
10106
10107function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
10108 var update = createUpdate(expirationTime);
10109 // Unmount the root by rendering null.
10110 update.tag = CaptureUpdate;
10111 // Caution: React DevTools currently depends on this property
10112 // being called "element".
10113 update.payload = { element: null };
10114 var error = errorInfo.value;
10115 update.callback = function () {
10116 onUncaughtError(error);
10117 logError(fiber, errorInfo);
10118 };
10119 return update;
10120}
10121
10122function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
10123 var update = createUpdate(expirationTime);
10124 update.tag = CaptureUpdate;
10125 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
10126 if (typeof getDerivedStateFromError === 'function') {
10127 var error = errorInfo.value;
10128 update.payload = function () {
10129 return getDerivedStateFromError(error);
10130 };
10131 }
10132
10133 var inst = fiber.stateNode;
10134 if (inst !== null && typeof inst.componentDidCatch === 'function') {
10135 update.callback = function callback() {
10136 if (typeof getDerivedStateFromError !== 'function') {
10137 // To preserve the preexisting retry behavior of error boundaries,
10138 // we keep track of which ones already failed during this batch.
10139 // This gets reset before we yield back to the browser.
10140 // TODO: Warn in strict mode if getDerivedStateFromError is
10141 // not defined.
10142 markLegacyErrorBoundaryAsFailed(this);
10143 }
10144 var error = errorInfo.value;
10145 var stack = errorInfo.stack;
10146 logError(fiber, errorInfo);
10147 this.componentDidCatch(error, {
10148 componentStack: stack !== null ? stack : ''
10149 });
10150 {
10151 if (typeof getDerivedStateFromError !== 'function') {
10152 // If componentDidCatch is the only error boundary method defined,
10153 // then it needs to call setState to recover from errors.
10154 // If no state update is scheduled then the boundary will swallow the error.
10155 !(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;
10156 }
10157 }
10158 };
10159 }
10160 return update;
10161}
10162
10163function attachPingListener(root, renderExpirationTime, thenable) {
10164 // Attach a listener to the promise to "ping" the root and retry. But
10165 // only if one does not already exist for the current render expiration
10166 // time (which acts like a "thread ID" here).
10167 var pingCache = root.pingCache;
10168 var threadIDs = void 0;
10169 if (pingCache === null) {
10170 pingCache = root.pingCache = new PossiblyWeakMap();
10171 threadIDs = new Set();
10172 pingCache.set(thenable, threadIDs);
10173 } else {
10174 threadIDs = pingCache.get(thenable);
10175 if (threadIDs === undefined) {
10176 threadIDs = new Set();
10177 pingCache.set(thenable, threadIDs);
10178 }
10179 }
10180 if (!threadIDs.has(renderExpirationTime)) {
10181 // Memoize using the thread ID to prevent redundant listeners.
10182 threadIDs.add(renderExpirationTime);
10183 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
10184 if (enableSchedulerTracing) {
10185 ping = unstable_wrap(ping);
10186 }
10187 thenable.then(ping, ping);
10188 }
10189}
10190
10191function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
10192 // The source fiber did not complete.
10193 sourceFiber.effectTag |= Incomplete;
10194 // Its effect list is no longer valid.
10195 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
10196
10197 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
10198 // This is a thenable.
10199 var thenable = value;
10200
10201 // Find the earliest timeout threshold of all the placeholders in the
10202 // ancestor path. We could avoid this traversal by storing the thresholds on
10203 // the stack, but we choose not to because we only hit this path if we're
10204 // IO-bound (i.e. if something suspends). Whereas the stack is used even in
10205 // the non-IO- bound case.
10206 var _workInProgress = returnFiber;
10207 var earliestTimeoutMs = -1;
10208 var startTimeMs = -1;
10209 do {
10210 if (_workInProgress.tag === SuspenseComponent) {
10211 var current$$1 = _workInProgress.alternate;
10212 if (current$$1 !== null) {
10213 var currentState = current$$1.memoizedState;
10214 if (currentState !== null) {
10215 // Reached a boundary that already timed out. Do not search
10216 // any further.
10217 var timedOutAt = currentState.timedOutAt;
10218 startTimeMs = expirationTimeToMs(timedOutAt);
10219 // Do not search any further.
10220 break;
10221 }
10222 }
10223 var timeoutPropMs = _workInProgress.pendingProps.maxDuration;
10224 if (typeof timeoutPropMs === 'number') {
10225 if (timeoutPropMs <= 0) {
10226 earliestTimeoutMs = 0;
10227 } else if (earliestTimeoutMs === -1 || timeoutPropMs < earliestTimeoutMs) {
10228 earliestTimeoutMs = timeoutPropMs;
10229 }
10230 }
10231 }
10232 // If there is a DehydratedSuspenseComponent we don't have to do anything because
10233 // if something suspends inside it, we will simply leave that as dehydrated. It
10234 // will never timeout.
10235 _workInProgress = _workInProgress.return;
10236 } while (_workInProgress !== null);
10237
10238 // Schedule the nearest Suspense to re-render the timed out view.
10239 _workInProgress = returnFiber;
10240 do {
10241 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress)) {
10242 // Found the nearest boundary.
10243
10244 // Stash the promise on the boundary fiber. If the boundary times out, we'll
10245 var thenables = _workInProgress.updateQueue;
10246 if (thenables === null) {
10247 var updateQueue = new Set();
10248 updateQueue.add(thenable);
10249 _workInProgress.updateQueue = updateQueue;
10250 } else {
10251 thenables.add(thenable);
10252 }
10253
10254 // If the boundary is outside of concurrent mode, we should *not*
10255 // suspend the commit. Pretend as if the suspended component rendered
10256 // null and keep rendering. In the commit phase, we'll schedule a
10257 // subsequent synchronous update to re-render the Suspense.
10258 //
10259 // Note: It doesn't matter whether the component that suspended was
10260 // inside a concurrent mode tree. If the Suspense is outside of it, we
10261 // should *not* suspend the commit.
10262 if ((_workInProgress.mode & ConcurrentMode) === NoEffect) {
10263 _workInProgress.effectTag |= DidCapture;
10264
10265 // We're going to commit this fiber even though it didn't complete.
10266 // But we shouldn't call any lifecycle methods or callbacks. Remove
10267 // all lifecycle effect tags.
10268 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
10269
10270 if (sourceFiber.tag === ClassComponent) {
10271 var currentSourceFiber = sourceFiber.alternate;
10272 if (currentSourceFiber === null) {
10273 // This is a new mount. Change the tag so it's not mistaken for a
10274 // completed class component. For example, we should not call
10275 // componentWillUnmount if it is deleted.
10276 sourceFiber.tag = IncompleteClassComponent;
10277 } else {
10278 // When we try rendering again, we should not reuse the current fiber,
10279 // since it's known to be in an inconsistent state. Use a force updte to
10280 // prevent a bail out.
10281 var update = createUpdate(Sync);
10282 update.tag = ForceUpdate;
10283 enqueueUpdate(sourceFiber, update);
10284 }
10285 }
10286
10287 // The source fiber did not complete. Mark it with Sync priority to
10288 // indicate that it still has pending work.
10289 sourceFiber.expirationTime = Sync;
10290
10291 // Exit without suspending.
10292 return;
10293 }
10294
10295 // Confirmed that the boundary is in a concurrent mode tree. Continue
10296 // with the normal suspend path.
10297
10298 attachPingListener(root, renderExpirationTime, thenable);
10299
10300 var absoluteTimeoutMs = void 0;
10301 if (earliestTimeoutMs === -1) {
10302 // If no explicit threshold is given, default to an arbitrarily large
10303 // value. The actual size doesn't matter because the threshold for the
10304 // whole tree will be clamped to the expiration time.
10305 absoluteTimeoutMs = maxSigned31BitInt;
10306 } else {
10307 if (startTimeMs === -1) {
10308 // This suspend happened outside of any already timed-out
10309 // placeholders. We don't know exactly when the update was
10310 // scheduled, but we can infer an approximate start time from the
10311 // expiration time. First, find the earliest uncommitted expiration
10312 // time in the tree, including work that is suspended. Then subtract
10313 // the offset used to compute an async update's expiration time.
10314 // This will cause high priority (interactive) work to expire
10315 // earlier than necessary, but we can account for this by adjusting
10316 // for the Just Noticeable Difference.
10317 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, renderExpirationTime);
10318 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
10319 startTimeMs = earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
10320 }
10321 absoluteTimeoutMs = startTimeMs + earliestTimeoutMs;
10322 }
10323
10324 // Mark the earliest timeout in the suspended fiber's ancestor path.
10325 // After completing the root, we'll take the largest of all the
10326 // suspended fiber's timeouts and use it to compute a timeout for the
10327 // whole tree.
10328 renderDidSuspend(root, absoluteTimeoutMs, renderExpirationTime);
10329
10330 _workInProgress.effectTag |= ShouldCapture;
10331 _workInProgress.expirationTime = renderExpirationTime;
10332 return;
10333 } else if (enableSuspenseServerRenderer && _workInProgress.tag === DehydratedSuspenseComponent) {
10334 attachPingListener(root, renderExpirationTime, thenable);
10335
10336 // Since we already have a current fiber, we can eagerly add a retry listener.
10337 var retryCache = _workInProgress.memoizedState;
10338 if (retryCache === null) {
10339 retryCache = _workInProgress.memoizedState = new PossiblyWeakSet();
10340 var _current = _workInProgress.alternate;
10341 !_current ? invariant(false, 'A dehydrated suspense boundary must commit before trying to render. This is probably a bug in React.') : void 0;
10342 _current.memoizedState = retryCache;
10343 }
10344 // Memoize using the boundary fiber to prevent redundant listeners.
10345 if (!retryCache.has(thenable)) {
10346 retryCache.add(thenable);
10347 var retry = retryTimedOutBoundary.bind(null, _workInProgress, thenable);
10348 if (enableSchedulerTracing) {
10349 retry = unstable_wrap(retry);
10350 }
10351 thenable.then(retry, retry);
10352 }
10353 _workInProgress.effectTag |= ShouldCapture;
10354 _workInProgress.expirationTime = renderExpirationTime;
10355 return;
10356 }
10357 // This boundary already captured during this render. Continue to the next
10358 // boundary.
10359 _workInProgress = _workInProgress.return;
10360 } while (_workInProgress !== null);
10361 // No boundary was found. Fallthrough to error mode.
10362 // TODO: Use invariant so the message is stripped in prod?
10363 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));
10364 }
10365
10366 // We didn't find a boundary that could handle this type of exception. Start
10367 // over and traverse parent path again, this time treating the exception
10368 // as an error.
10369 renderDidError();
10370 value = createCapturedValue(value, sourceFiber);
10371 var workInProgress = returnFiber;
10372 do {
10373 switch (workInProgress.tag) {
10374 case HostRoot:
10375 {
10376 var _errorInfo = value;
10377 workInProgress.effectTag |= ShouldCapture;
10378 workInProgress.expirationTime = renderExpirationTime;
10379 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
10380 enqueueCapturedUpdate(workInProgress, _update);
10381 return;
10382 }
10383 case ClassComponent:
10384 // Capture and retry
10385 var errorInfo = value;
10386 var ctor = workInProgress.type;
10387 var instance = workInProgress.stateNode;
10388 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
10389 workInProgress.effectTag |= ShouldCapture;
10390 workInProgress.expirationTime = renderExpirationTime;
10391 // Schedule the error boundary to re-render using updated state
10392 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
10393 enqueueCapturedUpdate(workInProgress, _update2);
10394 return;
10395 }
10396 break;
10397 default:
10398 break;
10399 }
10400 workInProgress = workInProgress.return;
10401 } while (workInProgress !== null);
10402}
10403
10404function unwindWork(workInProgress, renderExpirationTime) {
10405 switch (workInProgress.tag) {
10406 case ClassComponent:
10407 {
10408 var Component = workInProgress.type;
10409 if (isContextProvider(Component)) {
10410 popContext(workInProgress);
10411 }
10412 var effectTag = workInProgress.effectTag;
10413 if (effectTag & ShouldCapture) {
10414 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
10415 return workInProgress;
10416 }
10417 return null;
10418 }
10419 case HostRoot:
10420 {
10421 popHostContainer(workInProgress);
10422 popTopLevelContextObject(workInProgress);
10423 var _effectTag = workInProgress.effectTag;
10424 !((_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;
10425 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
10426 return workInProgress;
10427 }
10428 case HostComponent:
10429 {
10430 // TODO: popHydrationState
10431 popHostContext(workInProgress);
10432 return null;
10433 }
10434 case SuspenseComponent:
10435 {
10436 var _effectTag2 = workInProgress.effectTag;
10437 if (_effectTag2 & ShouldCapture) {
10438 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture;
10439 // Captured a suspense effect. Re-render the boundary.
10440 return workInProgress;
10441 }
10442 return null;
10443 }
10444 case DehydratedSuspenseComponent:
10445 {
10446 if (enableSuspenseServerRenderer) {
10447 // TODO: popHydrationState
10448 var _effectTag3 = workInProgress.effectTag;
10449 if (_effectTag3 & ShouldCapture) {
10450 workInProgress.effectTag = _effectTag3 & ~ShouldCapture | DidCapture;
10451 // Captured a suspense effect. Re-render the boundary.
10452 return workInProgress;
10453 }
10454 }
10455 return null;
10456 }
10457 case HostPortal:
10458 popHostContainer(workInProgress);
10459 return null;
10460 case ContextProvider:
10461 popProvider(workInProgress);
10462 return null;
10463 default:
10464 return null;
10465 }
10466}
10467
10468function unwindInterruptedWork(interruptedWork) {
10469 switch (interruptedWork.tag) {
10470 case ClassComponent:
10471 {
10472 var childContextTypes = interruptedWork.type.childContextTypes;
10473 if (childContextTypes !== null && childContextTypes !== undefined) {
10474 popContext(interruptedWork);
10475 }
10476 break;
10477 }
10478 case HostRoot:
10479 {
10480 popHostContainer(interruptedWork);
10481 popTopLevelContextObject(interruptedWork);
10482 break;
10483 }
10484 case HostComponent:
10485 {
10486 popHostContext(interruptedWork);
10487 break;
10488 }
10489 case HostPortal:
10490 popHostContainer(interruptedWork);
10491 break;
10492 case ContextProvider:
10493 popProvider(interruptedWork);
10494 break;
10495 default:
10496 break;
10497 }
10498}
10499
10500var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
10501var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
10502
10503
10504var didWarnAboutStateTransition = void 0;
10505var didWarnSetStateChildContext = void 0;
10506var warnAboutUpdateOnUnmounted = void 0;
10507var warnAboutInvalidUpdates = void 0;
10508
10509if (enableSchedulerTracing) {
10510 // Provide explicit error message when production+profiling bundle of e.g. react-dom
10511 // is used with production (non-profiling) bundle of scheduler/tracing
10512 !(__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;
10513}
10514
10515{
10516 didWarnAboutStateTransition = false;
10517 didWarnSetStateChildContext = false;
10518 var didWarnStateUpdateForUnmountedComponent = {};
10519
10520 warnAboutUpdateOnUnmounted = function (fiber, isClass) {
10521 // We show the whole stack but dedupe on the top component's name because
10522 // the problematic code almost always lies inside that component.
10523 var componentName = getComponentName(fiber.type) || 'ReactComponent';
10524 if (didWarnStateUpdateForUnmountedComponent[componentName]) {
10525 return;
10526 }
10527 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));
10528 didWarnStateUpdateForUnmountedComponent[componentName] = true;
10529 };
10530
10531 warnAboutInvalidUpdates = function (instance) {
10532 switch (phase) {
10533 case 'getChildContext':
10534 if (didWarnSetStateChildContext) {
10535 return;
10536 }
10537 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
10538 didWarnSetStateChildContext = true;
10539 break;
10540 case 'render':
10541 if (didWarnAboutStateTransition) {
10542 return;
10543 }
10544 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.');
10545 didWarnAboutStateTransition = true;
10546 break;
10547 }
10548 };
10549}
10550
10551var isWorking = false;
10552
10553// The next work in progress fiber that we're currently working on.
10554var nextUnitOfWork = null;
10555var nextRoot = null;
10556// The time at which we're currently rendering work.
10557var nextRenderExpirationTime = NoWork;
10558var nextLatestAbsoluteTimeoutMs = -1;
10559var nextRenderDidError = false;
10560
10561// The next fiber with an effect that we're currently committing.
10562var nextEffect = null;
10563
10564var isCommitting$1 = false;
10565var rootWithPendingPassiveEffects = null;
10566var passiveEffectCallbackHandle = null;
10567var passiveEffectCallback = null;
10568
10569var legacyErrorBoundariesThatAlreadyFailed = null;
10570
10571// Used for performance tracking.
10572var interruptedBy = null;
10573
10574var stashedWorkInProgressProperties = void 0;
10575var replayUnitOfWork = void 0;
10576var mayReplayFailedUnitOfWork = void 0;
10577var isReplayingFailedUnitOfWork = void 0;
10578var originalReplayError = void 0;
10579var rethrowOriginalError = void 0;
10580if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10581 stashedWorkInProgressProperties = null;
10582 mayReplayFailedUnitOfWork = true;
10583 isReplayingFailedUnitOfWork = false;
10584 originalReplayError = null;
10585 replayUnitOfWork = function (failedUnitOfWork, thrownValue, isYieldy) {
10586 if (thrownValue !== null && typeof thrownValue === 'object' && typeof thrownValue.then === 'function') {
10587 // Don't replay promises. Treat everything else like an error.
10588 // TODO: Need to figure out a different strategy if/when we add
10589 // support for catching other types.
10590 return;
10591 }
10592
10593 // Restore the original state of the work-in-progress
10594 if (stashedWorkInProgressProperties === null) {
10595 // This should never happen. Don't throw because this code is DEV-only.
10596 warningWithoutStack$1(false, 'Could not replay rendering after an error. This is likely a bug in React. ' + 'Please file an issue.');
10597 return;
10598 }
10599 assignFiberPropertiesInDEV(failedUnitOfWork, stashedWorkInProgressProperties);
10600
10601 switch (failedUnitOfWork.tag) {
10602 case HostRoot:
10603 popHostContainer(failedUnitOfWork);
10604 popTopLevelContextObject(failedUnitOfWork);
10605 break;
10606 case HostComponent:
10607 popHostContext(failedUnitOfWork);
10608 break;
10609 case ClassComponent:
10610 {
10611 var Component = failedUnitOfWork.type;
10612 if (isContextProvider(Component)) {
10613 popContext(failedUnitOfWork);
10614 }
10615 break;
10616 }
10617 case HostPortal:
10618 popHostContainer(failedUnitOfWork);
10619 break;
10620 case ContextProvider:
10621 popProvider(failedUnitOfWork);
10622 break;
10623 }
10624 // Replay the begin phase.
10625 isReplayingFailedUnitOfWork = true;
10626 originalReplayError = thrownValue;
10627 invokeGuardedCallback(null, workLoop, null, isYieldy);
10628 isReplayingFailedUnitOfWork = false;
10629 originalReplayError = null;
10630 if (hasCaughtError()) {
10631 var replayError = clearCaughtError();
10632 if (replayError != null && thrownValue != null) {
10633 try {
10634 // Reading the expando property is intentionally
10635 // inside `try` because it might be a getter or Proxy.
10636 if (replayError._suppressLogging) {
10637 // Also suppress logging for the original error.
10638 thrownValue._suppressLogging = true;
10639 }
10640 } catch (inner) {
10641 // Ignore.
10642 }
10643 }
10644 } else {
10645 // If the begin phase did not fail the second time, set this pointer
10646 // back to the original value.
10647 nextUnitOfWork = failedUnitOfWork;
10648 }
10649 };
10650 rethrowOriginalError = function () {
10651 throw originalReplayError;
10652 };
10653}
10654
10655function resetStack() {
10656 if (nextUnitOfWork !== null) {
10657 var interruptedWork = nextUnitOfWork.return;
10658 while (interruptedWork !== null) {
10659 unwindInterruptedWork(interruptedWork);
10660 interruptedWork = interruptedWork.return;
10661 }
10662 }
10663
10664 {
10665 ReactStrictModeWarnings.discardPendingWarnings();
10666 checkThatStackIsEmpty();
10667 }
10668
10669 nextRoot = null;
10670 nextRenderExpirationTime = NoWork;
10671 nextLatestAbsoluteTimeoutMs = -1;
10672 nextRenderDidError = false;
10673 nextUnitOfWork = null;
10674}
10675
10676function commitAllHostEffects() {
10677 while (nextEffect !== null) {
10678 {
10679 setCurrentFiber(nextEffect);
10680 }
10681 recordEffect();
10682
10683 var effectTag = nextEffect.effectTag;
10684
10685 if (effectTag & ContentReset) {
10686 commitResetTextContent(nextEffect);
10687 }
10688
10689 if (effectTag & Ref) {
10690 var current$$1 = nextEffect.alternate;
10691 if (current$$1 !== null) {
10692 commitDetachRef(current$$1);
10693 }
10694 }
10695
10696 // The following switch statement is only concerned about placement,
10697 // updates, and deletions. To avoid needing to add a case for every
10698 // possible bitmap value, we remove the secondary effects from the
10699 // effect tag and switch on that value.
10700 var primaryEffectTag = effectTag & (Placement | Update | Deletion);
10701 switch (primaryEffectTag) {
10702 case Placement:
10703 {
10704 commitPlacement(nextEffect);
10705 // Clear the "placement" from effect tag so that we know that this is inserted, before
10706 // any life-cycles like componentDidMount gets called.
10707 // TODO: findDOMNode doesn't rely on this any more but isMounted
10708 // does and isMounted is deprecated anyway so we should be able
10709 // to kill this.
10710 nextEffect.effectTag &= ~Placement;
10711 break;
10712 }
10713 case PlacementAndUpdate:
10714 {
10715 // Placement
10716 commitPlacement(nextEffect);
10717 // Clear the "placement" from effect tag so that we know that this is inserted, before
10718 // any life-cycles like componentDidMount gets called.
10719 nextEffect.effectTag &= ~Placement;
10720
10721 // Update
10722 var _current = nextEffect.alternate;
10723 commitWork(_current, nextEffect);
10724 break;
10725 }
10726 case Update:
10727 {
10728 var _current2 = nextEffect.alternate;
10729 commitWork(_current2, nextEffect);
10730 break;
10731 }
10732 case Deletion:
10733 {
10734 commitDeletion(nextEffect);
10735 break;
10736 }
10737 }
10738 nextEffect = nextEffect.nextEffect;
10739 }
10740
10741 {
10742 resetCurrentFiber();
10743 }
10744}
10745
10746function commitBeforeMutationLifecycles() {
10747 while (nextEffect !== null) {
10748 {
10749 setCurrentFiber(nextEffect);
10750 }
10751
10752 var effectTag = nextEffect.effectTag;
10753 if (effectTag & Snapshot) {
10754 recordEffect();
10755 var current$$1 = nextEffect.alternate;
10756 commitBeforeMutationLifeCycles(current$$1, nextEffect);
10757 }
10758
10759 nextEffect = nextEffect.nextEffect;
10760 }
10761
10762 {
10763 resetCurrentFiber();
10764 }
10765}
10766
10767function commitAllLifeCycles(finishedRoot, committedExpirationTime) {
10768 {
10769 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
10770 ReactStrictModeWarnings.flushLegacyContextWarning();
10771
10772 if (warnAboutDeprecatedLifecycles) {
10773 ReactStrictModeWarnings.flushPendingDeprecationWarnings();
10774 }
10775 }
10776 while (nextEffect !== null) {
10777 {
10778 setCurrentFiber(nextEffect);
10779 }
10780 var effectTag = nextEffect.effectTag;
10781
10782 if (effectTag & (Update | Callback)) {
10783 recordEffect();
10784 var current$$1 = nextEffect.alternate;
10785 commitLifeCycles(finishedRoot, current$$1, nextEffect, committedExpirationTime);
10786 }
10787
10788 if (effectTag & Ref) {
10789 recordEffect();
10790 commitAttachRef(nextEffect);
10791 }
10792
10793 if (effectTag & Passive) {
10794 rootWithPendingPassiveEffects = finishedRoot;
10795 }
10796
10797 nextEffect = nextEffect.nextEffect;
10798 }
10799 {
10800 resetCurrentFiber();
10801 }
10802}
10803
10804function commitPassiveEffects(root, firstEffect) {
10805 rootWithPendingPassiveEffects = null;
10806 passiveEffectCallbackHandle = null;
10807 passiveEffectCallback = null;
10808
10809 // Set this to true to prevent re-entrancy
10810 var previousIsRendering = isRendering;
10811 isRendering = true;
10812
10813 var effect = firstEffect;
10814 do {
10815 {
10816 setCurrentFiber(effect);
10817 }
10818
10819 if (effect.effectTag & Passive) {
10820 var didError = false;
10821 var error = void 0;
10822 {
10823 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
10824 if (hasCaughtError()) {
10825 didError = true;
10826 error = clearCaughtError();
10827 }
10828 }
10829 if (didError) {
10830 captureCommitPhaseError(effect, error);
10831 }
10832 }
10833 effect = effect.nextEffect;
10834 } while (effect !== null);
10835 {
10836 resetCurrentFiber();
10837 }
10838
10839 isRendering = previousIsRendering;
10840
10841 // Check if work was scheduled by one of the effects
10842 var rootExpirationTime = root.expirationTime;
10843 if (rootExpirationTime !== NoWork) {
10844 requestWork(root, rootExpirationTime);
10845 }
10846 // Flush any sync work that was scheduled by effects
10847 if (!isBatchingUpdates && !isRendering) {
10848 performSyncWork();
10849 }
10850}
10851
10852function isAlreadyFailedLegacyErrorBoundary(instance) {
10853 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
10854}
10855
10856function markLegacyErrorBoundaryAsFailed(instance) {
10857 if (legacyErrorBoundariesThatAlreadyFailed === null) {
10858 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
10859 } else {
10860 legacyErrorBoundariesThatAlreadyFailed.add(instance);
10861 }
10862}
10863
10864function flushPassiveEffects$1() {
10865 if (passiveEffectCallbackHandle !== null) {
10866 cancelPassiveEffects(passiveEffectCallbackHandle);
10867 }
10868 if (passiveEffectCallback !== null) {
10869 // We call the scheduled callback instead of commitPassiveEffects directly
10870 // to ensure tracing works correctly.
10871 passiveEffectCallback();
10872 }
10873}
10874
10875function commitRoot(root, finishedWork) {
10876 isWorking = true;
10877 isCommitting$1 = true;
10878 startCommitTimer();
10879
10880 !(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;
10881 var committedExpirationTime = root.pendingCommitExpirationTime;
10882 !(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;
10883 root.pendingCommitExpirationTime = NoWork;
10884
10885 // Update the pending priority levels to account for the work that we are
10886 // about to commit. This needs to happen before calling the lifecycles, since
10887 // they may schedule additional updates.
10888 var updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
10889 var childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
10890 var earliestRemainingTimeBeforeCommit = childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit ? childExpirationTimeBeforeCommit : updateExpirationTimeBeforeCommit;
10891 markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
10892
10893 var prevInteractions = null;
10894 if (enableSchedulerTracing) {
10895 // Restore any pending interactions at this point,
10896 // So that cascading work triggered during the render phase will be accounted for.
10897 prevInteractions = __interactionsRef.current;
10898 __interactionsRef.current = root.memoizedInteractions;
10899 }
10900
10901 // Reset this to null before calling lifecycles
10902 ReactCurrentOwner$1.current = null;
10903
10904 var firstEffect = void 0;
10905 if (finishedWork.effectTag > PerformedWork) {
10906 // A fiber's effect list consists only of its children, not itself. So if
10907 // the root has an effect, we need to add it to the end of the list. The
10908 // resulting list is the set that would belong to the root's parent, if
10909 // it had one; that is, all the effects in the tree including the root.
10910 if (finishedWork.lastEffect !== null) {
10911 finishedWork.lastEffect.nextEffect = finishedWork;
10912 firstEffect = finishedWork.firstEffect;
10913 } else {
10914 firstEffect = finishedWork;
10915 }
10916 } else {
10917 // There is no effect on the root.
10918 firstEffect = finishedWork.firstEffect;
10919 }
10920
10921 prepareForCommit(root.containerInfo);
10922
10923 // Invoke instances of getSnapshotBeforeUpdate before mutation.
10924 nextEffect = firstEffect;
10925 startCommitSnapshotEffectsTimer();
10926 while (nextEffect !== null) {
10927 var didError = false;
10928 var error = void 0;
10929 {
10930 invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
10931 if (hasCaughtError()) {
10932 didError = true;
10933 error = clearCaughtError();
10934 }
10935 }
10936 if (didError) {
10937 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10938 captureCommitPhaseError(nextEffect, error);
10939 // Clean-up
10940 if (nextEffect !== null) {
10941 nextEffect = nextEffect.nextEffect;
10942 }
10943 }
10944 }
10945 stopCommitSnapshotEffectsTimer();
10946
10947 if (enableProfilerTimer) {
10948 // Mark the current commit time to be shared by all Profilers in this batch.
10949 // This enables them to be grouped later.
10950 recordCommitTime();
10951 }
10952
10953 // Commit all the side-effects within a tree. We'll do this in two passes.
10954 // The first pass performs all the host insertions, updates, deletions and
10955 // ref unmounts.
10956 nextEffect = firstEffect;
10957 startCommitHostEffectsTimer();
10958 while (nextEffect !== null) {
10959 var _didError = false;
10960 var _error = void 0;
10961 {
10962 invokeGuardedCallback(null, commitAllHostEffects, null);
10963 if (hasCaughtError()) {
10964 _didError = true;
10965 _error = clearCaughtError();
10966 }
10967 }
10968 if (_didError) {
10969 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10970 captureCommitPhaseError(nextEffect, _error);
10971 // Clean-up
10972 if (nextEffect !== null) {
10973 nextEffect = nextEffect.nextEffect;
10974 }
10975 }
10976 }
10977 stopCommitHostEffectsTimer();
10978
10979 resetAfterCommit(root.containerInfo);
10980
10981 // The work-in-progress tree is now the current tree. This must come after
10982 // the first pass of the commit phase, so that the previous tree is still
10983 // current during componentWillUnmount, but before the second pass, so that
10984 // the finished work is current during componentDidMount/Update.
10985 root.current = finishedWork;
10986
10987 // In the second pass we'll perform all life-cycles and ref callbacks.
10988 // Life-cycles happen as a separate pass so that all placements, updates,
10989 // and deletions in the entire tree have already been invoked.
10990 // This pass also triggers any renderer-specific initial effects.
10991 nextEffect = firstEffect;
10992 startCommitLifeCyclesTimer();
10993 while (nextEffect !== null) {
10994 var _didError2 = false;
10995 var _error2 = void 0;
10996 {
10997 invokeGuardedCallback(null, commitAllLifeCycles, null, root, committedExpirationTime);
10998 if (hasCaughtError()) {
10999 _didError2 = true;
11000 _error2 = clearCaughtError();
11001 }
11002 }
11003 if (_didError2) {
11004 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11005 captureCommitPhaseError(nextEffect, _error2);
11006 if (nextEffect !== null) {
11007 nextEffect = nextEffect.nextEffect;
11008 }
11009 }
11010 }
11011
11012 if (firstEffect !== null && rootWithPendingPassiveEffects !== null) {
11013 // This commit included a passive effect. These do not need to fire until
11014 // after the next paint. Schedule an callback to fire them in an async
11015 // event. To ensure serial execution, the callback will be flushed early if
11016 // we enter rootWithPendingPassiveEffects commit phase before then.
11017 var callback = commitPassiveEffects.bind(null, root, firstEffect);
11018 if (enableSchedulerTracing) {
11019 // TODO: Avoid this extra callback by mutating the tracing ref directly,
11020 // like we do at the beginning of commitRoot. I've opted not to do that
11021 // here because that code is still in flux.
11022 callback = unstable_wrap(callback);
11023 }
11024 passiveEffectCallbackHandle = unstable_runWithPriority(unstable_NormalPriority, function () {
11025 return schedulePassiveEffects(callback);
11026 });
11027 passiveEffectCallback = callback;
11028 }
11029
11030 isCommitting$1 = false;
11031 isWorking = false;
11032 stopCommitLifeCyclesTimer();
11033 stopCommitTimer();
11034 onCommitRoot(finishedWork.stateNode);
11035 if (true && ReactFiberInstrumentation_1.debugTool) {
11036 ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork);
11037 }
11038
11039 var updateExpirationTimeAfterCommit = finishedWork.expirationTime;
11040 var childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
11041 var earliestRemainingTimeAfterCommit = childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit ? childExpirationTimeAfterCommit : updateExpirationTimeAfterCommit;
11042 if (earliestRemainingTimeAfterCommit === NoWork) {
11043 // If there's no remaining work, we can clear the set of already failed
11044 // error boundaries.
11045 legacyErrorBoundariesThatAlreadyFailed = null;
11046 }
11047 onCommit(root, earliestRemainingTimeAfterCommit);
11048
11049 if (enableSchedulerTracing) {
11050 __interactionsRef.current = prevInteractions;
11051
11052 var subscriber = void 0;
11053
11054 try {
11055 subscriber = __subscriberRef.current;
11056 if (subscriber !== null && root.memoizedInteractions.size > 0) {
11057 var threadID = computeThreadID(committedExpirationTime, root.interactionThreadID);
11058 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
11059 }
11060 } catch (error) {
11061 // It's not safe for commitRoot() to throw.
11062 // Store the error for now and we'll re-throw in finishRendering().
11063 if (!hasUnhandledError) {
11064 hasUnhandledError = true;
11065 unhandledError = error;
11066 }
11067 } finally {
11068 // Clear completed interactions from the pending Map.
11069 // Unless the render was suspended or cascading work was scheduled,
11070 // In which case– leave pending interactions until the subsequent render.
11071 var pendingInteractionMap = root.pendingInteractionMap;
11072 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11073 // Only decrement the pending interaction count if we're done.
11074 // If there's still work at the current priority,
11075 // That indicates that we are waiting for suspense data.
11076 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
11077 pendingInteractionMap.delete(scheduledExpirationTime);
11078
11079 scheduledInteractions.forEach(function (interaction) {
11080 interaction.__count--;
11081
11082 if (subscriber !== null && interaction.__count === 0) {
11083 try {
11084 subscriber.onInteractionScheduledWorkCompleted(interaction);
11085 } catch (error) {
11086 // It's not safe for commitRoot() to throw.
11087 // Store the error for now and we'll re-throw in finishRendering().
11088 if (!hasUnhandledError) {
11089 hasUnhandledError = true;
11090 unhandledError = error;
11091 }
11092 }
11093 }
11094 });
11095 }
11096 });
11097 }
11098 }
11099}
11100
11101function resetChildExpirationTime(workInProgress, renderTime) {
11102 if (renderTime !== Never && workInProgress.childExpirationTime === Never) {
11103 // The children of this component are hidden. Don't bubble their
11104 // expiration times.
11105 return;
11106 }
11107
11108 var newChildExpirationTime = NoWork;
11109
11110 // Bubble up the earliest expiration time.
11111 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11112 // We're in profiling mode.
11113 // Let's use this same traversal to update the render durations.
11114 var actualDuration = workInProgress.actualDuration;
11115 var treeBaseDuration = workInProgress.selfBaseDuration;
11116
11117 // When a fiber is cloned, its actualDuration is reset to 0.
11118 // This value will only be updated if work is done on the fiber (i.e. it doesn't bailout).
11119 // When work is done, it should bubble to the parent's actualDuration.
11120 // If the fiber has not been cloned though, (meaning no work was done),
11121 // Then this value will reflect the amount of time spent working on a previous render.
11122 // In that case it should not bubble.
11123 // We determine whether it was cloned by comparing the child pointer.
11124 var shouldBubbleActualDurations = workInProgress.alternate === null || workInProgress.child !== workInProgress.alternate.child;
11125
11126 var child = workInProgress.child;
11127 while (child !== null) {
11128 var childUpdateExpirationTime = child.expirationTime;
11129 var childChildExpirationTime = child.childExpirationTime;
11130 if (childUpdateExpirationTime > newChildExpirationTime) {
11131 newChildExpirationTime = childUpdateExpirationTime;
11132 }
11133 if (childChildExpirationTime > newChildExpirationTime) {
11134 newChildExpirationTime = childChildExpirationTime;
11135 }
11136 if (shouldBubbleActualDurations) {
11137 actualDuration += child.actualDuration;
11138 }
11139 treeBaseDuration += child.treeBaseDuration;
11140 child = child.sibling;
11141 }
11142 workInProgress.actualDuration = actualDuration;
11143 workInProgress.treeBaseDuration = treeBaseDuration;
11144 } else {
11145 var _child = workInProgress.child;
11146 while (_child !== null) {
11147 var _childUpdateExpirationTime = _child.expirationTime;
11148 var _childChildExpirationTime = _child.childExpirationTime;
11149 if (_childUpdateExpirationTime > newChildExpirationTime) {
11150 newChildExpirationTime = _childUpdateExpirationTime;
11151 }
11152 if (_childChildExpirationTime > newChildExpirationTime) {
11153 newChildExpirationTime = _childChildExpirationTime;
11154 }
11155 _child = _child.sibling;
11156 }
11157 }
11158
11159 workInProgress.childExpirationTime = newChildExpirationTime;
11160}
11161
11162function completeUnitOfWork(workInProgress) {
11163 // Attempt to complete the current unit of work, then move to the
11164 // next sibling. If there are no more siblings, return to the
11165 // parent fiber.
11166 while (true) {
11167 // The current, flushed, state of this fiber is the alternate.
11168 // Ideally nothing should rely on this, but relying on it here
11169 // means that we don't need an additional field on the work in
11170 // progress.
11171 var current$$1 = workInProgress.alternate;
11172 {
11173 setCurrentFiber(workInProgress);
11174 }
11175
11176 var returnFiber = workInProgress.return;
11177 var siblingFiber = workInProgress.sibling;
11178
11179 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
11180 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11181 // Don't replay if it fails during completion phase.
11182 mayReplayFailedUnitOfWork = false;
11183 }
11184 // This fiber completed.
11185 // Remember we're completing this unit so we can find a boundary if it fails.
11186 nextUnitOfWork = workInProgress;
11187 if (enableProfilerTimer) {
11188 if (workInProgress.mode & ProfileMode) {
11189 startProfilerTimer(workInProgress);
11190 }
11191 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
11192 if (workInProgress.mode & ProfileMode) {
11193 // Update render duration assuming we didn't error.
11194 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11195 }
11196 } else {
11197 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
11198 }
11199 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11200 // We're out of completion phase so replaying is fine now.
11201 mayReplayFailedUnitOfWork = true;
11202 }
11203 stopWorkTimer(workInProgress);
11204 resetChildExpirationTime(workInProgress, nextRenderExpirationTime);
11205 {
11206 resetCurrentFiber();
11207 }
11208
11209 if (nextUnitOfWork !== null) {
11210 // Completing this fiber spawned new work. Work on that next.
11211 return nextUnitOfWork;
11212 }
11213
11214 if (returnFiber !== null &&
11215 // Do not append effects to parents if a sibling failed to complete
11216 (returnFiber.effectTag & Incomplete) === NoEffect) {
11217 // Append all the effects of the subtree and this fiber onto the effect
11218 // list of the parent. The completion order of the children affects the
11219 // side-effect order.
11220 if (returnFiber.firstEffect === null) {
11221 returnFiber.firstEffect = workInProgress.firstEffect;
11222 }
11223 if (workInProgress.lastEffect !== null) {
11224 if (returnFiber.lastEffect !== null) {
11225 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
11226 }
11227 returnFiber.lastEffect = workInProgress.lastEffect;
11228 }
11229
11230 // If this fiber had side-effects, we append it AFTER the children's
11231 // side-effects. We can perform certain side-effects earlier if
11232 // needed, by doing multiple passes over the effect list. We don't want
11233 // to schedule our own side-effect on our own list because if end up
11234 // reusing children we'll schedule this effect onto itself since we're
11235 // at the end.
11236 var effectTag = workInProgress.effectTag;
11237 // Skip both NoWork and PerformedWork tags when creating the effect list.
11238 // PerformedWork effect is read by React DevTools but shouldn't be committed.
11239 if (effectTag > PerformedWork) {
11240 if (returnFiber.lastEffect !== null) {
11241 returnFiber.lastEffect.nextEffect = workInProgress;
11242 } else {
11243 returnFiber.firstEffect = workInProgress;
11244 }
11245 returnFiber.lastEffect = workInProgress;
11246 }
11247 }
11248
11249 if (true && ReactFiberInstrumentation_1.debugTool) {
11250 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11251 }
11252
11253 if (siblingFiber !== null) {
11254 // If there is more work to do in this returnFiber, do that next.
11255 return siblingFiber;
11256 } else if (returnFiber !== null) {
11257 // If there's no more work in this returnFiber. Complete the returnFiber.
11258 workInProgress = returnFiber;
11259 continue;
11260 } else {
11261 // We've reached the root.
11262 return null;
11263 }
11264 } else {
11265 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11266 // Record the render duration for the fiber that errored.
11267 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11268
11269 // Include the time spent working on failed children before continuing.
11270 var actualDuration = workInProgress.actualDuration;
11271 var child = workInProgress.child;
11272 while (child !== null) {
11273 actualDuration += child.actualDuration;
11274 child = child.sibling;
11275 }
11276 workInProgress.actualDuration = actualDuration;
11277 }
11278
11279 // This fiber did not complete because something threw. Pop values off
11280 // the stack without entering the complete phase. If this is a boundary,
11281 // capture values if possible.
11282 var next = unwindWork(workInProgress, nextRenderExpirationTime);
11283 // Because this fiber did not complete, don't reset its expiration time.
11284 if (workInProgress.effectTag & DidCapture) {
11285 // Restarting an error boundary
11286 stopFailedWorkTimer(workInProgress);
11287 } else {
11288 stopWorkTimer(workInProgress);
11289 }
11290
11291 {
11292 resetCurrentFiber();
11293 }
11294
11295 if (next !== null) {
11296 stopWorkTimer(workInProgress);
11297 if (true && ReactFiberInstrumentation_1.debugTool) {
11298 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11299 }
11300
11301 // If completing this work spawned new work, do that next. We'll come
11302 // back here again.
11303 // Since we're restarting, remove anything that is not a host effect
11304 // from the effect tag.
11305 next.effectTag &= HostEffectMask;
11306 return next;
11307 }
11308
11309 if (returnFiber !== null) {
11310 // Mark the parent fiber as incomplete and clear its effect list.
11311 returnFiber.firstEffect = returnFiber.lastEffect = null;
11312 returnFiber.effectTag |= Incomplete;
11313 }
11314
11315 if (true && ReactFiberInstrumentation_1.debugTool) {
11316 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11317 }
11318
11319 if (siblingFiber !== null) {
11320 // If there is more work to do in this returnFiber, do that next.
11321 return siblingFiber;
11322 } else if (returnFiber !== null) {
11323 // If there's no more work in this returnFiber. Complete the returnFiber.
11324 workInProgress = returnFiber;
11325 continue;
11326 } else {
11327 return null;
11328 }
11329 }
11330 }
11331
11332 // Without this explicit null return Flow complains of invalid return type
11333 // TODO Remove the above while(true) loop
11334 // eslint-disable-next-line no-unreachable
11335 return null;
11336}
11337
11338function performUnitOfWork(workInProgress) {
11339 // The current, flushed, state of this fiber is the alternate.
11340 // Ideally nothing should rely on this, but relying on it here
11341 // means that we don't need an additional field on the work in
11342 // progress.
11343 var current$$1 = workInProgress.alternate;
11344
11345 // See if beginning this work spawns more work.
11346 startWorkTimer(workInProgress);
11347 {
11348 setCurrentFiber(workInProgress);
11349 }
11350
11351 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11352 stashedWorkInProgressProperties = assignFiberPropertiesInDEV(stashedWorkInProgressProperties, workInProgress);
11353 }
11354
11355 var next = void 0;
11356 if (enableProfilerTimer) {
11357 if (workInProgress.mode & ProfileMode) {
11358 startProfilerTimer(workInProgress);
11359 }
11360
11361 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11362 workInProgress.memoizedProps = workInProgress.pendingProps;
11363
11364 if (workInProgress.mode & ProfileMode) {
11365 // Record the render duration assuming we didn't bailout (or error).
11366 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
11367 }
11368 } else {
11369 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11370 workInProgress.memoizedProps = workInProgress.pendingProps;
11371 }
11372
11373 {
11374 resetCurrentFiber();
11375 if (isReplayingFailedUnitOfWork) {
11376 // Currently replaying a failed unit of work. This should be unreachable,
11377 // because the render phase is meant to be idempotent, and it should
11378 // have thrown again. Since it didn't, rethrow the original error, so
11379 // React's internal stack is not misaligned.
11380 rethrowOriginalError();
11381 }
11382 }
11383 if (true && ReactFiberInstrumentation_1.debugTool) {
11384 ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress);
11385 }
11386
11387 if (next === null) {
11388 // If this doesn't spawn new work, complete the current work.
11389 next = completeUnitOfWork(workInProgress);
11390 }
11391
11392 ReactCurrentOwner$1.current = null;
11393
11394 return next;
11395}
11396
11397function workLoop(isYieldy) {
11398 if (!isYieldy) {
11399 // Flush work without yielding
11400 while (nextUnitOfWork !== null) {
11401 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11402 }
11403 } else {
11404 // Flush asynchronous work until there's a higher priority event
11405 while (nextUnitOfWork !== null && !shouldYieldToRenderer()) {
11406 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11407 }
11408 }
11409}
11410
11411function renderRoot(root, isYieldy) {
11412 !!isWorking ? invariant(false, 'renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11413
11414 flushPassiveEffects$1();
11415
11416 isWorking = true;
11417 var previousDispatcher = ReactCurrentDispatcher.current;
11418 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
11419
11420 var expirationTime = root.nextExpirationTimeToWorkOn;
11421
11422 // Check if we're starting from a fresh stack, or if we're resuming from
11423 // previously yielded work.
11424 if (expirationTime !== nextRenderExpirationTime || root !== nextRoot || nextUnitOfWork === null) {
11425 // Reset the stack and start working from the root.
11426 resetStack();
11427 nextRoot = root;
11428 nextRenderExpirationTime = expirationTime;
11429 nextUnitOfWork = createWorkInProgress(nextRoot.current, null, nextRenderExpirationTime);
11430 root.pendingCommitExpirationTime = NoWork;
11431
11432 if (enableSchedulerTracing) {
11433 // Determine which interactions this batch of work currently includes,
11434 // So that we can accurately attribute time spent working on it,
11435 var interactions = new Set();
11436 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11437 if (scheduledExpirationTime >= expirationTime) {
11438 scheduledInteractions.forEach(function (interaction) {
11439 return interactions.add(interaction);
11440 });
11441 }
11442 });
11443
11444 // Store the current set of interactions on the FiberRoot for a few reasons:
11445 // We can re-use it in hot functions like renderRoot() without having to recalculate it.
11446 // We will also use it in commitWork() to pass to any Profiler onRender() hooks.
11447 // This also provides DevTools with a way to access it when the onCommitRoot() hook is called.
11448 root.memoizedInteractions = interactions;
11449
11450 if (interactions.size > 0) {
11451 var subscriber = __subscriberRef.current;
11452 if (subscriber !== null) {
11453 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11454 try {
11455 subscriber.onWorkStarted(interactions, threadID);
11456 } catch (error) {
11457 // Work thrown by an interaction tracing subscriber should be rethrown,
11458 // But only once it's safe (to avoid leaving the scheduler in an invalid state).
11459 // Store the error for now and we'll re-throw in finishRendering().
11460 if (!hasUnhandledError) {
11461 hasUnhandledError = true;
11462 unhandledError = error;
11463 }
11464 }
11465 }
11466 }
11467 }
11468 }
11469
11470 var prevInteractions = null;
11471 if (enableSchedulerTracing) {
11472 // We're about to start new traced work.
11473 // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
11474 prevInteractions = __interactionsRef.current;
11475 __interactionsRef.current = root.memoizedInteractions;
11476 }
11477
11478 var didFatal = false;
11479
11480 startWorkLoopTimer(nextUnitOfWork);
11481
11482 do {
11483 try {
11484 workLoop(isYieldy);
11485 } catch (thrownValue) {
11486 resetContextDependences();
11487 resetHooks();
11488
11489 // Reset in case completion throws.
11490 // This is only used in DEV and when replaying is on.
11491 var mayReplay = void 0;
11492 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11493 mayReplay = mayReplayFailedUnitOfWork;
11494 mayReplayFailedUnitOfWork = true;
11495 }
11496
11497 if (nextUnitOfWork === null) {
11498 // This is a fatal error.
11499 didFatal = true;
11500 onUncaughtError(thrownValue);
11501 } else {
11502 if (enableProfilerTimer && nextUnitOfWork.mode & ProfileMode) {
11503 // Record the time spent rendering before an error was thrown.
11504 // This avoids inaccurate Profiler durations in the case of a suspended render.
11505 stopProfilerTimerIfRunningAndRecordDelta(nextUnitOfWork, true);
11506 }
11507
11508 {
11509 // Reset global debug state
11510 // We assume this is defined in DEV
11511 resetCurrentlyProcessingQueue();
11512 }
11513
11514 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11515 if (mayReplay) {
11516 var failedUnitOfWork = nextUnitOfWork;
11517 replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
11518 }
11519 }
11520
11521 // TODO: we already know this isn't true in some cases.
11522 // At least this shows a nicer error message until we figure out the cause.
11523 // https://github.com/facebook/react/issues/12449#issuecomment-386727431
11524 !(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;
11525
11526 var sourceFiber = nextUnitOfWork;
11527 var returnFiber = sourceFiber.return;
11528 if (returnFiber === null) {
11529 // This is the root. The root could capture its own errors. However,
11530 // we don't know if it errors before or after we pushed the host
11531 // context. This information is needed to avoid a stack mismatch.
11532 // Because we're not sure, treat this as a fatal error. We could track
11533 // which phase it fails in, but doesn't seem worth it. At least
11534 // for now.
11535 didFatal = true;
11536 onUncaughtError(thrownValue);
11537 } else {
11538 throwException(root, returnFiber, sourceFiber, thrownValue, nextRenderExpirationTime);
11539 nextUnitOfWork = completeUnitOfWork(sourceFiber);
11540 continue;
11541 }
11542 }
11543 }
11544 break;
11545 } while (true);
11546
11547 if (enableSchedulerTracing) {
11548 // Traced work is done for now; restore the previous interactions.
11549 __interactionsRef.current = prevInteractions;
11550 }
11551
11552 // We're done performing work. Time to clean up.
11553 isWorking = false;
11554 ReactCurrentDispatcher.current = previousDispatcher;
11555 resetContextDependences();
11556 resetHooks();
11557
11558 // Yield back to main thread.
11559 if (didFatal) {
11560 var _didCompleteRoot = false;
11561 stopWorkLoopTimer(interruptedBy, _didCompleteRoot);
11562 interruptedBy = null;
11563 // There was a fatal error.
11564 {
11565 resetStackAfterFatalErrorInDev();
11566 }
11567 // `nextRoot` points to the in-progress root. A non-null value indicates
11568 // that we're in the middle of an async render. Set it to null to indicate
11569 // there's no more work to be done in the current batch.
11570 nextRoot = null;
11571 onFatal(root);
11572 return;
11573 }
11574
11575 if (nextUnitOfWork !== null) {
11576 // There's still remaining async work in this tree, but we ran out of time
11577 // in the current frame. Yield back to the renderer. Unless we're
11578 // interrupted by a higher priority update, we'll continue later from where
11579 // we left off.
11580 var _didCompleteRoot2 = false;
11581 stopWorkLoopTimer(interruptedBy, _didCompleteRoot2);
11582 interruptedBy = null;
11583 onYield(root);
11584 return;
11585 }
11586
11587 // We completed the whole tree.
11588 var didCompleteRoot = true;
11589 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
11590 var rootWorkInProgress = root.current.alternate;
11591 !(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;
11592
11593 // `nextRoot` points to the in-progress root. A non-null value indicates
11594 // that we're in the middle of an async render. Set it to null to indicate
11595 // there's no more work to be done in the current batch.
11596 nextRoot = null;
11597 interruptedBy = null;
11598
11599 if (nextRenderDidError) {
11600 // There was an error
11601 if (hasLowerPriorityWork(root, expirationTime)) {
11602 // There's lower priority work. If so, it may have the effect of fixing
11603 // the exception that was just thrown. Exit without committing. This is
11604 // similar to a suspend, but without a timeout because we're not waiting
11605 // for a promise to resolve. React will restart at the lower
11606 // priority level.
11607 markSuspendedPriorityLevel(root, expirationTime);
11608 var suspendedExpirationTime = expirationTime;
11609 var rootExpirationTime = root.expirationTime;
11610 onSuspend(root, rootWorkInProgress, suspendedExpirationTime, rootExpirationTime, -1 // Indicates no timeout
11611 );
11612 return;
11613 } else if (
11614 // There's no lower priority work, but we're rendering asynchronously.
11615 // Synchronously attempt to render the same level one more time. This is
11616 // similar to a suspend, but without a timeout because we're not waiting
11617 // for a promise to resolve.
11618 !root.didError && isYieldy) {
11619 root.didError = true;
11620 var _suspendedExpirationTime = root.nextExpirationTimeToWorkOn = expirationTime;
11621 var _rootExpirationTime = root.expirationTime = Sync;
11622 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime, _rootExpirationTime, -1 // Indicates no timeout
11623 );
11624 return;
11625 }
11626 }
11627
11628 if (isYieldy && nextLatestAbsoluteTimeoutMs !== -1) {
11629 // The tree was suspended.
11630 var _suspendedExpirationTime2 = expirationTime;
11631 markSuspendedPriorityLevel(root, _suspendedExpirationTime2);
11632
11633 // Find the earliest uncommitted expiration time in the tree, including
11634 // work that is suspended. The timeout threshold cannot be longer than
11635 // the overall expiration.
11636 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, expirationTime);
11637 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
11638 if (earliestExpirationTimeMs < nextLatestAbsoluteTimeoutMs) {
11639 nextLatestAbsoluteTimeoutMs = earliestExpirationTimeMs;
11640 }
11641
11642 // Subtract the current time from the absolute timeout to get the number
11643 // of milliseconds until the timeout. In other words, convert an absolute
11644 // timestamp to a relative time. This is the value that is passed
11645 // to `setTimeout`.
11646 var currentTimeMs = expirationTimeToMs(requestCurrentTime());
11647 var msUntilTimeout = nextLatestAbsoluteTimeoutMs - currentTimeMs;
11648 msUntilTimeout = msUntilTimeout < 0 ? 0 : msUntilTimeout;
11649
11650 // TODO: Account for the Just Noticeable Difference
11651
11652 var _rootExpirationTime2 = root.expirationTime;
11653 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime2, _rootExpirationTime2, msUntilTimeout);
11654 return;
11655 }
11656
11657 // Ready to commit.
11658 onComplete(root, rootWorkInProgress, expirationTime);
11659}
11660
11661function captureCommitPhaseError(sourceFiber, value) {
11662 var expirationTime = Sync;
11663 var fiber = sourceFiber.return;
11664 while (fiber !== null) {
11665 switch (fiber.tag) {
11666 case ClassComponent:
11667 var ctor = fiber.type;
11668 var instance = fiber.stateNode;
11669 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
11670 var errorInfo = createCapturedValue(value, sourceFiber);
11671 var update = createClassErrorUpdate(fiber, errorInfo, expirationTime);
11672 enqueueUpdate(fiber, update);
11673 scheduleWork(fiber, expirationTime);
11674 return;
11675 }
11676 break;
11677 case HostRoot:
11678 {
11679 var _errorInfo = createCapturedValue(value, sourceFiber);
11680 var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime);
11681 enqueueUpdate(fiber, _update);
11682 scheduleWork(fiber, expirationTime);
11683 return;
11684 }
11685 }
11686 fiber = fiber.return;
11687 }
11688
11689 if (sourceFiber.tag === HostRoot) {
11690 // Error was thrown at the root. There is no parent, so the root
11691 // itself should capture it.
11692 var rootFiber = sourceFiber;
11693 var _errorInfo2 = createCapturedValue(value, rootFiber);
11694 var _update2 = createRootErrorUpdate(rootFiber, _errorInfo2, expirationTime);
11695 enqueueUpdate(rootFiber, _update2);
11696 scheduleWork(rootFiber, expirationTime);
11697 }
11698}
11699
11700function computeThreadID(expirationTime, interactionThreadID) {
11701 // Interaction threads are unique per root and expiration time.
11702 return expirationTime * 1000 + interactionThreadID;
11703}
11704
11705function computeExpirationForFiber(currentTime, fiber) {
11706 var priorityLevel = unstable_getCurrentPriorityLevel();
11707
11708 var expirationTime = void 0;
11709 if ((fiber.mode & ConcurrentMode) === NoContext) {
11710 // Outside of concurrent mode, updates are always synchronous.
11711 expirationTime = Sync;
11712 } else if (isWorking && !isCommitting$1) {
11713 // During render phase, updates expire during as the current render.
11714 expirationTime = nextRenderExpirationTime;
11715 } else {
11716 switch (priorityLevel) {
11717 case unstable_ImmediatePriority:
11718 expirationTime = Sync;
11719 break;
11720 case unstable_UserBlockingPriority:
11721 expirationTime = computeInteractiveExpiration(currentTime);
11722 break;
11723 case unstable_NormalPriority:
11724 // This is a normal, concurrent update
11725 expirationTime = computeAsyncExpiration(currentTime);
11726 break;
11727 case unstable_LowPriority:
11728 case unstable_IdlePriority:
11729 expirationTime = Never;
11730 break;
11731 default:
11732 invariant(false, 'Unknown priority level. This error is likely caused by a bug in React. Please file an issue.');
11733 }
11734
11735 // If we're in the middle of rendering a tree, do not update at the same
11736 // expiration time that is already rendering.
11737 if (nextRoot !== null && expirationTime === nextRenderExpirationTime) {
11738 expirationTime -= 1;
11739 }
11740 }
11741
11742 // Keep track of the lowest pending interactive expiration time. This
11743 // allows us to synchronously flush all interactive updates
11744 // when needed.
11745 // TODO: Move this to renderer?
11746 return expirationTime;
11747}
11748
11749function renderDidSuspend(root, absoluteTimeoutMs, suspendedTime) {
11750 // Schedule the timeout.
11751 if (absoluteTimeoutMs >= 0 && nextLatestAbsoluteTimeoutMs < absoluteTimeoutMs) {
11752 nextLatestAbsoluteTimeoutMs = absoluteTimeoutMs;
11753 }
11754}
11755
11756function renderDidError() {
11757 nextRenderDidError = true;
11758}
11759
11760function pingSuspendedRoot(root, thenable, pingTime) {
11761 // A promise that previously suspended React from committing has resolved.
11762 // If React is still suspended, try again at the previous level (pingTime).
11763
11764 var pingCache = root.pingCache;
11765 if (pingCache !== null) {
11766 // The thenable resolved, so we no longer need to memoize, because it will
11767 // never be thrown again.
11768 pingCache.delete(thenable);
11769 }
11770
11771 if (nextRoot !== null && nextRenderExpirationTime === pingTime) {
11772 // Received a ping at the same priority level at which we're currently
11773 // rendering. Restart from the root.
11774 nextRoot = null;
11775 } else {
11776 // Confirm that the root is still suspended at this level. Otherwise exit.
11777 if (isPriorityLevelSuspended(root, pingTime)) {
11778 // Ping at the original level
11779 markPingedPriorityLevel(root, pingTime);
11780 var rootExpirationTime = root.expirationTime;
11781 if (rootExpirationTime !== NoWork) {
11782 requestWork(root, rootExpirationTime);
11783 }
11784 }
11785 }
11786}
11787
11788function retryTimedOutBoundary(boundaryFiber, thenable) {
11789 // The boundary fiber (a Suspense component) previously timed out and was
11790 // rendered in its fallback state. One of the promises that suspended it has
11791 // resolved, which means at least part of the tree was likely unblocked. Try
11792 var retryCache = void 0;
11793 if (enableSuspenseServerRenderer) {
11794 switch (boundaryFiber.tag) {
11795 case SuspenseComponent:
11796 retryCache = boundaryFiber.stateNode;
11797 break;
11798 case DehydratedSuspenseComponent:
11799 retryCache = boundaryFiber.memoizedState;
11800 break;
11801 default:
11802 invariant(false, 'Pinged unknown suspense boundary type. This is probably a bug in React.');
11803 }
11804 } else {
11805 retryCache = boundaryFiber.stateNode;
11806 }
11807 if (retryCache !== null) {
11808 // The thenable resolved, so we no longer need to memoize, because it will
11809 // never be thrown again.
11810 retryCache.delete(thenable);
11811 }
11812
11813 var currentTime = requestCurrentTime();
11814 var retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
11815 var root = scheduleWorkToRoot(boundaryFiber, retryTime);
11816 if (root !== null) {
11817 markPendingPriorityLevel(root, retryTime);
11818 var rootExpirationTime = root.expirationTime;
11819 if (rootExpirationTime !== NoWork) {
11820 requestWork(root, rootExpirationTime);
11821 }
11822 }
11823}
11824
11825function scheduleWorkToRoot(fiber, expirationTime) {
11826 recordScheduleUpdate();
11827
11828 {
11829 if (fiber.tag === ClassComponent) {
11830 var instance = fiber.stateNode;
11831 warnAboutInvalidUpdates(instance);
11832 }
11833 }
11834
11835 // Update the source fiber's expiration time
11836 if (fiber.expirationTime < expirationTime) {
11837 fiber.expirationTime = expirationTime;
11838 }
11839 var alternate = fiber.alternate;
11840 if (alternate !== null && alternate.expirationTime < expirationTime) {
11841 alternate.expirationTime = expirationTime;
11842 }
11843 // Walk the parent path to the root and update the child expiration time.
11844 var node = fiber.return;
11845 var root = null;
11846 if (node === null && fiber.tag === HostRoot) {
11847 root = fiber.stateNode;
11848 } else {
11849 while (node !== null) {
11850 alternate = node.alternate;
11851 if (node.childExpirationTime < expirationTime) {
11852 node.childExpirationTime = expirationTime;
11853 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
11854 alternate.childExpirationTime = expirationTime;
11855 }
11856 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
11857 alternate.childExpirationTime = expirationTime;
11858 }
11859 if (node.return === null && node.tag === HostRoot) {
11860 root = node.stateNode;
11861 break;
11862 }
11863 node = node.return;
11864 }
11865 }
11866
11867 if (enableSchedulerTracing) {
11868 if (root !== null) {
11869 var interactions = __interactionsRef.current;
11870 if (interactions.size > 0) {
11871 var pendingInteractionMap = root.pendingInteractionMap;
11872 var pendingInteractions = pendingInteractionMap.get(expirationTime);
11873 if (pendingInteractions != null) {
11874 interactions.forEach(function (interaction) {
11875 if (!pendingInteractions.has(interaction)) {
11876 // Update the pending async work count for previously unscheduled interaction.
11877 interaction.__count++;
11878 }
11879
11880 pendingInteractions.add(interaction);
11881 });
11882 } else {
11883 pendingInteractionMap.set(expirationTime, new Set(interactions));
11884
11885 // Update the pending async work count for the current interactions.
11886 interactions.forEach(function (interaction) {
11887 interaction.__count++;
11888 });
11889 }
11890
11891 var subscriber = __subscriberRef.current;
11892 if (subscriber !== null) {
11893 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11894 subscriber.onWorkScheduled(interactions, threadID);
11895 }
11896 }
11897 }
11898 }
11899 return root;
11900}
11901
11902function warnIfNotCurrentlyBatchingInDev(fiber) {
11903 {
11904 if (isRendering === false && isBatchingUpdates === false) {
11905 warningWithoutStack$1(false, 'An update to %s inside a test was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see in the browser." + ' Learn more at https://fb.me/react-wrap-tests-with-act' + '%s', getComponentName(fiber.type), getStackByFiberInDevAndProd(fiber));
11906 }
11907 }
11908}
11909
11910function scheduleWork(fiber, expirationTime) {
11911 var root = scheduleWorkToRoot(fiber, expirationTime);
11912 if (root === null) {
11913 {
11914 switch (fiber.tag) {
11915 case ClassComponent:
11916 warnAboutUpdateOnUnmounted(fiber, true);
11917 break;
11918 case FunctionComponent:
11919 case ForwardRef:
11920 case MemoComponent:
11921 case SimpleMemoComponent:
11922 warnAboutUpdateOnUnmounted(fiber, false);
11923 break;
11924 }
11925 }
11926 return;
11927 }
11928
11929 if (!isWorking && nextRenderExpirationTime !== NoWork && expirationTime > nextRenderExpirationTime) {
11930 // This is an interruption. (Used for performance tracking.)
11931 interruptedBy = fiber;
11932 resetStack();
11933 }
11934 markPendingPriorityLevel(root, expirationTime);
11935 if (
11936 // If we're in the render phase, we don't need to schedule this root
11937 // for an update, because we'll do it before we exit...
11938 !isWorking || isCommitting$1 ||
11939 // ...unless this is a different root than the one we're rendering.
11940 nextRoot !== root) {
11941 var rootExpirationTime = root.expirationTime;
11942 requestWork(root, rootExpirationTime);
11943 }
11944 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
11945 // Reset this back to zero so subsequent updates don't throw.
11946 nestedUpdateCount = 0;
11947 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.');
11948 }
11949}
11950
11951function syncUpdates(fn, a, b, c, d) {
11952 return unstable_runWithPriority(unstable_ImmediatePriority, function () {
11953 return fn(a, b, c, d);
11954 });
11955}
11956
11957// TODO: Everything below this is written as if it has been lifted to the
11958// renderers. I'll do this in a follow-up.
11959
11960// Linked-list of roots
11961var firstScheduledRoot = null;
11962var lastScheduledRoot = null;
11963
11964var callbackExpirationTime = NoWork;
11965var callbackID = void 0;
11966var isRendering = false;
11967var nextFlushedRoot = null;
11968var nextFlushedExpirationTime = NoWork;
11969var hasUnhandledError = false;
11970var unhandledError = null;
11971
11972var isBatchingUpdates = false;
11973var isUnbatchingUpdates = false;
11974
11975var completedBatches = null;
11976
11977var originalStartTimeMs = now();
11978var currentRendererTime = msToExpirationTime(originalStartTimeMs);
11979var currentSchedulerTime = currentRendererTime;
11980
11981// Use these to prevent an infinite loop of nested updates
11982var NESTED_UPDATE_LIMIT = 50;
11983var nestedUpdateCount = 0;
11984var lastCommittedRootDuringThisBatch = null;
11985
11986function recomputeCurrentRendererTime() {
11987 var currentTimeMs = now() - originalStartTimeMs;
11988 currentRendererTime = msToExpirationTime(currentTimeMs);
11989}
11990
11991function scheduleCallbackWithExpirationTime(root, expirationTime) {
11992 if (callbackExpirationTime !== NoWork) {
11993 // A callback is already scheduled. Check its expiration time (timeout).
11994 if (expirationTime < callbackExpirationTime) {
11995 // Existing callback has sufficient timeout. Exit.
11996 return;
11997 } else {
11998 if (callbackID !== null) {
11999 // Existing callback has insufficient timeout. Cancel and schedule a
12000 // new one.
12001 cancelDeferredCallback$$1(callbackID);
12002 }
12003 }
12004 // The request callback timer is already running. Don't start a new one.
12005 } else {
12006 startRequestCallbackTimer();
12007 }
12008
12009 callbackExpirationTime = expirationTime;
12010 var currentMs = now() - originalStartTimeMs;
12011 var expirationTimeMs = expirationTimeToMs(expirationTime);
12012 var timeout = expirationTimeMs - currentMs;
12013 callbackID = scheduleDeferredCallback$$1(performAsyncWork, { timeout: timeout });
12014}
12015
12016// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and
12017// onYield is called upon exiting. We use these in lieu of returning a tuple.
12018// I've also chosen not to inline them into renderRoot because these will
12019// eventually be lifted into the renderer.
12020function onFatal(root) {
12021 root.finishedWork = null;
12022}
12023
12024function onComplete(root, finishedWork, expirationTime) {
12025 root.pendingCommitExpirationTime = expirationTime;
12026 root.finishedWork = finishedWork;
12027}
12028
12029function onSuspend(root, finishedWork, suspendedExpirationTime, rootExpirationTime, msUntilTimeout) {
12030 root.expirationTime = rootExpirationTime;
12031 if (msUntilTimeout === 0 && !shouldYieldToRenderer()) {
12032 // Don't wait an additional tick. Commit the tree immediately.
12033 root.pendingCommitExpirationTime = suspendedExpirationTime;
12034 root.finishedWork = finishedWork;
12035 } else if (msUntilTimeout > 0) {
12036 // Wait `msUntilTimeout` milliseconds before committing.
12037 root.timeoutHandle = scheduleTimeout(onTimeout.bind(null, root, finishedWork, suspendedExpirationTime), msUntilTimeout);
12038 }
12039}
12040
12041function onYield(root) {
12042 root.finishedWork = null;
12043}
12044
12045function onTimeout(root, finishedWork, suspendedExpirationTime) {
12046 // The root timed out. Commit it.
12047 root.pendingCommitExpirationTime = suspendedExpirationTime;
12048 root.finishedWork = finishedWork;
12049 // Read the current time before entering the commit phase. We can be
12050 // certain this won't cause tearing related to batching of event updates
12051 // because we're at the top of a timer event.
12052 recomputeCurrentRendererTime();
12053 currentSchedulerTime = currentRendererTime;
12054 flushRoot(root, suspendedExpirationTime);
12055}
12056
12057function onCommit(root, expirationTime) {
12058 root.expirationTime = expirationTime;
12059 root.finishedWork = null;
12060}
12061
12062function requestCurrentTime() {
12063 // requestCurrentTime is called by the scheduler to compute an expiration
12064 // time.
12065 //
12066 // Expiration times are computed by adding to the current time (the start
12067 // time). However, if two updates are scheduled within the same event, we
12068 // should treat their start times as simultaneous, even if the actual clock
12069 // time has advanced between the first and second call.
12070
12071 // In other words, because expiration times determine how updates are batched,
12072 // we want all updates of like priority that occur within the same event to
12073 // receive the same expiration time. Otherwise we get tearing.
12074 //
12075 // We keep track of two separate times: the current "renderer" time and the
12076 // current "scheduler" time. The renderer time can be updated whenever; it
12077 // only exists to minimize the calls performance.now.
12078 //
12079 // But the scheduler time can only be updated if there's no pending work, or
12080 // if we know for certain that we're not in the middle of an event.
12081
12082 if (isRendering) {
12083 // We're already rendering. Return the most recently read time.
12084 return currentSchedulerTime;
12085 }
12086 // Check if there's pending work.
12087 findHighestPriorityRoot();
12088 if (nextFlushedExpirationTime === NoWork || nextFlushedExpirationTime === Never) {
12089 // If there's no pending work, or if the pending work is offscreen, we can
12090 // read the current time without risk of tearing.
12091 recomputeCurrentRendererTime();
12092 currentSchedulerTime = currentRendererTime;
12093 return currentSchedulerTime;
12094 }
12095 // There's already pending work. We might be in the middle of a browser
12096 // event. If we were to read the current time, it could cause multiple updates
12097 // within the same event to receive different expiration times, leading to
12098 // tearing. Return the last read time. During the next idle callback, the
12099 // time will be updated.
12100 return currentSchedulerTime;
12101}
12102
12103// requestWork is called by the scheduler whenever a root receives an update.
12104// It's up to the renderer to call renderRoot at some point in the future.
12105function requestWork(root, expirationTime) {
12106 addRootToSchedule(root, expirationTime);
12107 if (isRendering) {
12108 // Prevent reentrancy. Remaining work will be scheduled at the end of
12109 // the currently rendering batch.
12110 return;
12111 }
12112
12113 if (isBatchingUpdates) {
12114 // Flush work at the end of the batch.
12115 if (isUnbatchingUpdates) {
12116 // ...unless we're inside unbatchedUpdates, in which case we should
12117 // flush it now.
12118 nextFlushedRoot = root;
12119 nextFlushedExpirationTime = Sync;
12120 performWorkOnRoot(root, Sync, false);
12121 }
12122 return;
12123 }
12124
12125 // TODO: Get rid of Sync and use current time?
12126 if (expirationTime === Sync) {
12127 performSyncWork();
12128 } else {
12129 scheduleCallbackWithExpirationTime(root, expirationTime);
12130 }
12131}
12132
12133function addRootToSchedule(root, expirationTime) {
12134 // Add the root to the schedule.
12135 // Check if this root is already part of the schedule.
12136 if (root.nextScheduledRoot === null) {
12137 // This root is not already scheduled. Add it.
12138 root.expirationTime = expirationTime;
12139 if (lastScheduledRoot === null) {
12140 firstScheduledRoot = lastScheduledRoot = root;
12141 root.nextScheduledRoot = root;
12142 } else {
12143 lastScheduledRoot.nextScheduledRoot = root;
12144 lastScheduledRoot = root;
12145 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12146 }
12147 } else {
12148 // This root is already scheduled, but its priority may have increased.
12149 var remainingExpirationTime = root.expirationTime;
12150 if (expirationTime > remainingExpirationTime) {
12151 // Update the priority.
12152 root.expirationTime = expirationTime;
12153 }
12154 }
12155}
12156
12157function findHighestPriorityRoot() {
12158 var highestPriorityWork = NoWork;
12159 var highestPriorityRoot = null;
12160 if (lastScheduledRoot !== null) {
12161 var previousScheduledRoot = lastScheduledRoot;
12162 var root = firstScheduledRoot;
12163 while (root !== null) {
12164 var remainingExpirationTime = root.expirationTime;
12165 if (remainingExpirationTime === NoWork) {
12166 // This root no longer has work. Remove it from the scheduler.
12167
12168 // TODO: This check is redudant, but Flow is confused by the branch
12169 // below where we set lastScheduledRoot to null, even though we break
12170 // from the loop right after.
12171 !(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;
12172 if (root === root.nextScheduledRoot) {
12173 // This is the only root in the list.
12174 root.nextScheduledRoot = null;
12175 firstScheduledRoot = lastScheduledRoot = null;
12176 break;
12177 } else if (root === firstScheduledRoot) {
12178 // This is the first root in the list.
12179 var next = root.nextScheduledRoot;
12180 firstScheduledRoot = next;
12181 lastScheduledRoot.nextScheduledRoot = next;
12182 root.nextScheduledRoot = null;
12183 } else if (root === lastScheduledRoot) {
12184 // This is the last root in the list.
12185 lastScheduledRoot = previousScheduledRoot;
12186 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12187 root.nextScheduledRoot = null;
12188 break;
12189 } else {
12190 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
12191 root.nextScheduledRoot = null;
12192 }
12193 root = previousScheduledRoot.nextScheduledRoot;
12194 } else {
12195 if (remainingExpirationTime > highestPriorityWork) {
12196 // Update the priority, if it's higher
12197 highestPriorityWork = remainingExpirationTime;
12198 highestPriorityRoot = root;
12199 }
12200 if (root === lastScheduledRoot) {
12201 break;
12202 }
12203 if (highestPriorityWork === Sync) {
12204 // Sync is highest priority by definition so
12205 // we can stop searching.
12206 break;
12207 }
12208 previousScheduledRoot = root;
12209 root = root.nextScheduledRoot;
12210 }
12211 }
12212 }
12213
12214 nextFlushedRoot = highestPriorityRoot;
12215 nextFlushedExpirationTime = highestPriorityWork;
12216}
12217
12218// TODO: This wrapper exists because many of the older tests (the ones that use
12219// flushDeferredPri) rely on the number of times `shouldYield` is called. We
12220// should get rid of it.
12221var didYield = false;
12222function shouldYieldToRenderer() {
12223 if (didYield) {
12224 return true;
12225 }
12226 if (shouldYield$$1()) {
12227 didYield = true;
12228 return true;
12229 }
12230 return false;
12231}
12232
12233function performAsyncWork() {
12234 try {
12235 if (!shouldYieldToRenderer()) {
12236 // The callback timed out. That means at least one update has expired.
12237 // Iterate through the root schedule. If they contain expired work, set
12238 // the next render expiration time to the current time. This has the effect
12239 // of flushing all expired work in a single batch, instead of flushing each
12240 // level one at a time.
12241 if (firstScheduledRoot !== null) {
12242 recomputeCurrentRendererTime();
12243 var root = firstScheduledRoot;
12244 do {
12245 didExpireAtExpirationTime(root, currentRendererTime);
12246 // The root schedule is circular, so this is never null.
12247 root = root.nextScheduledRoot;
12248 } while (root !== firstScheduledRoot);
12249 }
12250 }
12251 performWork(NoWork, true);
12252 } finally {
12253 didYield = false;
12254 }
12255}
12256
12257function performSyncWork() {
12258 performWork(Sync, false);
12259}
12260
12261function performWork(minExpirationTime, isYieldy) {
12262 // Keep working on roots until there's no more work, or until there's a higher
12263 // priority event.
12264 findHighestPriorityRoot();
12265
12266 if (isYieldy) {
12267 recomputeCurrentRendererTime();
12268 currentSchedulerTime = currentRendererTime;
12269
12270 if (enableUserTimingAPI) {
12271 var didExpire = nextFlushedExpirationTime > currentRendererTime;
12272 var timeout = expirationTimeToMs(nextFlushedExpirationTime);
12273 stopRequestCallbackTimer(didExpire, timeout);
12274 }
12275
12276 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime && !(didYield && currentRendererTime > nextFlushedExpirationTime)) {
12277 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, currentRendererTime > nextFlushedExpirationTime);
12278 findHighestPriorityRoot();
12279 recomputeCurrentRendererTime();
12280 currentSchedulerTime = currentRendererTime;
12281 }
12282 } else {
12283 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime) {
12284 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
12285 findHighestPriorityRoot();
12286 }
12287 }
12288
12289 // We're done flushing work. Either we ran out of time in this callback,
12290 // or there's no more work left with sufficient priority.
12291
12292 // If we're inside a callback, set this to false since we just completed it.
12293 if (isYieldy) {
12294 callbackExpirationTime = NoWork;
12295 callbackID = null;
12296 }
12297 // If there's work left over, schedule a new callback.
12298 if (nextFlushedExpirationTime !== NoWork) {
12299 scheduleCallbackWithExpirationTime(nextFlushedRoot, nextFlushedExpirationTime);
12300 }
12301
12302 // Clean-up.
12303 finishRendering();
12304}
12305
12306function flushRoot(root, expirationTime) {
12307 !!isRendering ? invariant(false, 'work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method.') : void 0;
12308 // Perform work on root as if the given expiration time is the current time.
12309 // This has the effect of synchronously flushing all work up to and
12310 // including the given time.
12311 nextFlushedRoot = root;
12312 nextFlushedExpirationTime = expirationTime;
12313 performWorkOnRoot(root, expirationTime, false);
12314 // Flush any sync work that was scheduled by lifecycles
12315 performSyncWork();
12316}
12317
12318function finishRendering() {
12319 nestedUpdateCount = 0;
12320 lastCommittedRootDuringThisBatch = null;
12321
12322 if (completedBatches !== null) {
12323 var batches = completedBatches;
12324 completedBatches = null;
12325 for (var i = 0; i < batches.length; i++) {
12326 var batch = batches[i];
12327 try {
12328 batch._onComplete();
12329 } catch (error) {
12330 if (!hasUnhandledError) {
12331 hasUnhandledError = true;
12332 unhandledError = error;
12333 }
12334 }
12335 }
12336 }
12337
12338 if (hasUnhandledError) {
12339 var error = unhandledError;
12340 unhandledError = null;
12341 hasUnhandledError = false;
12342 throw error;
12343 }
12344}
12345
12346function performWorkOnRoot(root, expirationTime, isYieldy) {
12347 !!isRendering ? invariant(false, 'performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
12348
12349 isRendering = true;
12350
12351 // Check if this is async work or sync/expired work.
12352 if (!isYieldy) {
12353 // Flush work without yielding.
12354 // TODO: Non-yieldy work does not necessarily imply expired work. A renderer
12355 // may want to perform some work without yielding, but also without
12356 // requiring the root to complete (by triggering placeholders).
12357
12358 var finishedWork = root.finishedWork;
12359 if (finishedWork !== null) {
12360 // This root is already complete. We can commit it.
12361 completeRoot(root, finishedWork, expirationTime);
12362 } else {
12363 root.finishedWork = null;
12364 // If this root previously suspended, clear its existing timeout, since
12365 // we're about to try rendering again.
12366 var timeoutHandle = root.timeoutHandle;
12367 if (timeoutHandle !== noTimeout) {
12368 root.timeoutHandle = noTimeout;
12369 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12370 cancelTimeout(timeoutHandle);
12371 }
12372 renderRoot(root, isYieldy);
12373 finishedWork = root.finishedWork;
12374 if (finishedWork !== null) {
12375 // We've completed the root. Commit it.
12376 completeRoot(root, finishedWork, expirationTime);
12377 }
12378 }
12379 } else {
12380 // Flush async work.
12381 var _finishedWork = root.finishedWork;
12382 if (_finishedWork !== null) {
12383 // This root is already complete. We can commit it.
12384 completeRoot(root, _finishedWork, expirationTime);
12385 } else {
12386 root.finishedWork = null;
12387 // If this root previously suspended, clear its existing timeout, since
12388 // we're about to try rendering again.
12389 var _timeoutHandle = root.timeoutHandle;
12390 if (_timeoutHandle !== noTimeout) {
12391 root.timeoutHandle = noTimeout;
12392 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12393 cancelTimeout(_timeoutHandle);
12394 }
12395 renderRoot(root, isYieldy);
12396 _finishedWork = root.finishedWork;
12397 if (_finishedWork !== null) {
12398 // We've completed the root. Check the if we should yield one more time
12399 // before committing.
12400 if (!shouldYieldToRenderer()) {
12401 // Still time left. Commit the root.
12402 completeRoot(root, _finishedWork, expirationTime);
12403 } else {
12404 // There's no time left. Mark this root as complete. We'll come
12405 // back and commit it later.
12406 root.finishedWork = _finishedWork;
12407 }
12408 }
12409 }
12410 }
12411
12412 isRendering = false;
12413}
12414
12415function completeRoot(root, finishedWork, expirationTime) {
12416 // Check if there's a batch that matches this expiration time.
12417 var firstBatch = root.firstBatch;
12418 if (firstBatch !== null && firstBatch._expirationTime >= expirationTime) {
12419 if (completedBatches === null) {
12420 completedBatches = [firstBatch];
12421 } else {
12422 completedBatches.push(firstBatch);
12423 }
12424 if (firstBatch._defer) {
12425 // This root is blocked from committing by a batch. Unschedule it until
12426 // we receive another update.
12427 root.finishedWork = finishedWork;
12428 root.expirationTime = NoWork;
12429 return;
12430 }
12431 }
12432
12433 // Commit the root.
12434 root.finishedWork = null;
12435
12436 // Check if this is a nested update (a sync update scheduled during the
12437 // commit phase).
12438 if (root === lastCommittedRootDuringThisBatch) {
12439 // If the next root is the same as the previous root, this is a nested
12440 // update. To prevent an infinite loop, increment the nested update count.
12441 nestedUpdateCount++;
12442 } else {
12443 // Reset whenever we switch roots.
12444 lastCommittedRootDuringThisBatch = root;
12445 nestedUpdateCount = 0;
12446 }
12447 unstable_runWithPriority(unstable_ImmediatePriority, function () {
12448 commitRoot(root, finishedWork);
12449 });
12450}
12451
12452function onUncaughtError(error) {
12453 !(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;
12454 // Unschedule this root so we don't work on it again until there's
12455 // another update.
12456 nextFlushedRoot.expirationTime = NoWork;
12457 if (!hasUnhandledError) {
12458 hasUnhandledError = true;
12459 unhandledError = error;
12460 }
12461}
12462
12463// TODO: Batching should be implemented at the renderer level, not inside
12464// the reconciler.
12465function batchedUpdates(fn, a) {
12466 var previousIsBatchingUpdates = isBatchingUpdates;
12467 isBatchingUpdates = true;
12468 try {
12469 return fn(a);
12470 } finally {
12471 isBatchingUpdates = previousIsBatchingUpdates;
12472 if (!isBatchingUpdates && !isRendering) {
12473 performSyncWork();
12474 }
12475 }
12476}
12477
12478// TODO: Batching should be implemented at the renderer level, not within
12479// the reconciler.
12480function flushSync(fn, a) {
12481 !!isRendering ? invariant(false, 'flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.') : void 0;
12482 var previousIsBatchingUpdates = isBatchingUpdates;
12483 isBatchingUpdates = true;
12484 try {
12485 return syncUpdates(fn, a);
12486 } finally {
12487 isBatchingUpdates = previousIsBatchingUpdates;
12488 performSyncWork();
12489 }
12490}
12491
12492// 0 is PROD, 1 is DEV.
12493// Might add PROFILE later.
12494
12495
12496var didWarnAboutNestedUpdates = void 0;
12497{
12498 didWarnAboutNestedUpdates = false;
12499
12500}
12501
12502function getContextForSubtree(parentComponent) {
12503 if (!parentComponent) {
12504 return emptyContextObject;
12505 }
12506
12507 var fiber = get(parentComponent);
12508 var parentContext = findCurrentUnmaskedContext(fiber);
12509
12510 if (fiber.tag === ClassComponent) {
12511 var Component = fiber.type;
12512 if (isContextProvider(Component)) {
12513 return processChildContext(fiber, Component, parentContext);
12514 }
12515 }
12516
12517 return parentContext;
12518}
12519
12520function scheduleRootUpdate(current$$1, element, expirationTime, callback) {
12521 {
12522 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
12523 didWarnAboutNestedUpdates = true;
12524 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');
12525 }
12526 }
12527
12528 var update = createUpdate(expirationTime);
12529 // Caution: React DevTools currently depends on this property
12530 // being called "element".
12531 update.payload = { element: element };
12532
12533 callback = callback === undefined ? null : callback;
12534 if (callback !== null) {
12535 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
12536 update.callback = callback;
12537 }
12538
12539 flushPassiveEffects$1();
12540 enqueueUpdate(current$$1, update);
12541 scheduleWork(current$$1, expirationTime);
12542
12543 return expirationTime;
12544}
12545
12546function updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback) {
12547 // TODO: If this is a nested container, this won't be the root.
12548 var current$$1 = container.current;
12549
12550 {
12551 if (ReactFiberInstrumentation_1.debugTool) {
12552 if (current$$1.alternate === null) {
12553 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
12554 } else if (element === null) {
12555 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
12556 } else {
12557 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
12558 }
12559 }
12560 }
12561
12562 var context = getContextForSubtree(parentComponent);
12563 if (container.context === null) {
12564 container.context = context;
12565 } else {
12566 container.pendingContext = context;
12567 }
12568
12569 return scheduleRootUpdate(current$$1, element, expirationTime, callback);
12570}
12571
12572function createContainer(containerInfo, isConcurrent, hydrate) {
12573 return createFiberRoot(containerInfo, isConcurrent, hydrate);
12574}
12575
12576function updateContainer(element, container, parentComponent, callback) {
12577 var current$$1 = container.current;
12578 var currentTime = requestCurrentTime();
12579 var expirationTime = computeExpirationForFiber(currentTime, current$$1);
12580 return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback);
12581}
12582
12583function getPublicRootInstance(container) {
12584 var containerFiber = container.current;
12585 if (!containerFiber.child) {
12586 return null;
12587 }
12588 switch (containerFiber.child.tag) {
12589 case HostComponent:
12590 return getPublicInstance(containerFiber.child.stateNode);
12591 default:
12592 return containerFiber.child.stateNode;
12593 }
12594}
12595
12596
12597
12598var overrideProps = null;
12599
12600{
12601 var copyWithSetImpl = function (obj, path, idx, value) {
12602 if (idx >= path.length) {
12603 return value;
12604 }
12605 var key = path[idx];
12606 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
12607 // $FlowFixMe number or string is fine here
12608 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
12609 return updated;
12610 };
12611
12612 var copyWithSet = function (obj, path, value) {
12613 return copyWithSetImpl(obj, path, 0, value);
12614 };
12615
12616 // Support DevTools props for function components, forwardRef, memo, host components, etc.
12617 overrideProps = function (fiber, path, value) {
12618 flushPassiveEffects$1();
12619 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
12620 if (fiber.alternate) {
12621 fiber.alternate.pendingProps = fiber.pendingProps;
12622 }
12623 scheduleWork(fiber, Sync);
12624 };
12625}
12626
12627function injectIntoDevTools(devToolsConfig) {
12628 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
12629 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
12630
12631
12632 return injectInternals(_assign({}, devToolsConfig, {
12633 overrideProps: overrideProps,
12634 currentDispatcherRef: ReactCurrentDispatcher,
12635 findHostInstanceByFiber: function (fiber) {
12636 var hostFiber = findCurrentHostFiber(fiber);
12637 if (hostFiber === null) {
12638 return null;
12639 }
12640 return hostFiber.stateNode;
12641 },
12642 findFiberByHostInstance: function (instance) {
12643 if (!findFiberByHostInstance) {
12644 // Might not be implemented by the renderer.
12645 return null;
12646 }
12647 return findFiberByHostInstance(instance);
12648 }
12649 }));
12650}
12651
12652// This file intentionally does *not* have the Flow annotation.
12653// Don't add it. See `./inline-typed.js` for an explanation.
12654
12655// TODO: this is special because it gets imported during build.
12656
12657var ReactVersion = '16.8.3';
12658
12659var _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; }; }();
12660
12661function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12662
12663function _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; }
12664
12665// for .act's return value
12666
12667
12668var defaultTestOptions = {
12669 createNodeMock: function () {
12670 return null;
12671 }
12672};
12673
12674function toJSON(inst) {
12675 if (inst.isHidden) {
12676 // Omit timed out children from output entirely. This seems like the least
12677 // surprising behavior. We could perhaps add a separate API that includes
12678 // them, if it turns out people need it.
12679 return null;
12680 }
12681 switch (inst.tag) {
12682 case 'TEXT':
12683 return inst.text;
12684 case 'INSTANCE':
12685 {
12686 /* eslint-disable no-unused-vars */
12687 // We don't include the `children` prop in JSON.
12688 // Instead, we will include the actual rendered children.
12689 var _inst$props = inst.props,
12690 _children = _inst$props.children,
12691 _props = _objectWithoutProperties(_inst$props, ['children']);
12692 /* eslint-enable */
12693
12694
12695 var renderedChildren = null;
12696 if (inst.children && inst.children.length) {
12697 for (var i = 0; i < inst.children.length; i++) {
12698 var renderedChild = toJSON(inst.children[i]);
12699 if (renderedChild !== null) {
12700 if (renderedChildren === null) {
12701 renderedChildren = [renderedChild];
12702 } else {
12703 renderedChildren.push(renderedChild);
12704 }
12705 }
12706 }
12707 }
12708 var json = {
12709 type: inst.type,
12710 props: _props,
12711 children: renderedChildren
12712 };
12713 Object.defineProperty(json, '$$typeof', {
12714 value: Symbol.for('react.test.json')
12715 });
12716 return json;
12717 }
12718 default:
12719 throw new Error('Unexpected node type in toJSON: ' + inst.tag);
12720 }
12721}
12722
12723function childrenToTree(node) {
12724 if (!node) {
12725 return null;
12726 }
12727 var children = nodeAndSiblingsArray(node);
12728 if (children.length === 0) {
12729 return null;
12730 } else if (children.length === 1) {
12731 return toTree(children[0]);
12732 }
12733 return flatten(children.map(toTree));
12734}
12735
12736function nodeAndSiblingsArray(nodeWithSibling) {
12737 var array = [];
12738 var node = nodeWithSibling;
12739 while (node != null) {
12740 array.push(node);
12741 node = node.sibling;
12742 }
12743 return array;
12744}
12745
12746function flatten(arr) {
12747 var result = [];
12748 var stack = [{ i: 0, array: arr }];
12749 while (stack.length) {
12750 var n = stack.pop();
12751 while (n.i < n.array.length) {
12752 var el = n.array[n.i];
12753 n.i += 1;
12754 if (Array.isArray(el)) {
12755 stack.push(n);
12756 stack.push({ i: 0, array: el });
12757 break;
12758 }
12759 result.push(el);
12760 }
12761 }
12762 return result;
12763}
12764
12765function toTree(node) {
12766 if (node == null) {
12767 return null;
12768 }
12769 switch (node.tag) {
12770 case HostRoot:
12771 return childrenToTree(node.child);
12772 case HostPortal:
12773 return childrenToTree(node.child);
12774 case ClassComponent:
12775 return {
12776 nodeType: 'component',
12777 type: node.type,
12778 props: _assign({}, node.memoizedProps),
12779 instance: node.stateNode,
12780 rendered: childrenToTree(node.child)
12781 };
12782 case FunctionComponent:
12783 case SimpleMemoComponent:
12784 return {
12785 nodeType: 'component',
12786 type: node.type,
12787 props: _assign({}, node.memoizedProps),
12788 instance: null,
12789 rendered: childrenToTree(node.child)
12790 };
12791 case HostComponent:
12792 {
12793 return {
12794 nodeType: 'host',
12795 type: node.type,
12796 props: _assign({}, node.memoizedProps),
12797 instance: null, // TODO: use createNodeMock here somehow?
12798 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
12799 };
12800 }
12801 case HostText:
12802 return node.stateNode.text;
12803 case Fragment:
12804 case ContextProvider:
12805 case ContextConsumer:
12806 case Mode:
12807 case Profiler:
12808 case ForwardRef:
12809 case MemoComponent:
12810 case IncompleteClassComponent:
12811 return childrenToTree(node.child);
12812 default:
12813 invariant(false, 'toTree() does not yet know how to handle nodes with tag=%s', node.tag);
12814 }
12815}
12816
12817var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent,
12818// Normally skipped, but used when there's more than one root child.
12819HostRoot]);
12820
12821function getChildren(parent) {
12822 var children = [];
12823 var startingNode = parent;
12824 var node = startingNode;
12825 if (node.child === null) {
12826 return children;
12827 }
12828 node.child.return = node;
12829 node = node.child;
12830 outer: while (true) {
12831 var descend = false;
12832 if (validWrapperTypes.has(node.tag)) {
12833 children.push(wrapFiber(node));
12834 } else if (node.tag === HostText) {
12835 children.push('' + node.memoizedProps);
12836 } else {
12837 descend = true;
12838 }
12839 if (descend && node.child !== null) {
12840 node.child.return = node;
12841 node = node.child;
12842 continue;
12843 }
12844 while (node.sibling === null) {
12845 if (node.return === startingNode) {
12846 break outer;
12847 }
12848 node = node.return;
12849 }
12850 node.sibling.return = node.return;
12851 node = node.sibling;
12852 }
12853 return children;
12854}
12855
12856var ReactTestInstance = function () {
12857 ReactTestInstance.prototype._currentFiber = function _currentFiber() {
12858 // Throws if this component has been unmounted.
12859 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
12860 !(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;
12861 return fiber;
12862 };
12863
12864 function ReactTestInstance(fiber) {
12865 _classCallCheck(this, ReactTestInstance);
12866
12867 !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;
12868 this._fiber = fiber;
12869 }
12870
12871 // Custom search functions
12872 ReactTestInstance.prototype.find = function find(predicate) {
12873 return expectOne(this.findAll(predicate, { deep: false }), 'matching custom predicate: ' + predicate.toString());
12874 };
12875
12876 ReactTestInstance.prototype.findByType = function findByType(type) {
12877 return expectOne(this.findAllByType(type, { deep: false }), 'with node type: "' + (type.displayName || type.name) + '"');
12878 };
12879
12880 ReactTestInstance.prototype.findByProps = function findByProps(props) {
12881 return expectOne(this.findAllByProps(props, { deep: false }), 'with props: ' + JSON.stringify(props));
12882 };
12883
12884 ReactTestInstance.prototype.findAll = function findAll(predicate) {
12885 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12886
12887 return _findAll(this, predicate, options);
12888 };
12889
12890 ReactTestInstance.prototype.findAllByType = function findAllByType(type) {
12891 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12892
12893 return _findAll(this, function (node) {
12894 return node.type === type;
12895 }, options);
12896 };
12897
12898 ReactTestInstance.prototype.findAllByProps = function findAllByProps(props) {
12899 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12900
12901 return _findAll(this, function (node) {
12902 return node.props && propsMatch(node.props, props);
12903 }, options);
12904 };
12905
12906 _createClass(ReactTestInstance, [{
12907 key: 'instance',
12908 get: function () {
12909 if (this._fiber.tag === HostComponent) {
12910 return getPublicInstance(this._fiber.stateNode);
12911 } else {
12912 return this._fiber.stateNode;
12913 }
12914 }
12915 }, {
12916 key: 'type',
12917 get: function () {
12918 return this._fiber.type;
12919 }
12920 }, {
12921 key: 'props',
12922 get: function () {
12923 return this._currentFiber().memoizedProps;
12924 }
12925 }, {
12926 key: 'parent',
12927 get: function () {
12928 var parent = this._fiber.return;
12929 while (parent !== null) {
12930 if (validWrapperTypes.has(parent.tag)) {
12931 if (parent.tag === HostRoot) {
12932 // Special case: we only "materialize" instances for roots
12933 // if they have more than a single child. So we'll check that now.
12934 if (getChildren(parent).length < 2) {
12935 return null;
12936 }
12937 }
12938 return wrapFiber(parent);
12939 }
12940 parent = parent.return;
12941 }
12942 return null;
12943 }
12944 }, {
12945 key: 'children',
12946 get: function () {
12947 return getChildren(this._currentFiber());
12948 }
12949 }]);
12950
12951 return ReactTestInstance;
12952}();
12953
12954function _findAll(root, predicate, options) {
12955 var deep = options ? options.deep : true;
12956 var results = [];
12957
12958 if (predicate(root)) {
12959 results.push(root);
12960 if (!deep) {
12961 return results;
12962 }
12963 }
12964
12965 root.children.forEach(function (child) {
12966 if (typeof child === 'string') {
12967 return;
12968 }
12969 results.push.apply(results, _findAll(child, predicate, options));
12970 });
12971
12972 return results;
12973}
12974
12975function expectOne(all, message) {
12976 if (all.length === 1) {
12977 return all[0];
12978 }
12979
12980 var prefix = all.length === 0 ? 'No instances found ' : 'Expected 1 but found ' + all.length + ' instances ';
12981
12982 throw new Error(prefix + message);
12983}
12984
12985function propsMatch(props, filter) {
12986 for (var key in filter) {
12987 if (props[key] !== filter[key]) {
12988 return false;
12989 }
12990 }
12991 return true;
12992}
12993
12994var ReactTestRendererFiber = {
12995 create: function (element, options) {
12996 var createNodeMock = defaultTestOptions.createNodeMock;
12997 var isConcurrent = false;
12998 if (typeof options === 'object' && options !== null) {
12999 if (typeof options.createNodeMock === 'function') {
13000 createNodeMock = options.createNodeMock;
13001 }
13002 if (options.unstable_isConcurrent === true) {
13003 isConcurrent = true;
13004 }
13005 }
13006 var container = {
13007 children: [],
13008 createNodeMock: createNodeMock,
13009 tag: 'CONTAINER'
13010 };
13011 var root = createContainer(container, isConcurrent, false);
13012 !(root != null) ? invariant(false, 'something went wrong') : void 0;
13013 updateContainer(element, root, null, null);
13014
13015 var entry = {
13016 root: undefined, // makes flow happy
13017 // we define a 'getter' for 'root' below using 'Object.defineProperty'
13018 toJSON: function () {
13019 if (root == null || root.current == null || container == null) {
13020 return null;
13021 }
13022 if (container.children.length === 0) {
13023 return null;
13024 }
13025 if (container.children.length === 1) {
13026 return toJSON(container.children[0]);
13027 }
13028 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
13029 // Omit timed out children from output entirely, including the fact that we
13030 // temporarily wrap fallback and timed out children in an array.
13031 return toJSON(container.children[1]);
13032 }
13033 var renderedChildren = null;
13034 if (container.children && container.children.length) {
13035 for (var i = 0; i < container.children.length; i++) {
13036 var renderedChild = toJSON(container.children[i]);
13037 if (renderedChild !== null) {
13038 if (renderedChildren === null) {
13039 renderedChildren = [renderedChild];
13040 } else {
13041 renderedChildren.push(renderedChild);
13042 }
13043 }
13044 }
13045 }
13046 return renderedChildren;
13047 },
13048 toTree: function () {
13049 if (root == null || root.current == null) {
13050 return null;
13051 }
13052 return toTree(root.current);
13053 },
13054 update: function (newElement) {
13055 if (root == null || root.current == null) {
13056 return;
13057 }
13058 updateContainer(newElement, root, null, null);
13059 },
13060 unmount: function () {
13061 if (root == null || root.current == null) {
13062 return;
13063 }
13064 updateContainer(null, root, null, null);
13065 container = null;
13066 root = null;
13067 },
13068 getInstance: function () {
13069 if (root == null || root.current == null) {
13070 return null;
13071 }
13072 return getPublicRootInstance(root);
13073 },
13074
13075
13076 unstable_flushAll: flushAll,
13077 unstable_flushSync: function (fn) {
13078 clearYields();
13079 return flushSync(fn);
13080 },
13081
13082 unstable_flushNumberOfYields: flushNumberOfYields,
13083 unstable_clearYields: clearYields
13084 };
13085
13086 Object.defineProperty(entry, 'root', {
13087 configurable: true,
13088 enumerable: true,
13089 get: function () {
13090 if (root === null) {
13091 throw new Error("Can't access .root on unmounted test renderer");
13092 }
13093 var children = getChildren(root.current);
13094 if (children.length === 0) {
13095 throw new Error("Can't access .root on unmounted test renderer");
13096 } else if (children.length === 1) {
13097 // Normally, we skip the root and just give you the child.
13098 return children[0];
13099 } else {
13100 // However, we give you the root if there's more than one root child.
13101 // We could make this the behavior for all cases but it would be a breaking change.
13102 return wrapFiber(root.current);
13103 }
13104 }
13105 });
13106
13107 return entry;
13108 },
13109
13110
13111 unstable_yield: yieldValue,
13112 unstable_clearYields: clearYields,
13113
13114 /* eslint-disable camelcase */
13115 unstable_batchedUpdates: batchedUpdates,
13116 /* eslint-enable camelcase */
13117
13118 unstable_setNowImplementation: setNowImplementation,
13119
13120 act: function (callback) {
13121 // note: keep these warning messages in sync with
13122 // createNoop.js and ReactTestUtils.js
13123 var result = batchedUpdates(callback);
13124 {
13125 if (result !== undefined) {
13126 var addendum = void 0;
13127 if (result !== null && typeof result.then === 'function') {
13128 addendum = "\n\nIt looks like you wrote TestRenderer.act(async () => ...) or returned a Promise from it's callback. " + 'Putting asynchronous logic inside TestRenderer.act(...) is not supported.\n';
13129 } else {
13130 addendum = ' You returned: ' + result;
13131 }
13132 warningWithoutStack$1(false, 'The callback passed to TestRenderer.act(...) function must not return anything.%s', addendum);
13133 }
13134 }
13135 flushPassiveEffects();
13136 // we want the user to not expect a return,
13137 // but we want to warn if they use it like they can await on it.
13138 return {
13139 then: function () {
13140 {
13141 warningWithoutStack$1(false, 'Do not await the result of calling TestRenderer.act(...), it is not a Promise.');
13142 }
13143 }
13144 };
13145 }
13146};
13147
13148// root used to flush effects during .act() calls
13149var actRoot = createContainer({
13150 children: [],
13151 createNodeMock: defaultTestOptions.createNodeMock,
13152 tag: 'CONTAINER'
13153}, true, false);
13154
13155function flushPassiveEffects() {
13156 // Trick to flush passive effects without exposing an internal API:
13157 // Create a throwaway root and schedule a dummy update on it.
13158 updateContainer(null, actRoot, null, null);
13159}
13160
13161var fiberToWrapper = new WeakMap();
13162function wrapFiber(fiber) {
13163 var wrapper = fiberToWrapper.get(fiber);
13164 if (wrapper === undefined && fiber.alternate !== null) {
13165 wrapper = fiberToWrapper.get(fiber.alternate);
13166 }
13167 if (wrapper === undefined) {
13168 wrapper = new ReactTestInstance(fiber);
13169 fiberToWrapper.set(fiber, wrapper);
13170 }
13171 return wrapper;
13172}
13173
13174// Enable ReactTestRenderer to be used to test DevTools integration.
13175injectIntoDevTools({
13176 findFiberByHostInstance: function () {
13177 throw new Error('TestRenderer does not support findFiberByHostInstance()');
13178 },
13179 bundleType: 1,
13180 version: ReactVersion,
13181 rendererPackageName: 'react-test-renderer'
13182});
13183
13184
13185
13186var ReactTestRenderer = Object.freeze({
13187 default: ReactTestRendererFiber
13188});
13189
13190var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
13191
13192// TODO: decide on the top-level export form.
13193// This is hacky but makes it work with both Rollup and Jest.
13194var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
13195
13196return reactTestRenderer;
13197
13198})));