UNPKG

498 kBJavaScriptView Raw
1/** @license React v16.8.6
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
13
14if (process.env.NODE_ENV !== "production") {
15 (function() {
16'use strict';
17
18var _assign = require('object-assign');
19var React = require('react');
20var checkPropTypes = require('prop-types/checkPropTypes');
21var tracing = require('scheduler/tracing');
22var scheduler = require('scheduler');
23
24/**
25 * Use invariant() to assert state which your program assumes to be true.
26 *
27 * Provide sprintf-style format (only %s is supported) and arguments
28 * to provide information about what broke and what you were
29 * expecting.
30 *
31 * The invariant message will be stripped in production, but the invariant
32 * will remain to ensure logic does not differ in production.
33 */
34
35var validateFormat = function () {};
36
37{
38 validateFormat = function (format) {
39 if (format === undefined) {
40 throw new Error('invariant requires an error message argument');
41 }
42 };
43}
44
45function invariant(condition, format, a, b, c, d, e, f) {
46 validateFormat(format);
47
48 if (!condition) {
49 var error = void 0;
50 if (format === undefined) {
51 error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
52 } else {
53 var args = [a, b, c, d, e, f];
54 var argIndex = 0;
55 error = new Error(format.replace(/%s/g, function () {
56 return args[argIndex++];
57 }));
58 error.name = 'Invariant Violation';
59 }
60
61 error.framesToPop = 1; // we don't care about invariant's own frame
62 throw error;
63 }
64}
65
66// Relying on the `invariant()` implementation lets us
67// preserve the format and params in the www builds.
68
69/**
70 * Similar to invariant but only logs a warning if the condition is not met.
71 * This can be used to log issues in development environments in critical
72 * paths. Removing the logging code for production environments will keep the
73 * same logic and follow the same code paths.
74 */
75
76var warningWithoutStack = function () {};
77
78{
79 warningWithoutStack = function (condition, format) {
80 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
81 args[_key - 2] = arguments[_key];
82 }
83
84 if (format === undefined) {
85 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
86 }
87 if (args.length > 8) {
88 // Check before the condition to catch violations early.
89 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
90 }
91 if (condition) {
92 return;
93 }
94 if (typeof console !== 'undefined') {
95 var argsWithFormat = args.map(function (item) {
96 return '' + item;
97 });
98 argsWithFormat.unshift('Warning: ' + format);
99
100 // We intentionally don't use spread (or .apply) directly because it
101 // breaks IE9: https://github.com/facebook/react/issues/13610
102 Function.prototype.apply.call(console.error, console, argsWithFormat);
103 }
104 try {
105 // --- Welcome to debugging React ---
106 // This error was thrown as a convenience so that you can use this stack
107 // to find the callsite that caused this warning to fire.
108 var argIndex = 0;
109 var message = 'Warning: ' + format.replace(/%s/g, function () {
110 return args[argIndex++];
111 });
112 throw new Error(message);
113 } catch (x) {}
114 };
115}
116
117var warningWithoutStack$1 = warningWithoutStack;
118
119/**
120 * `ReactInstanceMap` maintains a mapping from a public facing stateful
121 * instance (key) and the internal representation (value). This allows public
122 * methods to accept the user facing instance as an argument and map them back
123 * to internal methods.
124 *
125 * Note that this module is currently shared and assumed to be stateless.
126 * If this becomes an actual Map, that will break.
127 */
128
129/**
130 * This API should be called `delete` but we'd have to make sure to always
131 * transform these to strings for IE support. When this transform is fully
132 * supported we can rename it.
133 */
134
135
136function get(key) {
137 return key._reactInternalFiber;
138}
139
140
141
142function set(key, value) {
143 key._reactInternalFiber = value;
144}
145
146var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
147
148// Prevent newer renderers from RTE when used with older react package versions.
149// Current owner and dispatcher used to share the same ref,
150// but PR #14548 split them out to better support the react-debug-tools package.
151if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
152 ReactSharedInternals.ReactCurrentDispatcher = {
153 current: null
154 };
155}
156
157// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
158// nor polyfill, then a plain number is used for performance.
159var hasSymbol = typeof Symbol === 'function' && Symbol.for;
160
161var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
162var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
163var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
164var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
165var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
166var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
167var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
168
169var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
170var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
171var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
172var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
173var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
174
175var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
176var FAUX_ITERATOR_SYMBOL = '@@iterator';
177
178function getIteratorFn(maybeIterable) {
179 if (maybeIterable === null || typeof maybeIterable !== 'object') {
180 return null;
181 }
182 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
183 if (typeof maybeIterator === 'function') {
184 return maybeIterator;
185 }
186 return null;
187}
188
189var Pending = 0;
190var Resolved = 1;
191var Rejected = 2;
192
193function refineResolvedLazyComponent(lazyComponent) {
194 return lazyComponent._status === Resolved ? lazyComponent._result : null;
195}
196
197function getWrappedName(outerType, innerType, wrapperName) {
198 var functionName = innerType.displayName || innerType.name || '';
199 return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
200}
201
202function getComponentName(type) {
203 if (type == null) {
204 // Host root, text node or just invalid type.
205 return null;
206 }
207 {
208 if (typeof type.tag === 'number') {
209 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
210 }
211 }
212 if (typeof type === 'function') {
213 return type.displayName || type.name || null;
214 }
215 if (typeof type === 'string') {
216 return type;
217 }
218 switch (type) {
219 case REACT_CONCURRENT_MODE_TYPE:
220 return 'ConcurrentMode';
221 case REACT_FRAGMENT_TYPE:
222 return 'Fragment';
223 case REACT_PORTAL_TYPE:
224 return 'Portal';
225 case REACT_PROFILER_TYPE:
226 return 'Profiler';
227 case REACT_STRICT_MODE_TYPE:
228 return 'StrictMode';
229 case REACT_SUSPENSE_TYPE:
230 return 'Suspense';
231 }
232 if (typeof type === 'object') {
233 switch (type.$$typeof) {
234 case REACT_CONTEXT_TYPE:
235 return 'Context.Consumer';
236 case REACT_PROVIDER_TYPE:
237 return 'Context.Provider';
238 case REACT_FORWARD_REF_TYPE:
239 return getWrappedName(type, type.render, 'ForwardRef');
240 case REACT_MEMO_TYPE:
241 return getComponentName(type.type);
242 case REACT_LAZY_TYPE:
243 {
244 var thenable = type;
245 var resolvedThenable = refineResolvedLazyComponent(thenable);
246 if (resolvedThenable) {
247 return getComponentName(resolvedThenable);
248 }
249 }
250 }
251 }
252 return null;
253}
254
255var FunctionComponent = 0;
256var ClassComponent = 1;
257var IndeterminateComponent = 2; // Before we know whether it is function or class
258var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
259var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
260var HostComponent = 5;
261var HostText = 6;
262var Fragment = 7;
263var Mode = 8;
264var ContextConsumer = 9;
265var ContextProvider = 10;
266var ForwardRef = 11;
267var Profiler = 12;
268var SuspenseComponent = 13;
269var MemoComponent = 14;
270var SimpleMemoComponent = 15;
271var LazyComponent = 16;
272var IncompleteClassComponent = 17;
273var DehydratedSuspenseComponent = 18;
274
275// Don't change these two values. They're used by React Dev Tools.
276var NoEffect = /* */0;
277var PerformedWork = /* */1;
278
279// You can change the rest (and add more).
280var Placement = /* */2;
281var Update = /* */4;
282var PlacementAndUpdate = /* */6;
283var Deletion = /* */8;
284var ContentReset = /* */16;
285var Callback = /* */32;
286var DidCapture = /* */64;
287var Ref = /* */128;
288var Snapshot = /* */256;
289var Passive = /* */512;
290
291// Passive & Update & Callback & Ref & Snapshot
292var LifecycleEffectMask = /* */932;
293
294// Union of all host effects
295var HostEffectMask = /* */1023;
296
297var Incomplete = /* */1024;
298var ShouldCapture = /* */2048;
299
300var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
301
302var MOUNTING = 1;
303var MOUNTED = 2;
304var UNMOUNTED = 3;
305
306function isFiberMountedImpl(fiber) {
307 var node = fiber;
308 if (!fiber.alternate) {
309 // If there is no alternate, this might be a new tree that isn't inserted
310 // yet. If it is, then it will have a pending insertion effect on it.
311 if ((node.effectTag & Placement) !== NoEffect) {
312 return MOUNTING;
313 }
314 while (node.return) {
315 node = node.return;
316 if ((node.effectTag & Placement) !== NoEffect) {
317 return MOUNTING;
318 }
319 }
320 } else {
321 while (node.return) {
322 node = node.return;
323 }
324 }
325 if (node.tag === HostRoot) {
326 // TODO: Check if this was a nested HostRoot when used with
327 // renderContainerIntoSubtree.
328 return MOUNTED;
329 }
330 // If we didn't hit the root, that means that we're in an disconnected tree
331 // that has been unmounted.
332 return UNMOUNTED;
333}
334
335function isFiberMounted(fiber) {
336 return isFiberMountedImpl(fiber) === MOUNTED;
337}
338
339function isMounted(component) {
340 {
341 var owner = ReactCurrentOwner.current;
342 if (owner !== null && owner.tag === ClassComponent) {
343 var ownerFiber = owner;
344 var instance = ownerFiber.stateNode;
345 !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;
346 instance._warnedAboutRefsInRender = true;
347 }
348 }
349
350 var fiber = get(component);
351 if (!fiber) {
352 return false;
353 }
354 return isFiberMountedImpl(fiber) === MOUNTED;
355}
356
357function assertIsMounted(fiber) {
358 !(isFiberMountedImpl(fiber) === MOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
359}
360
361function findCurrentFiberUsingSlowPath(fiber) {
362 var alternate = fiber.alternate;
363 if (!alternate) {
364 // If there is no alternate, then we only need to check if it is mounted.
365 var state = isFiberMountedImpl(fiber);
366 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
367 if (state === MOUNTING) {
368 return null;
369 }
370 return fiber;
371 }
372 // If we have two possible branches, we'll walk backwards up to the root
373 // to see what path the root points to. On the way we may hit one of the
374 // special cases and we'll deal with them.
375 var a = fiber;
376 var b = alternate;
377 while (true) {
378 var parentA = a.return;
379 var parentB = parentA ? parentA.alternate : null;
380 if (!parentA || !parentB) {
381 // We're at the root.
382 break;
383 }
384
385 // If both copies of the parent fiber point to the same child, we can
386 // assume that the child is current. This happens when we bailout on low
387 // priority: the bailed out fiber's child reuses the current child.
388 if (parentA.child === parentB.child) {
389 var child = parentA.child;
390 while (child) {
391 if (child === a) {
392 // We've determined that A is the current branch.
393 assertIsMounted(parentA);
394 return fiber;
395 }
396 if (child === b) {
397 // We've determined that B is the current branch.
398 assertIsMounted(parentA);
399 return alternate;
400 }
401 child = child.sibling;
402 }
403 // We should never have an alternate for any mounting node. So the only
404 // way this could possibly happen is if this was unmounted, if at all.
405 invariant(false, 'Unable to find node on an unmounted component.');
406 }
407
408 if (a.return !== b.return) {
409 // The return pointer of A and the return pointer of B point to different
410 // fibers. We assume that return pointers never criss-cross, so A must
411 // belong to the child set of A.return, and B must belong to the child
412 // set of B.return.
413 a = parentA;
414 b = parentB;
415 } else {
416 // The return pointers point to the same fiber. We'll have to use the
417 // default, slow path: scan the child sets of each parent alternate to see
418 // which child belongs to which set.
419 //
420 // Search parent A's child set
421 var didFindChild = false;
422 var _child = parentA.child;
423 while (_child) {
424 if (_child === a) {
425 didFindChild = true;
426 a = parentA;
427 b = parentB;
428 break;
429 }
430 if (_child === b) {
431 didFindChild = true;
432 b = parentA;
433 a = parentB;
434 break;
435 }
436 _child = _child.sibling;
437 }
438 if (!didFindChild) {
439 // Search parent B's child set
440 _child = parentB.child;
441 while (_child) {
442 if (_child === a) {
443 didFindChild = true;
444 a = parentB;
445 b = parentA;
446 break;
447 }
448 if (_child === b) {
449 didFindChild = true;
450 b = parentB;
451 a = parentA;
452 break;
453 }
454 _child = _child.sibling;
455 }
456 !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;
457 }
458 }
459
460 !(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;
461 }
462 // If the root is not a host container, we're in a disconnected tree. I.e.
463 // unmounted.
464 !(a.tag === HostRoot) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
465 if (a.stateNode.current === a) {
466 // We've determined that A is the current branch.
467 return fiber;
468 }
469 // Otherwise B has to be current branch.
470 return alternate;
471}
472
473function findCurrentHostFiber(parent) {
474 var currentParent = findCurrentFiberUsingSlowPath(parent);
475 if (!currentParent) {
476 return null;
477 }
478
479 // Next we'll drill down this component to find the first HostComponent/Text.
480 var node = currentParent;
481 while (true) {
482 if (node.tag === HostComponent || node.tag === HostText) {
483 return node;
484 } else if (node.child) {
485 node.child.return = node;
486 node = node.child;
487 continue;
488 }
489 if (node === currentParent) {
490 return null;
491 }
492 while (!node.sibling) {
493 if (!node.return || node.return === currentParent) {
494 return null;
495 }
496 node = node.return;
497 }
498 node.sibling.return = node.return;
499 node = node.sibling;
500 }
501 // Flow needs the return null here, but ESLint complains about it.
502 // eslint-disable-next-line no-unreachable
503 return null;
504}
505
506/**
507 * Similar to invariant but only logs a warning if the condition is not met.
508 * This can be used to log issues in development environments in critical
509 * paths. Removing the logging code for production environments will keep the
510 * same logic and follow the same code paths.
511 */
512
513var warning = warningWithoutStack$1;
514
515{
516 warning = function (condition, format) {
517 if (condition) {
518 return;
519 }
520 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
521 var stack = ReactDebugCurrentFrame.getStackAddendum();
522 // eslint-disable-next-line react-internal/warning-and-invariant-args
523
524 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
525 args[_key - 2] = arguments[_key];
526 }
527
528 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
529 };
530}
531
532var warning$1 = warning;
533
534// Current virtual time
535var nowImplementation = function () {
536 return 0;
537};
538var scheduledCallback = null;
539var yieldedValues = [];
540
541var didStop = false;
542var expectedNumberOfYields = -1;
543
544function scheduleDeferredCallback$1(callback, options) {
545 scheduledCallback = callback;
546 var fakeCallbackId = 0;
547 return fakeCallbackId;
548}
549
550function cancelDeferredCallback$1(timeoutID) {
551 scheduledCallback = null;
552}
553
554function setNowImplementation(implementation) {
555 nowImplementation = implementation;
556}
557
558function shouldYield$1() {
559 if (expectedNumberOfYields !== -1 && yieldedValues.length >= expectedNumberOfYields) {
560 // We yielded at least as many values as expected. Stop rendering.
561 didStop = true;
562 return true;
563 }
564 // Keep rendering.
565 return false;
566}
567
568function flushAll() {
569 yieldedValues = [];
570 while (scheduledCallback !== null) {
571 var cb = scheduledCallback;
572 scheduledCallback = null;
573 cb();
574 }
575 var values = yieldedValues;
576 yieldedValues = [];
577 return values;
578}
579
580function flushNumberOfYields(count) {
581 expectedNumberOfYields = count;
582 didStop = false;
583 yieldedValues = [];
584 try {
585 while (scheduledCallback !== null && !didStop) {
586 var cb = scheduledCallback;
587 scheduledCallback = null;
588 cb();
589 }
590 return yieldedValues;
591 } finally {
592 expectedNumberOfYields = -1;
593 didStop = false;
594 yieldedValues = [];
595 }
596}
597
598function yieldValue(value) {
599 yieldedValues.push(value);
600}
601
602function clearYields() {
603 var values = yieldedValues;
604 yieldedValues = [];
605 return values;
606}
607
608// Renderers that don't support persistence
609// can re-export everything from this module.
610
611function shim() {
612 invariant(false, 'The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.');
613}
614
615// Persistence (when unsupported)
616var supportsPersistence = false;
617var cloneInstance = shim;
618var createContainerChildSet = shim;
619var appendChildToContainerChildSet = shim;
620var finalizeContainerChildren = shim;
621var replaceContainerChildren = shim;
622var cloneHiddenInstance = shim;
623var cloneUnhiddenInstance = shim;
624var createHiddenTextInstance = shim;
625
626// Renderers that don't support hydration
627// can re-export everything from this module.
628
629function shim$1() {
630 invariant(false, 'The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.');
631}
632
633// Hydration (when unsupported)
634
635var supportsHydration = false;
636var canHydrateInstance = shim$1;
637var canHydrateTextInstance = shim$1;
638var canHydrateSuspenseInstance = shim$1;
639var getNextHydratableSibling = shim$1;
640var getFirstHydratableChild = shim$1;
641var hydrateInstance = shim$1;
642var hydrateTextInstance = shim$1;
643var getNextHydratableInstanceAfterSuspenseInstance = shim$1;
644var clearSuspenseBoundary = shim$1;
645var clearSuspenseBoundaryFromContainer = shim$1;
646var didNotMatchHydratedContainerTextInstance = shim$1;
647var didNotMatchHydratedTextInstance = shim$1;
648var didNotHydrateContainerInstance = shim$1;
649var didNotHydrateInstance = shim$1;
650var didNotFindHydratableContainerInstance = shim$1;
651var didNotFindHydratableContainerTextInstance = shim$1;
652var didNotFindHydratableContainerSuspenseInstance = shim$1;
653var didNotFindHydratableInstance = shim$1;
654var didNotFindHydratableTextInstance = shim$1;
655var didNotFindHydratableSuspenseInstance = shim$1;
656
657var NO_CONTEXT = {};
658var UPDATE_SIGNAL = {};
659{
660 Object.freeze(NO_CONTEXT);
661 Object.freeze(UPDATE_SIGNAL);
662}
663
664function getPublicInstance(inst) {
665 switch (inst.tag) {
666 case 'INSTANCE':
667 var _createNodeMock = inst.rootContainerInstance.createNodeMock;
668 return _createNodeMock({
669 type: inst.type,
670 props: inst.props
671 });
672 default:
673 return inst;
674 }
675}
676
677function appendChild(parentInstance, child) {
678 {
679 !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;
680 }
681 var index = parentInstance.children.indexOf(child);
682 if (index !== -1) {
683 parentInstance.children.splice(index, 1);
684 }
685 parentInstance.children.push(child);
686}
687
688function insertBefore(parentInstance, child, beforeChild) {
689 var index = parentInstance.children.indexOf(child);
690 if (index !== -1) {
691 parentInstance.children.splice(index, 1);
692 }
693 var beforeIndex = parentInstance.children.indexOf(beforeChild);
694 parentInstance.children.splice(beforeIndex, 0, child);
695}
696
697function removeChild(parentInstance, child) {
698 var index = parentInstance.children.indexOf(child);
699 parentInstance.children.splice(index, 1);
700}
701
702function getRootHostContext(rootContainerInstance) {
703 return NO_CONTEXT;
704}
705
706function getChildHostContext(parentHostContext, type, rootContainerInstance) {
707 return NO_CONTEXT;
708}
709
710function prepareForCommit(containerInfo) {
711 // noop
712}
713
714function resetAfterCommit(containerInfo) {
715 // noop
716}
717
718function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
719 return {
720 type: type,
721 props: props,
722 isHidden: false,
723 children: [],
724 rootContainerInstance: rootContainerInstance,
725 tag: 'INSTANCE'
726 };
727}
728
729function appendInitialChild(parentInstance, child) {
730 var index = parentInstance.children.indexOf(child);
731 if (index !== -1) {
732 parentInstance.children.splice(index, 1);
733 }
734 parentInstance.children.push(child);
735}
736
737function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
738 return false;
739}
740
741function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
742 return UPDATE_SIGNAL;
743}
744
745function shouldSetTextContent(type, props) {
746 return false;
747}
748
749function shouldDeprioritizeSubtree(type, props) {
750 return false;
751}
752
753function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
754 return {
755 text: text,
756 isHidden: false,
757 tag: 'TEXT'
758 };
759}
760
761var isPrimaryRenderer = false;
762// This approach enables `now` to be mocked by tests,
763// Even after the reconciler has initialized and read host config values.
764var now = function () {
765 return nowImplementation();
766};
767var scheduleDeferredCallback$$1 = scheduleDeferredCallback$1;
768var cancelDeferredCallback$$1 = cancelDeferredCallback$1;
769var shouldYield$$1 = shouldYield$1;
770
771var scheduleTimeout = setTimeout;
772var cancelTimeout = clearTimeout;
773var noTimeout = -1;
774var schedulePassiveEffects = scheduleDeferredCallback$$1;
775var cancelPassiveEffects = cancelDeferredCallback$$1;
776
777// -------------------
778// Mutation
779// -------------------
780
781var supportsMutation = true;
782
783function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
784 instance.type = type;
785 instance.props = newProps;
786}
787
788
789
790function commitTextUpdate(textInstance, oldText, newText) {
791 textInstance.text = newText;
792}
793
794function resetTextContent(testElement) {
795 // noop
796}
797
798var appendChildToContainer = appendChild;
799var insertInContainerBefore = insertBefore;
800var removeChildFromContainer = removeChild;
801
802function hideInstance(instance) {
803 instance.isHidden = true;
804}
805
806function hideTextInstance(textInstance) {
807 textInstance.isHidden = true;
808}
809
810function unhideInstance(instance, props) {
811 instance.isHidden = false;
812}
813
814function unhideTextInstance(textInstance, text) {
815 textInstance.isHidden = false;
816}
817
818var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
819
820var describeComponentFrame = function (name, source, ownerName) {
821 var sourceInfo = '';
822 if (source) {
823 var path = source.fileName;
824 var fileName = path.replace(BEFORE_SLASH_RE, '');
825 {
826 // In DEV, include code for a common special case:
827 // prefer "folder/index.js" instead of just "index.js".
828 if (/^index\./.test(fileName)) {
829 var match = path.match(BEFORE_SLASH_RE);
830 if (match) {
831 var pathBeforeSlash = match[1];
832 if (pathBeforeSlash) {
833 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
834 fileName = folderName + '/' + fileName;
835 }
836 }
837 }
838 }
839 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
840 } else if (ownerName) {
841 sourceInfo = ' (created by ' + ownerName + ')';
842 }
843 return '\n in ' + (name || 'Unknown') + sourceInfo;
844};
845
846var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
847
848function describeFiber(fiber) {
849 switch (fiber.tag) {
850 case HostRoot:
851 case HostPortal:
852 case HostText:
853 case Fragment:
854 case ContextProvider:
855 case ContextConsumer:
856 return '';
857 default:
858 var owner = fiber._debugOwner;
859 var source = fiber._debugSource;
860 var name = getComponentName(fiber.type);
861 var ownerName = null;
862 if (owner) {
863 ownerName = getComponentName(owner.type);
864 }
865 return describeComponentFrame(name, source, ownerName);
866 }
867}
868
869function getStackByFiberInDevAndProd(workInProgress) {
870 var info = '';
871 var node = workInProgress;
872 do {
873 info += describeFiber(node);
874 node = node.return;
875 } while (node);
876 return info;
877}
878
879var current = null;
880var phase = null;
881
882function getCurrentFiberOwnerNameInDevOrNull() {
883 {
884 if (current === null) {
885 return null;
886 }
887 var owner = current._debugOwner;
888 if (owner !== null && typeof owner !== 'undefined') {
889 return getComponentName(owner.type);
890 }
891 }
892 return null;
893}
894
895function getCurrentFiberStackInDev() {
896 {
897 if (current === null) {
898 return '';
899 }
900 // Safe because if current fiber exists, we are reconciling,
901 // and it is guaranteed to be the work-in-progress version.
902 return getStackByFiberInDevAndProd(current);
903 }
904 return '';
905}
906
907function resetCurrentFiber() {
908 {
909 ReactDebugCurrentFrame.getCurrentStack = null;
910 current = null;
911 phase = null;
912 }
913}
914
915function setCurrentFiber(fiber) {
916 {
917 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
918 current = fiber;
919 phase = null;
920 }
921}
922
923function setCurrentPhase(lifeCyclePhase) {
924 {
925 phase = lifeCyclePhase;
926 }
927}
928
929var debugRenderPhaseSideEffects = false;
930var debugRenderPhaseSideEffectsForStrictMode = false;
931var enableUserTimingAPI = true;
932var warnAboutDeprecatedLifecycles = false;
933var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
934var enableProfilerTimer = false;
935var enableSchedulerTracing = false;
936var enableSuspenseServerRenderer = false;
937
938
939
940
941
942// Only used in www builds.
943
944// Prefix measurements so that it's possible to filter them.
945// Longer prefixes are hard to read in DevTools.
946var reactEmoji = '\u269B';
947var warningEmoji = '\u26D4';
948var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
949
950// Keep track of current fiber so that we know the path to unwind on pause.
951// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
952var currentFiber = null;
953// If we're in the middle of user code, which fiber and method is it?
954// Reusing `currentFiber` would be confusing for this because user code fiber
955// can change during commit phase too, but we don't need to unwind it (since
956// lifecycles in the commit phase don't resemble a tree).
957var currentPhase = null;
958var currentPhaseFiber = null;
959// Did lifecycle hook schedule an update? This is often a performance problem,
960// so we will keep track of it, and include it in the report.
961// Track commits caused by cascading updates.
962var isCommitting = false;
963var hasScheduledUpdateInCurrentCommit = false;
964var hasScheduledUpdateInCurrentPhase = false;
965var commitCountInCurrentWorkLoop = 0;
966var effectCountInCurrentCommit = 0;
967var isWaitingForCallback = false;
968// During commits, we only show a measurement once per method name
969// to avoid stretch the commit phase with measurement overhead.
970var labelsInCurrentCommit = new Set();
971
972var formatMarkName = function (markName) {
973 return reactEmoji + ' ' + markName;
974};
975
976var formatLabel = function (label, warning) {
977 var prefix = warning ? warningEmoji + ' ' : reactEmoji + ' ';
978 var suffix = warning ? ' Warning: ' + warning : '';
979 return '' + prefix + label + suffix;
980};
981
982var beginMark = function (markName) {
983 performance.mark(formatMarkName(markName));
984};
985
986var clearMark = function (markName) {
987 performance.clearMarks(formatMarkName(markName));
988};
989
990var endMark = function (label, markName, warning) {
991 var formattedMarkName = formatMarkName(markName);
992 var formattedLabel = formatLabel(label, warning);
993 try {
994 performance.measure(formattedLabel, formattedMarkName);
995 } catch (err) {}
996 // If previous mark was missing for some reason, this will throw.
997 // This could only happen if React crashed in an unexpected place earlier.
998 // Don't pile on with more errors.
999
1000 // Clear marks immediately to avoid growing buffer.
1001 performance.clearMarks(formattedMarkName);
1002 performance.clearMeasures(formattedLabel);
1003};
1004
1005var getFiberMarkName = function (label, debugID) {
1006 return label + ' (#' + debugID + ')';
1007};
1008
1009var getFiberLabel = function (componentName, isMounted, phase) {
1010 if (phase === null) {
1011 // These are composite component total time measurements.
1012 return componentName + ' [' + (isMounted ? 'update' : 'mount') + ']';
1013 } else {
1014 // Composite component methods.
1015 return componentName + '.' + phase;
1016 }
1017};
1018
1019var beginFiberMark = function (fiber, phase) {
1020 var componentName = getComponentName(fiber.type) || 'Unknown';
1021 var debugID = fiber._debugID;
1022 var isMounted = fiber.alternate !== null;
1023 var label = getFiberLabel(componentName, isMounted, phase);
1024
1025 if (isCommitting && labelsInCurrentCommit.has(label)) {
1026 // During the commit phase, we don't show duplicate labels because
1027 // there is a fixed overhead for every measurement, and we don't
1028 // want to stretch the commit phase beyond necessary.
1029 return false;
1030 }
1031 labelsInCurrentCommit.add(label);
1032
1033 var markName = getFiberMarkName(label, debugID);
1034 beginMark(markName);
1035 return true;
1036};
1037
1038var clearFiberMark = function (fiber, phase) {
1039 var componentName = getComponentName(fiber.type) || 'Unknown';
1040 var debugID = fiber._debugID;
1041 var isMounted = fiber.alternate !== null;
1042 var label = getFiberLabel(componentName, isMounted, phase);
1043 var markName = getFiberMarkName(label, debugID);
1044 clearMark(markName);
1045};
1046
1047var endFiberMark = function (fiber, phase, warning) {
1048 var componentName = getComponentName(fiber.type) || 'Unknown';
1049 var debugID = fiber._debugID;
1050 var isMounted = fiber.alternate !== null;
1051 var label = getFiberLabel(componentName, isMounted, phase);
1052 var markName = getFiberMarkName(label, debugID);
1053 endMark(label, markName, warning);
1054};
1055
1056var shouldIgnoreFiber = function (fiber) {
1057 // Host components should be skipped in the timeline.
1058 // We could check typeof fiber.type, but does this work with RN?
1059 switch (fiber.tag) {
1060 case HostRoot:
1061 case HostComponent:
1062 case HostText:
1063 case HostPortal:
1064 case Fragment:
1065 case ContextProvider:
1066 case ContextConsumer:
1067 case Mode:
1068 return true;
1069 default:
1070 return false;
1071 }
1072};
1073
1074var clearPendingPhaseMeasurement = function () {
1075 if (currentPhase !== null && currentPhaseFiber !== null) {
1076 clearFiberMark(currentPhaseFiber, currentPhase);
1077 }
1078 currentPhaseFiber = null;
1079 currentPhase = null;
1080 hasScheduledUpdateInCurrentPhase = false;
1081};
1082
1083var pauseTimers = function () {
1084 // Stops all currently active measurements so that they can be resumed
1085 // if we continue in a later deferred loop from the same unit of work.
1086 var fiber = currentFiber;
1087 while (fiber) {
1088 if (fiber._debugIsCurrentlyTiming) {
1089 endFiberMark(fiber, null, null);
1090 }
1091 fiber = fiber.return;
1092 }
1093};
1094
1095var resumeTimersRecursively = function (fiber) {
1096 if (fiber.return !== null) {
1097 resumeTimersRecursively(fiber.return);
1098 }
1099 if (fiber._debugIsCurrentlyTiming) {
1100 beginFiberMark(fiber, null);
1101 }
1102};
1103
1104var resumeTimers = function () {
1105 // Resumes all measurements that were active during the last deferred loop.
1106 if (currentFiber !== null) {
1107 resumeTimersRecursively(currentFiber);
1108 }
1109};
1110
1111function recordEffect() {
1112 if (enableUserTimingAPI) {
1113 effectCountInCurrentCommit++;
1114 }
1115}
1116
1117function recordScheduleUpdate() {
1118 if (enableUserTimingAPI) {
1119 if (isCommitting) {
1120 hasScheduledUpdateInCurrentCommit = true;
1121 }
1122 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1123 hasScheduledUpdateInCurrentPhase = true;
1124 }
1125 }
1126}
1127
1128function startRequestCallbackTimer() {
1129 if (enableUserTimingAPI) {
1130 if (supportsUserTiming && !isWaitingForCallback) {
1131 isWaitingForCallback = true;
1132 beginMark('(Waiting for async callback...)');
1133 }
1134 }
1135}
1136
1137function stopRequestCallbackTimer(didExpire, expirationTime) {
1138 if (enableUserTimingAPI) {
1139 if (supportsUserTiming) {
1140 isWaitingForCallback = false;
1141 var warning = didExpire ? 'React was blocked by main thread' : null;
1142 endMark('(Waiting for async callback... will force flush in ' + expirationTime + ' ms)', '(Waiting for async callback...)', warning);
1143 }
1144 }
1145}
1146
1147function startWorkTimer(fiber) {
1148 if (enableUserTimingAPI) {
1149 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1150 return;
1151 }
1152 // If we pause, this is the fiber to unwind from.
1153 currentFiber = fiber;
1154 if (!beginFiberMark(fiber, null)) {
1155 return;
1156 }
1157 fiber._debugIsCurrentlyTiming = true;
1158 }
1159}
1160
1161function cancelWorkTimer(fiber) {
1162 if (enableUserTimingAPI) {
1163 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1164 return;
1165 }
1166 // Remember we shouldn't complete measurement for this fiber.
1167 // Otherwise flamechart will be deep even for small updates.
1168 fiber._debugIsCurrentlyTiming = false;
1169 clearFiberMark(fiber, null);
1170 }
1171}
1172
1173function stopWorkTimer(fiber) {
1174 if (enableUserTimingAPI) {
1175 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1176 return;
1177 }
1178 // If we pause, its parent is the fiber to unwind from.
1179 currentFiber = fiber.return;
1180 if (!fiber._debugIsCurrentlyTiming) {
1181 return;
1182 }
1183 fiber._debugIsCurrentlyTiming = false;
1184 endFiberMark(fiber, null, null);
1185 }
1186}
1187
1188function stopFailedWorkTimer(fiber) {
1189 if (enableUserTimingAPI) {
1190 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1191 return;
1192 }
1193 // If we pause, its parent is the fiber to unwind from.
1194 currentFiber = fiber.return;
1195 if (!fiber._debugIsCurrentlyTiming) {
1196 return;
1197 }
1198 fiber._debugIsCurrentlyTiming = false;
1199 var warning = fiber.tag === SuspenseComponent || fiber.tag === DehydratedSuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1200 endFiberMark(fiber, null, warning);
1201 }
1202}
1203
1204function startPhaseTimer(fiber, phase) {
1205 if (enableUserTimingAPI) {
1206 if (!supportsUserTiming) {
1207 return;
1208 }
1209 clearPendingPhaseMeasurement();
1210 if (!beginFiberMark(fiber, phase)) {
1211 return;
1212 }
1213 currentPhaseFiber = fiber;
1214 currentPhase = phase;
1215 }
1216}
1217
1218function stopPhaseTimer() {
1219 if (enableUserTimingAPI) {
1220 if (!supportsUserTiming) {
1221 return;
1222 }
1223 if (currentPhase !== null && currentPhaseFiber !== null) {
1224 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1225 endFiberMark(currentPhaseFiber, currentPhase, warning);
1226 }
1227 currentPhase = null;
1228 currentPhaseFiber = null;
1229 }
1230}
1231
1232function startWorkLoopTimer(nextUnitOfWork) {
1233 if (enableUserTimingAPI) {
1234 currentFiber = nextUnitOfWork;
1235 if (!supportsUserTiming) {
1236 return;
1237 }
1238 commitCountInCurrentWorkLoop = 0;
1239 // This is top level call.
1240 // Any other measurements are performed within.
1241 beginMark('(React Tree Reconciliation)');
1242 // Resume any measurements that were in progress during the last loop.
1243 resumeTimers();
1244 }
1245}
1246
1247function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1248 if (enableUserTimingAPI) {
1249 if (!supportsUserTiming) {
1250 return;
1251 }
1252 var warning = null;
1253 if (interruptedBy !== null) {
1254 if (interruptedBy.tag === HostRoot) {
1255 warning = 'A top-level update interrupted the previous render';
1256 } else {
1257 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1258 warning = 'An update to ' + componentName + ' interrupted the previous render';
1259 }
1260 } else if (commitCountInCurrentWorkLoop > 1) {
1261 warning = 'There were cascading updates';
1262 }
1263 commitCountInCurrentWorkLoop = 0;
1264 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)';
1265 // Pause any measurements until the next loop.
1266 pauseTimers();
1267 endMark(label, '(React Tree Reconciliation)', warning);
1268 }
1269}
1270
1271function startCommitTimer() {
1272 if (enableUserTimingAPI) {
1273 if (!supportsUserTiming) {
1274 return;
1275 }
1276 isCommitting = true;
1277 hasScheduledUpdateInCurrentCommit = false;
1278 labelsInCurrentCommit.clear();
1279 beginMark('(Committing Changes)');
1280 }
1281}
1282
1283function stopCommitTimer() {
1284 if (enableUserTimingAPI) {
1285 if (!supportsUserTiming) {
1286 return;
1287 }
1288
1289 var warning = null;
1290 if (hasScheduledUpdateInCurrentCommit) {
1291 warning = 'Lifecycle hook scheduled a cascading update';
1292 } else if (commitCountInCurrentWorkLoop > 0) {
1293 warning = 'Caused by a cascading update in earlier commit';
1294 }
1295 hasScheduledUpdateInCurrentCommit = false;
1296 commitCountInCurrentWorkLoop++;
1297 isCommitting = false;
1298 labelsInCurrentCommit.clear();
1299
1300 endMark('(Committing Changes)', '(Committing Changes)', warning);
1301 }
1302}
1303
1304function startCommitSnapshotEffectsTimer() {
1305 if (enableUserTimingAPI) {
1306 if (!supportsUserTiming) {
1307 return;
1308 }
1309 effectCountInCurrentCommit = 0;
1310 beginMark('(Committing Snapshot Effects)');
1311 }
1312}
1313
1314function stopCommitSnapshotEffectsTimer() {
1315 if (enableUserTimingAPI) {
1316 if (!supportsUserTiming) {
1317 return;
1318 }
1319 var count = effectCountInCurrentCommit;
1320 effectCountInCurrentCommit = 0;
1321 endMark('(Committing Snapshot Effects: ' + count + ' Total)', '(Committing Snapshot Effects)', null);
1322 }
1323}
1324
1325function startCommitHostEffectsTimer() {
1326 if (enableUserTimingAPI) {
1327 if (!supportsUserTiming) {
1328 return;
1329 }
1330 effectCountInCurrentCommit = 0;
1331 beginMark('(Committing Host Effects)');
1332 }
1333}
1334
1335function stopCommitHostEffectsTimer() {
1336 if (enableUserTimingAPI) {
1337 if (!supportsUserTiming) {
1338 return;
1339 }
1340 var count = effectCountInCurrentCommit;
1341 effectCountInCurrentCommit = 0;
1342 endMark('(Committing Host Effects: ' + count + ' Total)', '(Committing Host Effects)', null);
1343 }
1344}
1345
1346function startCommitLifeCyclesTimer() {
1347 if (enableUserTimingAPI) {
1348 if (!supportsUserTiming) {
1349 return;
1350 }
1351 effectCountInCurrentCommit = 0;
1352 beginMark('(Calling Lifecycle Methods)');
1353 }
1354}
1355
1356function stopCommitLifeCyclesTimer() {
1357 if (enableUserTimingAPI) {
1358 if (!supportsUserTiming) {
1359 return;
1360 }
1361 var count = effectCountInCurrentCommit;
1362 effectCountInCurrentCommit = 0;
1363 endMark('(Calling Lifecycle Methods: ' + count + ' Total)', '(Calling Lifecycle Methods)', null);
1364 }
1365}
1366
1367var valueStack = [];
1368
1369var fiberStack = void 0;
1370
1371{
1372 fiberStack = [];
1373}
1374
1375var index = -1;
1376
1377function createCursor(defaultValue) {
1378 return {
1379 current: defaultValue
1380 };
1381}
1382
1383function pop(cursor, fiber) {
1384 if (index < 0) {
1385 {
1386 warningWithoutStack$1(false, 'Unexpected pop.');
1387 }
1388 return;
1389 }
1390
1391 {
1392 if (fiber !== fiberStack[index]) {
1393 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1394 }
1395 }
1396
1397 cursor.current = valueStack[index];
1398
1399 valueStack[index] = null;
1400
1401 {
1402 fiberStack[index] = null;
1403 }
1404
1405 index--;
1406}
1407
1408function push(cursor, value, fiber) {
1409 index++;
1410
1411 valueStack[index] = cursor.current;
1412
1413 {
1414 fiberStack[index] = fiber;
1415 }
1416
1417 cursor.current = value;
1418}
1419
1420function checkThatStackIsEmpty() {
1421 {
1422 if (index !== -1) {
1423 warningWithoutStack$1(false, 'Expected an empty stack. Something was not reset properly.');
1424 }
1425 }
1426}
1427
1428function resetStackAfterFatalErrorInDev() {
1429 {
1430 index = -1;
1431 valueStack.length = 0;
1432 fiberStack.length = 0;
1433 }
1434}
1435
1436var warnedAboutMissingGetChildContext = void 0;
1437
1438{
1439 warnedAboutMissingGetChildContext = {};
1440}
1441
1442var emptyContextObject = {};
1443{
1444 Object.freeze(emptyContextObject);
1445}
1446
1447// A cursor to the current merged context object on the stack.
1448var contextStackCursor = createCursor(emptyContextObject);
1449// A cursor to a boolean indicating whether the context has changed.
1450var didPerformWorkStackCursor = createCursor(false);
1451// Keep track of the previous context object that was on the stack.
1452// We use this to get access to the parent context after we have already
1453// pushed the next context provider, and now need to merge their contexts.
1454var previousContext = emptyContextObject;
1455
1456function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1457 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1458 // If the fiber is a context provider itself, when we read its context
1459 // we may have already pushed its own child context on the stack. A context
1460 // provider should not "see" its own child context. Therefore we read the
1461 // previous (parent) context instead for a context provider.
1462 return previousContext;
1463 }
1464 return contextStackCursor.current;
1465}
1466
1467function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1468 var instance = workInProgress.stateNode;
1469 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1470 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1471}
1472
1473function getMaskedContext(workInProgress, unmaskedContext) {
1474 var type = workInProgress.type;
1475 var contextTypes = type.contextTypes;
1476 if (!contextTypes) {
1477 return emptyContextObject;
1478 }
1479
1480 // Avoid recreating masked context unless unmasked context has changed.
1481 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1482 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1483 var instance = workInProgress.stateNode;
1484 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1485 return instance.__reactInternalMemoizedMaskedChildContext;
1486 }
1487
1488 var context = {};
1489 for (var key in contextTypes) {
1490 context[key] = unmaskedContext[key];
1491 }
1492
1493 {
1494 var name = getComponentName(type) || 'Unknown';
1495 checkPropTypes(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1496 }
1497
1498 // Cache unmasked context so we can avoid recreating masked context unless necessary.
1499 // Context is created before the class component is instantiated so check for instance.
1500 if (instance) {
1501 cacheContext(workInProgress, unmaskedContext, context);
1502 }
1503
1504 return context;
1505}
1506
1507function hasContextChanged() {
1508 return didPerformWorkStackCursor.current;
1509}
1510
1511function isContextProvider(type) {
1512 var childContextTypes = type.childContextTypes;
1513 return childContextTypes !== null && childContextTypes !== undefined;
1514}
1515
1516function popContext(fiber) {
1517 pop(didPerformWorkStackCursor, fiber);
1518 pop(contextStackCursor, fiber);
1519}
1520
1521function popTopLevelContextObject(fiber) {
1522 pop(didPerformWorkStackCursor, fiber);
1523 pop(contextStackCursor, fiber);
1524}
1525
1526function pushTopLevelContextObject(fiber, context, didChange) {
1527 !(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;
1528
1529 push(contextStackCursor, context, fiber);
1530 push(didPerformWorkStackCursor, didChange, fiber);
1531}
1532
1533function processChildContext(fiber, type, parentContext) {
1534 var instance = fiber.stateNode;
1535 var childContextTypes = type.childContextTypes;
1536
1537 // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1538 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1539 if (typeof instance.getChildContext !== 'function') {
1540 {
1541 var componentName = getComponentName(type) || 'Unknown';
1542
1543 if (!warnedAboutMissingGetChildContext[componentName]) {
1544 warnedAboutMissingGetChildContext[componentName] = true;
1545 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);
1546 }
1547 }
1548 return parentContext;
1549 }
1550
1551 var childContext = void 0;
1552 {
1553 setCurrentPhase('getChildContext');
1554 }
1555 startPhaseTimer(fiber, 'getChildContext');
1556 childContext = instance.getChildContext();
1557 stopPhaseTimer();
1558 {
1559 setCurrentPhase(null);
1560 }
1561 for (var contextKey in childContext) {
1562 !(contextKey in childContextTypes) ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(type) || 'Unknown', contextKey) : void 0;
1563 }
1564 {
1565 var name = getComponentName(type) || 'Unknown';
1566 checkPropTypes(childContextTypes, childContext, 'child context', name,
1567 // In practice, there is one case in which we won't get a stack. It's when
1568 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1569 // context from the parent component instance. The stack will be missing
1570 // because it's outside of the reconciliation, and so the pointer has not
1571 // been set. This is rare and doesn't matter. We'll also remove that API.
1572 getCurrentFiberStackInDev);
1573 }
1574
1575 return _assign({}, parentContext, childContext);
1576}
1577
1578function pushContextProvider(workInProgress) {
1579 var instance = workInProgress.stateNode;
1580 // We push the context as early as possible to ensure stack integrity.
1581 // If the instance does not exist yet, we will push null at first,
1582 // and replace it on the stack later when invalidating the context.
1583 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject;
1584
1585 // Remember the parent context so we can merge with it later.
1586 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1587 previousContext = contextStackCursor.current;
1588 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1589 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1590
1591 return true;
1592}
1593
1594function invalidateContextProvider(workInProgress, type, didChange) {
1595 var instance = workInProgress.stateNode;
1596 !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;
1597
1598 if (didChange) {
1599 // Merge parent and own context.
1600 // Skip this if we're not updating due to sCU.
1601 // This avoids unnecessarily recomputing memoized values.
1602 var mergedContext = processChildContext(workInProgress, type, previousContext);
1603 instance.__reactInternalMemoizedMergedChildContext = mergedContext;
1604
1605 // Replace the old (or empty) context with the new one.
1606 // It is important to unwind the context in the reverse order.
1607 pop(didPerformWorkStackCursor, workInProgress);
1608 pop(contextStackCursor, workInProgress);
1609 // Now push the new context and mark that it has changed.
1610 push(contextStackCursor, mergedContext, workInProgress);
1611 push(didPerformWorkStackCursor, didChange, workInProgress);
1612 } else {
1613 pop(didPerformWorkStackCursor, workInProgress);
1614 push(didPerformWorkStackCursor, didChange, workInProgress);
1615 }
1616}
1617
1618function findCurrentUnmaskedContext(fiber) {
1619 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1620 // makes sense elsewhere
1621 !(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;
1622
1623 var node = fiber;
1624 do {
1625 switch (node.tag) {
1626 case HostRoot:
1627 return node.stateNode.context;
1628 case ClassComponent:
1629 {
1630 var Component = node.type;
1631 if (isContextProvider(Component)) {
1632 return node.stateNode.__reactInternalMemoizedMergedChildContext;
1633 }
1634 break;
1635 }
1636 }
1637 node = node.return;
1638 } while (node !== null);
1639 invariant(false, 'Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.');
1640}
1641
1642var onCommitFiberRoot = null;
1643var onCommitFiberUnmount = null;
1644var hasLoggedError = false;
1645
1646function catchErrors(fn) {
1647 return function (arg) {
1648 try {
1649 return fn(arg);
1650 } catch (err) {
1651 if (true && !hasLoggedError) {
1652 hasLoggedError = true;
1653 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
1654 }
1655 }
1656 };
1657}
1658
1659var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
1660
1661function injectInternals(internals) {
1662 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
1663 // No DevTools
1664 return false;
1665 }
1666 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
1667 if (hook.isDisabled) {
1668 // This isn't a real property on the hook, but it can be set to opt out
1669 // of DevTools integration and associated warnings and logs.
1670 // https://github.com/facebook/react/issues/3877
1671 return true;
1672 }
1673 if (!hook.supportsFiber) {
1674 {
1675 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');
1676 }
1677 // DevTools exists, even though it doesn't support Fiber.
1678 return true;
1679 }
1680 try {
1681 var rendererID = hook.inject(internals);
1682 // We have successfully injected, so now it is safe to set up hooks.
1683 onCommitFiberRoot = catchErrors(function (root) {
1684 return hook.onCommitFiberRoot(rendererID, root);
1685 });
1686 onCommitFiberUnmount = catchErrors(function (fiber) {
1687 return hook.onCommitFiberUnmount(rendererID, fiber);
1688 });
1689 } catch (err) {
1690 // Catch all errors because it is unsafe to throw during initialization.
1691 {
1692 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
1693 }
1694 }
1695 // DevTools exists
1696 return true;
1697}
1698
1699function onCommitRoot(root) {
1700 if (typeof onCommitFiberRoot === 'function') {
1701 onCommitFiberRoot(root);
1702 }
1703}
1704
1705function onCommitUnmount(fiber) {
1706 if (typeof onCommitFiberUnmount === 'function') {
1707 onCommitFiberUnmount(fiber);
1708 }
1709}
1710
1711// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
1712// Math.pow(2, 30) - 1
1713// 0b111111111111111111111111111111
1714var maxSigned31BitInt = 1073741823;
1715
1716var NoWork = 0;
1717var Never = 1;
1718var Sync = maxSigned31BitInt;
1719
1720var UNIT_SIZE = 10;
1721var MAGIC_NUMBER_OFFSET = maxSigned31BitInt - 1;
1722
1723// 1 unit of expiration time represents 10ms.
1724function msToExpirationTime(ms) {
1725 // Always add an offset so that we don't clash with the magic number for NoWork.
1726 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
1727}
1728
1729function expirationTimeToMs(expirationTime) {
1730 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
1731}
1732
1733function ceiling(num, precision) {
1734 return ((num / precision | 0) + 1) * precision;
1735}
1736
1737function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
1738 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
1739}
1740
1741var LOW_PRIORITY_EXPIRATION = 5000;
1742var LOW_PRIORITY_BATCH_SIZE = 250;
1743
1744function computeAsyncExpiration(currentTime) {
1745 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
1746}
1747
1748// We intentionally set a higher expiration time for interactive updates in
1749// dev than in production.
1750//
1751// If the main thread is being blocked so long that you hit the expiration,
1752// it's a problem that could be solved with better scheduling.
1753//
1754// People will be more likely to notice this and fix it with the long
1755// expiration time in development.
1756//
1757// In production we opt for better UX at the risk of masking scheduling
1758// problems, by expiring fast.
1759var HIGH_PRIORITY_EXPIRATION = 500;
1760var HIGH_PRIORITY_BATCH_SIZE = 100;
1761
1762function computeInteractiveExpiration(currentTime) {
1763 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
1764}
1765
1766var NoContext = 0;
1767var ConcurrentMode = 1;
1768var StrictMode = 2;
1769var ProfileMode = 4;
1770
1771var hasBadMapPolyfill = void 0;
1772
1773{
1774 hasBadMapPolyfill = false;
1775 try {
1776 var nonExtensibleObject = Object.preventExtensions({});
1777 var testMap = new Map([[nonExtensibleObject, null]]);
1778 var testSet = new Set([nonExtensibleObject]);
1779 // This is necessary for Rollup to not consider these unused.
1780 // https://github.com/rollup/rollup/issues/1771
1781 // TODO: we can remove these if Rollup fixes the bug.
1782 testMap.set(0, 0);
1783 testSet.add(0);
1784 } catch (e) {
1785 // TODO: Consider warning about bad polyfills
1786 hasBadMapPolyfill = true;
1787 }
1788}
1789
1790// A Fiber is work on a Component that needs to be done or was done. There can
1791// be more than one per component.
1792
1793
1794var debugCounter = void 0;
1795
1796{
1797 debugCounter = 1;
1798}
1799
1800function FiberNode(tag, pendingProps, key, mode) {
1801 // Instance
1802 this.tag = tag;
1803 this.key = key;
1804 this.elementType = null;
1805 this.type = null;
1806 this.stateNode = null;
1807
1808 // Fiber
1809 this.return = null;
1810 this.child = null;
1811 this.sibling = null;
1812 this.index = 0;
1813
1814 this.ref = null;
1815
1816 this.pendingProps = pendingProps;
1817 this.memoizedProps = null;
1818 this.updateQueue = null;
1819 this.memoizedState = null;
1820 this.contextDependencies = null;
1821
1822 this.mode = mode;
1823
1824 // Effects
1825 this.effectTag = NoEffect;
1826 this.nextEffect = null;
1827
1828 this.firstEffect = null;
1829 this.lastEffect = null;
1830
1831 this.expirationTime = NoWork;
1832 this.childExpirationTime = NoWork;
1833
1834 this.alternate = null;
1835
1836 if (enableProfilerTimer) {
1837 // Note: The following is done to avoid a v8 performance cliff.
1838 //
1839 // Initializing the fields below to smis and later updating them with
1840 // double values will cause Fibers to end up having separate shapes.
1841 // This behavior/bug has something to do with Object.preventExtension().
1842 // Fortunately this only impacts DEV builds.
1843 // Unfortunately it makes React unusably slow for some applications.
1844 // To work around this, initialize the fields below with doubles.
1845 //
1846 // Learn more about this here:
1847 // https://github.com/facebook/react/issues/14365
1848 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
1849 this.actualDuration = Number.NaN;
1850 this.actualStartTime = Number.NaN;
1851 this.selfBaseDuration = Number.NaN;
1852 this.treeBaseDuration = Number.NaN;
1853
1854 // It's okay to replace the initial doubles with smis after initialization.
1855 // This won't trigger the performance cliff mentioned above,
1856 // and it simplifies other profiler code (including DevTools).
1857 this.actualDuration = 0;
1858 this.actualStartTime = -1;
1859 this.selfBaseDuration = 0;
1860 this.treeBaseDuration = 0;
1861 }
1862
1863 {
1864 this._debugID = debugCounter++;
1865 this._debugSource = null;
1866 this._debugOwner = null;
1867 this._debugIsCurrentlyTiming = false;
1868 this._debugHookTypes = null;
1869 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
1870 Object.preventExtensions(this);
1871 }
1872 }
1873}
1874
1875// This is a constructor function, rather than a POJO constructor, still
1876// please ensure we do the following:
1877// 1) Nobody should add any instance methods on this. Instance methods can be
1878// more difficult to predict when they get optimized and they are almost
1879// never inlined properly in static compilers.
1880// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
1881// always know when it is a fiber.
1882// 3) We might want to experiment with using numeric keys since they are easier
1883// to optimize in a non-JIT environment.
1884// 4) We can easily go from a constructor to a createFiber object literal if that
1885// is faster.
1886// 5) It should be easy to port this to a C struct and keep a C implementation
1887// compatible.
1888var createFiber = function (tag, pendingProps, key, mode) {
1889 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
1890 return new FiberNode(tag, pendingProps, key, mode);
1891};
1892
1893function shouldConstruct(Component) {
1894 var prototype = Component.prototype;
1895 return !!(prototype && prototype.isReactComponent);
1896}
1897
1898function isSimpleFunctionComponent(type) {
1899 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
1900}
1901
1902function resolveLazyComponentTag(Component) {
1903 if (typeof Component === 'function') {
1904 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
1905 } else if (Component !== undefined && Component !== null) {
1906 var $$typeof = Component.$$typeof;
1907 if ($$typeof === REACT_FORWARD_REF_TYPE) {
1908 return ForwardRef;
1909 }
1910 if ($$typeof === REACT_MEMO_TYPE) {
1911 return MemoComponent;
1912 }
1913 }
1914 return IndeterminateComponent;
1915}
1916
1917// This is used to create an alternate fiber to do work on.
1918function createWorkInProgress(current, pendingProps, expirationTime) {
1919 var workInProgress = current.alternate;
1920 if (workInProgress === null) {
1921 // We use a double buffering pooling technique because we know that we'll
1922 // only ever need at most two versions of a tree. We pool the "other" unused
1923 // node that we're free to reuse. This is lazily created to avoid allocating
1924 // extra objects for things that are never updated. It also allow us to
1925 // reclaim the extra memory if needed.
1926 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
1927 workInProgress.elementType = current.elementType;
1928 workInProgress.type = current.type;
1929 workInProgress.stateNode = current.stateNode;
1930
1931 {
1932 // DEV-only fields
1933 workInProgress._debugID = current._debugID;
1934 workInProgress._debugSource = current._debugSource;
1935 workInProgress._debugOwner = current._debugOwner;
1936 workInProgress._debugHookTypes = current._debugHookTypes;
1937 }
1938
1939 workInProgress.alternate = current;
1940 current.alternate = workInProgress;
1941 } else {
1942 workInProgress.pendingProps = pendingProps;
1943
1944 // We already have an alternate.
1945 // Reset the effect tag.
1946 workInProgress.effectTag = NoEffect;
1947
1948 // The effect list is no longer valid.
1949 workInProgress.nextEffect = null;
1950 workInProgress.firstEffect = null;
1951 workInProgress.lastEffect = null;
1952
1953 if (enableProfilerTimer) {
1954 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
1955 // This prevents time from endlessly accumulating in new commits.
1956 // This has the downside of resetting values for different priority renders,
1957 // But works for yielding (the common case) and should support resuming.
1958 workInProgress.actualDuration = 0;
1959 workInProgress.actualStartTime = -1;
1960 }
1961 }
1962
1963 workInProgress.childExpirationTime = current.childExpirationTime;
1964 workInProgress.expirationTime = current.expirationTime;
1965
1966 workInProgress.child = current.child;
1967 workInProgress.memoizedProps = current.memoizedProps;
1968 workInProgress.memoizedState = current.memoizedState;
1969 workInProgress.updateQueue = current.updateQueue;
1970 workInProgress.contextDependencies = current.contextDependencies;
1971
1972 // These will be overridden during the parent's reconciliation
1973 workInProgress.sibling = current.sibling;
1974 workInProgress.index = current.index;
1975 workInProgress.ref = current.ref;
1976
1977 if (enableProfilerTimer) {
1978 workInProgress.selfBaseDuration = current.selfBaseDuration;
1979 workInProgress.treeBaseDuration = current.treeBaseDuration;
1980 }
1981
1982 return workInProgress;
1983}
1984
1985function createHostRootFiber(isConcurrent) {
1986 var mode = isConcurrent ? ConcurrentMode | StrictMode : NoContext;
1987
1988 if (enableProfilerTimer && isDevToolsPresent) {
1989 // Always collect profile timings when DevTools are present.
1990 // This enables DevTools to start capturing timing at any point–
1991 // Without some nodes in the tree having empty base times.
1992 mode |= ProfileMode;
1993 }
1994
1995 return createFiber(HostRoot, null, null, mode);
1996}
1997
1998function createFiberFromTypeAndProps(type, // React$ElementType
1999key, pendingProps, owner, mode, expirationTime) {
2000 var fiber = void 0;
2001
2002 var fiberTag = IndeterminateComponent;
2003 // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
2004 var resolvedType = type;
2005 if (typeof type === 'function') {
2006 if (shouldConstruct(type)) {
2007 fiberTag = ClassComponent;
2008 }
2009 } else if (typeof type === 'string') {
2010 fiberTag = HostComponent;
2011 } else {
2012 getTag: switch (type) {
2013 case REACT_FRAGMENT_TYPE:
2014 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
2015 case REACT_CONCURRENT_MODE_TYPE:
2016 return createFiberFromMode(pendingProps, mode | ConcurrentMode | StrictMode, expirationTime, key);
2017 case REACT_STRICT_MODE_TYPE:
2018 return createFiberFromMode(pendingProps, mode | StrictMode, expirationTime, key);
2019 case REACT_PROFILER_TYPE:
2020 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
2021 case REACT_SUSPENSE_TYPE:
2022 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
2023 default:
2024 {
2025 if (typeof type === 'object' && type !== null) {
2026 switch (type.$$typeof) {
2027 case REACT_PROVIDER_TYPE:
2028 fiberTag = ContextProvider;
2029 break getTag;
2030 case REACT_CONTEXT_TYPE:
2031 // This is a consumer
2032 fiberTag = ContextConsumer;
2033 break getTag;
2034 case REACT_FORWARD_REF_TYPE:
2035 fiberTag = ForwardRef;
2036 break getTag;
2037 case REACT_MEMO_TYPE:
2038 fiberTag = MemoComponent;
2039 break getTag;
2040 case REACT_LAZY_TYPE:
2041 fiberTag = LazyComponent;
2042 resolvedType = null;
2043 break getTag;
2044 }
2045 }
2046 var info = '';
2047 {
2048 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2049 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.';
2050 }
2051 var ownerName = owner ? getComponentName(owner.type) : null;
2052 if (ownerName) {
2053 info += '\n\nCheck the render method of `' + ownerName + '`.';
2054 }
2055 }
2056 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);
2057 }
2058 }
2059 }
2060
2061 fiber = createFiber(fiberTag, pendingProps, key, mode);
2062 fiber.elementType = type;
2063 fiber.type = resolvedType;
2064 fiber.expirationTime = expirationTime;
2065
2066 return fiber;
2067}
2068
2069function createFiberFromElement(element, mode, expirationTime) {
2070 var owner = null;
2071 {
2072 owner = element._owner;
2073 }
2074 var type = element.type;
2075 var key = element.key;
2076 var pendingProps = element.props;
2077 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
2078 {
2079 fiber._debugSource = element._source;
2080 fiber._debugOwner = element._owner;
2081 }
2082 return fiber;
2083}
2084
2085function createFiberFromFragment(elements, mode, expirationTime, key) {
2086 var fiber = createFiber(Fragment, elements, key, mode);
2087 fiber.expirationTime = expirationTime;
2088 return fiber;
2089}
2090
2091function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
2092 {
2093 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
2094 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
2095 }
2096 }
2097
2098 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode);
2099 // TODO: The Profiler fiber shouldn't have a type. It has a tag.
2100 fiber.elementType = REACT_PROFILER_TYPE;
2101 fiber.type = REACT_PROFILER_TYPE;
2102 fiber.expirationTime = expirationTime;
2103
2104 return fiber;
2105}
2106
2107function createFiberFromMode(pendingProps, mode, expirationTime, key) {
2108 var fiber = createFiber(Mode, pendingProps, key, mode);
2109
2110 // TODO: The Mode fiber shouldn't have a type. It has a tag.
2111 var type = (mode & ConcurrentMode) === NoContext ? REACT_STRICT_MODE_TYPE : REACT_CONCURRENT_MODE_TYPE;
2112 fiber.elementType = type;
2113 fiber.type = type;
2114
2115 fiber.expirationTime = expirationTime;
2116 return fiber;
2117}
2118
2119function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
2120 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode);
2121
2122 // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
2123 var type = REACT_SUSPENSE_TYPE;
2124 fiber.elementType = type;
2125 fiber.type = type;
2126
2127 fiber.expirationTime = expirationTime;
2128 return fiber;
2129}
2130
2131function createFiberFromText(content, mode, expirationTime) {
2132 var fiber = createFiber(HostText, content, null, mode);
2133 fiber.expirationTime = expirationTime;
2134 return fiber;
2135}
2136
2137function createFiberFromHostInstanceForDeletion() {
2138 var fiber = createFiber(HostComponent, null, null, NoContext);
2139 // TODO: These should not need a type.
2140 fiber.elementType = 'DELETED';
2141 fiber.type = 'DELETED';
2142 return fiber;
2143}
2144
2145function createFiberFromPortal(portal, mode, expirationTime) {
2146 var pendingProps = portal.children !== null ? portal.children : [];
2147 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
2148 fiber.expirationTime = expirationTime;
2149 fiber.stateNode = {
2150 containerInfo: portal.containerInfo,
2151 pendingChildren: null, // Used by persistent updates
2152 implementation: portal.implementation
2153 };
2154 return fiber;
2155}
2156
2157// Used for stashing WIP properties to replay failed work in DEV.
2158function assignFiberPropertiesInDEV(target, source) {
2159 if (target === null) {
2160 // This Fiber's initial properties will always be overwritten.
2161 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
2162 target = createFiber(IndeterminateComponent, null, null, NoContext);
2163 }
2164
2165 // This is intentionally written as a list of all properties.
2166 // We tried to use Object.assign() instead but this is called in
2167 // the hottest path, and Object.assign() was too slow:
2168 // https://github.com/facebook/react/issues/12502
2169 // This code is DEV-only so size is not a concern.
2170
2171 target.tag = source.tag;
2172 target.key = source.key;
2173 target.elementType = source.elementType;
2174 target.type = source.type;
2175 target.stateNode = source.stateNode;
2176 target.return = source.return;
2177 target.child = source.child;
2178 target.sibling = source.sibling;
2179 target.index = source.index;
2180 target.ref = source.ref;
2181 target.pendingProps = source.pendingProps;
2182 target.memoizedProps = source.memoizedProps;
2183 target.updateQueue = source.updateQueue;
2184 target.memoizedState = source.memoizedState;
2185 target.contextDependencies = source.contextDependencies;
2186 target.mode = source.mode;
2187 target.effectTag = source.effectTag;
2188 target.nextEffect = source.nextEffect;
2189 target.firstEffect = source.firstEffect;
2190 target.lastEffect = source.lastEffect;
2191 target.expirationTime = source.expirationTime;
2192 target.childExpirationTime = source.childExpirationTime;
2193 target.alternate = source.alternate;
2194 if (enableProfilerTimer) {
2195 target.actualDuration = source.actualDuration;
2196 target.actualStartTime = source.actualStartTime;
2197 target.selfBaseDuration = source.selfBaseDuration;
2198 target.treeBaseDuration = source.treeBaseDuration;
2199 }
2200 target._debugID = source._debugID;
2201 target._debugSource = source._debugSource;
2202 target._debugOwner = source._debugOwner;
2203 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
2204 target._debugHookTypes = source._debugHookTypes;
2205 return target;
2206}
2207
2208// TODO: This should be lifted into the renderer.
2209
2210
2211// The following attributes are only used by interaction tracing builds.
2212// They enable interactions to be associated with their async work,
2213// And expose interaction metadata to the React DevTools Profiler plugin.
2214// Note that these attributes are only defined when the enableSchedulerTracing flag is enabled.
2215
2216
2217// Exported FiberRoot type includes all properties,
2218// To avoid requiring potentially error-prone :any casts throughout the project.
2219// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracing is true).
2220// The types are defined separately within this file to ensure they stay in sync.
2221// (We don't have to use an inline :any cast when enableSchedulerTracing is disabled.)
2222
2223
2224function createFiberRoot(containerInfo, isConcurrent, hydrate) {
2225 // Cyclic construction. This cheats the type system right now because
2226 // stateNode is any.
2227 var uninitializedFiber = createHostRootFiber(isConcurrent);
2228
2229 var root = void 0;
2230 if (enableSchedulerTracing) {
2231 root = {
2232 current: uninitializedFiber,
2233 containerInfo: containerInfo,
2234 pendingChildren: null,
2235
2236 earliestPendingTime: NoWork,
2237 latestPendingTime: NoWork,
2238 earliestSuspendedTime: NoWork,
2239 latestSuspendedTime: NoWork,
2240 latestPingedTime: NoWork,
2241
2242 pingCache: null,
2243
2244 didError: false,
2245
2246 pendingCommitExpirationTime: NoWork,
2247 finishedWork: null,
2248 timeoutHandle: noTimeout,
2249 context: null,
2250 pendingContext: null,
2251 hydrate: hydrate,
2252 nextExpirationTimeToWorkOn: NoWork,
2253 expirationTime: NoWork,
2254 firstBatch: null,
2255 nextScheduledRoot: null,
2256
2257 interactionThreadID: tracing.unstable_getThreadID(),
2258 memoizedInteractions: new Set(),
2259 pendingInteractionMap: new Map()
2260 };
2261 } else {
2262 root = {
2263 current: uninitializedFiber,
2264 containerInfo: containerInfo,
2265 pendingChildren: null,
2266
2267 pingCache: null,
2268
2269 earliestPendingTime: NoWork,
2270 latestPendingTime: NoWork,
2271 earliestSuspendedTime: NoWork,
2272 latestSuspendedTime: NoWork,
2273 latestPingedTime: NoWork,
2274
2275 didError: false,
2276
2277 pendingCommitExpirationTime: NoWork,
2278 finishedWork: null,
2279 timeoutHandle: noTimeout,
2280 context: null,
2281 pendingContext: null,
2282 hydrate: hydrate,
2283 nextExpirationTimeToWorkOn: NoWork,
2284 expirationTime: NoWork,
2285 firstBatch: null,
2286 nextScheduledRoot: null
2287 };
2288 }
2289
2290 uninitializedFiber.stateNode = root;
2291
2292 // The reason for the way the Flow types are structured in this file,
2293 // Is to avoid needing :any casts everywhere interaction tracing fields are used.
2294 // Unfortunately that requires an :any cast for non-interaction tracing capable builds.
2295 // $FlowFixMe Remove this :any cast and replace it with something better.
2296 return root;
2297}
2298
2299var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
2300 var funcArgs = Array.prototype.slice.call(arguments, 3);
2301 try {
2302 func.apply(context, funcArgs);
2303 } catch (error) {
2304 this.onError(error);
2305 }
2306};
2307
2308{
2309 // In DEV mode, we swap out invokeGuardedCallback for a special version
2310 // that plays more nicely with the browser's DevTools. The idea is to preserve
2311 // "Pause on exceptions" behavior. Because React wraps all user-provided
2312 // functions in invokeGuardedCallback, and the production version of
2313 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
2314 // like caught exceptions, and the DevTools won't pause unless the developer
2315 // takes the extra step of enabling pause on caught exceptions. This is
2316 // unintuitive, though, because even though React has caught the error, from
2317 // the developer's perspective, the error is uncaught.
2318 //
2319 // To preserve the expected "Pause on exceptions" behavior, we don't use a
2320 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
2321 // DOM node, and call the user-provided callback from inside an event handler
2322 // for that fake event. If the callback throws, the error is "captured" using
2323 // a global event handler. But because the error happens in a different
2324 // event loop context, it does not interrupt the normal program flow.
2325 // Effectively, this gives us try-catch behavior without actually using
2326 // try-catch. Neat!
2327
2328 // Check that the browser supports the APIs we need to implement our special
2329 // DEV version of invokeGuardedCallback
2330 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
2331 var fakeNode = document.createElement('react');
2332
2333 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
2334 // If document doesn't exist we know for sure we will crash in this method
2335 // when we call document.createEvent(). However this can cause confusing
2336 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
2337 // So we preemptively throw with a better message instead.
2338 !(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;
2339 var evt = document.createEvent('Event');
2340
2341 // Keeps track of whether the user-provided callback threw an error. We
2342 // set this to true at the beginning, then set it to false right after
2343 // calling the function. If the function errors, `didError` will never be
2344 // set to false. This strategy works even if the browser is flaky and
2345 // fails to call our global error handler, because it doesn't rely on
2346 // the error event at all.
2347 var didError = true;
2348
2349 // Keeps track of the value of window.event so that we can reset it
2350 // during the callback to let user code access window.event in the
2351 // browsers that support it.
2352 var windowEvent = window.event;
2353
2354 // Keeps track of the descriptor of window.event to restore it after event
2355 // dispatching: https://github.com/facebook/react/issues/13688
2356 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
2357
2358 // Create an event handler for our fake event. We will synchronously
2359 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
2360 // call the user-provided callback.
2361 var funcArgs = Array.prototype.slice.call(arguments, 3);
2362 function callCallback() {
2363 // We immediately remove the callback from event listeners so that
2364 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
2365 // nested call would trigger the fake event handlers of any call higher
2366 // in the stack.
2367 fakeNode.removeEventListener(evtType, callCallback, false);
2368
2369 // We check for window.hasOwnProperty('event') to prevent the
2370 // window.event assignment in both IE <= 10 as they throw an error
2371 // "Member not found" in strict mode, and in Firefox which does not
2372 // support window.event.
2373 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
2374 window.event = windowEvent;
2375 }
2376
2377 func.apply(context, funcArgs);
2378 didError = false;
2379 }
2380
2381 // Create a global error event handler. We use this to capture the value
2382 // that was thrown. It's possible that this error handler will fire more
2383 // than once; for example, if non-React code also calls `dispatchEvent`
2384 // and a handler for that event throws. We should be resilient to most of
2385 // those cases. Even if our error event handler fires more than once, the
2386 // last error event is always used. If the callback actually does error,
2387 // we know that the last error event is the correct one, because it's not
2388 // possible for anything else to have happened in between our callback
2389 // erroring and the code that follows the `dispatchEvent` call below. If
2390 // the callback doesn't error, but the error event was fired, we know to
2391 // ignore it because `didError` will be false, as described above.
2392 var error = void 0;
2393 // Use this to track whether the error event is ever called.
2394 var didSetError = false;
2395 var isCrossOriginError = false;
2396
2397 function handleWindowError(event) {
2398 error = event.error;
2399 didSetError = true;
2400 if (error === null && event.colno === 0 && event.lineno === 0) {
2401 isCrossOriginError = true;
2402 }
2403 if (event.defaultPrevented) {
2404 // Some other error handler has prevented default.
2405 // Browsers silence the error report if this happens.
2406 // We'll remember this to later decide whether to log it or not.
2407 if (error != null && typeof error === 'object') {
2408 try {
2409 error._suppressLogging = true;
2410 } catch (inner) {
2411 // Ignore.
2412 }
2413 }
2414 }
2415 }
2416
2417 // Create a fake event type.
2418 var evtType = 'react-' + (name ? name : 'invokeguardedcallback');
2419
2420 // Attach our event handlers
2421 window.addEventListener('error', handleWindowError);
2422 fakeNode.addEventListener(evtType, callCallback, false);
2423
2424 // Synchronously dispatch our fake event. If the user-provided function
2425 // errors, it will trigger our global error handler.
2426 evt.initEvent(evtType, false, false);
2427 fakeNode.dispatchEvent(evt);
2428
2429 if (windowEventDescriptor) {
2430 Object.defineProperty(window, 'event', windowEventDescriptor);
2431 }
2432
2433 if (didError) {
2434 if (!didSetError) {
2435 // The callback errored, but the error event never fired.
2436 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.');
2437 } else if (isCrossOriginError) {
2438 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.');
2439 }
2440 this.onError(error);
2441 }
2442
2443 // Remove our event listeners
2444 window.removeEventListener('error', handleWindowError);
2445 };
2446
2447 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
2448 }
2449}
2450
2451var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
2452
2453// Used by Fiber to simulate a try-catch.
2454var hasError = false;
2455var caughtError = null;
2456
2457var reporter = {
2458 onError: function (error) {
2459 hasError = true;
2460 caughtError = error;
2461 }
2462};
2463
2464/**
2465 * Call a function while guarding against errors that happens within it.
2466 * Returns an error if it throws, otherwise null.
2467 *
2468 * In production, this is implemented using a try-catch. The reason we don't
2469 * use a try-catch directly is so that we can swap out a different
2470 * implementation in DEV mode.
2471 *
2472 * @param {String} name of the guard to use for logging or debugging
2473 * @param {Function} func The function to invoke
2474 * @param {*} context The context to use when calling the function
2475 * @param {...*} args Arguments for function
2476 */
2477function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
2478 hasError = false;
2479 caughtError = null;
2480 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
2481}
2482
2483/**
2484 * Same as invokeGuardedCallback, but instead of returning an error, it stores
2485 * it in a global so it can be rethrown by `rethrowCaughtError` later.
2486 * TODO: See if caughtError and rethrowError can be unified.
2487 *
2488 * @param {String} name of the guard to use for logging or debugging
2489 * @param {Function} func The function to invoke
2490 * @param {*} context The context to use when calling the function
2491 * @param {...*} args Arguments for function
2492 */
2493
2494
2495/**
2496 * During execution of guarded functions we will capture the first error which
2497 * we will rethrow to be handled by the top level error handler.
2498 */
2499
2500
2501function hasCaughtError() {
2502 return hasError;
2503}
2504
2505function clearCaughtError() {
2506 if (hasError) {
2507 var error = caughtError;
2508 hasError = false;
2509 caughtError = null;
2510 return error;
2511 } else {
2512 invariant(false, 'clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.');
2513 }
2514}
2515
2516/**
2517 * Forked from fbjs/warning:
2518 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2519 *
2520 * Only change is we use console.warn instead of console.error,
2521 * and do nothing when 'console' is not supported.
2522 * This really simplifies the code.
2523 * ---
2524 * Similar to invariant but only logs a warning if the condition is not met.
2525 * This can be used to log issues in development environments in critical
2526 * paths. Removing the logging code for production environments will keep the
2527 * same logic and follow the same code paths.
2528 */
2529
2530var lowPriorityWarning = function () {};
2531
2532{
2533 var printWarning = function (format) {
2534 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2535 args[_key - 1] = arguments[_key];
2536 }
2537
2538 var argIndex = 0;
2539 var message = 'Warning: ' + format.replace(/%s/g, function () {
2540 return args[argIndex++];
2541 });
2542 if (typeof console !== 'undefined') {
2543 console.warn(message);
2544 }
2545 try {
2546 // --- Welcome to debugging React ---
2547 // This error was thrown as a convenience so that you can use this stack
2548 // to find the callsite that caused this warning to fire.
2549 throw new Error(message);
2550 } catch (x) {}
2551 };
2552
2553 lowPriorityWarning = function (condition, format) {
2554 if (format === undefined) {
2555 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
2556 }
2557 if (!condition) {
2558 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2559 args[_key2 - 2] = arguments[_key2];
2560 }
2561
2562 printWarning.apply(undefined, [format].concat(args));
2563 }
2564 };
2565}
2566
2567var lowPriorityWarning$1 = lowPriorityWarning;
2568
2569var ReactStrictModeWarnings = {
2570 discardPendingWarnings: function () {},
2571 flushPendingDeprecationWarnings: function () {},
2572 flushPendingUnsafeLifecycleWarnings: function () {},
2573 recordDeprecationWarnings: function (fiber, instance) {},
2574 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2575 recordLegacyContextWarning: function (fiber, instance) {},
2576 flushLegacyContextWarning: function () {}
2577};
2578
2579{
2580 var LIFECYCLE_SUGGESTIONS = {
2581 UNSAFE_componentWillMount: 'componentDidMount',
2582 UNSAFE_componentWillReceiveProps: 'static getDerivedStateFromProps',
2583 UNSAFE_componentWillUpdate: 'componentDidUpdate'
2584 };
2585
2586 var pendingComponentWillMountWarnings = [];
2587 var pendingComponentWillReceivePropsWarnings = [];
2588 var pendingComponentWillUpdateWarnings = [];
2589 var pendingUnsafeLifecycleWarnings = new Map();
2590 var pendingLegacyContextWarning = new Map();
2591
2592 // Tracks components we have already warned about.
2593 var didWarnAboutDeprecatedLifecycles = new Set();
2594 var didWarnAboutUnsafeLifecycles = new Set();
2595 var didWarnAboutLegacyContext = new Set();
2596
2597 var setToSortedString = function (set) {
2598 var array = [];
2599 set.forEach(function (value) {
2600 array.push(value);
2601 });
2602 return array.sort().join(', ');
2603 };
2604
2605 ReactStrictModeWarnings.discardPendingWarnings = function () {
2606 pendingComponentWillMountWarnings = [];
2607 pendingComponentWillReceivePropsWarnings = [];
2608 pendingComponentWillUpdateWarnings = [];
2609 pendingUnsafeLifecycleWarnings = new Map();
2610 pendingLegacyContextWarning = new Map();
2611 };
2612
2613 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2614 pendingUnsafeLifecycleWarnings.forEach(function (lifecycleWarningsMap, strictRoot) {
2615 var lifecyclesWarningMessages = [];
2616
2617 Object.keys(lifecycleWarningsMap).forEach(function (lifecycle) {
2618 var lifecycleWarnings = lifecycleWarningsMap[lifecycle];
2619 if (lifecycleWarnings.length > 0) {
2620 var componentNames = new Set();
2621 lifecycleWarnings.forEach(function (fiber) {
2622 componentNames.add(getComponentName(fiber.type) || 'Component');
2623 didWarnAboutUnsafeLifecycles.add(fiber.type);
2624 });
2625
2626 var formatted = lifecycle.replace('UNSAFE_', '');
2627 var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle];
2628 var sortedComponentNames = setToSortedString(componentNames);
2629
2630 lifecyclesWarningMessages.push(formatted + ': Please update the following components to use ' + (suggestion + ' instead: ' + sortedComponentNames));
2631 }
2632 });
2633
2634 if (lifecyclesWarningMessages.length > 0) {
2635 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2636
2637 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'));
2638 }
2639 });
2640
2641 pendingUnsafeLifecycleWarnings = new Map();
2642 };
2643
2644 var findStrictRoot = function (fiber) {
2645 var maybeStrictRoot = null;
2646
2647 var node = fiber;
2648 while (node !== null) {
2649 if (node.mode & StrictMode) {
2650 maybeStrictRoot = node;
2651 }
2652 node = node.return;
2653 }
2654
2655 return maybeStrictRoot;
2656 };
2657
2658 ReactStrictModeWarnings.flushPendingDeprecationWarnings = function () {
2659 if (pendingComponentWillMountWarnings.length > 0) {
2660 var uniqueNames = new Set();
2661 pendingComponentWillMountWarnings.forEach(function (fiber) {
2662 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2663 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2664 });
2665
2666 var sortedNames = setToSortedString(uniqueNames);
2667
2668 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);
2669
2670 pendingComponentWillMountWarnings = [];
2671 }
2672
2673 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2674 var _uniqueNames = new Set();
2675 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2676 _uniqueNames.add(getComponentName(fiber.type) || 'Component');
2677 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2678 });
2679
2680 var _sortedNames = setToSortedString(_uniqueNames);
2681
2682 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);
2683
2684 pendingComponentWillReceivePropsWarnings = [];
2685 }
2686
2687 if (pendingComponentWillUpdateWarnings.length > 0) {
2688 var _uniqueNames2 = new Set();
2689 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2690 _uniqueNames2.add(getComponentName(fiber.type) || 'Component');
2691 didWarnAboutDeprecatedLifecycles.add(fiber.type);
2692 });
2693
2694 var _sortedNames2 = setToSortedString(_uniqueNames2);
2695
2696 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);
2697
2698 pendingComponentWillUpdateWarnings = [];
2699 }
2700 };
2701
2702 ReactStrictModeWarnings.recordDeprecationWarnings = function (fiber, instance) {
2703 // Dedup strategy: Warn once per component.
2704 if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) {
2705 return;
2706 }
2707
2708 // Don't warn about react-lifecycles-compat polyfilled components.
2709 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
2710 pendingComponentWillMountWarnings.push(fiber);
2711 }
2712 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2713 pendingComponentWillReceivePropsWarnings.push(fiber);
2714 }
2715 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2716 pendingComponentWillUpdateWarnings.push(fiber);
2717 }
2718 };
2719
2720 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2721 var strictRoot = findStrictRoot(fiber);
2722 if (strictRoot === null) {
2723 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.');
2724 return;
2725 }
2726
2727 // Dedup strategy: Warn once per component.
2728 // This is difficult to track any other way since component names
2729 // are often vague and are likely to collide between 3rd party libraries.
2730 // An expand property is probably okay to use here since it's DEV-only,
2731 // and will only be set in the event of serious warnings.
2732 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2733 return;
2734 }
2735
2736 var warningsForRoot = void 0;
2737 if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) {
2738 warningsForRoot = {
2739 UNSAFE_componentWillMount: [],
2740 UNSAFE_componentWillReceiveProps: [],
2741 UNSAFE_componentWillUpdate: []
2742 };
2743
2744 pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot);
2745 } else {
2746 warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot);
2747 }
2748
2749 var unsafeLifecycles = [];
2750 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillMount === 'function') {
2751 unsafeLifecycles.push('UNSAFE_componentWillMount');
2752 }
2753 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2754 unsafeLifecycles.push('UNSAFE_componentWillReceiveProps');
2755 }
2756 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true || typeof instance.UNSAFE_componentWillUpdate === 'function') {
2757 unsafeLifecycles.push('UNSAFE_componentWillUpdate');
2758 }
2759
2760 if (unsafeLifecycles.length > 0) {
2761 unsafeLifecycles.forEach(function (lifecycle) {
2762 warningsForRoot[lifecycle].push(fiber);
2763 });
2764 }
2765 };
2766
2767 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2768 var strictRoot = findStrictRoot(fiber);
2769 if (strictRoot === null) {
2770 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.');
2771 return;
2772 }
2773
2774 // Dedup strategy: Warn once per component.
2775 if (didWarnAboutLegacyContext.has(fiber.type)) {
2776 return;
2777 }
2778
2779 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2780
2781 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2782 if (warningsForRoot === undefined) {
2783 warningsForRoot = [];
2784 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2785 }
2786 warningsForRoot.push(fiber);
2787 }
2788 };
2789
2790 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2791 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2792 var uniqueNames = new Set();
2793 fiberArray.forEach(function (fiber) {
2794 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2795 didWarnAboutLegacyContext.add(fiber.type);
2796 });
2797
2798 var sortedNames = setToSortedString(uniqueNames);
2799 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2800
2801 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);
2802 });
2803 };
2804}
2805
2806// This lets us hook into Fiber to debug what it's doing.
2807// See https://github.com/facebook/react/pull/8033.
2808// This is not part of the public API, not even for React DevTools.
2809// You may only inject a debugTool if you work on React Fiber itself.
2810var ReactFiberInstrumentation = {
2811 debugTool: null
2812};
2813
2814var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
2815
2816// TODO: Offscreen updates should never suspend. However, a promise that
2817// suspended inside an offscreen subtree should be able to ping at the priority
2818// of the outer render.
2819
2820function markPendingPriorityLevel(root, expirationTime) {
2821 // If there's a gap between completing a failed root and retrying it,
2822 // additional updates may be scheduled. Clear `didError`, in case the update
2823 // is sufficient to fix the error.
2824 root.didError = false;
2825
2826 // Update the latest and earliest pending times
2827 var earliestPendingTime = root.earliestPendingTime;
2828 if (earliestPendingTime === NoWork) {
2829 // No other pending updates.
2830 root.earliestPendingTime = root.latestPendingTime = expirationTime;
2831 } else {
2832 if (earliestPendingTime < expirationTime) {
2833 // This is the earliest pending update.
2834 root.earliestPendingTime = expirationTime;
2835 } else {
2836 var latestPendingTime = root.latestPendingTime;
2837 if (latestPendingTime > expirationTime) {
2838 // This is the latest pending update
2839 root.latestPendingTime = expirationTime;
2840 }
2841 }
2842 }
2843 findNextExpirationTimeToWorkOn(expirationTime, root);
2844}
2845
2846function markCommittedPriorityLevels(root, earliestRemainingTime) {
2847 root.didError = false;
2848
2849 if (earliestRemainingTime === NoWork) {
2850 // Fast path. There's no remaining work. Clear everything.
2851 root.earliestPendingTime = NoWork;
2852 root.latestPendingTime = NoWork;
2853 root.earliestSuspendedTime = NoWork;
2854 root.latestSuspendedTime = NoWork;
2855 root.latestPingedTime = NoWork;
2856 findNextExpirationTimeToWorkOn(NoWork, root);
2857 return;
2858 }
2859
2860 if (earliestRemainingTime < root.latestPingedTime) {
2861 root.latestPingedTime = NoWork;
2862 }
2863
2864 // Let's see if the previous latest known pending level was just flushed.
2865 var latestPendingTime = root.latestPendingTime;
2866 if (latestPendingTime !== NoWork) {
2867 if (latestPendingTime > earliestRemainingTime) {
2868 // We've flushed all the known pending levels.
2869 root.earliestPendingTime = root.latestPendingTime = NoWork;
2870 } else {
2871 var earliestPendingTime = root.earliestPendingTime;
2872 if (earliestPendingTime > earliestRemainingTime) {
2873 // We've flushed the earliest known pending level. Set this to the
2874 // latest pending time.
2875 root.earliestPendingTime = root.latestPendingTime;
2876 }
2877 }
2878 }
2879
2880 // Now let's handle the earliest remaining level in the whole tree. We need to
2881 // decide whether to treat it as a pending level or as suspended. Check
2882 // it falls within the range of known suspended levels.
2883
2884 var earliestSuspendedTime = root.earliestSuspendedTime;
2885 if (earliestSuspendedTime === NoWork) {
2886 // There's no suspended work. Treat the earliest remaining level as a
2887 // pending level.
2888 markPendingPriorityLevel(root, earliestRemainingTime);
2889 findNextExpirationTimeToWorkOn(NoWork, root);
2890 return;
2891 }
2892
2893 var latestSuspendedTime = root.latestSuspendedTime;
2894 if (earliestRemainingTime < latestSuspendedTime) {
2895 // The earliest remaining level is later than all the suspended work. That
2896 // means we've flushed all the suspended work.
2897 root.earliestSuspendedTime = NoWork;
2898 root.latestSuspendedTime = NoWork;
2899 root.latestPingedTime = NoWork;
2900
2901 // There's no suspended work. Treat the earliest remaining level as a
2902 // pending level.
2903 markPendingPriorityLevel(root, earliestRemainingTime);
2904 findNextExpirationTimeToWorkOn(NoWork, root);
2905 return;
2906 }
2907
2908 if (earliestRemainingTime > earliestSuspendedTime) {
2909 // The earliest remaining time is earlier than all the suspended work.
2910 // Treat it as a pending update.
2911 markPendingPriorityLevel(root, earliestRemainingTime);
2912 findNextExpirationTimeToWorkOn(NoWork, root);
2913 return;
2914 }
2915
2916 // The earliest remaining time falls within the range of known suspended
2917 // levels. We should treat this as suspended work.
2918 findNextExpirationTimeToWorkOn(NoWork, root);
2919}
2920
2921function hasLowerPriorityWork(root, erroredExpirationTime) {
2922 var latestPendingTime = root.latestPendingTime;
2923 var latestSuspendedTime = root.latestSuspendedTime;
2924 var latestPingedTime = root.latestPingedTime;
2925 return latestPendingTime !== NoWork && latestPendingTime < erroredExpirationTime || latestSuspendedTime !== NoWork && latestSuspendedTime < erroredExpirationTime || latestPingedTime !== NoWork && latestPingedTime < erroredExpirationTime;
2926}
2927
2928function isPriorityLevelSuspended(root, expirationTime) {
2929 var earliestSuspendedTime = root.earliestSuspendedTime;
2930 var latestSuspendedTime = root.latestSuspendedTime;
2931 return earliestSuspendedTime !== NoWork && expirationTime <= earliestSuspendedTime && expirationTime >= latestSuspendedTime;
2932}
2933
2934function markSuspendedPriorityLevel(root, suspendedTime) {
2935 root.didError = false;
2936 clearPing(root, suspendedTime);
2937
2938 // First, check the known pending levels and update them if needed.
2939 var earliestPendingTime = root.earliestPendingTime;
2940 var latestPendingTime = root.latestPendingTime;
2941 if (earliestPendingTime === suspendedTime) {
2942 if (latestPendingTime === suspendedTime) {
2943 // Both known pending levels were suspended. Clear them.
2944 root.earliestPendingTime = root.latestPendingTime = NoWork;
2945 } else {
2946 // The earliest pending level was suspended. Clear by setting it to the
2947 // latest pending level.
2948 root.earliestPendingTime = latestPendingTime;
2949 }
2950 } else if (latestPendingTime === suspendedTime) {
2951 // The latest pending level was suspended. Clear by setting it to the
2952 // latest pending level.
2953 root.latestPendingTime = earliestPendingTime;
2954 }
2955
2956 // Finally, update the known suspended levels.
2957 var earliestSuspendedTime = root.earliestSuspendedTime;
2958 var latestSuspendedTime = root.latestSuspendedTime;
2959 if (earliestSuspendedTime === NoWork) {
2960 // No other suspended levels.
2961 root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime;
2962 } else {
2963 if (earliestSuspendedTime < suspendedTime) {
2964 // This is the earliest suspended level.
2965 root.earliestSuspendedTime = suspendedTime;
2966 } else if (latestSuspendedTime > suspendedTime) {
2967 // This is the latest suspended level
2968 root.latestSuspendedTime = suspendedTime;
2969 }
2970 }
2971
2972 findNextExpirationTimeToWorkOn(suspendedTime, root);
2973}
2974
2975function markPingedPriorityLevel(root, pingedTime) {
2976 root.didError = false;
2977
2978 // TODO: When we add back resuming, we need to ensure the progressed work
2979 // is thrown out and not reused during the restarted render. One way to
2980 // invalidate the progressed work is to restart at expirationTime + 1.
2981 var latestPingedTime = root.latestPingedTime;
2982 if (latestPingedTime === NoWork || latestPingedTime > pingedTime) {
2983 root.latestPingedTime = pingedTime;
2984 }
2985 findNextExpirationTimeToWorkOn(pingedTime, root);
2986}
2987
2988function clearPing(root, completedTime) {
2989 var latestPingedTime = root.latestPingedTime;
2990 if (latestPingedTime >= completedTime) {
2991 root.latestPingedTime = NoWork;
2992 }
2993}
2994
2995function findEarliestOutstandingPriorityLevel(root, renderExpirationTime) {
2996 var earliestExpirationTime = renderExpirationTime;
2997
2998 var earliestPendingTime = root.earliestPendingTime;
2999 var earliestSuspendedTime = root.earliestSuspendedTime;
3000 if (earliestPendingTime > earliestExpirationTime) {
3001 earliestExpirationTime = earliestPendingTime;
3002 }
3003 if (earliestSuspendedTime > earliestExpirationTime) {
3004 earliestExpirationTime = earliestSuspendedTime;
3005 }
3006 return earliestExpirationTime;
3007}
3008
3009function didExpireAtExpirationTime(root, currentTime) {
3010 var expirationTime = root.expirationTime;
3011 if (expirationTime !== NoWork && currentTime <= expirationTime) {
3012 // The root has expired. Flush all work up to the current time.
3013 root.nextExpirationTimeToWorkOn = currentTime;
3014 }
3015}
3016
3017function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
3018 var earliestSuspendedTime = root.earliestSuspendedTime;
3019 var latestSuspendedTime = root.latestSuspendedTime;
3020 var earliestPendingTime = root.earliestPendingTime;
3021 var latestPingedTime = root.latestPingedTime;
3022
3023 // Work on the earliest pending time. Failing that, work on the latest
3024 // pinged time.
3025 var nextExpirationTimeToWorkOn = earliestPendingTime !== NoWork ? earliestPendingTime : latestPingedTime;
3026
3027 // If there is no pending or pinged work, check if there's suspended work
3028 // that's lower priority than what we just completed.
3029 if (nextExpirationTimeToWorkOn === NoWork && (completedExpirationTime === NoWork || latestSuspendedTime < completedExpirationTime)) {
3030 // The lowest priority suspended work is the work most likely to be
3031 // committed next. Let's start rendering it again, so that if it times out,
3032 // it's ready to commit.
3033 nextExpirationTimeToWorkOn = latestSuspendedTime;
3034 }
3035
3036 var expirationTime = nextExpirationTimeToWorkOn;
3037 if (expirationTime !== NoWork && earliestSuspendedTime > expirationTime) {
3038 // Expire using the earliest known expiration time.
3039 expirationTime = earliestSuspendedTime;
3040 }
3041
3042 root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn;
3043 root.expirationTime = expirationTime;
3044}
3045
3046/**
3047 * inlined Object.is polyfill to avoid requiring consumers ship their own
3048 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
3049 */
3050function is(x, y) {
3051 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
3052 ;
3053}
3054
3055var hasOwnProperty = Object.prototype.hasOwnProperty;
3056
3057/**
3058 * Performs equality by iterating through keys on an object and returning false
3059 * when any key has values which are not strictly equal between the arguments.
3060 * Returns true when the values of all keys are strictly equal.
3061 */
3062function shallowEqual(objA, objB) {
3063 if (is(objA, objB)) {
3064 return true;
3065 }
3066
3067 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
3068 return false;
3069 }
3070
3071 var keysA = Object.keys(objA);
3072 var keysB = Object.keys(objB);
3073
3074 if (keysA.length !== keysB.length) {
3075 return false;
3076 }
3077
3078 // Test for A's keys different from B.
3079 for (var i = 0; i < keysA.length; i++) {
3080 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
3081 return false;
3082 }
3083 }
3084
3085 return true;
3086}
3087
3088function resolveDefaultProps(Component, baseProps) {
3089 if (Component && Component.defaultProps) {
3090 // Resolve default props. Taken from ReactElement
3091 var props = _assign({}, baseProps);
3092 var defaultProps = Component.defaultProps;
3093 for (var propName in defaultProps) {
3094 if (props[propName] === undefined) {
3095 props[propName] = defaultProps[propName];
3096 }
3097 }
3098 return props;
3099 }
3100 return baseProps;
3101}
3102
3103function readLazyComponentType(lazyComponent) {
3104 var status = lazyComponent._status;
3105 var result = lazyComponent._result;
3106 switch (status) {
3107 case Resolved:
3108 {
3109 var Component = result;
3110 return Component;
3111 }
3112 case Rejected:
3113 {
3114 var error = result;
3115 throw error;
3116 }
3117 case Pending:
3118 {
3119 var thenable = result;
3120 throw thenable;
3121 }
3122 default:
3123 {
3124 lazyComponent._status = Pending;
3125 var ctor = lazyComponent._ctor;
3126 var _thenable = ctor();
3127 _thenable.then(function (moduleObject) {
3128 if (lazyComponent._status === Pending) {
3129 var defaultExport = moduleObject.default;
3130 {
3131 if (defaultExport === undefined) {
3132 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);
3133 }
3134 }
3135 lazyComponent._status = Resolved;
3136 lazyComponent._result = defaultExport;
3137 }
3138 }, function (error) {
3139 if (lazyComponent._status === Pending) {
3140 lazyComponent._status = Rejected;
3141 lazyComponent._result = error;
3142 }
3143 });
3144 // Handle synchronous thenables.
3145 switch (lazyComponent._status) {
3146 case Resolved:
3147 return lazyComponent._result;
3148 case Rejected:
3149 throw lazyComponent._result;
3150 }
3151 lazyComponent._result = _thenable;
3152 throw _thenable;
3153 }
3154 }
3155}
3156
3157var fakeInternalInstance = {};
3158var isArray$1 = Array.isArray;
3159
3160// React.Component uses a shared frozen object by default.
3161// We'll use it to determine whether we need to initialize legacy refs.
3162var emptyRefsObject = new React.Component().refs;
3163
3164var didWarnAboutStateAssignmentForComponent = void 0;
3165var didWarnAboutUninitializedState = void 0;
3166var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0;
3167var didWarnAboutLegacyLifecyclesAndDerivedState = void 0;
3168var didWarnAboutUndefinedDerivedState = void 0;
3169var warnOnUndefinedDerivedState = void 0;
3170var warnOnInvalidCallback = void 0;
3171var didWarnAboutDirectlyAssigningPropsToState = void 0;
3172var didWarnAboutContextTypeAndContextTypes = void 0;
3173var didWarnAboutInvalidateContextType = void 0;
3174
3175{
3176 didWarnAboutStateAssignmentForComponent = new Set();
3177 didWarnAboutUninitializedState = new Set();
3178 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3179 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3180 didWarnAboutDirectlyAssigningPropsToState = new Set();
3181 didWarnAboutUndefinedDerivedState = new Set();
3182 didWarnAboutContextTypeAndContextTypes = new Set();
3183 didWarnAboutInvalidateContextType = new Set();
3184
3185 var didWarnOnInvalidCallback = new Set();
3186
3187 warnOnInvalidCallback = function (callback, callerName) {
3188 if (callback === null || typeof callback === 'function') {
3189 return;
3190 }
3191 var key = callerName + '_' + callback;
3192 if (!didWarnOnInvalidCallback.has(key)) {
3193 didWarnOnInvalidCallback.add(key);
3194 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
3195 }
3196 };
3197
3198 warnOnUndefinedDerivedState = function (type, partialState) {
3199 if (partialState === undefined) {
3200 var componentName = getComponentName(type) || 'Component';
3201 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
3202 didWarnAboutUndefinedDerivedState.add(componentName);
3203 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
3204 }
3205 }
3206 };
3207
3208 // This is so gross but it's at least non-critical and can be removed if
3209 // it causes problems. This is meant to give a nicer error message for
3210 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
3211 // ...)) which otherwise throws a "_processChildContext is not a function"
3212 // exception.
3213 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
3214 enumerable: false,
3215 value: function () {
3216 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).');
3217 }
3218 });
3219 Object.freeze(fakeInternalInstance);
3220}
3221
3222function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
3223 var prevState = workInProgress.memoizedState;
3224
3225 {
3226 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3227 // Invoke the function an extra time to help detect side-effects.
3228 getDerivedStateFromProps(nextProps, prevState);
3229 }
3230 }
3231
3232 var partialState = getDerivedStateFromProps(nextProps, prevState);
3233
3234 {
3235 warnOnUndefinedDerivedState(ctor, partialState);
3236 }
3237 // Merge the partial state and the previous state.
3238 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
3239 workInProgress.memoizedState = memoizedState;
3240
3241 // Once the update queue is empty, persist the derived state onto the
3242 // base state.
3243 var updateQueue = workInProgress.updateQueue;
3244 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
3245 updateQueue.baseState = memoizedState;
3246 }
3247}
3248
3249var classComponentUpdater = {
3250 isMounted: isMounted,
3251 enqueueSetState: function (inst, payload, callback) {
3252 var fiber = get(inst);
3253 var currentTime = requestCurrentTime();
3254 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3255
3256 var update = createUpdate(expirationTime);
3257 update.payload = payload;
3258 if (callback !== undefined && callback !== null) {
3259 {
3260 warnOnInvalidCallback(callback, 'setState');
3261 }
3262 update.callback = callback;
3263 }
3264
3265 flushPassiveEffects$1();
3266 enqueueUpdate(fiber, update);
3267 scheduleWork(fiber, expirationTime);
3268 },
3269 enqueueReplaceState: function (inst, payload, callback) {
3270 var fiber = get(inst);
3271 var currentTime = requestCurrentTime();
3272 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3273
3274 var update = createUpdate(expirationTime);
3275 update.tag = ReplaceState;
3276 update.payload = payload;
3277
3278 if (callback !== undefined && callback !== null) {
3279 {
3280 warnOnInvalidCallback(callback, 'replaceState');
3281 }
3282 update.callback = callback;
3283 }
3284
3285 flushPassiveEffects$1();
3286 enqueueUpdate(fiber, update);
3287 scheduleWork(fiber, expirationTime);
3288 },
3289 enqueueForceUpdate: function (inst, callback) {
3290 var fiber = get(inst);
3291 var currentTime = requestCurrentTime();
3292 var expirationTime = computeExpirationForFiber(currentTime, fiber);
3293
3294 var update = createUpdate(expirationTime);
3295 update.tag = ForceUpdate;
3296
3297 if (callback !== undefined && callback !== null) {
3298 {
3299 warnOnInvalidCallback(callback, 'forceUpdate');
3300 }
3301 update.callback = callback;
3302 }
3303
3304 flushPassiveEffects$1();
3305 enqueueUpdate(fiber, update);
3306 scheduleWork(fiber, expirationTime);
3307 }
3308};
3309
3310function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
3311 var instance = workInProgress.stateNode;
3312 if (typeof instance.shouldComponentUpdate === 'function') {
3313 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
3314 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
3315 stopPhaseTimer();
3316
3317 {
3318 !(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;
3319 }
3320
3321 return shouldUpdate;
3322 }
3323
3324 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
3325 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
3326 }
3327
3328 return true;
3329}
3330
3331function checkClassInstance(workInProgress, ctor, newProps) {
3332 var instance = workInProgress.stateNode;
3333 {
3334 var name = getComponentName(ctor) || 'Component';
3335 var renderPresent = instance.render;
3336
3337 if (!renderPresent) {
3338 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
3339 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
3340 } else {
3341 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
3342 }
3343 }
3344
3345 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
3346 !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;
3347 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
3348 !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;
3349 var noInstancePropTypes = !instance.propTypes;
3350 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
3351 var noInstanceContextType = !instance.contextType;
3352 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
3353 var noInstanceContextTypes = !instance.contextTypes;
3354 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
3355
3356 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
3357 didWarnAboutContextTypeAndContextTypes.add(ctor);
3358 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
3359 }
3360
3361 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
3362 !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;
3363 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
3364 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');
3365 }
3366 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
3367 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
3368 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
3369 !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;
3370 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
3371 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
3372 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
3373 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
3374 var hasMutatedProps = instance.props !== newProps;
3375 !(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;
3376 var noInstanceDefaultProps = !instance.defaultProps;
3377 !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;
3378
3379 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
3380 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
3381 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
3382 }
3383
3384 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
3385 !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;
3386 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
3387 !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;
3388 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
3389 !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;
3390 var _state = instance.state;
3391 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
3392 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
3393 }
3394 if (typeof instance.getChildContext === 'function') {
3395 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
3396 }
3397 }
3398}
3399
3400function adoptClassInstance(workInProgress, instance) {
3401 instance.updater = classComponentUpdater;
3402 workInProgress.stateNode = instance;
3403 // The instance needs access to the fiber so that it can schedule updates
3404 set(instance, workInProgress);
3405 {
3406 instance._reactInternalInstance = fakeInternalInstance;
3407 }
3408}
3409
3410function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
3411 var isLegacyContextConsumer = false;
3412 var unmaskedContext = emptyContextObject;
3413 var context = null;
3414 var contextType = ctor.contextType;
3415
3416 {
3417 if ('contextType' in ctor) {
3418 var isValid =
3419 // Allow null for conditional declaration
3420 contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
3421
3422 if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
3423 didWarnAboutInvalidateContextType.add(ctor);
3424
3425 var addendum = '';
3426 if (contextType === undefined) {
3427 addendum = ' However, it is set to undefined. ' + 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, so ' + 'try moving the createContext() call to a separate file.';
3428 } else if (typeof contextType !== 'object') {
3429 addendum = ' However, it is set to a ' + typeof contextType + '.';
3430 } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
3431 addendum = ' Did you accidentally pass the Context.Provider instead?';
3432 } else if (contextType._context !== undefined) {
3433 // <Context.Consumer>
3434 addendum = ' Did you accidentally pass the Context.Consumer instead?';
3435 } else {
3436 addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
3437 }
3438 warningWithoutStack$1(false, '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
3439 }
3440 }
3441 }
3442
3443 if (typeof contextType === 'object' && contextType !== null) {
3444 context = readContext(contextType);
3445 } else {
3446 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3447 var contextTypes = ctor.contextTypes;
3448 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
3449 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
3450 }
3451
3452 // Instantiate twice to help detect side-effects.
3453 {
3454 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3455 new ctor(props, context); // eslint-disable-line no-new
3456 }
3457 }
3458
3459 var instance = new ctor(props, context);
3460 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
3461 adoptClassInstance(workInProgress, instance);
3462
3463 {
3464 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
3465 var componentName = getComponentName(ctor) || 'Component';
3466 if (!didWarnAboutUninitializedState.has(componentName)) {
3467 didWarnAboutUninitializedState.add(componentName);
3468 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);
3469 }
3470 }
3471
3472 // If new component APIs are defined, "unsafe" lifecycles won't be called.
3473 // Warn about these lifecycles if they are present.
3474 // Don't warn about react-lifecycles-compat polyfilled methods though.
3475 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
3476 var foundWillMountName = null;
3477 var foundWillReceivePropsName = null;
3478 var foundWillUpdateName = null;
3479 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
3480 foundWillMountName = 'componentWillMount';
3481 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
3482 foundWillMountName = 'UNSAFE_componentWillMount';
3483 }
3484 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
3485 foundWillReceivePropsName = 'componentWillReceiveProps';
3486 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3487 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
3488 }
3489 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
3490 foundWillUpdateName = 'componentWillUpdate';
3491 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3492 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
3493 }
3494 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
3495 var _componentName = getComponentName(ctor) || 'Component';
3496 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
3497 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
3498 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
3499 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 : '');
3500 }
3501 }
3502 }
3503 }
3504
3505 // Cache unmasked context so we can avoid recreating masked context unless necessary.
3506 // ReactFiberContext usually updates this cache but can't for newly-created instances.
3507 if (isLegacyContextConsumer) {
3508 cacheContext(workInProgress, unmaskedContext, context);
3509 }
3510
3511 return instance;
3512}
3513
3514function callComponentWillMount(workInProgress, instance) {
3515 startPhaseTimer(workInProgress, 'componentWillMount');
3516 var oldState = instance.state;
3517
3518 if (typeof instance.componentWillMount === 'function') {
3519 instance.componentWillMount();
3520 }
3521 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3522 instance.UNSAFE_componentWillMount();
3523 }
3524
3525 stopPhaseTimer();
3526
3527 if (oldState !== instance.state) {
3528 {
3529 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');
3530 }
3531 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3532 }
3533}
3534
3535function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
3536 var oldState = instance.state;
3537 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
3538 if (typeof instance.componentWillReceiveProps === 'function') {
3539 instance.componentWillReceiveProps(newProps, nextContext);
3540 }
3541 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
3542 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
3543 }
3544 stopPhaseTimer();
3545
3546 if (instance.state !== oldState) {
3547 {
3548 var componentName = getComponentName(workInProgress.type) || 'Component';
3549 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
3550 didWarnAboutStateAssignmentForComponent.add(componentName);
3551 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
3552 }
3553 }
3554 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
3555 }
3556}
3557
3558// Invokes the mount life-cycles on a previously never rendered instance.
3559function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3560 {
3561 checkClassInstance(workInProgress, ctor, newProps);
3562 }
3563
3564 var instance = workInProgress.stateNode;
3565 instance.props = newProps;
3566 instance.state = workInProgress.memoizedState;
3567 instance.refs = emptyRefsObject;
3568
3569 var contextType = ctor.contextType;
3570 if (typeof contextType === 'object' && contextType !== null) {
3571 instance.context = readContext(contextType);
3572 } else {
3573 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3574 instance.context = getMaskedContext(workInProgress, unmaskedContext);
3575 }
3576
3577 {
3578 if (instance.state === newProps) {
3579 var componentName = getComponentName(ctor) || 'Component';
3580 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
3581 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
3582 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);
3583 }
3584 }
3585
3586 if (workInProgress.mode & StrictMode) {
3587 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
3588
3589 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
3590 }
3591
3592 if (warnAboutDeprecatedLifecycles) {
3593 ReactStrictModeWarnings.recordDeprecationWarnings(workInProgress, instance);
3594 }
3595 }
3596
3597 var updateQueue = workInProgress.updateQueue;
3598 if (updateQueue !== null) {
3599 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3600 instance.state = workInProgress.memoizedState;
3601 }
3602
3603 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3604 if (typeof getDerivedStateFromProps === 'function') {
3605 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3606 instance.state = workInProgress.memoizedState;
3607 }
3608
3609 // In order to support react-lifecycles-compat polyfilled components,
3610 // Unsafe lifecycles should not be invoked for components using the new APIs.
3611 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3612 callComponentWillMount(workInProgress, instance);
3613 // If we had additional state updates during this life-cycle, let's
3614 // process them now.
3615 updateQueue = workInProgress.updateQueue;
3616 if (updateQueue !== null) {
3617 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3618 instance.state = workInProgress.memoizedState;
3619 }
3620 }
3621
3622 if (typeof instance.componentDidMount === 'function') {
3623 workInProgress.effectTag |= Update;
3624 }
3625}
3626
3627function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
3628 var instance = workInProgress.stateNode;
3629
3630 var oldProps = workInProgress.memoizedProps;
3631 instance.props = oldProps;
3632
3633 var oldContext = instance.context;
3634 var contextType = ctor.contextType;
3635 var nextContext = void 0;
3636 if (typeof contextType === 'object' && contextType !== null) {
3637 nextContext = readContext(contextType);
3638 } else {
3639 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3640 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
3641 }
3642
3643 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3644 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3645
3646 // Note: During these life-cycles, instance.props/instance.state are what
3647 // ever the previously attempted to render - not the "current". However,
3648 // during componentDidUpdate we pass the "current" props.
3649
3650 // In order to support react-lifecycles-compat polyfilled components,
3651 // Unsafe lifecycles should not be invoked for components using the new APIs.
3652 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3653 if (oldProps !== newProps || oldContext !== nextContext) {
3654 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3655 }
3656 }
3657
3658 resetHasForceUpdateBeforeProcessing();
3659
3660 var oldState = workInProgress.memoizedState;
3661 var newState = instance.state = oldState;
3662 var updateQueue = workInProgress.updateQueue;
3663 if (updateQueue !== null) {
3664 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3665 newState = workInProgress.memoizedState;
3666 }
3667 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3668 // If an update was already in progress, we should schedule an Update
3669 // effect even though we're bailing out, so that cWU/cDU are called.
3670 if (typeof instance.componentDidMount === 'function') {
3671 workInProgress.effectTag |= Update;
3672 }
3673 return false;
3674 }
3675
3676 if (typeof getDerivedStateFromProps === 'function') {
3677 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3678 newState = workInProgress.memoizedState;
3679 }
3680
3681 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3682
3683 if (shouldUpdate) {
3684 // In order to support react-lifecycles-compat polyfilled components,
3685 // Unsafe lifecycles should not be invoked for components using the new APIs.
3686 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
3687 startPhaseTimer(workInProgress, 'componentWillMount');
3688 if (typeof instance.componentWillMount === 'function') {
3689 instance.componentWillMount();
3690 }
3691 if (typeof instance.UNSAFE_componentWillMount === 'function') {
3692 instance.UNSAFE_componentWillMount();
3693 }
3694 stopPhaseTimer();
3695 }
3696 if (typeof instance.componentDidMount === 'function') {
3697 workInProgress.effectTag |= Update;
3698 }
3699 } else {
3700 // If an update was already in progress, we should schedule an Update
3701 // effect even though we're bailing out, so that cWU/cDU are called.
3702 if (typeof instance.componentDidMount === 'function') {
3703 workInProgress.effectTag |= Update;
3704 }
3705
3706 // If shouldComponentUpdate returned false, we should still update the
3707 // memoized state to indicate that this work can be reused.
3708 workInProgress.memoizedProps = newProps;
3709 workInProgress.memoizedState = newState;
3710 }
3711
3712 // Update the existing instance's state, props, and context pointers even
3713 // if shouldComponentUpdate returns false.
3714 instance.props = newProps;
3715 instance.state = newState;
3716 instance.context = nextContext;
3717
3718 return shouldUpdate;
3719}
3720
3721// Invokes the update life-cycles and returns false if it shouldn't rerender.
3722function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
3723 var instance = workInProgress.stateNode;
3724
3725 var oldProps = workInProgress.memoizedProps;
3726 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
3727
3728 var oldContext = instance.context;
3729 var contextType = ctor.contextType;
3730 var nextContext = void 0;
3731 if (typeof contextType === 'object' && contextType !== null) {
3732 nextContext = readContext(contextType);
3733 } else {
3734 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
3735 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
3736 }
3737
3738 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
3739 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function';
3740
3741 // Note: During these life-cycles, instance.props/instance.state are what
3742 // ever the previously attempted to render - not the "current". However,
3743 // during componentDidUpdate we pass the "current" props.
3744
3745 // In order to support react-lifecycles-compat polyfilled components,
3746 // Unsafe lifecycles should not be invoked for components using the new APIs.
3747 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
3748 if (oldProps !== newProps || oldContext !== nextContext) {
3749 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
3750 }
3751 }
3752
3753 resetHasForceUpdateBeforeProcessing();
3754
3755 var oldState = workInProgress.memoizedState;
3756 var newState = instance.state = oldState;
3757 var updateQueue = workInProgress.updateQueue;
3758 if (updateQueue !== null) {
3759 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
3760 newState = workInProgress.memoizedState;
3761 }
3762
3763 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
3764 // If an update was already in progress, we should schedule an Update
3765 // effect even though we're bailing out, so that cWU/cDU are called.
3766 if (typeof instance.componentDidUpdate === 'function') {
3767 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3768 workInProgress.effectTag |= Update;
3769 }
3770 }
3771 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3772 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3773 workInProgress.effectTag |= Snapshot;
3774 }
3775 }
3776 return false;
3777 }
3778
3779 if (typeof getDerivedStateFromProps === 'function') {
3780 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
3781 newState = workInProgress.memoizedState;
3782 }
3783
3784 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
3785
3786 if (shouldUpdate) {
3787 // In order to support react-lifecycles-compat polyfilled components,
3788 // Unsafe lifecycles should not be invoked for components using the new APIs.
3789 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
3790 startPhaseTimer(workInProgress, 'componentWillUpdate');
3791 if (typeof instance.componentWillUpdate === 'function') {
3792 instance.componentWillUpdate(newProps, newState, nextContext);
3793 }
3794 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
3795 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
3796 }
3797 stopPhaseTimer();
3798 }
3799 if (typeof instance.componentDidUpdate === 'function') {
3800 workInProgress.effectTag |= Update;
3801 }
3802 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3803 workInProgress.effectTag |= Snapshot;
3804 }
3805 } else {
3806 // If an update was already in progress, we should schedule an Update
3807 // effect even though we're bailing out, so that cWU/cDU are called.
3808 if (typeof instance.componentDidUpdate === 'function') {
3809 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3810 workInProgress.effectTag |= Update;
3811 }
3812 }
3813 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
3814 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
3815 workInProgress.effectTag |= Snapshot;
3816 }
3817 }
3818
3819 // If shouldComponentUpdate returned false, we should still update the
3820 // memoized props/state to indicate that this work can be reused.
3821 workInProgress.memoizedProps = newProps;
3822 workInProgress.memoizedState = newState;
3823 }
3824
3825 // Update the existing instance's state, props, and context pointers even
3826 // if shouldComponentUpdate returns false.
3827 instance.props = newProps;
3828 instance.state = newState;
3829 instance.context = nextContext;
3830
3831 return shouldUpdate;
3832}
3833
3834var didWarnAboutMaps = void 0;
3835var didWarnAboutGenerators = void 0;
3836var didWarnAboutStringRefInStrictMode = void 0;
3837var ownerHasKeyUseWarning = void 0;
3838var ownerHasFunctionTypeWarning = void 0;
3839var warnForMissingKey = function (child) {};
3840
3841{
3842 didWarnAboutMaps = false;
3843 didWarnAboutGenerators = false;
3844 didWarnAboutStringRefInStrictMode = {};
3845
3846 /**
3847 * Warn if there's no key explicitly set on dynamic arrays of children or
3848 * object keys are not valid. This allows us to keep track of children between
3849 * updates.
3850 */
3851 ownerHasKeyUseWarning = {};
3852 ownerHasFunctionTypeWarning = {};
3853
3854 warnForMissingKey = function (child) {
3855 if (child === null || typeof child !== 'object') {
3856 return;
3857 }
3858 if (!child._store || child._store.validated || child.key != null) {
3859 return;
3860 }
3861 !(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;
3862 child._store.validated = true;
3863
3864 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
3865 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
3866 return;
3867 }
3868 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
3869
3870 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
3871 };
3872}
3873
3874var isArray = Array.isArray;
3875
3876function coerceRef(returnFiber, current$$1, element) {
3877 var mixedRef = element.ref;
3878 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
3879 {
3880 if (returnFiber.mode & StrictMode) {
3881 var componentName = getComponentName(returnFiber.type) || 'Component';
3882 if (!didWarnAboutStringRefInStrictMode[componentName]) {
3883 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));
3884 didWarnAboutStringRefInStrictMode[componentName] = true;
3885 }
3886 }
3887 }
3888
3889 if (element._owner) {
3890 var owner = element._owner;
3891 var inst = void 0;
3892 if (owner) {
3893 var ownerFiber = owner;
3894 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Function components cannot have refs. Did you mean to use React.forwardRef()?') : void 0;
3895 inst = ownerFiber.stateNode;
3896 }
3897 !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;
3898 var stringRef = '' + mixedRef;
3899 // Check if previous string ref matches new string ref
3900 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
3901 return current$$1.ref;
3902 }
3903 var ref = function (value) {
3904 var refs = inst.refs;
3905 if (refs === emptyRefsObject) {
3906 // This is a lazy pooled frozen object, so we need to initialize.
3907 refs = inst.refs = {};
3908 }
3909 if (value === null) {
3910 delete refs[stringRef];
3911 } else {
3912 refs[stringRef] = value;
3913 }
3914 };
3915 ref._stringRef = stringRef;
3916 return ref;
3917 } else {
3918 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.') : void 0;
3919 !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;
3920 }
3921 }
3922 return mixedRef;
3923}
3924
3925function throwOnInvalidObjectType(returnFiber, newChild) {
3926 if (returnFiber.type !== 'textarea') {
3927 var addendum = '';
3928 {
3929 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
3930 }
3931 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);
3932 }
3933}
3934
3935function warnOnFunctionType() {
3936 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();
3937
3938 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
3939 return;
3940 }
3941 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
3942
3943 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.');
3944}
3945
3946// This wrapper function exists because I expect to clone the code in each path
3947// to be able to optimize each path individually by branching early. This needs
3948// a compiler or we can do it manually. Helpers that don't need this branching
3949// live outside of this function.
3950function ChildReconciler(shouldTrackSideEffects) {
3951 function deleteChild(returnFiber, childToDelete) {
3952 if (!shouldTrackSideEffects) {
3953 // Noop.
3954 return;
3955 }
3956 // Deletions are added in reversed order so we add it to the front.
3957 // At this point, the return fiber's effect list is empty except for
3958 // deletions, so we can just append the deletion to the list. The remaining
3959 // effects aren't added until the complete phase. Once we implement
3960 // resuming, this may not be true.
3961 var last = returnFiber.lastEffect;
3962 if (last !== null) {
3963 last.nextEffect = childToDelete;
3964 returnFiber.lastEffect = childToDelete;
3965 } else {
3966 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
3967 }
3968 childToDelete.nextEffect = null;
3969 childToDelete.effectTag = Deletion;
3970 }
3971
3972 function deleteRemainingChildren(returnFiber, currentFirstChild) {
3973 if (!shouldTrackSideEffects) {
3974 // Noop.
3975 return null;
3976 }
3977
3978 // TODO: For the shouldClone case, this could be micro-optimized a bit by
3979 // assuming that after the first child we've already added everything.
3980 var childToDelete = currentFirstChild;
3981 while (childToDelete !== null) {
3982 deleteChild(returnFiber, childToDelete);
3983 childToDelete = childToDelete.sibling;
3984 }
3985 return null;
3986 }
3987
3988 function mapRemainingChildren(returnFiber, currentFirstChild) {
3989 // Add the remaining children to a temporary map so that we can find them by
3990 // keys quickly. Implicit (null) keys get added to this set with their index
3991 var existingChildren = new Map();
3992
3993 var existingChild = currentFirstChild;
3994 while (existingChild !== null) {
3995 if (existingChild.key !== null) {
3996 existingChildren.set(existingChild.key, existingChild);
3997 } else {
3998 existingChildren.set(existingChild.index, existingChild);
3999 }
4000 existingChild = existingChild.sibling;
4001 }
4002 return existingChildren;
4003 }
4004
4005 function useFiber(fiber, pendingProps, expirationTime) {
4006 // We currently set sibling to null and index to 0 here because it is easy
4007 // to forget to do before returning it. E.g. for the single child case.
4008 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4009 clone.index = 0;
4010 clone.sibling = null;
4011 return clone;
4012 }
4013
4014 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4015 newFiber.index = newIndex;
4016 if (!shouldTrackSideEffects) {
4017 // Noop.
4018 return lastPlacedIndex;
4019 }
4020 var current$$1 = newFiber.alternate;
4021 if (current$$1 !== null) {
4022 var oldIndex = current$$1.index;
4023 if (oldIndex < lastPlacedIndex) {
4024 // This is a move.
4025 newFiber.effectTag = Placement;
4026 return lastPlacedIndex;
4027 } else {
4028 // This item can stay in place.
4029 return oldIndex;
4030 }
4031 } else {
4032 // This is an insertion.
4033 newFiber.effectTag = Placement;
4034 return lastPlacedIndex;
4035 }
4036 }
4037
4038 function placeSingleChild(newFiber) {
4039 // This is simpler for the single child case. We only need to do a
4040 // placement for inserting new children.
4041 if (shouldTrackSideEffects && newFiber.alternate === null) {
4042 newFiber.effectTag = Placement;
4043 }
4044 return newFiber;
4045 }
4046
4047 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4048 if (current$$1 === null || current$$1.tag !== HostText) {
4049 // Insert
4050 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4051 created.return = returnFiber;
4052 return created;
4053 } else {
4054 // Update
4055 var existing = useFiber(current$$1, textContent, expirationTime);
4056 existing.return = returnFiber;
4057 return existing;
4058 }
4059 }
4060
4061 function updateElement(returnFiber, current$$1, element, expirationTime) {
4062 if (current$$1 !== null && current$$1.elementType === element.type) {
4063 // Move based on index
4064 var existing = useFiber(current$$1, element.props, expirationTime);
4065 existing.ref = coerceRef(returnFiber, current$$1, element);
4066 existing.return = returnFiber;
4067 {
4068 existing._debugSource = element._source;
4069 existing._debugOwner = element._owner;
4070 }
4071 return existing;
4072 } else {
4073 // Insert
4074 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
4075 created.ref = coerceRef(returnFiber, current$$1, element);
4076 created.return = returnFiber;
4077 return created;
4078 }
4079 }
4080
4081 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
4082 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
4083 // Insert
4084 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4085 created.return = returnFiber;
4086 return created;
4087 } else {
4088 // Update
4089 var existing = useFiber(current$$1, portal.children || [], expirationTime);
4090 existing.return = returnFiber;
4091 return existing;
4092 }
4093 }
4094
4095 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
4096 if (current$$1 === null || current$$1.tag !== Fragment) {
4097 // Insert
4098 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
4099 created.return = returnFiber;
4100 return created;
4101 } else {
4102 // Update
4103 var existing = useFiber(current$$1, fragment, expirationTime);
4104 existing.return = returnFiber;
4105 return existing;
4106 }
4107 }
4108
4109 function createChild(returnFiber, newChild, expirationTime) {
4110 if (typeof newChild === 'string' || typeof newChild === 'number') {
4111 // Text nodes don't have keys. If the previous node is implicitly keyed
4112 // we can continue to replace it without aborting even if it is not a text
4113 // node.
4114 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
4115 created.return = returnFiber;
4116 return created;
4117 }
4118
4119 if (typeof newChild === 'object' && newChild !== null) {
4120 switch (newChild.$$typeof) {
4121 case REACT_ELEMENT_TYPE:
4122 {
4123 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
4124 _created.ref = coerceRef(returnFiber, null, newChild);
4125 _created.return = returnFiber;
4126 return _created;
4127 }
4128 case REACT_PORTAL_TYPE:
4129 {
4130 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
4131 _created2.return = returnFiber;
4132 return _created2;
4133 }
4134 }
4135
4136 if (isArray(newChild) || getIteratorFn(newChild)) {
4137 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
4138 _created3.return = returnFiber;
4139 return _created3;
4140 }
4141
4142 throwOnInvalidObjectType(returnFiber, newChild);
4143 }
4144
4145 {
4146 if (typeof newChild === 'function') {
4147 warnOnFunctionType();
4148 }
4149 }
4150
4151 return null;
4152 }
4153
4154 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
4155 // Update the fiber if the keys match, otherwise return null.
4156
4157 var key = oldFiber !== null ? oldFiber.key : null;
4158
4159 if (typeof newChild === 'string' || typeof newChild === 'number') {
4160 // Text nodes don't have keys. If the previous node is implicitly keyed
4161 // we can continue to replace it without aborting even if it is not a text
4162 // node.
4163 if (key !== null) {
4164 return null;
4165 }
4166 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
4167 }
4168
4169 if (typeof newChild === 'object' && newChild !== null) {
4170 switch (newChild.$$typeof) {
4171 case REACT_ELEMENT_TYPE:
4172 {
4173 if (newChild.key === key) {
4174 if (newChild.type === REACT_FRAGMENT_TYPE) {
4175 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
4176 }
4177 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
4178 } else {
4179 return null;
4180 }
4181 }
4182 case REACT_PORTAL_TYPE:
4183 {
4184 if (newChild.key === key) {
4185 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
4186 } else {
4187 return null;
4188 }
4189 }
4190 }
4191
4192 if (isArray(newChild) || getIteratorFn(newChild)) {
4193 if (key !== null) {
4194 return null;
4195 }
4196
4197 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
4198 }
4199
4200 throwOnInvalidObjectType(returnFiber, newChild);
4201 }
4202
4203 {
4204 if (typeof newChild === 'function') {
4205 warnOnFunctionType();
4206 }
4207 }
4208
4209 return null;
4210 }
4211
4212 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
4213 if (typeof newChild === 'string' || typeof newChild === 'number') {
4214 // Text nodes don't have keys, so we neither have to check the old nor
4215 // new node for the key. If both are text nodes, they match.
4216 var matchedFiber = existingChildren.get(newIdx) || null;
4217 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
4218 }
4219
4220 if (typeof newChild === 'object' && newChild !== null) {
4221 switch (newChild.$$typeof) {
4222 case REACT_ELEMENT_TYPE:
4223 {
4224 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4225 if (newChild.type === REACT_FRAGMENT_TYPE) {
4226 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
4227 }
4228 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
4229 }
4230 case REACT_PORTAL_TYPE:
4231 {
4232 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
4233 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
4234 }
4235 }
4236
4237 if (isArray(newChild) || getIteratorFn(newChild)) {
4238 var _matchedFiber3 = existingChildren.get(newIdx) || null;
4239 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
4240 }
4241
4242 throwOnInvalidObjectType(returnFiber, newChild);
4243 }
4244
4245 {
4246 if (typeof newChild === 'function') {
4247 warnOnFunctionType();
4248 }
4249 }
4250
4251 return null;
4252 }
4253
4254 /**
4255 * Warns if there is a duplicate or missing key
4256 */
4257 function warnOnInvalidKey(child, knownKeys) {
4258 {
4259 if (typeof child !== 'object' || child === null) {
4260 return knownKeys;
4261 }
4262 switch (child.$$typeof) {
4263 case REACT_ELEMENT_TYPE:
4264 case REACT_PORTAL_TYPE:
4265 warnForMissingKey(child);
4266 var key = child.key;
4267 if (typeof key !== 'string') {
4268 break;
4269 }
4270 if (knownKeys === null) {
4271 knownKeys = new Set();
4272 knownKeys.add(key);
4273 break;
4274 }
4275 if (!knownKeys.has(key)) {
4276 knownKeys.add(key);
4277 break;
4278 }
4279 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);
4280 break;
4281 default:
4282 break;
4283 }
4284 }
4285 return knownKeys;
4286 }
4287
4288 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
4289 // This algorithm can't optimize by searching from both ends since we
4290 // don't have backpointers on fibers. I'm trying to see how far we can get
4291 // with that model. If it ends up not being worth the tradeoffs, we can
4292 // add it later.
4293
4294 // Even with a two ended optimization, we'd want to optimize for the case
4295 // where there are few changes and brute force the comparison instead of
4296 // going for the Map. It'd like to explore hitting that path first in
4297 // forward-only mode and only go for the Map once we notice that we need
4298 // lots of look ahead. This doesn't handle reversal as well as two ended
4299 // search but that's unusual. Besides, for the two ended optimization to
4300 // work on Iterables, we'd need to copy the whole set.
4301
4302 // In this first iteration, we'll just live with hitting the bad case
4303 // (adding everything to a Map) in for every insert/move.
4304
4305 // If you change this code, also update reconcileChildrenIterator() which
4306 // uses the same algorithm.
4307
4308 {
4309 // First, validate keys.
4310 var knownKeys = null;
4311 for (var i = 0; i < newChildren.length; i++) {
4312 var child = newChildren[i];
4313 knownKeys = warnOnInvalidKey(child, knownKeys);
4314 }
4315 }
4316
4317 var resultingFirstChild = null;
4318 var previousNewFiber = null;
4319
4320 var oldFiber = currentFirstChild;
4321 var lastPlacedIndex = 0;
4322 var newIdx = 0;
4323 var nextOldFiber = null;
4324 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
4325 if (oldFiber.index > newIdx) {
4326 nextOldFiber = oldFiber;
4327 oldFiber = null;
4328 } else {
4329 nextOldFiber = oldFiber.sibling;
4330 }
4331 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
4332 if (newFiber === null) {
4333 // TODO: This breaks on empty slots like null children. That's
4334 // unfortunate because it triggers the slow path all the time. We need
4335 // a better way to communicate whether this was a miss or null,
4336 // boolean, undefined, etc.
4337 if (oldFiber === null) {
4338 oldFiber = nextOldFiber;
4339 }
4340 break;
4341 }
4342 if (shouldTrackSideEffects) {
4343 if (oldFiber && newFiber.alternate === null) {
4344 // We matched the slot, but we didn't reuse the existing fiber, so we
4345 // need to delete the existing child.
4346 deleteChild(returnFiber, oldFiber);
4347 }
4348 }
4349 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4350 if (previousNewFiber === null) {
4351 // TODO: Move out of the loop. This only happens for the first run.
4352 resultingFirstChild = newFiber;
4353 } else {
4354 // TODO: Defer siblings if we're not at the right index for this slot.
4355 // I.e. if we had null values before, then we want to defer this
4356 // for each null value. However, we also don't want to call updateSlot
4357 // with the previous one.
4358 previousNewFiber.sibling = newFiber;
4359 }
4360 previousNewFiber = newFiber;
4361 oldFiber = nextOldFiber;
4362 }
4363
4364 if (newIdx === newChildren.length) {
4365 // We've reached the end of the new children. We can delete the rest.
4366 deleteRemainingChildren(returnFiber, oldFiber);
4367 return resultingFirstChild;
4368 }
4369
4370 if (oldFiber === null) {
4371 // If we don't have any more existing children we can choose a fast path
4372 // since the rest will all be insertions.
4373 for (; newIdx < newChildren.length; newIdx++) {
4374 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
4375 if (!_newFiber) {
4376 continue;
4377 }
4378 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
4379 if (previousNewFiber === null) {
4380 // TODO: Move out of the loop. This only happens for the first run.
4381 resultingFirstChild = _newFiber;
4382 } else {
4383 previousNewFiber.sibling = _newFiber;
4384 }
4385 previousNewFiber = _newFiber;
4386 }
4387 return resultingFirstChild;
4388 }
4389
4390 // Add all children to a key map for quick lookups.
4391 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4392
4393 // Keep scanning and use the map to restore deleted items as moves.
4394 for (; newIdx < newChildren.length; newIdx++) {
4395 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
4396 if (_newFiber2) {
4397 if (shouldTrackSideEffects) {
4398 if (_newFiber2.alternate !== null) {
4399 // The new fiber is a work in progress, but if there exists a
4400 // current, that means that we reused the fiber. We need to delete
4401 // it from the child list so that we don't add it to the deletion
4402 // list.
4403 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
4404 }
4405 }
4406 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
4407 if (previousNewFiber === null) {
4408 resultingFirstChild = _newFiber2;
4409 } else {
4410 previousNewFiber.sibling = _newFiber2;
4411 }
4412 previousNewFiber = _newFiber2;
4413 }
4414 }
4415
4416 if (shouldTrackSideEffects) {
4417 // Any existing children that weren't consumed above were deleted. We need
4418 // to add them to the deletion list.
4419 existingChildren.forEach(function (child) {
4420 return deleteChild(returnFiber, child);
4421 });
4422 }
4423
4424 return resultingFirstChild;
4425 }
4426
4427 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
4428 // This is the same implementation as reconcileChildrenArray(),
4429 // but using the iterator instead.
4430
4431 var iteratorFn = getIteratorFn(newChildrenIterable);
4432 !(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;
4433
4434 {
4435 // We don't support rendering Generators because it's a mutation.
4436 // See https://github.com/facebook/react/issues/12995
4437 if (typeof Symbol === 'function' &&
4438 // $FlowFixMe Flow doesn't know about toStringTag
4439 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
4440 !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;
4441 didWarnAboutGenerators = true;
4442 }
4443
4444 // Warn about using Maps as children
4445 if (newChildrenIterable.entries === iteratorFn) {
4446 !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;
4447 didWarnAboutMaps = true;
4448 }
4449
4450 // First, validate keys.
4451 // We'll get a different iterator later for the main pass.
4452 var _newChildren = iteratorFn.call(newChildrenIterable);
4453 if (_newChildren) {
4454 var knownKeys = null;
4455 var _step = _newChildren.next();
4456 for (; !_step.done; _step = _newChildren.next()) {
4457 var child = _step.value;
4458 knownKeys = warnOnInvalidKey(child, knownKeys);
4459 }
4460 }
4461 }
4462
4463 var newChildren = iteratorFn.call(newChildrenIterable);
4464 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
4465
4466 var resultingFirstChild = null;
4467 var previousNewFiber = null;
4468
4469 var oldFiber = currentFirstChild;
4470 var lastPlacedIndex = 0;
4471 var newIdx = 0;
4472 var nextOldFiber = null;
4473
4474 var step = newChildren.next();
4475 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
4476 if (oldFiber.index > newIdx) {
4477 nextOldFiber = oldFiber;
4478 oldFiber = null;
4479 } else {
4480 nextOldFiber = oldFiber.sibling;
4481 }
4482 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
4483 if (newFiber === null) {
4484 // TODO: This breaks on empty slots like null children. That's
4485 // unfortunate because it triggers the slow path all the time. We need
4486 // a better way to communicate whether this was a miss or null,
4487 // boolean, undefined, etc.
4488 if (!oldFiber) {
4489 oldFiber = nextOldFiber;
4490 }
4491 break;
4492 }
4493 if (shouldTrackSideEffects) {
4494 if (oldFiber && newFiber.alternate === null) {
4495 // We matched the slot, but we didn't reuse the existing fiber, so we
4496 // need to delete the existing child.
4497 deleteChild(returnFiber, oldFiber);
4498 }
4499 }
4500 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
4501 if (previousNewFiber === null) {
4502 // TODO: Move out of the loop. This only happens for the first run.
4503 resultingFirstChild = newFiber;
4504 } else {
4505 // TODO: Defer siblings if we're not at the right index for this slot.
4506 // I.e. if we had null values before, then we want to defer this
4507 // for each null value. However, we also don't want to call updateSlot
4508 // with the previous one.
4509 previousNewFiber.sibling = newFiber;
4510 }
4511 previousNewFiber = newFiber;
4512 oldFiber = nextOldFiber;
4513 }
4514
4515 if (step.done) {
4516 // We've reached the end of the new children. We can delete the rest.
4517 deleteRemainingChildren(returnFiber, oldFiber);
4518 return resultingFirstChild;
4519 }
4520
4521 if (oldFiber === null) {
4522 // If we don't have any more existing children we can choose a fast path
4523 // since the rest will all be insertions.
4524 for (; !step.done; newIdx++, step = newChildren.next()) {
4525 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
4526 if (_newFiber3 === null) {
4527 continue;
4528 }
4529 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
4530 if (previousNewFiber === null) {
4531 // TODO: Move out of the loop. This only happens for the first run.
4532 resultingFirstChild = _newFiber3;
4533 } else {
4534 previousNewFiber.sibling = _newFiber3;
4535 }
4536 previousNewFiber = _newFiber3;
4537 }
4538 return resultingFirstChild;
4539 }
4540
4541 // Add all children to a key map for quick lookups.
4542 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);
4543
4544 // Keep scanning and use the map to restore deleted items as moves.
4545 for (; !step.done; newIdx++, step = newChildren.next()) {
4546 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
4547 if (_newFiber4 !== null) {
4548 if (shouldTrackSideEffects) {
4549 if (_newFiber4.alternate !== null) {
4550 // The new fiber is a work in progress, but if there exists a
4551 // current, that means that we reused the fiber. We need to delete
4552 // it from the child list so that we don't add it to the deletion
4553 // list.
4554 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
4555 }
4556 }
4557 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
4558 if (previousNewFiber === null) {
4559 resultingFirstChild = _newFiber4;
4560 } else {
4561 previousNewFiber.sibling = _newFiber4;
4562 }
4563 previousNewFiber = _newFiber4;
4564 }
4565 }
4566
4567 if (shouldTrackSideEffects) {
4568 // Any existing children that weren't consumed above were deleted. We need
4569 // to add them to the deletion list.
4570 existingChildren.forEach(function (child) {
4571 return deleteChild(returnFiber, child);
4572 });
4573 }
4574
4575 return resultingFirstChild;
4576 }
4577
4578 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
4579 // There's no need to check for keys on text nodes since we don't have a
4580 // way to define them.
4581 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
4582 // We already have an existing node so let's just update it and delete
4583 // the rest.
4584 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
4585 var existing = useFiber(currentFirstChild, textContent, expirationTime);
4586 existing.return = returnFiber;
4587 return existing;
4588 }
4589 // The existing first child is not a text node so we need to create one
4590 // and delete the existing ones.
4591 deleteRemainingChildren(returnFiber, currentFirstChild);
4592 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4593 created.return = returnFiber;
4594 return created;
4595 }
4596
4597 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
4598 var key = element.key;
4599 var child = currentFirstChild;
4600 while (child !== null) {
4601 // TODO: If key === null and child.key === null, then this only applies to
4602 // the first item in the list.
4603 if (child.key === key) {
4604 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type) {
4605 deleteRemainingChildren(returnFiber, child.sibling);
4606 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
4607 existing.ref = coerceRef(returnFiber, child, element);
4608 existing.return = returnFiber;
4609 {
4610 existing._debugSource = element._source;
4611 existing._debugOwner = element._owner;
4612 }
4613 return existing;
4614 } else {
4615 deleteRemainingChildren(returnFiber, child);
4616 break;
4617 }
4618 } else {
4619 deleteChild(returnFiber, child);
4620 }
4621 child = child.sibling;
4622 }
4623
4624 if (element.type === REACT_FRAGMENT_TYPE) {
4625 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
4626 created.return = returnFiber;
4627 return created;
4628 } else {
4629 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
4630 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
4631 _created4.return = returnFiber;
4632 return _created4;
4633 }
4634 }
4635
4636 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
4637 var key = portal.key;
4638 var child = currentFirstChild;
4639 while (child !== null) {
4640 // TODO: If key === null and child.key === null, then this only applies to
4641 // the first item in the list.
4642 if (child.key === key) {
4643 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
4644 deleteRemainingChildren(returnFiber, child.sibling);
4645 var existing = useFiber(child, portal.children || [], expirationTime);
4646 existing.return = returnFiber;
4647 return existing;
4648 } else {
4649 deleteRemainingChildren(returnFiber, child);
4650 break;
4651 }
4652 } else {
4653 deleteChild(returnFiber, child);
4654 }
4655 child = child.sibling;
4656 }
4657
4658 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4659 created.return = returnFiber;
4660 return created;
4661 }
4662
4663 // This API will tag the children with the side-effect of the reconciliation
4664 // itself. They will be added to the side-effect list as we pass through the
4665 // children and the parent.
4666 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
4667 // This function is not recursive.
4668 // If the top level item is an array, we treat it as a set of children,
4669 // not as a fragment. Nested arrays on the other hand will be treated as
4670 // fragment nodes. Recursion happens at the normal flow.
4671
4672 // Handle top level unkeyed fragments as if they were arrays.
4673 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
4674 // We treat the ambiguous cases above the same.
4675 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
4676 if (isUnkeyedTopLevelFragment) {
4677 newChild = newChild.props.children;
4678 }
4679
4680 // Handle object types
4681 var isObject = typeof newChild === 'object' && newChild !== null;
4682
4683 if (isObject) {
4684 switch (newChild.$$typeof) {
4685 case REACT_ELEMENT_TYPE:
4686 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
4687 case REACT_PORTAL_TYPE:
4688 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
4689 }
4690 }
4691
4692 if (typeof newChild === 'string' || typeof newChild === 'number') {
4693 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
4694 }
4695
4696 if (isArray(newChild)) {
4697 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
4698 }
4699
4700 if (getIteratorFn(newChild)) {
4701 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
4702 }
4703
4704 if (isObject) {
4705 throwOnInvalidObjectType(returnFiber, newChild);
4706 }
4707
4708 {
4709 if (typeof newChild === 'function') {
4710 warnOnFunctionType();
4711 }
4712 }
4713 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
4714 // If the new child is undefined, and the return fiber is a composite
4715 // component, throw an error. If Fiber return types are disabled,
4716 // we already threw above.
4717 switch (returnFiber.tag) {
4718 case ClassComponent:
4719 {
4720 {
4721 var instance = returnFiber.stateNode;
4722 if (instance.render._isMockFunction) {
4723 // We allow auto-mocks to proceed as if they're returning null.
4724 break;
4725 }
4726 }
4727 }
4728 // Intentionally fall through to the next case, which handles both
4729 // functions and classes
4730 // eslint-disable-next-lined no-fallthrough
4731 case FunctionComponent:
4732 {
4733 var Component = returnFiber.type;
4734 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');
4735 }
4736 }
4737 }
4738
4739 // Remaining cases are all treated as empty.
4740 return deleteRemainingChildren(returnFiber, currentFirstChild);
4741 }
4742
4743 return reconcileChildFibers;
4744}
4745
4746var reconcileChildFibers = ChildReconciler(true);
4747var mountChildFibers = ChildReconciler(false);
4748
4749function cloneChildFibers(current$$1, workInProgress) {
4750 !(current$$1 === null || workInProgress.child === current$$1.child) ? invariant(false, 'Resuming work not yet implemented.') : void 0;
4751
4752 if (workInProgress.child === null) {
4753 return;
4754 }
4755
4756 var currentChild = workInProgress.child;
4757 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4758 workInProgress.child = newChild;
4759
4760 newChild.return = workInProgress;
4761 while (currentChild.sibling !== null) {
4762 currentChild = currentChild.sibling;
4763 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
4764 newChild.return = workInProgress;
4765 }
4766 newChild.sibling = null;
4767}
4768
4769var NO_CONTEXT$1 = {};
4770
4771var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
4772var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
4773var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
4774
4775function requiredContext(c) {
4776 !(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;
4777 return c;
4778}
4779
4780function getRootHostContainer() {
4781 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4782 return rootInstance;
4783}
4784
4785function pushHostContainer(fiber, nextRootInstance) {
4786 // Push current root instance onto the stack;
4787 // This allows us to reset root when portals are popped.
4788 push(rootInstanceStackCursor, nextRootInstance, fiber);
4789 // Track the context and the Fiber that provided it.
4790 // This enables us to pop only Fibers that provide unique contexts.
4791 push(contextFiberStackCursor, fiber, fiber);
4792
4793 // Finally, we need to push the host context to the stack.
4794 // However, we can't just call getRootHostContext() and push it because
4795 // we'd have a different number of entries on the stack depending on
4796 // whether getRootHostContext() throws somewhere in renderer code or not.
4797 // So we push an empty value first. This lets us safely unwind on errors.
4798 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
4799 var nextRootContext = getRootHostContext(nextRootInstance);
4800 // Now that we know this function doesn't throw, replace it.
4801 pop(contextStackCursor$1, fiber);
4802 push(contextStackCursor$1, nextRootContext, fiber);
4803}
4804
4805function popHostContainer(fiber) {
4806 pop(contextStackCursor$1, fiber);
4807 pop(contextFiberStackCursor, fiber);
4808 pop(rootInstanceStackCursor, fiber);
4809}
4810
4811function getHostContext() {
4812 var context = requiredContext(contextStackCursor$1.current);
4813 return context;
4814}
4815
4816function pushHostContext(fiber) {
4817 var rootInstance = requiredContext(rootInstanceStackCursor.current);
4818 var context = requiredContext(contextStackCursor$1.current);
4819 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
4820
4821 // Don't push this Fiber's context unless it's unique.
4822 if (context === nextContext) {
4823 return;
4824 }
4825
4826 // Track the context and the Fiber that provided it.
4827 // This enables us to pop only Fibers that provide unique contexts.
4828 push(contextFiberStackCursor, fiber, fiber);
4829 push(contextStackCursor$1, nextContext, fiber);
4830}
4831
4832function popHostContext(fiber) {
4833 // Do not pop unless this Fiber provided the current context.
4834 // pushHostContext() only pushes Fibers that provide unique contexts.
4835 if (contextFiberStackCursor.current !== fiber) {
4836 return;
4837 }
4838
4839 pop(contextStackCursor$1, fiber);
4840 pop(contextFiberStackCursor, fiber);
4841}
4842
4843var NoEffect$1 = /* */0;
4844var UnmountSnapshot = /* */2;
4845var UnmountMutation = /* */4;
4846var MountMutation = /* */8;
4847var UnmountLayout = /* */16;
4848var MountLayout = /* */32;
4849var MountPassive = /* */64;
4850var UnmountPassive = /* */128;
4851
4852var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
4853
4854
4855var didWarnAboutMismatchedHooksForComponent = void 0;
4856{
4857 didWarnAboutMismatchedHooksForComponent = new Set();
4858}
4859
4860// These are set right before calling the component.
4861var renderExpirationTime = NoWork;
4862// The work-in-progress fiber. I've named it differently to distinguish it from
4863// the work-in-progress hook.
4864var currentlyRenderingFiber$1 = null;
4865
4866// Hooks are stored as a linked list on the fiber's memoizedState field. The
4867// current hook list is the list that belongs to the current fiber. The
4868// work-in-progress hook list is a new list that will be added to the
4869// work-in-progress fiber.
4870var currentHook = null;
4871var nextCurrentHook = null;
4872var firstWorkInProgressHook = null;
4873var workInProgressHook = null;
4874var nextWorkInProgressHook = null;
4875
4876var remainingExpirationTime = NoWork;
4877var componentUpdateQueue = null;
4878var sideEffectTag = 0;
4879
4880// Updates scheduled during render will trigger an immediate re-render at the
4881// end of the current pass. We can't store these updates on the normal queue,
4882// because if the work is aborted, they should be discarded. Because this is
4883// a relatively rare case, we also don't want to add an additional field to
4884// either the hook or queue object types. So we store them in a lazily create
4885// map of queue -> render-phase updates, which are discarded once the component
4886// completes without re-rendering.
4887
4888// Whether an update was scheduled during the currently executing render pass.
4889var didScheduleRenderPhaseUpdate = false;
4890// Lazily created map of render-phase updates
4891var renderPhaseUpdates = null;
4892// Counter to prevent infinite loops.
4893var numberOfReRenders = 0;
4894var RE_RENDER_LIMIT = 25;
4895
4896// In DEV, this is the name of the currently executing primitive hook
4897var currentHookNameInDev = null;
4898
4899// In DEV, this list ensures that hooks are called in the same order between renders.
4900// The list stores the order of hooks used during the initial render (mount).
4901// Subsequent renders (updates) reference this list.
4902var hookTypesDev = null;
4903var hookTypesUpdateIndexDev = -1;
4904
4905function mountHookTypesDev() {
4906 {
4907 var hookName = currentHookNameInDev;
4908
4909 if (hookTypesDev === null) {
4910 hookTypesDev = [hookName];
4911 } else {
4912 hookTypesDev.push(hookName);
4913 }
4914 }
4915}
4916
4917function updateHookTypesDev() {
4918 {
4919 var hookName = currentHookNameInDev;
4920
4921 if (hookTypesDev !== null) {
4922 hookTypesUpdateIndexDev++;
4923 if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
4924 warnOnHookMismatchInDev(hookName);
4925 }
4926 }
4927 }
4928}
4929
4930function warnOnHookMismatchInDev(currentHookName) {
4931 {
4932 var componentName = getComponentName(currentlyRenderingFiber$1.type);
4933 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
4934 didWarnAboutMismatchedHooksForComponent.add(componentName);
4935
4936 if (hookTypesDev !== null) {
4937 var table = '';
4938
4939 var secondColumnStart = 30;
4940
4941 for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
4942 var oldHookName = hookTypesDev[i];
4943 var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
4944
4945 var row = i + 1 + '. ' + oldHookName;
4946
4947 // Extra space so second column lines up
4948 // lol @ IE not supporting String#repeat
4949 while (row.length < secondColumnStart) {
4950 row += ' ';
4951 }
4952
4953 row += newHookName + '\n';
4954
4955 table += row;
4956 }
4957
4958 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);
4959 }
4960 }
4961 }
4962}
4963
4964function throwInvalidHookError() {
4965 invariant(false, 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.');
4966}
4967
4968function areHookInputsEqual(nextDeps, prevDeps) {
4969 if (prevDeps === null) {
4970 {
4971 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);
4972 }
4973 return false;
4974 }
4975
4976 {
4977 // Don't bother comparing lengths in prod because these arrays should be
4978 // passed inline.
4979 if (nextDeps.length !== prevDeps.length) {
4980 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(', ') + ']');
4981 }
4982 }
4983 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
4984 if (is(nextDeps[i], prevDeps[i])) {
4985 continue;
4986 }
4987 return false;
4988 }
4989 return true;
4990}
4991
4992function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
4993 renderExpirationTime = nextRenderExpirationTime;
4994 currentlyRenderingFiber$1 = workInProgress;
4995 nextCurrentHook = current !== null ? current.memoizedState : null;
4996
4997 {
4998 hookTypesDev = current !== null ? current._debugHookTypes : null;
4999 hookTypesUpdateIndexDev = -1;
5000 }
5001
5002 // The following should have already been reset
5003 // currentHook = null;
5004 // workInProgressHook = null;
5005
5006 // remainingExpirationTime = NoWork;
5007 // componentUpdateQueue = null;
5008
5009 // didScheduleRenderPhaseUpdate = false;
5010 // renderPhaseUpdates = null;
5011 // numberOfReRenders = 0;
5012 // sideEffectTag = 0;
5013
5014 // TODO Warn if no hooks are used at all during mount, then some are used during update.
5015 // Currently we will identify the update render as a mount because nextCurrentHook === null.
5016 // This is tricky because it's valid for certain types of components (e.g. React.lazy)
5017
5018 // Using nextCurrentHook to differentiate between mount/update only works if at least one stateful hook is used.
5019 // Non-stateful hooks (e.g. context) don't get added to memoizedState,
5020 // so nextCurrentHook would be null during updates and mounts.
5021 {
5022 if (nextCurrentHook !== null) {
5023 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
5024 } else if (hookTypesDev !== null) {
5025 // This dispatcher handles an edge case where a component is updating,
5026 // but no stateful hooks have been used.
5027 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
5028 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
5029 // This dispatcher does that.
5030 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
5031 } else {
5032 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
5033 }
5034 }
5035
5036 var children = Component(props, refOrContext);
5037
5038 if (didScheduleRenderPhaseUpdate) {
5039 do {
5040 didScheduleRenderPhaseUpdate = false;
5041 numberOfReRenders += 1;
5042
5043 // Start over from the beginning of the list
5044 nextCurrentHook = current !== null ? current.memoizedState : null;
5045 nextWorkInProgressHook = firstWorkInProgressHook;
5046
5047 currentHook = null;
5048 workInProgressHook = null;
5049 componentUpdateQueue = null;
5050
5051 {
5052 // Also validate hook order for cascading updates.
5053 hookTypesUpdateIndexDev = -1;
5054 }
5055
5056 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
5057
5058 children = Component(props, refOrContext);
5059 } while (didScheduleRenderPhaseUpdate);
5060
5061 renderPhaseUpdates = null;
5062 numberOfReRenders = 0;
5063 }
5064
5065 // We can assume the previous dispatcher is always this one, since we set it
5066 // at the beginning of the render phase and there's no re-entrancy.
5067 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5068
5069 var renderedWork = currentlyRenderingFiber$1;
5070
5071 renderedWork.memoizedState = firstWorkInProgressHook;
5072 renderedWork.expirationTime = remainingExpirationTime;
5073 renderedWork.updateQueue = componentUpdateQueue;
5074 renderedWork.effectTag |= sideEffectTag;
5075
5076 {
5077 renderedWork._debugHookTypes = hookTypesDev;
5078 }
5079
5080 // This check uses currentHook so that it works the same in DEV and prod bundles.
5081 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
5082 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
5083
5084 renderExpirationTime = NoWork;
5085 currentlyRenderingFiber$1 = null;
5086
5087 currentHook = null;
5088 nextCurrentHook = null;
5089 firstWorkInProgressHook = null;
5090 workInProgressHook = null;
5091 nextWorkInProgressHook = null;
5092
5093 {
5094 currentHookNameInDev = null;
5095 hookTypesDev = null;
5096 hookTypesUpdateIndexDev = -1;
5097 }
5098
5099 remainingExpirationTime = NoWork;
5100 componentUpdateQueue = null;
5101 sideEffectTag = 0;
5102
5103 // These were reset above
5104 // didScheduleRenderPhaseUpdate = false;
5105 // renderPhaseUpdates = null;
5106 // numberOfReRenders = 0;
5107
5108 !!didRenderTooFewHooks ? invariant(false, 'Rendered fewer hooks than expected. This may be caused by an accidental early return statement.') : void 0;
5109
5110 return children;
5111}
5112
5113function bailoutHooks(current, workInProgress, expirationTime) {
5114 workInProgress.updateQueue = current.updateQueue;
5115 workInProgress.effectTag &= ~(Passive | Update);
5116 if (current.expirationTime <= expirationTime) {
5117 current.expirationTime = NoWork;
5118 }
5119}
5120
5121function resetHooks() {
5122 // We can assume the previous dispatcher is always this one, since we set it
5123 // at the beginning of the render phase and there's no re-entrancy.
5124 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
5125
5126 // This is used to reset the state of this module when a component throws.
5127 // It's also called inside mountIndeterminateComponent if we determine the
5128 // component is a module-style component.
5129 renderExpirationTime = NoWork;
5130 currentlyRenderingFiber$1 = null;
5131
5132 currentHook = null;
5133 nextCurrentHook = null;
5134 firstWorkInProgressHook = null;
5135 workInProgressHook = null;
5136 nextWorkInProgressHook = null;
5137
5138 {
5139 hookTypesDev = null;
5140 hookTypesUpdateIndexDev = -1;
5141
5142 currentHookNameInDev = null;
5143 }
5144
5145 remainingExpirationTime = NoWork;
5146 componentUpdateQueue = null;
5147 sideEffectTag = 0;
5148
5149 didScheduleRenderPhaseUpdate = false;
5150 renderPhaseUpdates = null;
5151 numberOfReRenders = 0;
5152}
5153
5154function mountWorkInProgressHook() {
5155 var hook = {
5156 memoizedState: null,
5157
5158 baseState: null,
5159 queue: null,
5160 baseUpdate: null,
5161
5162 next: null
5163 };
5164
5165 if (workInProgressHook === null) {
5166 // This is the first hook in the list
5167 firstWorkInProgressHook = workInProgressHook = hook;
5168 } else {
5169 // Append to the end of the list
5170 workInProgressHook = workInProgressHook.next = hook;
5171 }
5172 return workInProgressHook;
5173}
5174
5175function updateWorkInProgressHook() {
5176 // This function is used both for updates and for re-renders triggered by a
5177 // render phase update. It assumes there is either a current hook we can
5178 // clone, or a work-in-progress hook from a previous render pass that we can
5179 // use as a base. When we reach the end of the base list, we must switch to
5180 // the dispatcher used for mounts.
5181 if (nextWorkInProgressHook !== null) {
5182 // There's already a work-in-progress. Reuse it.
5183 workInProgressHook = nextWorkInProgressHook;
5184 nextWorkInProgressHook = workInProgressHook.next;
5185
5186 currentHook = nextCurrentHook;
5187 nextCurrentHook = currentHook !== null ? currentHook.next : null;
5188 } else {
5189 // Clone from the current hook.
5190 !(nextCurrentHook !== null) ? invariant(false, 'Rendered more hooks than during the previous render.') : void 0;
5191 currentHook = nextCurrentHook;
5192
5193 var newHook = {
5194 memoizedState: currentHook.memoizedState,
5195
5196 baseState: currentHook.baseState,
5197 queue: currentHook.queue,
5198 baseUpdate: currentHook.baseUpdate,
5199
5200 next: null
5201 };
5202
5203 if (workInProgressHook === null) {
5204 // This is the first hook in the list.
5205 workInProgressHook = firstWorkInProgressHook = newHook;
5206 } else {
5207 // Append to the end of the list.
5208 workInProgressHook = workInProgressHook.next = newHook;
5209 }
5210 nextCurrentHook = currentHook.next;
5211 }
5212 return workInProgressHook;
5213}
5214
5215function createFunctionComponentUpdateQueue() {
5216 return {
5217 lastEffect: null
5218 };
5219}
5220
5221function basicStateReducer(state, action) {
5222 return typeof action === 'function' ? action(state) : action;
5223}
5224
5225function mountReducer(reducer, initialArg, init) {
5226 var hook = mountWorkInProgressHook();
5227 var initialState = void 0;
5228 if (init !== undefined) {
5229 initialState = init(initialArg);
5230 } else {
5231 initialState = initialArg;
5232 }
5233 hook.memoizedState = hook.baseState = initialState;
5234 var queue = hook.queue = {
5235 last: null,
5236 dispatch: null,
5237 lastRenderedReducer: reducer,
5238 lastRenderedState: initialState
5239 };
5240 var dispatch = queue.dispatch = dispatchAction.bind(null,
5241 // Flow doesn't know this is non-null, but we do.
5242 currentlyRenderingFiber$1, queue);
5243 return [hook.memoizedState, dispatch];
5244}
5245
5246function updateReducer(reducer, initialArg, init) {
5247 var hook = updateWorkInProgressHook();
5248 var queue = hook.queue;
5249 !(queue !== null) ? invariant(false, 'Should have a queue. This is likely a bug in React. Please file an issue.') : void 0;
5250
5251 queue.lastRenderedReducer = reducer;
5252
5253 if (numberOfReRenders > 0) {
5254 // This is a re-render. Apply the new render phase updates to the previous
5255 var _dispatch = queue.dispatch;
5256 if (renderPhaseUpdates !== null) {
5257 // Render phase updates are stored in a map of queue -> linked list
5258 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5259 if (firstRenderPhaseUpdate !== undefined) {
5260 renderPhaseUpdates.delete(queue);
5261 var newState = hook.memoizedState;
5262 var update = firstRenderPhaseUpdate;
5263 do {
5264 // Process this render phase update. We don't have to check the
5265 // priority because it will always be the same as the current
5266 // render's.
5267 var _action = update.action;
5268 newState = reducer(newState, _action);
5269 update = update.next;
5270 } while (update !== null);
5271
5272 // Mark that the fiber performed work, but only if the new state is
5273 // different from the current state.
5274 if (!is(newState, hook.memoizedState)) {
5275 markWorkInProgressReceivedUpdate();
5276 }
5277
5278 hook.memoizedState = newState;
5279 // Don't persist the state accumlated from the render phase updates to
5280 // the base state unless the queue is empty.
5281 // TODO: Not sure if this is the desired semantics, but it's what we
5282 // do for gDSFP. I can't remember why.
5283 if (hook.baseUpdate === queue.last) {
5284 hook.baseState = newState;
5285 }
5286
5287 queue.lastRenderedState = newState;
5288
5289 return [newState, _dispatch];
5290 }
5291 }
5292 return [hook.memoizedState, _dispatch];
5293 }
5294
5295 // The last update in the entire queue
5296 var last = queue.last;
5297 // The last update that is part of the base state.
5298 var baseUpdate = hook.baseUpdate;
5299 var baseState = hook.baseState;
5300
5301 // Find the first unprocessed update.
5302 var first = void 0;
5303 if (baseUpdate !== null) {
5304 if (last !== null) {
5305 // For the first update, the queue is a circular linked list where
5306 // `queue.last.next = queue.first`. Once the first update commits, and
5307 // the `baseUpdate` is no longer empty, we can unravel the list.
5308 last.next = null;
5309 }
5310 first = baseUpdate.next;
5311 } else {
5312 first = last !== null ? last.next : null;
5313 }
5314 if (first !== null) {
5315 var _newState = baseState;
5316 var newBaseState = null;
5317 var newBaseUpdate = null;
5318 var prevUpdate = baseUpdate;
5319 var _update = first;
5320 var didSkip = false;
5321 do {
5322 var updateExpirationTime = _update.expirationTime;
5323 if (updateExpirationTime < renderExpirationTime) {
5324 // Priority is insufficient. Skip this update. If this is the first
5325 // skipped update, the previous update/state is the new base
5326 // update/state.
5327 if (!didSkip) {
5328 didSkip = true;
5329 newBaseUpdate = prevUpdate;
5330 newBaseState = _newState;
5331 }
5332 // Update the remaining priority in the queue.
5333 if (updateExpirationTime > remainingExpirationTime) {
5334 remainingExpirationTime = updateExpirationTime;
5335 }
5336 } else {
5337 // Process this update.
5338 if (_update.eagerReducer === reducer) {
5339 // If this update was processed eagerly, and its reducer matches the
5340 // current reducer, we can use the eagerly computed state.
5341 _newState = _update.eagerState;
5342 } else {
5343 var _action2 = _update.action;
5344 _newState = reducer(_newState, _action2);
5345 }
5346 }
5347 prevUpdate = _update;
5348 _update = _update.next;
5349 } while (_update !== null && _update !== first);
5350
5351 if (!didSkip) {
5352 newBaseUpdate = prevUpdate;
5353 newBaseState = _newState;
5354 }
5355
5356 // Mark that the fiber performed work, but only if the new state is
5357 // different from the current state.
5358 if (!is(_newState, hook.memoizedState)) {
5359 markWorkInProgressReceivedUpdate();
5360 }
5361
5362 hook.memoizedState = _newState;
5363 hook.baseUpdate = newBaseUpdate;
5364 hook.baseState = newBaseState;
5365
5366 queue.lastRenderedState = _newState;
5367 }
5368
5369 var dispatch = queue.dispatch;
5370 return [hook.memoizedState, dispatch];
5371}
5372
5373function mountState(initialState) {
5374 var hook = mountWorkInProgressHook();
5375 if (typeof initialState === 'function') {
5376 initialState = initialState();
5377 }
5378 hook.memoizedState = hook.baseState = initialState;
5379 var queue = hook.queue = {
5380 last: null,
5381 dispatch: null,
5382 lastRenderedReducer: basicStateReducer,
5383 lastRenderedState: initialState
5384 };
5385 var dispatch = queue.dispatch = dispatchAction.bind(null,
5386 // Flow doesn't know this is non-null, but we do.
5387 currentlyRenderingFiber$1, queue);
5388 return [hook.memoizedState, dispatch];
5389}
5390
5391function updateState(initialState) {
5392 return updateReducer(basicStateReducer, initialState);
5393}
5394
5395function pushEffect(tag, create, destroy, deps) {
5396 var effect = {
5397 tag: tag,
5398 create: create,
5399 destroy: destroy,
5400 deps: deps,
5401 // Circular
5402 next: null
5403 };
5404 if (componentUpdateQueue === null) {
5405 componentUpdateQueue = createFunctionComponentUpdateQueue();
5406 componentUpdateQueue.lastEffect = effect.next = effect;
5407 } else {
5408 var _lastEffect = componentUpdateQueue.lastEffect;
5409 if (_lastEffect === null) {
5410 componentUpdateQueue.lastEffect = effect.next = effect;
5411 } else {
5412 var firstEffect = _lastEffect.next;
5413 _lastEffect.next = effect;
5414 effect.next = firstEffect;
5415 componentUpdateQueue.lastEffect = effect;
5416 }
5417 }
5418 return effect;
5419}
5420
5421function mountRef(initialValue) {
5422 var hook = mountWorkInProgressHook();
5423 var ref = { current: initialValue };
5424 {
5425 Object.seal(ref);
5426 }
5427 hook.memoizedState = ref;
5428 return ref;
5429}
5430
5431function updateRef(initialValue) {
5432 var hook = updateWorkInProgressHook();
5433 return hook.memoizedState;
5434}
5435
5436function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5437 var hook = mountWorkInProgressHook();
5438 var nextDeps = deps === undefined ? null : deps;
5439 sideEffectTag |= fiberEffectTag;
5440 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
5441}
5442
5443function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
5444 var hook = updateWorkInProgressHook();
5445 var nextDeps = deps === undefined ? null : deps;
5446 var destroy = undefined;
5447
5448 if (currentHook !== null) {
5449 var prevEffect = currentHook.memoizedState;
5450 destroy = prevEffect.destroy;
5451 if (nextDeps !== null) {
5452 var prevDeps = prevEffect.deps;
5453 if (areHookInputsEqual(nextDeps, prevDeps)) {
5454 pushEffect(NoEffect$1, create, destroy, nextDeps);
5455 return;
5456 }
5457 }
5458 }
5459
5460 sideEffectTag |= fiberEffectTag;
5461 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
5462}
5463
5464function mountEffect(create, deps) {
5465 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5466}
5467
5468function updateEffect(create, deps) {
5469 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
5470}
5471
5472function mountLayoutEffect(create, deps) {
5473 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5474}
5475
5476function updateLayoutEffect(create, deps) {
5477 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
5478}
5479
5480function imperativeHandleEffect(create, ref) {
5481 if (typeof ref === 'function') {
5482 var refCallback = ref;
5483 var _inst = create();
5484 refCallback(_inst);
5485 return function () {
5486 refCallback(null);
5487 };
5488 } else if (ref !== null && ref !== undefined) {
5489 var refObject = ref;
5490 {
5491 !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;
5492 }
5493 var _inst2 = create();
5494 refObject.current = _inst2;
5495 return function () {
5496 refObject.current = null;
5497 };
5498 }
5499}
5500
5501function mountImperativeHandle(ref, create, deps) {
5502 {
5503 !(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;
5504 }
5505
5506 // TODO: If deps are provided, should we skip comparing the ref itself?
5507 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
5508
5509 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5510}
5511
5512function updateImperativeHandle(ref, create, deps) {
5513 {
5514 !(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;
5515 }
5516
5517 // TODO: If deps are provided, should we skip comparing the ref itself?
5518 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
5519
5520 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
5521}
5522
5523function mountDebugValue(value, formatterFn) {
5524 // This hook is normally a no-op.
5525 // The react-debug-hooks package injects its own implementation
5526 // so that e.g. DevTools can display custom hook values.
5527}
5528
5529var updateDebugValue = mountDebugValue;
5530
5531function mountCallback(callback, deps) {
5532 var hook = mountWorkInProgressHook();
5533 var nextDeps = deps === undefined ? null : deps;
5534 hook.memoizedState = [callback, nextDeps];
5535 return callback;
5536}
5537
5538function updateCallback(callback, deps) {
5539 var hook = updateWorkInProgressHook();
5540 var nextDeps = deps === undefined ? null : deps;
5541 var prevState = hook.memoizedState;
5542 if (prevState !== null) {
5543 if (nextDeps !== null) {
5544 var prevDeps = prevState[1];
5545 if (areHookInputsEqual(nextDeps, prevDeps)) {
5546 return prevState[0];
5547 }
5548 }
5549 }
5550 hook.memoizedState = [callback, nextDeps];
5551 return callback;
5552}
5553
5554function mountMemo(nextCreate, deps) {
5555 var hook = mountWorkInProgressHook();
5556 var nextDeps = deps === undefined ? null : deps;
5557 var nextValue = nextCreate();
5558 hook.memoizedState = [nextValue, nextDeps];
5559 return nextValue;
5560}
5561
5562function updateMemo(nextCreate, deps) {
5563 var hook = updateWorkInProgressHook();
5564 var nextDeps = deps === undefined ? null : deps;
5565 var prevState = hook.memoizedState;
5566 if (prevState !== null) {
5567 // Assume these are defined. If they're not, areHookInputsEqual will warn.
5568 if (nextDeps !== null) {
5569 var prevDeps = prevState[1];
5570 if (areHookInputsEqual(nextDeps, prevDeps)) {
5571 return prevState[0];
5572 }
5573 }
5574 }
5575 var nextValue = nextCreate();
5576 hook.memoizedState = [nextValue, nextDeps];
5577 return nextValue;
5578}
5579
5580// in a test-like environment, we want to warn if dispatchAction()
5581// is called outside of a batchedUpdates/TestUtils.act(...) call.
5582var shouldWarnForUnbatchedSetState = false;
5583
5584{
5585 // jest isn't a 'global', it's just exposed to tests via a wrapped function
5586 // further, this isn't a test file, so flow doesn't recognize the symbol. So...
5587 // $FlowExpectedError - because requirements don't give a damn about your type sigs.
5588 if ('undefined' !== typeof jest) {
5589 shouldWarnForUnbatchedSetState = true;
5590 }
5591}
5592
5593function dispatchAction(fiber, queue, action) {
5594 !(numberOfReRenders < RE_RENDER_LIMIT) ? invariant(false, 'Too many re-renders. React limits the number of renders to prevent an infinite loop.') : void 0;
5595
5596 {
5597 !(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;
5598 }
5599
5600 var alternate = fiber.alternate;
5601 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
5602 // This is a render phase update. Stash it in a lazily-created map of
5603 // queue -> linked list of updates. After this render pass, we'll restart
5604 // and apply the stashed updates on top of the work-in-progress hook.
5605 didScheduleRenderPhaseUpdate = true;
5606 var update = {
5607 expirationTime: renderExpirationTime,
5608 action: action,
5609 eagerReducer: null,
5610 eagerState: null,
5611 next: null
5612 };
5613 if (renderPhaseUpdates === null) {
5614 renderPhaseUpdates = new Map();
5615 }
5616 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
5617 if (firstRenderPhaseUpdate === undefined) {
5618 renderPhaseUpdates.set(queue, update);
5619 } else {
5620 // Append the update to the end of the list.
5621 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
5622 while (lastRenderPhaseUpdate.next !== null) {
5623 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
5624 }
5625 lastRenderPhaseUpdate.next = update;
5626 }
5627 } else {
5628 flushPassiveEffects$1();
5629
5630 var currentTime = requestCurrentTime();
5631 var _expirationTime = computeExpirationForFiber(currentTime, fiber);
5632
5633 var _update2 = {
5634 expirationTime: _expirationTime,
5635 action: action,
5636 eagerReducer: null,
5637 eagerState: null,
5638 next: null
5639 };
5640
5641 // Append the update to the end of the list.
5642 var _last = queue.last;
5643 if (_last === null) {
5644 // This is the first update. Create a circular list.
5645 _update2.next = _update2;
5646 } else {
5647 var first = _last.next;
5648 if (first !== null) {
5649 // Still circular.
5650 _update2.next = first;
5651 }
5652 _last.next = _update2;
5653 }
5654 queue.last = _update2;
5655
5656 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
5657 // The queue is currently empty, which means we can eagerly compute the
5658 // next state before entering the render phase. If the new state is the
5659 // same as the current state, we may be able to bail out entirely.
5660 var _lastRenderedReducer = queue.lastRenderedReducer;
5661 if (_lastRenderedReducer !== null) {
5662 var prevDispatcher = void 0;
5663 {
5664 prevDispatcher = ReactCurrentDispatcher$1.current;
5665 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5666 }
5667 try {
5668 var currentState = queue.lastRenderedState;
5669 var _eagerState = _lastRenderedReducer(currentState, action);
5670 // Stash the eagerly computed state, and the reducer used to compute
5671 // it, on the update object. If the reducer hasn't changed by the
5672 // time we enter the render phase, then the eager state can be used
5673 // without calling the reducer again.
5674 _update2.eagerReducer = _lastRenderedReducer;
5675 _update2.eagerState = _eagerState;
5676 if (is(_eagerState, currentState)) {
5677 // Fast path. We can bail out without scheduling React to re-render.
5678 // It's still possible that we'll need to rebase this update later,
5679 // if the component re-renders for a different reason and by that
5680 // time the reducer has changed.
5681 return;
5682 }
5683 } catch (error) {
5684 // Suppress the error. It will throw again in the render phase.
5685 } finally {
5686 {
5687 ReactCurrentDispatcher$1.current = prevDispatcher;
5688 }
5689 }
5690 }
5691 }
5692 {
5693 if (shouldWarnForUnbatchedSetState === true) {
5694 warnIfNotCurrentlyBatchingInDev(fiber);
5695 }
5696 }
5697 scheduleWork(fiber, _expirationTime);
5698 }
5699}
5700
5701var ContextOnlyDispatcher = {
5702 readContext: readContext,
5703
5704 useCallback: throwInvalidHookError,
5705 useContext: throwInvalidHookError,
5706 useEffect: throwInvalidHookError,
5707 useImperativeHandle: throwInvalidHookError,
5708 useLayoutEffect: throwInvalidHookError,
5709 useMemo: throwInvalidHookError,
5710 useReducer: throwInvalidHookError,
5711 useRef: throwInvalidHookError,
5712 useState: throwInvalidHookError,
5713 useDebugValue: throwInvalidHookError
5714};
5715
5716var HooksDispatcherOnMountInDEV = null;
5717var HooksDispatcherOnMountWithHookTypesInDEV = null;
5718var HooksDispatcherOnUpdateInDEV = null;
5719var InvalidNestedHooksDispatcherOnMountInDEV = null;
5720var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
5721
5722{
5723 var warnInvalidContextAccess = function () {
5724 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().');
5725 };
5726
5727 var warnInvalidHookAccess = function () {
5728 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');
5729 };
5730
5731 HooksDispatcherOnMountInDEV = {
5732 readContext: function (context, observedBits) {
5733 return readContext(context, observedBits);
5734 },
5735 useCallback: function (callback, deps) {
5736 currentHookNameInDev = 'useCallback';
5737 mountHookTypesDev();
5738 return mountCallback(callback, deps);
5739 },
5740 useContext: function (context, observedBits) {
5741 currentHookNameInDev = 'useContext';
5742 mountHookTypesDev();
5743 return readContext(context, observedBits);
5744 },
5745 useEffect: function (create, deps) {
5746 currentHookNameInDev = 'useEffect';
5747 mountHookTypesDev();
5748 return mountEffect(create, deps);
5749 },
5750 useImperativeHandle: function (ref, create, deps) {
5751 currentHookNameInDev = 'useImperativeHandle';
5752 mountHookTypesDev();
5753 return mountImperativeHandle(ref, create, deps);
5754 },
5755 useLayoutEffect: function (create, deps) {
5756 currentHookNameInDev = 'useLayoutEffect';
5757 mountHookTypesDev();
5758 return mountLayoutEffect(create, deps);
5759 },
5760 useMemo: function (create, deps) {
5761 currentHookNameInDev = 'useMemo';
5762 mountHookTypesDev();
5763 var prevDispatcher = ReactCurrentDispatcher$1.current;
5764 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5765 try {
5766 return mountMemo(create, deps);
5767 } finally {
5768 ReactCurrentDispatcher$1.current = prevDispatcher;
5769 }
5770 },
5771 useReducer: function (reducer, initialArg, init) {
5772 currentHookNameInDev = 'useReducer';
5773 mountHookTypesDev();
5774 var prevDispatcher = ReactCurrentDispatcher$1.current;
5775 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5776 try {
5777 return mountReducer(reducer, initialArg, init);
5778 } finally {
5779 ReactCurrentDispatcher$1.current = prevDispatcher;
5780 }
5781 },
5782 useRef: function (initialValue) {
5783 currentHookNameInDev = 'useRef';
5784 mountHookTypesDev();
5785 return mountRef(initialValue);
5786 },
5787 useState: function (initialState) {
5788 currentHookNameInDev = 'useState';
5789 mountHookTypesDev();
5790 var prevDispatcher = ReactCurrentDispatcher$1.current;
5791 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5792 try {
5793 return mountState(initialState);
5794 } finally {
5795 ReactCurrentDispatcher$1.current = prevDispatcher;
5796 }
5797 },
5798 useDebugValue: function (value, formatterFn) {
5799 currentHookNameInDev = 'useDebugValue';
5800 mountHookTypesDev();
5801 return mountDebugValue(value, formatterFn);
5802 }
5803 };
5804
5805 HooksDispatcherOnMountWithHookTypesInDEV = {
5806 readContext: function (context, observedBits) {
5807 return readContext(context, observedBits);
5808 },
5809 useCallback: function (callback, deps) {
5810 currentHookNameInDev = 'useCallback';
5811 updateHookTypesDev();
5812 return mountCallback(callback, deps);
5813 },
5814 useContext: function (context, observedBits) {
5815 currentHookNameInDev = 'useContext';
5816 updateHookTypesDev();
5817 return readContext(context, observedBits);
5818 },
5819 useEffect: function (create, deps) {
5820 currentHookNameInDev = 'useEffect';
5821 updateHookTypesDev();
5822 return mountEffect(create, deps);
5823 },
5824 useImperativeHandle: function (ref, create, deps) {
5825 currentHookNameInDev = 'useImperativeHandle';
5826 updateHookTypesDev();
5827 return mountImperativeHandle(ref, create, deps);
5828 },
5829 useLayoutEffect: function (create, deps) {
5830 currentHookNameInDev = 'useLayoutEffect';
5831 updateHookTypesDev();
5832 return mountLayoutEffect(create, deps);
5833 },
5834 useMemo: function (create, deps) {
5835 currentHookNameInDev = 'useMemo';
5836 updateHookTypesDev();
5837 var prevDispatcher = ReactCurrentDispatcher$1.current;
5838 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5839 try {
5840 return mountMemo(create, deps);
5841 } finally {
5842 ReactCurrentDispatcher$1.current = prevDispatcher;
5843 }
5844 },
5845 useReducer: function (reducer, initialArg, init) {
5846 currentHookNameInDev = 'useReducer';
5847 updateHookTypesDev();
5848 var prevDispatcher = ReactCurrentDispatcher$1.current;
5849 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5850 try {
5851 return mountReducer(reducer, initialArg, init);
5852 } finally {
5853 ReactCurrentDispatcher$1.current = prevDispatcher;
5854 }
5855 },
5856 useRef: function (initialValue) {
5857 currentHookNameInDev = 'useRef';
5858 updateHookTypesDev();
5859 return mountRef(initialValue);
5860 },
5861 useState: function (initialState) {
5862 currentHookNameInDev = 'useState';
5863 updateHookTypesDev();
5864 var prevDispatcher = ReactCurrentDispatcher$1.current;
5865 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5866 try {
5867 return mountState(initialState);
5868 } finally {
5869 ReactCurrentDispatcher$1.current = prevDispatcher;
5870 }
5871 },
5872 useDebugValue: function (value, formatterFn) {
5873 currentHookNameInDev = 'useDebugValue';
5874 updateHookTypesDev();
5875 return mountDebugValue(value, formatterFn);
5876 }
5877 };
5878
5879 HooksDispatcherOnUpdateInDEV = {
5880 readContext: function (context, observedBits) {
5881 return readContext(context, observedBits);
5882 },
5883 useCallback: function (callback, deps) {
5884 currentHookNameInDev = 'useCallback';
5885 updateHookTypesDev();
5886 return updateCallback(callback, deps);
5887 },
5888 useContext: function (context, observedBits) {
5889 currentHookNameInDev = 'useContext';
5890 updateHookTypesDev();
5891 return readContext(context, observedBits);
5892 },
5893 useEffect: function (create, deps) {
5894 currentHookNameInDev = 'useEffect';
5895 updateHookTypesDev();
5896 return updateEffect(create, deps);
5897 },
5898 useImperativeHandle: function (ref, create, deps) {
5899 currentHookNameInDev = 'useImperativeHandle';
5900 updateHookTypesDev();
5901 return updateImperativeHandle(ref, create, deps);
5902 },
5903 useLayoutEffect: function (create, deps) {
5904 currentHookNameInDev = 'useLayoutEffect';
5905 updateHookTypesDev();
5906 return updateLayoutEffect(create, deps);
5907 },
5908 useMemo: function (create, deps) {
5909 currentHookNameInDev = 'useMemo';
5910 updateHookTypesDev();
5911 var prevDispatcher = ReactCurrentDispatcher$1.current;
5912 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5913 try {
5914 return updateMemo(create, deps);
5915 } finally {
5916 ReactCurrentDispatcher$1.current = prevDispatcher;
5917 }
5918 },
5919 useReducer: function (reducer, initialArg, init) {
5920 currentHookNameInDev = 'useReducer';
5921 updateHookTypesDev();
5922 var prevDispatcher = ReactCurrentDispatcher$1.current;
5923 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5924 try {
5925 return updateReducer(reducer, initialArg, init);
5926 } finally {
5927 ReactCurrentDispatcher$1.current = prevDispatcher;
5928 }
5929 },
5930 useRef: function (initialValue) {
5931 currentHookNameInDev = 'useRef';
5932 updateHookTypesDev();
5933 return updateRef(initialValue);
5934 },
5935 useState: function (initialState) {
5936 currentHookNameInDev = 'useState';
5937 updateHookTypesDev();
5938 var prevDispatcher = ReactCurrentDispatcher$1.current;
5939 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
5940 try {
5941 return updateState(initialState);
5942 } finally {
5943 ReactCurrentDispatcher$1.current = prevDispatcher;
5944 }
5945 },
5946 useDebugValue: function (value, formatterFn) {
5947 currentHookNameInDev = 'useDebugValue';
5948 updateHookTypesDev();
5949 return updateDebugValue(value, formatterFn);
5950 }
5951 };
5952
5953 InvalidNestedHooksDispatcherOnMountInDEV = {
5954 readContext: function (context, observedBits) {
5955 warnInvalidContextAccess();
5956 return readContext(context, observedBits);
5957 },
5958 useCallback: function (callback, deps) {
5959 currentHookNameInDev = 'useCallback';
5960 warnInvalidHookAccess();
5961 mountHookTypesDev();
5962 return mountCallback(callback, deps);
5963 },
5964 useContext: function (context, observedBits) {
5965 currentHookNameInDev = 'useContext';
5966 warnInvalidHookAccess();
5967 mountHookTypesDev();
5968 return readContext(context, observedBits);
5969 },
5970 useEffect: function (create, deps) {
5971 currentHookNameInDev = 'useEffect';
5972 warnInvalidHookAccess();
5973 mountHookTypesDev();
5974 return mountEffect(create, deps);
5975 },
5976 useImperativeHandle: function (ref, create, deps) {
5977 currentHookNameInDev = 'useImperativeHandle';
5978 warnInvalidHookAccess();
5979 mountHookTypesDev();
5980 return mountImperativeHandle(ref, create, deps);
5981 },
5982 useLayoutEffect: function (create, deps) {
5983 currentHookNameInDev = 'useLayoutEffect';
5984 warnInvalidHookAccess();
5985 mountHookTypesDev();
5986 return mountLayoutEffect(create, deps);
5987 },
5988 useMemo: function (create, deps) {
5989 currentHookNameInDev = 'useMemo';
5990 warnInvalidHookAccess();
5991 mountHookTypesDev();
5992 var prevDispatcher = ReactCurrentDispatcher$1.current;
5993 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
5994 try {
5995 return mountMemo(create, deps);
5996 } finally {
5997 ReactCurrentDispatcher$1.current = prevDispatcher;
5998 }
5999 },
6000 useReducer: function (reducer, initialArg, init) {
6001 currentHookNameInDev = 'useReducer';
6002 warnInvalidHookAccess();
6003 mountHookTypesDev();
6004 var prevDispatcher = ReactCurrentDispatcher$1.current;
6005 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
6006 try {
6007 return mountReducer(reducer, initialArg, init);
6008 } finally {
6009 ReactCurrentDispatcher$1.current = prevDispatcher;
6010 }
6011 },
6012 useRef: function (initialValue) {
6013 currentHookNameInDev = 'useRef';
6014 warnInvalidHookAccess();
6015 mountHookTypesDev();
6016 return mountRef(initialValue);
6017 },
6018 useState: function (initialState) {
6019 currentHookNameInDev = 'useState';
6020 warnInvalidHookAccess();
6021 mountHookTypesDev();
6022 var prevDispatcher = ReactCurrentDispatcher$1.current;
6023 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
6024 try {
6025 return mountState(initialState);
6026 } finally {
6027 ReactCurrentDispatcher$1.current = prevDispatcher;
6028 }
6029 },
6030 useDebugValue: function (value, formatterFn) {
6031 currentHookNameInDev = 'useDebugValue';
6032 warnInvalidHookAccess();
6033 mountHookTypesDev();
6034 return mountDebugValue(value, formatterFn);
6035 }
6036 };
6037
6038 InvalidNestedHooksDispatcherOnUpdateInDEV = {
6039 readContext: function (context, observedBits) {
6040 warnInvalidContextAccess();
6041 return readContext(context, observedBits);
6042 },
6043 useCallback: function (callback, deps) {
6044 currentHookNameInDev = 'useCallback';
6045 warnInvalidHookAccess();
6046 updateHookTypesDev();
6047 return updateCallback(callback, deps);
6048 },
6049 useContext: function (context, observedBits) {
6050 currentHookNameInDev = 'useContext';
6051 warnInvalidHookAccess();
6052 updateHookTypesDev();
6053 return readContext(context, observedBits);
6054 },
6055 useEffect: function (create, deps) {
6056 currentHookNameInDev = 'useEffect';
6057 warnInvalidHookAccess();
6058 updateHookTypesDev();
6059 return updateEffect(create, deps);
6060 },
6061 useImperativeHandle: function (ref, create, deps) {
6062 currentHookNameInDev = 'useImperativeHandle';
6063 warnInvalidHookAccess();
6064 updateHookTypesDev();
6065 return updateImperativeHandle(ref, create, deps);
6066 },
6067 useLayoutEffect: function (create, deps) {
6068 currentHookNameInDev = 'useLayoutEffect';
6069 warnInvalidHookAccess();
6070 updateHookTypesDev();
6071 return updateLayoutEffect(create, deps);
6072 },
6073 useMemo: function (create, deps) {
6074 currentHookNameInDev = 'useMemo';
6075 warnInvalidHookAccess();
6076 updateHookTypesDev();
6077 var prevDispatcher = ReactCurrentDispatcher$1.current;
6078 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6079 try {
6080 return updateMemo(create, deps);
6081 } finally {
6082 ReactCurrentDispatcher$1.current = prevDispatcher;
6083 }
6084 },
6085 useReducer: function (reducer, initialArg, init) {
6086 currentHookNameInDev = 'useReducer';
6087 warnInvalidHookAccess();
6088 updateHookTypesDev();
6089 var prevDispatcher = ReactCurrentDispatcher$1.current;
6090 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6091 try {
6092 return updateReducer(reducer, initialArg, init);
6093 } finally {
6094 ReactCurrentDispatcher$1.current = prevDispatcher;
6095 }
6096 },
6097 useRef: function (initialValue) {
6098 currentHookNameInDev = 'useRef';
6099 warnInvalidHookAccess();
6100 updateHookTypesDev();
6101 return updateRef(initialValue);
6102 },
6103 useState: function (initialState) {
6104 currentHookNameInDev = 'useState';
6105 warnInvalidHookAccess();
6106 updateHookTypesDev();
6107 var prevDispatcher = ReactCurrentDispatcher$1.current;
6108 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
6109 try {
6110 return updateState(initialState);
6111 } finally {
6112 ReactCurrentDispatcher$1.current = prevDispatcher;
6113 }
6114 },
6115 useDebugValue: function (value, formatterFn) {
6116 currentHookNameInDev = 'useDebugValue';
6117 warnInvalidHookAccess();
6118 updateHookTypesDev();
6119 return updateDebugValue(value, formatterFn);
6120 }
6121 };
6122}
6123
6124var commitTime = 0;
6125var profilerStartTime = -1;
6126
6127function getCommitTime() {
6128 return commitTime;
6129}
6130
6131function recordCommitTime() {
6132 if (!enableProfilerTimer) {
6133 return;
6134 }
6135 commitTime = now();
6136}
6137
6138function startProfilerTimer(fiber) {
6139 if (!enableProfilerTimer) {
6140 return;
6141 }
6142
6143 profilerStartTime = now();
6144
6145 if (fiber.actualStartTime < 0) {
6146 fiber.actualStartTime = now();
6147 }
6148}
6149
6150function stopProfilerTimerIfRunning(fiber) {
6151 if (!enableProfilerTimer) {
6152 return;
6153 }
6154 profilerStartTime = -1;
6155}
6156
6157function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
6158 if (!enableProfilerTimer) {
6159 return;
6160 }
6161
6162 if (profilerStartTime >= 0) {
6163 var elapsedTime = now() - profilerStartTime;
6164 fiber.actualDuration += elapsedTime;
6165 if (overrideBaseTime) {
6166 fiber.selfBaseDuration = elapsedTime;
6167 }
6168 profilerStartTime = -1;
6169 }
6170}
6171
6172// The deepest Fiber on the stack involved in a hydration context.
6173// This may have been an insertion or a hydration.
6174var hydrationParentFiber = null;
6175var nextHydratableInstance = null;
6176var isHydrating = false;
6177
6178function enterHydrationState(fiber) {
6179 if (!supportsHydration) {
6180 return false;
6181 }
6182
6183 var parentInstance = fiber.stateNode.containerInfo;
6184 nextHydratableInstance = getFirstHydratableChild(parentInstance);
6185 hydrationParentFiber = fiber;
6186 isHydrating = true;
6187 return true;
6188}
6189
6190function reenterHydrationStateFromDehydratedSuspenseInstance(fiber) {
6191 if (!supportsHydration) {
6192 return false;
6193 }
6194
6195 var suspenseInstance = fiber.stateNode;
6196 nextHydratableInstance = getNextHydratableSibling(suspenseInstance);
6197 popToNextHostParent(fiber);
6198 isHydrating = true;
6199 return true;
6200}
6201
6202function deleteHydratableInstance(returnFiber, instance) {
6203 {
6204 switch (returnFiber.tag) {
6205 case HostRoot:
6206 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
6207 break;
6208 case HostComponent:
6209 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
6210 break;
6211 }
6212 }
6213
6214 var childToDelete = createFiberFromHostInstanceForDeletion();
6215 childToDelete.stateNode = instance;
6216 childToDelete.return = returnFiber;
6217 childToDelete.effectTag = Deletion;
6218
6219 // This might seem like it belongs on progressedFirstDeletion. However,
6220 // these children are not part of the reconciliation list of children.
6221 // Even if we abort and rereconcile the children, that will try to hydrate
6222 // again and the nodes are still in the host tree so these will be
6223 // recreated.
6224 if (returnFiber.lastEffect !== null) {
6225 returnFiber.lastEffect.nextEffect = childToDelete;
6226 returnFiber.lastEffect = childToDelete;
6227 } else {
6228 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
6229 }
6230}
6231
6232function insertNonHydratedInstance(returnFiber, fiber) {
6233 fiber.effectTag |= Placement;
6234 {
6235 switch (returnFiber.tag) {
6236 case HostRoot:
6237 {
6238 var parentContainer = returnFiber.stateNode.containerInfo;
6239 switch (fiber.tag) {
6240 case HostComponent:
6241 var type = fiber.type;
6242 var props = fiber.pendingProps;
6243 didNotFindHydratableContainerInstance(parentContainer, type, props);
6244 break;
6245 case HostText:
6246 var text = fiber.pendingProps;
6247 didNotFindHydratableContainerTextInstance(parentContainer, text);
6248 break;
6249 case SuspenseComponent:
6250 didNotFindHydratableContainerSuspenseInstance(parentContainer);
6251 break;
6252 }
6253 break;
6254 }
6255 case HostComponent:
6256 {
6257 var parentType = returnFiber.type;
6258 var parentProps = returnFiber.memoizedProps;
6259 var parentInstance = returnFiber.stateNode;
6260 switch (fiber.tag) {
6261 case HostComponent:
6262 var _type = fiber.type;
6263 var _props = fiber.pendingProps;
6264 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
6265 break;
6266 case HostText:
6267 var _text = fiber.pendingProps;
6268 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
6269 break;
6270 case SuspenseComponent:
6271 didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance);
6272 break;
6273 }
6274 break;
6275 }
6276 default:
6277 return;
6278 }
6279 }
6280}
6281
6282function tryHydrate(fiber, nextInstance) {
6283 switch (fiber.tag) {
6284 case HostComponent:
6285 {
6286 var type = fiber.type;
6287 var props = fiber.pendingProps;
6288 var instance = canHydrateInstance(nextInstance, type, props);
6289 if (instance !== null) {
6290 fiber.stateNode = instance;
6291 return true;
6292 }
6293 return false;
6294 }
6295 case HostText:
6296 {
6297 var text = fiber.pendingProps;
6298 var textInstance = canHydrateTextInstance(nextInstance, text);
6299 if (textInstance !== null) {
6300 fiber.stateNode = textInstance;
6301 return true;
6302 }
6303 return false;
6304 }
6305 case SuspenseComponent:
6306 {
6307 if (enableSuspenseServerRenderer) {
6308 var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
6309 if (suspenseInstance !== null) {
6310 // Downgrade the tag to a dehydrated component until we've hydrated it.
6311 fiber.tag = DehydratedSuspenseComponent;
6312 fiber.stateNode = suspenseInstance;
6313 return true;
6314 }
6315 }
6316 return false;
6317 }
6318 default:
6319 return false;
6320 }
6321}
6322
6323function tryToClaimNextHydratableInstance(fiber) {
6324 if (!isHydrating) {
6325 return;
6326 }
6327 var nextInstance = nextHydratableInstance;
6328 if (!nextInstance) {
6329 // Nothing to hydrate. Make it an insertion.
6330 insertNonHydratedInstance(hydrationParentFiber, fiber);
6331 isHydrating = false;
6332 hydrationParentFiber = fiber;
6333 return;
6334 }
6335 var firstAttemptedInstance = nextInstance;
6336 if (!tryHydrate(fiber, nextInstance)) {
6337 // If we can't hydrate this instance let's try the next one.
6338 // We use this as a heuristic. It's based on intuition and not data so it
6339 // might be flawed or unnecessary.
6340 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
6341 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
6342 // Nothing to hydrate. Make it an insertion.
6343 insertNonHydratedInstance(hydrationParentFiber, fiber);
6344 isHydrating = false;
6345 hydrationParentFiber = fiber;
6346 return;
6347 }
6348 // We matched the next one, we'll now assume that the first one was
6349 // superfluous and we'll delete it. Since we can't eagerly delete it
6350 // we'll have to schedule a deletion. To do that, this node needs a dummy
6351 // fiber associated with it.
6352 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
6353 }
6354 hydrationParentFiber = fiber;
6355 nextHydratableInstance = getFirstHydratableChild(nextInstance);
6356}
6357
6358function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
6359 if (!supportsHydration) {
6360 invariant(false, 'Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6361 }
6362
6363 var instance = fiber.stateNode;
6364 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber);
6365 // TODO: Type this specific to this type of component.
6366 fiber.updateQueue = updatePayload;
6367 // If the update payload indicates that there is a change or if there
6368 // is a new ref we mark this as an update.
6369 if (updatePayload !== null) {
6370 return true;
6371 }
6372 return false;
6373}
6374
6375function prepareToHydrateHostTextInstance(fiber) {
6376 if (!supportsHydration) {
6377 invariant(false, 'Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6378 }
6379
6380 var textInstance = fiber.stateNode;
6381 var textContent = fiber.memoizedProps;
6382 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
6383 {
6384 if (shouldUpdate) {
6385 // We assume that prepareToHydrateHostTextInstance is called in a context where the
6386 // hydration parent is the parent host component of this host text.
6387 var returnFiber = hydrationParentFiber;
6388 if (returnFiber !== null) {
6389 switch (returnFiber.tag) {
6390 case HostRoot:
6391 {
6392 var parentContainer = returnFiber.stateNode.containerInfo;
6393 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
6394 break;
6395 }
6396 case HostComponent:
6397 {
6398 var parentType = returnFiber.type;
6399 var parentProps = returnFiber.memoizedProps;
6400 var parentInstance = returnFiber.stateNode;
6401 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
6402 break;
6403 }
6404 }
6405 }
6406 }
6407 }
6408 return shouldUpdate;
6409}
6410
6411function skipPastDehydratedSuspenseInstance(fiber) {
6412 if (!supportsHydration) {
6413 invariant(false, 'Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.');
6414 }
6415 var suspenseInstance = fiber.stateNode;
6416 !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;
6417 nextHydratableInstance = getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
6418}
6419
6420function popToNextHostParent(fiber) {
6421 var parent = fiber.return;
6422 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== DehydratedSuspenseComponent) {
6423 parent = parent.return;
6424 }
6425 hydrationParentFiber = parent;
6426}
6427
6428function popHydrationState(fiber) {
6429 if (!supportsHydration) {
6430 return false;
6431 }
6432 if (fiber !== hydrationParentFiber) {
6433 // We're deeper than the current hydration context, inside an inserted
6434 // tree.
6435 return false;
6436 }
6437 if (!isHydrating) {
6438 // If we're not currently hydrating but we're in a hydration context, then
6439 // we were an insertion and now need to pop up reenter hydration of our
6440 // siblings.
6441 popToNextHostParent(fiber);
6442 isHydrating = true;
6443 return false;
6444 }
6445
6446 var type = fiber.type;
6447
6448 // If we have any remaining hydratable nodes, we need to delete them now.
6449 // We only do this deeper than head and body since they tend to have random
6450 // other nodes in them. We also ignore components with pure text content in
6451 // side of them.
6452 // TODO: Better heuristic.
6453 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
6454 var nextInstance = nextHydratableInstance;
6455 while (nextInstance) {
6456 deleteHydratableInstance(fiber, nextInstance);
6457 nextInstance = getNextHydratableSibling(nextInstance);
6458 }
6459 }
6460
6461 popToNextHostParent(fiber);
6462 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
6463 return true;
6464}
6465
6466function resetHydrationState() {
6467 if (!supportsHydration) {
6468 return;
6469 }
6470
6471 hydrationParentFiber = null;
6472 nextHydratableInstance = null;
6473 isHydrating = false;
6474}
6475
6476var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
6477
6478var didReceiveUpdate = false;
6479
6480var didWarnAboutBadClass = void 0;
6481var didWarnAboutContextTypeOnFunctionComponent = void 0;
6482var didWarnAboutGetDerivedStateOnFunctionComponent = void 0;
6483var didWarnAboutFunctionRefs = void 0;
6484var didWarnAboutReassigningProps = void 0;
6485
6486{
6487 didWarnAboutBadClass = {};
6488 didWarnAboutContextTypeOnFunctionComponent = {};
6489 didWarnAboutGetDerivedStateOnFunctionComponent = {};
6490 didWarnAboutFunctionRefs = {};
6491 didWarnAboutReassigningProps = false;
6492}
6493
6494function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6495 if (current$$1 === null) {
6496 // If this is a fresh new component that hasn't been rendered yet, we
6497 // won't update its child set by applying minimal side-effects. Instead,
6498 // we will add them all to the child before it gets rendered. That means
6499 // we can optimize this reconciliation pass by not tracking side-effects.
6500 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6501 } else {
6502 // If the current child is the same as the work in progress, it means that
6503 // we haven't yet started any work on these children. Therefore, we use
6504 // the clone algorithm to create a copy of all the current children.
6505
6506 // If we had any progressed work already, that is invalid at this point so
6507 // let's throw it out.
6508 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
6509 }
6510}
6511
6512function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
6513 // This function is fork of reconcileChildren. It's used in cases where we
6514 // want to reconcile without matching against the existing set. This has the
6515 // effect of all current children being unmounted; even if the type and key
6516 // are the same, the old child is unmounted and a new child is created.
6517 //
6518 // To do this, we're going to go through the reconcile algorithm twice. In
6519 // the first pass, we schedule a deletion for all the current children by
6520 // passing null.
6521 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
6522 // In the second pass, we mount the new children. The trick here is that we
6523 // pass null in place of where we usually pass the current child set. This has
6524 // the effect of remounting all children regardless of whether their their
6525 // identity matches.
6526 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6527}
6528
6529function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6530 // TODO: current can be non-null here even if the component
6531 // hasn't yet mounted. This happens after the first render suspends.
6532 // We'll need to figure out if this is fine or can cause issues.
6533
6534 {
6535 if (workInProgress.type !== workInProgress.elementType) {
6536 // Lazy component props can't be validated in createElement
6537 // because they're only guaranteed to be resolved here.
6538 var innerPropTypes = Component.propTypes;
6539 if (innerPropTypes) {
6540 checkPropTypes(innerPropTypes, nextProps, // Resolved props
6541 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6542 }
6543 }
6544 }
6545
6546 var render = Component.render;
6547 var ref = workInProgress.ref;
6548
6549 // The rest is a fork of updateFunctionComponent
6550 var nextChildren = void 0;
6551 prepareToReadContext(workInProgress, renderExpirationTime);
6552 {
6553 ReactCurrentOwner$2.current = workInProgress;
6554 setCurrentPhase('render');
6555 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6556 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6557 // Only double-render components with Hooks
6558 if (workInProgress.memoizedState !== null) {
6559 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
6560 }
6561 }
6562 setCurrentPhase(null);
6563 }
6564
6565 if (current$$1 !== null && !didReceiveUpdate) {
6566 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6567 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6568 }
6569
6570 // React DevTools reads this flag.
6571 workInProgress.effectTag |= PerformedWork;
6572 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6573 return workInProgress.child;
6574}
6575
6576function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6577 if (current$$1 === null) {
6578 var type = Component.type;
6579 if (isSimpleFunctionComponent(type) && Component.compare === null &&
6580 // SimpleMemoComponent codepath doesn't resolve outer props either.
6581 Component.defaultProps === undefined) {
6582 // If this is a plain function component without default props,
6583 // and with only the default shallow comparison, we upgrade it
6584 // to a SimpleMemoComponent to allow fast path updates.
6585 workInProgress.tag = SimpleMemoComponent;
6586 workInProgress.type = type;
6587 {
6588 validateFunctionComponentInDev(workInProgress, type);
6589 }
6590 return updateSimpleMemoComponent(current$$1, workInProgress, type, nextProps, updateExpirationTime, renderExpirationTime);
6591 }
6592 {
6593 var innerPropTypes = type.propTypes;
6594 if (innerPropTypes) {
6595 // Inner memo component props aren't currently validated in createElement.
6596 // We could move it there, but we'd still need this for lazy code path.
6597 checkPropTypes(innerPropTypes, nextProps, // Resolved props
6598 'prop', getComponentName(type), getCurrentFiberStackInDev);
6599 }
6600 }
6601 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
6602 child.ref = workInProgress.ref;
6603 child.return = workInProgress;
6604 workInProgress.child = child;
6605 return child;
6606 }
6607 {
6608 var _type = Component.type;
6609 var _innerPropTypes = _type.propTypes;
6610 if (_innerPropTypes) {
6611 // Inner memo component props aren't currently validated in createElement.
6612 // We could move it there, but we'd still need this for lazy code path.
6613 checkPropTypes(_innerPropTypes, nextProps, // Resolved props
6614 'prop', getComponentName(_type), getCurrentFiberStackInDev);
6615 }
6616 }
6617 var currentChild = current$$1.child; // This is always exactly one child
6618 if (updateExpirationTime < renderExpirationTime) {
6619 // This will be the props with resolved defaultProps,
6620 // unlike current.memoizedProps which will be the unresolved ones.
6621 var prevProps = currentChild.memoizedProps;
6622 // Default to shallow comparison
6623 var compare = Component.compare;
6624 compare = compare !== null ? compare : shallowEqual;
6625 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6626 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6627 }
6628 }
6629 // React DevTools reads this flag.
6630 workInProgress.effectTag |= PerformedWork;
6631 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
6632 newChild.ref = workInProgress.ref;
6633 newChild.return = workInProgress;
6634 workInProgress.child = newChild;
6635 return newChild;
6636}
6637
6638function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
6639 // TODO: current can be non-null here even if the component
6640 // hasn't yet mounted. This happens when the inner render suspends.
6641 // We'll need to figure out if this is fine or can cause issues.
6642
6643 {
6644 if (workInProgress.type !== workInProgress.elementType) {
6645 // Lazy component props can't be validated in createElement
6646 // because they're only guaranteed to be resolved here.
6647 var outerMemoType = workInProgress.elementType;
6648 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
6649 // We warn when you define propTypes on lazy()
6650 // so let's just skip over it to find memo() outer wrapper.
6651 // Inner props for memo are validated later.
6652 outerMemoType = refineResolvedLazyComponent(outerMemoType);
6653 }
6654 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
6655 if (outerPropTypes) {
6656 checkPropTypes(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
6657 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
6658 }
6659 // Inner propTypes will be validated in the function component path.
6660 }
6661 }
6662 if (current$$1 !== null) {
6663 var prevProps = current$$1.memoizedProps;
6664 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
6665 didReceiveUpdate = false;
6666 if (updateExpirationTime < renderExpirationTime) {
6667 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6668 }
6669 }
6670 }
6671 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6672}
6673
6674function updateFragment(current$$1, workInProgress, renderExpirationTime) {
6675 var nextChildren = workInProgress.pendingProps;
6676 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6677 return workInProgress.child;
6678}
6679
6680function updateMode(current$$1, workInProgress, renderExpirationTime) {
6681 var nextChildren = workInProgress.pendingProps.children;
6682 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6683 return workInProgress.child;
6684}
6685
6686function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
6687 if (enableProfilerTimer) {
6688 workInProgress.effectTag |= Update;
6689 }
6690 var nextProps = workInProgress.pendingProps;
6691 var nextChildren = nextProps.children;
6692 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6693 return workInProgress.child;
6694}
6695
6696function markRef(current$$1, workInProgress) {
6697 var ref = workInProgress.ref;
6698 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
6699 // Schedule a Ref effect
6700 workInProgress.effectTag |= Ref;
6701 }
6702}
6703
6704function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6705 {
6706 if (workInProgress.type !== workInProgress.elementType) {
6707 // Lazy component props can't be validated in createElement
6708 // because they're only guaranteed to be resolved here.
6709 var innerPropTypes = Component.propTypes;
6710 if (innerPropTypes) {
6711 checkPropTypes(innerPropTypes, nextProps, // Resolved props
6712 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6713 }
6714 }
6715 }
6716
6717 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
6718 var context = getMaskedContext(workInProgress, unmaskedContext);
6719
6720 var nextChildren = void 0;
6721 prepareToReadContext(workInProgress, renderExpirationTime);
6722 {
6723 ReactCurrentOwner$2.current = workInProgress;
6724 setCurrentPhase('render');
6725 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6726 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6727 // Only double-render components with Hooks
6728 if (workInProgress.memoizedState !== null) {
6729 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
6730 }
6731 }
6732 setCurrentPhase(null);
6733 }
6734
6735 if (current$$1 !== null && !didReceiveUpdate) {
6736 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
6737 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6738 }
6739
6740 // React DevTools reads this flag.
6741 workInProgress.effectTag |= PerformedWork;
6742 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6743 return workInProgress.child;
6744}
6745
6746function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
6747 {
6748 if (workInProgress.type !== workInProgress.elementType) {
6749 // Lazy component props can't be validated in createElement
6750 // because they're only guaranteed to be resolved here.
6751 var innerPropTypes = Component.propTypes;
6752 if (innerPropTypes) {
6753 checkPropTypes(innerPropTypes, nextProps, // Resolved props
6754 'prop', getComponentName(Component), getCurrentFiberStackInDev);
6755 }
6756 }
6757 }
6758
6759 // Push context providers early to prevent context stack mismatches.
6760 // During mounting we don't know the child context yet as the instance doesn't exist.
6761 // We will invalidate the child context in finishClassComponent() right after rendering.
6762 var hasContext = void 0;
6763 if (isContextProvider(Component)) {
6764 hasContext = true;
6765 pushContextProvider(workInProgress);
6766 } else {
6767 hasContext = false;
6768 }
6769 prepareToReadContext(workInProgress, renderExpirationTime);
6770
6771 var instance = workInProgress.stateNode;
6772 var shouldUpdate = void 0;
6773 if (instance === null) {
6774 if (current$$1 !== null) {
6775 // An class component without an instance only mounts if it suspended
6776 // inside a non- concurrent tree, in an inconsistent state. We want to
6777 // tree it like a new mount, even though an empty version of it already
6778 // committed. Disconnect the alternate pointers.
6779 current$$1.alternate = null;
6780 workInProgress.alternate = null;
6781 // Since this is conceptually a new fiber, schedule a Placement effect
6782 workInProgress.effectTag |= Placement;
6783 }
6784 // In the initial pass we might need to construct the instance.
6785 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6786 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6787 shouldUpdate = true;
6788 } else if (current$$1 === null) {
6789 // In a resume, we'll already have an instance we can reuse.
6790 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
6791 } else {
6792 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
6793 }
6794 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
6795 {
6796 var inst = workInProgress.stateNode;
6797 if (inst.props !== nextProps) {
6798 !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;
6799 didWarnAboutReassigningProps = true;
6800 }
6801 }
6802 return nextUnitOfWork;
6803}
6804
6805function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
6806 // Refs should update even if shouldComponentUpdate returns false
6807 markRef(current$$1, workInProgress);
6808
6809 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
6810
6811 if (!shouldUpdate && !didCaptureError) {
6812 // Context providers should defer to sCU for rendering
6813 if (hasContext) {
6814 invalidateContextProvider(workInProgress, Component, false);
6815 }
6816
6817 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6818 }
6819
6820 var instance = workInProgress.stateNode;
6821
6822 // Rerender
6823 ReactCurrentOwner$2.current = workInProgress;
6824 var nextChildren = void 0;
6825 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
6826 // If we captured an error, but getDerivedStateFrom catch is not defined,
6827 // unmount all the children. componentDidCatch will schedule an update to
6828 // re-render a fallback. This is temporary until we migrate everyone to
6829 // the new API.
6830 // TODO: Warn in a future release.
6831 nextChildren = null;
6832
6833 if (enableProfilerTimer) {
6834 stopProfilerTimerIfRunning(workInProgress);
6835 }
6836 } else {
6837 {
6838 setCurrentPhase('render');
6839 nextChildren = instance.render();
6840 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
6841 instance.render();
6842 }
6843 setCurrentPhase(null);
6844 }
6845 }
6846
6847 // React DevTools reads this flag.
6848 workInProgress.effectTag |= PerformedWork;
6849 if (current$$1 !== null && didCaptureError) {
6850 // If we're recovering from an error, reconcile without reusing any of
6851 // the existing children. Conceptually, the normal children and the children
6852 // that are shown on error are two different sets, so we shouldn't reuse
6853 // normal children even if their identities match.
6854 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
6855 } else {
6856 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6857 }
6858
6859 // Memoize state using the values we just used to render.
6860 // TODO: Restructure so we never read values from the instance.
6861 workInProgress.memoizedState = instance.state;
6862
6863 // The context might have changed so we need to recalculate it.
6864 if (hasContext) {
6865 invalidateContextProvider(workInProgress, Component, true);
6866 }
6867
6868 return workInProgress.child;
6869}
6870
6871function pushHostRootContext(workInProgress) {
6872 var root = workInProgress.stateNode;
6873 if (root.pendingContext) {
6874 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
6875 } else if (root.context) {
6876 // Should always be set
6877 pushTopLevelContextObject(workInProgress, root.context, false);
6878 }
6879 pushHostContainer(workInProgress, root.containerInfo);
6880}
6881
6882function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
6883 pushHostRootContext(workInProgress);
6884 var updateQueue = workInProgress.updateQueue;
6885 !(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;
6886 var nextProps = workInProgress.pendingProps;
6887 var prevState = workInProgress.memoizedState;
6888 var prevChildren = prevState !== null ? prevState.element : null;
6889 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
6890 var nextState = workInProgress.memoizedState;
6891 // Caution: React DevTools currently depends on this property
6892 // being called "element".
6893 var nextChildren = nextState.element;
6894 if (nextChildren === prevChildren) {
6895 // If the state is the same as before, that's a bailout because we had
6896 // no work that expires at this time.
6897 resetHydrationState();
6898 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
6899 }
6900 var root = workInProgress.stateNode;
6901 if ((current$$1 === null || current$$1.child === null) && root.hydrate && enterHydrationState(workInProgress)) {
6902 // If we don't have any current children this might be the first pass.
6903 // We always try to hydrate. If this isn't a hydration pass there won't
6904 // be any children to hydrate which is effectively the same thing as
6905 // not hydrating.
6906
6907 // This is a bit of a hack. We track the host root as a placement to
6908 // know that we're currently in a mounting state. That way isMounted
6909 // works as expected. We must reset this before committing.
6910 // TODO: Delete this when we delete isMounted and findDOMNode.
6911 workInProgress.effectTag |= Placement;
6912
6913 // Ensure that children mount into this root without tracking
6914 // side-effects. This ensures that we don't store Placement effects on
6915 // nodes that will be hydrated.
6916 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
6917 } else {
6918 // Otherwise reset hydration state in case we aborted and resumed another
6919 // root.
6920 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6921 resetHydrationState();
6922 }
6923 return workInProgress.child;
6924}
6925
6926function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
6927 pushHostContext(workInProgress);
6928
6929 if (current$$1 === null) {
6930 tryToClaimNextHydratableInstance(workInProgress);
6931 }
6932
6933 var type = workInProgress.type;
6934 var nextProps = workInProgress.pendingProps;
6935 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
6936
6937 var nextChildren = nextProps.children;
6938 var isDirectTextChild = shouldSetTextContent(type, nextProps);
6939
6940 if (isDirectTextChild) {
6941 // We special case a direct text child of a host node. This is a common
6942 // case. We won't handle it as a reified child. We will instead handle
6943 // this in the host environment that also have access to this prop. That
6944 // avoids allocating another HostText fiber and traversing it.
6945 nextChildren = null;
6946 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
6947 // If we're switching from a direct text child to a normal child, or to
6948 // empty, we need to schedule the text content to be reset.
6949 workInProgress.effectTag |= ContentReset;
6950 }
6951
6952 markRef(current$$1, workInProgress);
6953
6954 // Check the host config to see if the children are offscreen/hidden.
6955 if (renderExpirationTime !== Never && workInProgress.mode & ConcurrentMode && shouldDeprioritizeSubtree(type, nextProps)) {
6956 // Schedule this fiber to re-render at offscreen priority. Then bailout.
6957 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
6958 return null;
6959 }
6960
6961 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
6962 return workInProgress.child;
6963}
6964
6965function updateHostText(current$$1, workInProgress) {
6966 if (current$$1 === null) {
6967 tryToClaimNextHydratableInstance(workInProgress);
6968 }
6969 // Nothing to do here. This is terminal. We'll do the completion step
6970 // immediately after.
6971 return null;
6972}
6973
6974function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
6975 if (_current !== null) {
6976 // An lazy component only mounts if it suspended inside a non-
6977 // concurrent tree, in an inconsistent state. We want to treat it like
6978 // a new mount, even though an empty version of it already committed.
6979 // Disconnect the alternate pointers.
6980 _current.alternate = null;
6981 workInProgress.alternate = null;
6982 // Since this is conceptually a new fiber, schedule a Placement effect
6983 workInProgress.effectTag |= Placement;
6984 }
6985
6986 var props = workInProgress.pendingProps;
6987 // We can't start a User Timing measurement with correct label yet.
6988 // Cancel and resume right after we know the tag.
6989 cancelWorkTimer(workInProgress);
6990 var Component = readLazyComponentType(elementType);
6991 // Store the unwrapped component in the type.
6992 workInProgress.type = Component;
6993 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
6994 startWorkTimer(workInProgress);
6995 var resolvedProps = resolveDefaultProps(Component, props);
6996 var child = void 0;
6997 switch (resolvedTag) {
6998 case FunctionComponent:
6999 {
7000 {
7001 validateFunctionComponentInDev(workInProgress, Component);
7002 }
7003 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7004 break;
7005 }
7006 case ClassComponent:
7007 {
7008 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7009 break;
7010 }
7011 case ForwardRef:
7012 {
7013 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
7014 break;
7015 }
7016 case MemoComponent:
7017 {
7018 {
7019 if (workInProgress.type !== workInProgress.elementType) {
7020 var outerPropTypes = Component.propTypes;
7021 if (outerPropTypes) {
7022 checkPropTypes(outerPropTypes, resolvedProps, // Resolved for outer only
7023 'prop', getComponentName(Component), getCurrentFiberStackInDev);
7024 }
7025 }
7026 }
7027 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
7028 updateExpirationTime, renderExpirationTime);
7029 break;
7030 }
7031 default:
7032 {
7033 var hint = '';
7034 {
7035 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
7036 hint = ' Did you wrap a component in React.lazy() more than once?';
7037 }
7038 }
7039 // This message intentionally doesn't mention ForwardRef or MemoComponent
7040 // because the fact that it's a separate type of work is an
7041 // implementation detail.
7042 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);
7043 }
7044 }
7045 return child;
7046}
7047
7048function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
7049 if (_current !== null) {
7050 // An incomplete component only mounts if it suspended inside a non-
7051 // concurrent tree, in an inconsistent state. We want to treat it like
7052 // a new mount, even though an empty version of it already committed.
7053 // Disconnect the alternate pointers.
7054 _current.alternate = null;
7055 workInProgress.alternate = null;
7056 // Since this is conceptually a new fiber, schedule a Placement effect
7057 workInProgress.effectTag |= Placement;
7058 }
7059
7060 // Promote the fiber to a class and try rendering again.
7061 workInProgress.tag = ClassComponent;
7062
7063 // The rest of this function is a fork of `updateClassComponent`
7064
7065 // Push context providers early to prevent context stack mismatches.
7066 // During mounting we don't know the child context yet as the instance doesn't exist.
7067 // We will invalidate the child context in finishClassComponent() right after rendering.
7068 var hasContext = void 0;
7069 if (isContextProvider(Component)) {
7070 hasContext = true;
7071 pushContextProvider(workInProgress);
7072 } else {
7073 hasContext = false;
7074 }
7075 prepareToReadContext(workInProgress, renderExpirationTime);
7076
7077 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7078 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
7079
7080 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7081}
7082
7083function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
7084 if (_current !== null) {
7085 // An indeterminate component only mounts if it suspended inside a non-
7086 // concurrent tree, in an inconsistent state. We want to treat it like
7087 // a new mount, even though an empty version of it already committed.
7088 // Disconnect the alternate pointers.
7089 _current.alternate = null;
7090 workInProgress.alternate = null;
7091 // Since this is conceptually a new fiber, schedule a Placement effect
7092 workInProgress.effectTag |= Placement;
7093 }
7094
7095 var props = workInProgress.pendingProps;
7096 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
7097 var context = getMaskedContext(workInProgress, unmaskedContext);
7098
7099 prepareToReadContext(workInProgress, renderExpirationTime);
7100
7101 var value = void 0;
7102
7103 {
7104 if (Component.prototype && typeof Component.prototype.render === 'function') {
7105 var componentName = getComponentName(Component) || 'Unknown';
7106
7107 if (!didWarnAboutBadClass[componentName]) {
7108 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);
7109 didWarnAboutBadClass[componentName] = true;
7110 }
7111 }
7112
7113 if (workInProgress.mode & StrictMode) {
7114 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
7115 }
7116
7117 ReactCurrentOwner$2.current = workInProgress;
7118 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7119 }
7120 // React DevTools reads this flag.
7121 workInProgress.effectTag |= PerformedWork;
7122
7123 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
7124 // Proceed under the assumption that this is a class instance
7125 workInProgress.tag = ClassComponent;
7126
7127 // Throw out any hooks that were used.
7128 resetHooks();
7129
7130 // Push context providers early to prevent context stack mismatches.
7131 // During mounting we don't know the child context yet as the instance doesn't exist.
7132 // We will invalidate the child context in finishClassComponent() right after rendering.
7133 var hasContext = false;
7134 if (isContextProvider(Component)) {
7135 hasContext = true;
7136 pushContextProvider(workInProgress);
7137 } else {
7138 hasContext = false;
7139 }
7140
7141 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
7142
7143 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
7144 if (typeof getDerivedStateFromProps === 'function') {
7145 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
7146 }
7147
7148 adoptClassInstance(workInProgress, value);
7149 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
7150 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
7151 } else {
7152 // Proceed under the assumption that this is a function component
7153 workInProgress.tag = FunctionComponent;
7154 {
7155 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
7156 // Only double-render components with Hooks
7157 if (workInProgress.memoizedState !== null) {
7158 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
7159 }
7160 }
7161 }
7162 reconcileChildren(null, workInProgress, value, renderExpirationTime);
7163 {
7164 validateFunctionComponentInDev(workInProgress, Component);
7165 }
7166 return workInProgress.child;
7167 }
7168}
7169
7170function validateFunctionComponentInDev(workInProgress, Component) {
7171 if (Component) {
7172 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
7173 }
7174 if (workInProgress.ref !== null) {
7175 var info = '';
7176 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
7177 if (ownerName) {
7178 info += '\n\nCheck the render method of `' + ownerName + '`.';
7179 }
7180
7181 var warningKey = ownerName || workInProgress._debugID || '';
7182 var debugSource = workInProgress._debugSource;
7183 if (debugSource) {
7184 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
7185 }
7186 if (!didWarnAboutFunctionRefs[warningKey]) {
7187 didWarnAboutFunctionRefs[warningKey] = true;
7188 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);
7189 }
7190 }
7191
7192 if (typeof Component.getDerivedStateFromProps === 'function') {
7193 var componentName = getComponentName(Component) || 'Unknown';
7194
7195 if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) {
7196 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', componentName);
7197 didWarnAboutGetDerivedStateOnFunctionComponent[componentName] = true;
7198 }
7199 }
7200
7201 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
7202 var _componentName = getComponentName(Component) || 'Unknown';
7203
7204 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName]) {
7205 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName);
7206 didWarnAboutContextTypeOnFunctionComponent[_componentName] = true;
7207 }
7208 }
7209}
7210
7211function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7212 var mode = workInProgress.mode;
7213 var nextProps = workInProgress.pendingProps;
7214
7215 // We should attempt to render the primary children unless this boundary
7216 // already suspended during this render (`alreadyCaptured` is true).
7217 var nextState = workInProgress.memoizedState;
7218
7219 var nextDidTimeout = void 0;
7220 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7221 // This is the first attempt.
7222 nextState = null;
7223 nextDidTimeout = false;
7224 } else {
7225 // Something in this boundary's subtree already suspended. Switch to
7226 // rendering the fallback children.
7227 nextState = {
7228 timedOutAt: nextState !== null ? nextState.timedOutAt : NoWork
7229 };
7230 nextDidTimeout = true;
7231 workInProgress.effectTag &= ~DidCapture;
7232 }
7233
7234 // This next part is a bit confusing. If the children timeout, we switch to
7235 // showing the fallback children in place of the "primary" children.
7236 // However, we don't want to delete the primary children because then their
7237 // state will be lost (both the React state and the host state, e.g.
7238 // uncontrolled form inputs). Instead we keep them mounted and hide them.
7239 // Both the fallback children AND the primary children are rendered at the
7240 // same time. Once the primary children are un-suspended, we can delete
7241 // the fallback children — don't need to preserve their state.
7242 //
7243 // The two sets of children are siblings in the host environment, but
7244 // semantically, for purposes of reconciliation, they are two separate sets.
7245 // So we store them using two fragment fibers.
7246 //
7247 // However, we want to avoid allocating extra fibers for every placeholder.
7248 // They're only necessary when the children time out, because that's the
7249 // only time when both sets are mounted.
7250 //
7251 // So, the extra fragment fibers are only used if the children time out.
7252 // Otherwise, we render the primary children directly. This requires some
7253 // custom reconciliation logic to preserve the state of the primary
7254 // children. It's essentially a very basic form of re-parenting.
7255
7256 // `child` points to the child fiber. In the normal case, this is the first
7257 // fiber of the primary children set. In the timed-out case, it's a
7258 // a fragment fiber containing the primary children.
7259 var child = void 0;
7260 // `next` points to the next fiber React should render. In the normal case,
7261 // it's the same as `child`: the first fiber of the primary children set.
7262 // In the timed-out case, it's a fragment fiber containing the *fallback*
7263 // children -- we skip over the primary children entirely.
7264 var next = void 0;
7265 if (current$$1 === null) {
7266 if (enableSuspenseServerRenderer) {
7267 // If we're currently hydrating, try to hydrate this boundary.
7268 // But only if this has a fallback.
7269 if (nextProps.fallback !== undefined) {
7270 tryToClaimNextHydratableInstance(workInProgress);
7271 // This could've changed the tag if this was a dehydrated suspense component.
7272 if (workInProgress.tag === DehydratedSuspenseComponent) {
7273 return updateDehydratedSuspenseComponent(null, workInProgress, renderExpirationTime);
7274 }
7275 }
7276 }
7277
7278 // This is the initial mount. This branch is pretty simple because there's
7279 // no previous state that needs to be preserved.
7280 if (nextDidTimeout) {
7281 // Mount separate fragments for primary and fallback children.
7282 var nextFallbackChildren = nextProps.fallback;
7283 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
7284
7285 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7286 // Outside of concurrent mode, we commit the effects from the
7287 var progressedState = workInProgress.memoizedState;
7288 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
7289 primaryChildFragment.child = progressedPrimaryChild;
7290 }
7291
7292 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
7293 primaryChildFragment.sibling = fallbackChildFragment;
7294 child = primaryChildFragment;
7295 // Skip the primary children, and continue working on the
7296 // fallback children.
7297 next = fallbackChildFragment;
7298 child.return = next.return = workInProgress;
7299 } else {
7300 // Mount the primary children without an intermediate fragment fiber.
7301 var nextPrimaryChildren = nextProps.children;
7302 child = next = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
7303 }
7304 } else {
7305 // This is an update. This branch is more complicated because we need to
7306 // ensure the state of the primary children is preserved.
7307 var prevState = current$$1.memoizedState;
7308 var prevDidTimeout = prevState !== null;
7309 if (prevDidTimeout) {
7310 // The current tree already timed out. That means each child set is
7311 var currentPrimaryChildFragment = current$$1.child;
7312 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
7313 if (nextDidTimeout) {
7314 // Still timed out. Reuse the current primary children by cloning
7315 // its fragment. We're going to skip over these entirely.
7316 var _nextFallbackChildren = nextProps.fallback;
7317 var _primaryChildFragment = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
7318
7319 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7320 // Outside of concurrent mode, we commit the effects from the
7321 var _progressedState = workInProgress.memoizedState;
7322 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
7323 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
7324 _primaryChildFragment.child = _progressedPrimaryChild;
7325 }
7326 }
7327
7328 // Because primaryChildFragment is a new fiber that we're inserting as the
7329 // parent of a new tree, we need to set its treeBaseDuration.
7330 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7331 // treeBaseDuration is the sum of all the child tree base durations.
7332 var treeBaseDuration = 0;
7333 var hiddenChild = _primaryChildFragment.child;
7334 while (hiddenChild !== null) {
7335 treeBaseDuration += hiddenChild.treeBaseDuration;
7336 hiddenChild = hiddenChild.sibling;
7337 }
7338 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
7339 }
7340
7341 // Clone the fallback child fragment, too. These we'll continue
7342 // working on.
7343 var _fallbackChildFragment = _primaryChildFragment.sibling = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren, currentFallbackChildFragment.expirationTime);
7344 child = _primaryChildFragment;
7345 _primaryChildFragment.childExpirationTime = NoWork;
7346 // Skip the primary children, and continue working on the
7347 // fallback children.
7348 next = _fallbackChildFragment;
7349 child.return = next.return = workInProgress;
7350 } else {
7351 // No longer suspended. Switch back to showing the primary children,
7352 // and remove the intermediate fragment fiber.
7353 var _nextPrimaryChildren = nextProps.children;
7354 var currentPrimaryChild = currentPrimaryChildFragment.child;
7355 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime);
7356
7357 // If this render doesn't suspend, we need to delete the fallback
7358 // children. Wait until the complete phase, after we've confirmed the
7359 // fallback is no longer needed.
7360 // TODO: Would it be better to store the fallback fragment on
7361 // the stateNode?
7362
7363 // Continue rendering the children, like we normally do.
7364 child = next = primaryChild;
7365 }
7366 } else {
7367 // The current tree has not already timed out. That means the primary
7368 // children are not wrapped in a fragment fiber.
7369 var _currentPrimaryChild = current$$1.child;
7370 if (nextDidTimeout) {
7371 // Timed out. Wrap the children in a fragment fiber to keep them
7372 // separate from the fallback children.
7373 var _nextFallbackChildren2 = nextProps.fallback;
7374 var _primaryChildFragment2 = createFiberFromFragment(
7375 // It shouldn't matter what the pending props are because we aren't
7376 // going to render this fragment.
7377 null, mode, NoWork, null);
7378 _primaryChildFragment2.child = _currentPrimaryChild;
7379
7380 // Even though we're creating a new fiber, there are no new children,
7381 // because we're reusing an already mounted tree. So we don't need to
7382 // schedule a placement.
7383 // primaryChildFragment.effectTag |= Placement;
7384
7385 if ((workInProgress.mode & ConcurrentMode) === NoContext) {
7386 // Outside of concurrent mode, we commit the effects from the
7387 var _progressedState2 = workInProgress.memoizedState;
7388 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
7389 _primaryChildFragment2.child = _progressedPrimaryChild2;
7390 }
7391
7392 // Because primaryChildFragment is a new fiber that we're inserting as the
7393 // parent of a new tree, we need to set its treeBaseDuration.
7394 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
7395 // treeBaseDuration is the sum of all the child tree base durations.
7396 var _treeBaseDuration = 0;
7397 var _hiddenChild = _primaryChildFragment2.child;
7398 while (_hiddenChild !== null) {
7399 _treeBaseDuration += _hiddenChild.treeBaseDuration;
7400 _hiddenChild = _hiddenChild.sibling;
7401 }
7402 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
7403 }
7404
7405 // Create a fragment from the fallback children, too.
7406 var _fallbackChildFragment2 = _primaryChildFragment2.sibling = createFiberFromFragment(_nextFallbackChildren2, mode, renderExpirationTime, null);
7407 _fallbackChildFragment2.effectTag |= Placement;
7408 child = _primaryChildFragment2;
7409 _primaryChildFragment2.childExpirationTime = NoWork;
7410 // Skip the primary children, and continue working on the
7411 // fallback children.
7412 next = _fallbackChildFragment2;
7413 child.return = next.return = workInProgress;
7414 } else {
7415 // Still haven't timed out. Continue rendering the children, like we
7416 // normally do.
7417 var _nextPrimaryChildren2 = nextProps.children;
7418 next = child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
7419 }
7420 }
7421 workInProgress.stateNode = current$$1.stateNode;
7422 }
7423
7424 workInProgress.memoizedState = nextState;
7425 workInProgress.child = child;
7426 return next;
7427}
7428
7429function updateDehydratedSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
7430 if (current$$1 === null) {
7431 // During the first pass, we'll bail out and not drill into the children.
7432 // Instead, we'll leave the content in place and try to hydrate it later.
7433 workInProgress.expirationTime = Never;
7434 return null;
7435 }
7436 // We use childExpirationTime to indicate that a child might depend on context, so if
7437 // any context has changed, we need to treat is as if the input might have changed.
7438 var hasContextChanged$$1 = current$$1.childExpirationTime >= renderExpirationTime;
7439 if (didReceiveUpdate || hasContextChanged$$1) {
7440 // This boundary has changed since the first render. This means that we are now unable to
7441 // hydrate it. We might still be able to hydrate it using an earlier expiration time but
7442 // during this render we can't. Instead, we're going to delete the whole subtree and
7443 // instead inject a new real Suspense boundary to take its place, which may render content
7444 // or fallback. The real Suspense boundary will suspend for a while so we have some time
7445 // to ensure it can produce real content, but all state and pending events will be lost.
7446
7447 // Detach from the current dehydrated boundary.
7448 current$$1.alternate = null;
7449 workInProgress.alternate = null;
7450
7451 // Insert a deletion in the effect list.
7452 var returnFiber = workInProgress.return;
7453 !(returnFiber !== null) ? invariant(false, 'Suspense boundaries are never on the root. This is probably a bug in React.') : void 0;
7454 var last = returnFiber.lastEffect;
7455 if (last !== null) {
7456 last.nextEffect = current$$1;
7457 returnFiber.lastEffect = current$$1;
7458 } else {
7459 returnFiber.firstEffect = returnFiber.lastEffect = current$$1;
7460 }
7461 current$$1.nextEffect = null;
7462 current$$1.effectTag = Deletion;
7463
7464 // Upgrade this work in progress to a real Suspense component.
7465 workInProgress.tag = SuspenseComponent;
7466 workInProgress.stateNode = null;
7467 workInProgress.memoizedState = null;
7468 // This is now an insertion.
7469 workInProgress.effectTag |= Placement;
7470 // Retry as a real Suspense component.
7471 return updateSuspenseComponent(null, workInProgress, renderExpirationTime);
7472 }
7473 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
7474 // This is the first attempt.
7475 reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress);
7476 var nextProps = workInProgress.pendingProps;
7477 var nextChildren = nextProps.children;
7478 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7479 return workInProgress.child;
7480 } else {
7481 // Something suspended. Leave the existing children in place.
7482 // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far?
7483 workInProgress.child = null;
7484 return null;
7485 }
7486}
7487
7488function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
7489 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7490 var nextChildren = workInProgress.pendingProps;
7491 if (current$$1 === null) {
7492 // Portals are special because we don't append the children during mount
7493 // but at commit. Therefore we need to track insertions which the normal
7494 // flow doesn't do during mount. This doesn't happen at the root because
7495 // the root always starts with a "current" with a null child.
7496 // TODO: Consider unifying this with how the root works.
7497 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
7498 } else {
7499 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
7500 }
7501 return workInProgress.child;
7502}
7503
7504function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
7505 var providerType = workInProgress.type;
7506 var context = providerType._context;
7507
7508 var newProps = workInProgress.pendingProps;
7509 var oldProps = workInProgress.memoizedProps;
7510
7511 var newValue = newProps.value;
7512
7513 {
7514 var providerPropTypes = workInProgress.type.propTypes;
7515
7516 if (providerPropTypes) {
7517 checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
7518 }
7519 }
7520
7521 pushProvider(workInProgress, newValue);
7522
7523 if (oldProps !== null) {
7524 var oldValue = oldProps.value;
7525 var changedBits = calculateChangedBits(context, newValue, oldValue);
7526 if (changedBits === 0) {
7527 // No change. Bailout early if children are the same.
7528 if (oldProps.children === newProps.children && !hasContextChanged()) {
7529 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7530 }
7531 } else {
7532 // The context value changed. Search for matching consumers and schedule
7533 // them to update.
7534 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
7535 }
7536 }
7537
7538 var newChildren = newProps.children;
7539 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7540 return workInProgress.child;
7541}
7542
7543var hasWarnedAboutUsingContextAsConsumer = false;
7544
7545function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
7546 var context = workInProgress.type;
7547 // The logic below for Context differs depending on PROD or DEV mode. In
7548 // DEV mode, we create a separate object for Context.Consumer that acts
7549 // like a proxy to Context. This proxy object adds unnecessary code in PROD
7550 // so we use the old behaviour (Context.Consumer references Context) to
7551 // reduce size and overhead. The separate object references context via
7552 // a property called "_context", which also gives us the ability to check
7553 // in DEV mode if this property exists or not and warn if it does not.
7554 {
7555 if (context._context === undefined) {
7556 // This may be because it's a Context (rather than a Consumer).
7557 // Or it may be because it's older React where they're the same thing.
7558 // We only want to warn if we're sure it's a new React.
7559 if (context !== context.Consumer) {
7560 if (!hasWarnedAboutUsingContextAsConsumer) {
7561 hasWarnedAboutUsingContextAsConsumer = true;
7562 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?');
7563 }
7564 }
7565 } else {
7566 context = context._context;
7567 }
7568 }
7569 var newProps = workInProgress.pendingProps;
7570 var render = newProps.children;
7571
7572 {
7573 !(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;
7574 }
7575
7576 prepareToReadContext(workInProgress, renderExpirationTime);
7577 var newValue = readContext(context, newProps.unstable_observedBits);
7578 var newChildren = void 0;
7579 {
7580 ReactCurrentOwner$2.current = workInProgress;
7581 setCurrentPhase('render');
7582 newChildren = render(newValue);
7583 setCurrentPhase(null);
7584 }
7585
7586 // React DevTools reads this flag.
7587 workInProgress.effectTag |= PerformedWork;
7588 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
7589 return workInProgress.child;
7590}
7591
7592function markWorkInProgressReceivedUpdate() {
7593 didReceiveUpdate = true;
7594}
7595
7596function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
7597 cancelWorkTimer(workInProgress);
7598
7599 if (current$$1 !== null) {
7600 // Reuse previous context list
7601 workInProgress.contextDependencies = current$$1.contextDependencies;
7602 }
7603
7604 if (enableProfilerTimer) {
7605 // Don't update "base" render times for bailouts.
7606 stopProfilerTimerIfRunning(workInProgress);
7607 }
7608
7609 // Check if the children have any pending work.
7610 var childExpirationTime = workInProgress.childExpirationTime;
7611 if (childExpirationTime < renderExpirationTime) {
7612 // The children don't have any work either. We can skip them.
7613 // TODO: Once we add back resuming, we should check if the children are
7614 // a work-in-progress set. If so, we need to transfer their effects.
7615 return null;
7616 } else {
7617 // This fiber doesn't have work, but its subtree does. Clone the child
7618 // fibers and continue.
7619 cloneChildFibers(current$$1, workInProgress);
7620 return workInProgress.child;
7621 }
7622}
7623
7624function beginWork(current$$1, workInProgress, renderExpirationTime) {
7625 var updateExpirationTime = workInProgress.expirationTime;
7626
7627 if (current$$1 !== null) {
7628 var oldProps = current$$1.memoizedProps;
7629 var newProps = workInProgress.pendingProps;
7630
7631 if (oldProps !== newProps || hasContextChanged()) {
7632 // If props or context changed, mark the fiber as having performed work.
7633 // This may be unset if the props are determined to be equal later (memo).
7634 didReceiveUpdate = true;
7635 } else if (updateExpirationTime < renderExpirationTime) {
7636 didReceiveUpdate = false;
7637 // This fiber does not have any pending work. Bailout without entering
7638 // the begin phase. There's still some bookkeeping we that needs to be done
7639 // in this optimized path, mostly pushing stuff onto the stack.
7640 switch (workInProgress.tag) {
7641 case HostRoot:
7642 pushHostRootContext(workInProgress);
7643 resetHydrationState();
7644 break;
7645 case HostComponent:
7646 pushHostContext(workInProgress);
7647 break;
7648 case ClassComponent:
7649 {
7650 var Component = workInProgress.type;
7651 if (isContextProvider(Component)) {
7652 pushContextProvider(workInProgress);
7653 }
7654 break;
7655 }
7656 case HostPortal:
7657 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
7658 break;
7659 case ContextProvider:
7660 {
7661 var newValue = workInProgress.memoizedProps.value;
7662 pushProvider(workInProgress, newValue);
7663 break;
7664 }
7665 case Profiler:
7666 if (enableProfilerTimer) {
7667 workInProgress.effectTag |= Update;
7668 }
7669 break;
7670 case SuspenseComponent:
7671 {
7672 var state = workInProgress.memoizedState;
7673 var didTimeout = state !== null;
7674 if (didTimeout) {
7675 // If this boundary is currently timed out, we need to decide
7676 // whether to retry the primary children, or to skip over it and
7677 // go straight to the fallback. Check the priority of the primary
7678 var primaryChildFragment = workInProgress.child;
7679 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
7680 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
7681 // The primary children have pending work. Use the normal path
7682 // to attempt to render the primary children again.
7683 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7684 } else {
7685 // The primary children do not have pending work with sufficient
7686 // priority. Bailout.
7687 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7688 if (child !== null) {
7689 // The fallback children have pending work. Skip over the
7690 // primary children and work on the fallback.
7691 return child.sibling;
7692 } else {
7693 return null;
7694 }
7695 }
7696 }
7697 break;
7698 }
7699 case DehydratedSuspenseComponent:
7700 {
7701 if (enableSuspenseServerRenderer) {
7702 // We know that this component will suspend again because if it has
7703 // been unsuspended it has committed as a regular Suspense component.
7704 // If it needs to be retried, it should have work scheduled on it.
7705 workInProgress.effectTag |= DidCapture;
7706 break;
7707 }
7708 }
7709 }
7710 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
7711 }
7712 } else {
7713 didReceiveUpdate = false;
7714 }
7715
7716 // Before entering the begin phase, clear the expiration time.
7717 workInProgress.expirationTime = NoWork;
7718
7719 switch (workInProgress.tag) {
7720 case IndeterminateComponent:
7721 {
7722 var elementType = workInProgress.elementType;
7723 return mountIndeterminateComponent(current$$1, workInProgress, elementType, renderExpirationTime);
7724 }
7725 case LazyComponent:
7726 {
7727 var _elementType = workInProgress.elementType;
7728 return mountLazyComponent(current$$1, workInProgress, _elementType, updateExpirationTime, renderExpirationTime);
7729 }
7730 case FunctionComponent:
7731 {
7732 var _Component = workInProgress.type;
7733 var unresolvedProps = workInProgress.pendingProps;
7734 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
7735 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
7736 }
7737 case ClassComponent:
7738 {
7739 var _Component2 = workInProgress.type;
7740 var _unresolvedProps = workInProgress.pendingProps;
7741 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
7742 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
7743 }
7744 case HostRoot:
7745 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
7746 case HostComponent:
7747 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
7748 case HostText:
7749 return updateHostText(current$$1, workInProgress);
7750 case SuspenseComponent:
7751 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7752 case HostPortal:
7753 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
7754 case ForwardRef:
7755 {
7756 var type = workInProgress.type;
7757 var _unresolvedProps2 = workInProgress.pendingProps;
7758 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
7759 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
7760 }
7761 case Fragment:
7762 return updateFragment(current$$1, workInProgress, renderExpirationTime);
7763 case Mode:
7764 return updateMode(current$$1, workInProgress, renderExpirationTime);
7765 case Profiler:
7766 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
7767 case ContextProvider:
7768 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
7769 case ContextConsumer:
7770 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
7771 case MemoComponent:
7772 {
7773 var _type2 = workInProgress.type;
7774 var _unresolvedProps3 = workInProgress.pendingProps;
7775 // Resolve outer props first, then resolve inner props.
7776 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
7777 {
7778 if (workInProgress.type !== workInProgress.elementType) {
7779 var outerPropTypes = _type2.propTypes;
7780 if (outerPropTypes) {
7781 checkPropTypes(outerPropTypes, _resolvedProps3, // Resolved for outer only
7782 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
7783 }
7784 }
7785 }
7786 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
7787 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
7788 }
7789 case SimpleMemoComponent:
7790 {
7791 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
7792 }
7793 case IncompleteClassComponent:
7794 {
7795 var _Component3 = workInProgress.type;
7796 var _unresolvedProps4 = workInProgress.pendingProps;
7797 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
7798 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
7799 }
7800 case DehydratedSuspenseComponent:
7801 {
7802 if (enableSuspenseServerRenderer) {
7803 return updateDehydratedSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
7804 }
7805 break;
7806 }
7807 }
7808 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
7809}
7810
7811var valueCursor = createCursor(null);
7812
7813var rendererSigil = void 0;
7814{
7815 // Use this to detect multiple renderers using the same context
7816 rendererSigil = {};
7817}
7818
7819var currentlyRenderingFiber = null;
7820var lastContextDependency = null;
7821var lastContextWithAllBitsObserved = null;
7822
7823var isDisallowedContextReadInDEV = false;
7824
7825function resetContextDependences() {
7826 // This is called right before React yields execution, to ensure `readContext`
7827 // cannot be called outside the render phase.
7828 currentlyRenderingFiber = null;
7829 lastContextDependency = null;
7830 lastContextWithAllBitsObserved = null;
7831 {
7832 isDisallowedContextReadInDEV = false;
7833 }
7834}
7835
7836function enterDisallowedContextReadInDEV() {
7837 {
7838 isDisallowedContextReadInDEV = true;
7839 }
7840}
7841
7842function exitDisallowedContextReadInDEV() {
7843 {
7844 isDisallowedContextReadInDEV = false;
7845 }
7846}
7847
7848function pushProvider(providerFiber, nextValue) {
7849 var context = providerFiber.type._context;
7850
7851 if (isPrimaryRenderer) {
7852 push(valueCursor, context._currentValue, providerFiber);
7853
7854 context._currentValue = nextValue;
7855 {
7856 !(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;
7857 context._currentRenderer = rendererSigil;
7858 }
7859 } else {
7860 push(valueCursor, context._currentValue2, providerFiber);
7861
7862 context._currentValue2 = nextValue;
7863 {
7864 !(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;
7865 context._currentRenderer2 = rendererSigil;
7866 }
7867 }
7868}
7869
7870function popProvider(providerFiber) {
7871 var currentValue = valueCursor.current;
7872
7873 pop(valueCursor, providerFiber);
7874
7875 var context = providerFiber.type._context;
7876 if (isPrimaryRenderer) {
7877 context._currentValue = currentValue;
7878 } else {
7879 context._currentValue2 = currentValue;
7880 }
7881}
7882
7883function calculateChangedBits(context, newValue, oldValue) {
7884 if (is(oldValue, newValue)) {
7885 // No change
7886 return 0;
7887 } else {
7888 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : maxSigned31BitInt;
7889
7890 {
7891 !((changedBits & maxSigned31BitInt) === changedBits) ? warning$1(false, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits) : void 0;
7892 }
7893 return changedBits | 0;
7894 }
7895}
7896
7897function scheduleWorkOnParentPath(parent, renderExpirationTime) {
7898 // Update the child expiration time of all the ancestors, including
7899 // the alternates.
7900 var node = parent;
7901 while (node !== null) {
7902 var alternate = node.alternate;
7903 if (node.childExpirationTime < renderExpirationTime) {
7904 node.childExpirationTime = renderExpirationTime;
7905 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
7906 alternate.childExpirationTime = renderExpirationTime;
7907 }
7908 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
7909 alternate.childExpirationTime = renderExpirationTime;
7910 } else {
7911 // Neither alternate was updated, which means the rest of the
7912 // ancestor path already has sufficient priority.
7913 break;
7914 }
7915 node = node.return;
7916 }
7917}
7918
7919function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
7920 var fiber = workInProgress.child;
7921 if (fiber !== null) {
7922 // Set the return pointer of the child to the work-in-progress fiber.
7923 fiber.return = workInProgress;
7924 }
7925 while (fiber !== null) {
7926 var nextFiber = void 0;
7927
7928 // Visit this fiber.
7929 var list = fiber.contextDependencies;
7930 if (list !== null) {
7931 nextFiber = fiber.child;
7932
7933 var dependency = list.first;
7934 while (dependency !== null) {
7935 // Check if the context matches.
7936 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
7937 // Match! Schedule an update on this fiber.
7938
7939 if (fiber.tag === ClassComponent) {
7940 // Schedule a force update on the work-in-progress.
7941 var update = createUpdate(renderExpirationTime);
7942 update.tag = ForceUpdate;
7943 // TODO: Because we don't have a work-in-progress, this will add the
7944 // update to the current fiber, too, which means it will persist even if
7945 // this render is thrown away. Since it's a race condition, not sure it's
7946 // worth fixing.
7947 enqueueUpdate(fiber, update);
7948 }
7949
7950 if (fiber.expirationTime < renderExpirationTime) {
7951 fiber.expirationTime = renderExpirationTime;
7952 }
7953 var alternate = fiber.alternate;
7954 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
7955 alternate.expirationTime = renderExpirationTime;
7956 }
7957
7958 scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
7959
7960 // Mark the expiration time on the list, too.
7961 if (list.expirationTime < renderExpirationTime) {
7962 list.expirationTime = renderExpirationTime;
7963 }
7964
7965 // Since we already found a match, we can stop traversing the
7966 // dependency list.
7967 break;
7968 }
7969 dependency = dependency.next;
7970 }
7971 } else if (fiber.tag === ContextProvider) {
7972 // Don't scan deeper if this is a matching provider
7973 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
7974 } else if (enableSuspenseServerRenderer && fiber.tag === DehydratedSuspenseComponent) {
7975 // If a dehydrated suspense component is in this subtree, we don't know
7976 // if it will have any context consumers in it. The best we can do is
7977 // mark it as having updates on its children.
7978 if (fiber.expirationTime < renderExpirationTime) {
7979 fiber.expirationTime = renderExpirationTime;
7980 }
7981 var _alternate = fiber.alternate;
7982 if (_alternate !== null && _alternate.expirationTime < renderExpirationTime) {
7983 _alternate.expirationTime = renderExpirationTime;
7984 }
7985 // This is intentionally passing this fiber as the parent
7986 // because we want to schedule this fiber as having work
7987 // on its children. We'll use the childExpirationTime on
7988 // this fiber to indicate that a context has changed.
7989 scheduleWorkOnParentPath(fiber, renderExpirationTime);
7990 nextFiber = fiber.sibling;
7991 } else {
7992 // Traverse down.
7993 nextFiber = fiber.child;
7994 }
7995
7996 if (nextFiber !== null) {
7997 // Set the return pointer of the child to the work-in-progress fiber.
7998 nextFiber.return = fiber;
7999 } else {
8000 // No child. Traverse to next sibling.
8001 nextFiber = fiber;
8002 while (nextFiber !== null) {
8003 if (nextFiber === workInProgress) {
8004 // We're back to the root of this subtree. Exit.
8005 nextFiber = null;
8006 break;
8007 }
8008 var sibling = nextFiber.sibling;
8009 if (sibling !== null) {
8010 // Set the return pointer of the sibling to the work-in-progress fiber.
8011 sibling.return = nextFiber.return;
8012 nextFiber = sibling;
8013 break;
8014 }
8015 // No more siblings. Traverse up.
8016 nextFiber = nextFiber.return;
8017 }
8018 }
8019 fiber = nextFiber;
8020 }
8021}
8022
8023function prepareToReadContext(workInProgress, renderExpirationTime) {
8024 currentlyRenderingFiber = workInProgress;
8025 lastContextDependency = null;
8026 lastContextWithAllBitsObserved = null;
8027
8028 var currentDependencies = workInProgress.contextDependencies;
8029 if (currentDependencies !== null && currentDependencies.expirationTime >= renderExpirationTime) {
8030 // Context list has a pending update. Mark that this fiber performed work.
8031 markWorkInProgressReceivedUpdate();
8032 }
8033
8034 // Reset the work-in-progress list
8035 workInProgress.contextDependencies = null;
8036}
8037
8038function readContext(context, observedBits) {
8039 {
8040 // This warning would fire if you read context inside a Hook like useMemo.
8041 // Unlike the class check below, it's not enforced in production for perf.
8042 !!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;
8043 }
8044
8045 if (lastContextWithAllBitsObserved === context) {
8046 // Nothing to do. We already observe everything in this context.
8047 } else if (observedBits === false || observedBits === 0) {
8048 // Do not observe any updates.
8049 } else {
8050 var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types.
8051 if (typeof observedBits !== 'number' || observedBits === maxSigned31BitInt) {
8052 // Observe all updates.
8053 lastContextWithAllBitsObserved = context;
8054 resolvedObservedBits = maxSigned31BitInt;
8055 } else {
8056 resolvedObservedBits = observedBits;
8057 }
8058
8059 var contextItem = {
8060 context: context,
8061 observedBits: resolvedObservedBits,
8062 next: null
8063 };
8064
8065 if (lastContextDependency === null) {
8066 !(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;
8067
8068 // This is the first dependency for this component. Create a new list.
8069 lastContextDependency = contextItem;
8070 currentlyRenderingFiber.contextDependencies = {
8071 first: contextItem,
8072 expirationTime: NoWork
8073 };
8074 } else {
8075 // Append a new context item.
8076 lastContextDependency = lastContextDependency.next = contextItem;
8077 }
8078 }
8079 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
8080}
8081
8082// UpdateQueue is a linked list of prioritized updates.
8083//
8084// Like fibers, update queues come in pairs: a current queue, which represents
8085// the visible state of the screen, and a work-in-progress queue, which can be
8086// mutated and processed asynchronously before it is committed — a form of
8087// double buffering. If a work-in-progress render is discarded before finishing,
8088// we create a new work-in-progress by cloning the current queue.
8089//
8090// Both queues share a persistent, singly-linked list structure. To schedule an
8091// update, we append it to the end of both queues. Each queue maintains a
8092// pointer to first update in the persistent list that hasn't been processed.
8093// The work-in-progress pointer always has a position equal to or greater than
8094// the current queue, since we always work on that one. The current queue's
8095// pointer is only updated during the commit phase, when we swap in the
8096// work-in-progress.
8097//
8098// For example:
8099//
8100// Current pointer: A - B - C - D - E - F
8101// Work-in-progress pointer: D - E - F
8102// ^
8103// The work-in-progress queue has
8104// processed more updates than current.
8105//
8106// The reason we append to both queues is because otherwise we might drop
8107// updates without ever processing them. For example, if we only add updates to
8108// the work-in-progress queue, some updates could be lost whenever a work-in
8109// -progress render restarts by cloning from current. Similarly, if we only add
8110// updates to the current queue, the updates will be lost whenever an already
8111// in-progress queue commits and swaps with the current queue. However, by
8112// adding to both queues, we guarantee that the update will be part of the next
8113// work-in-progress. (And because the work-in-progress queue becomes the
8114// current queue once it commits, there's no danger of applying the same
8115// update twice.)
8116//
8117// Prioritization
8118// --------------
8119//
8120// Updates are not sorted by priority, but by insertion; new updates are always
8121// appended to the end of the list.
8122//
8123// The priority is still important, though. When processing the update queue
8124// during the render phase, only the updates with sufficient priority are
8125// included in the result. If we skip an update because it has insufficient
8126// priority, it remains in the queue to be processed later, during a lower
8127// priority render. Crucially, all updates subsequent to a skipped update also
8128// remain in the queue *regardless of their priority*. That means high priority
8129// updates are sometimes processed twice, at two separate priorities. We also
8130// keep track of a base state, that represents the state before the first
8131// update in the queue is applied.
8132//
8133// For example:
8134//
8135// Given a base state of '', and the following queue of updates
8136//
8137// A1 - B2 - C1 - D2
8138//
8139// where the number indicates the priority, and the update is applied to the
8140// previous state by appending a letter, React will process these updates as
8141// two separate renders, one per distinct priority level:
8142//
8143// First render, at priority 1:
8144// Base state: ''
8145// Updates: [A1, C1]
8146// Result state: 'AC'
8147//
8148// Second render, at priority 2:
8149// Base state: 'A' <- The base state does not include C1,
8150// because B2 was skipped.
8151// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
8152// Result state: 'ABCD'
8153//
8154// Because we process updates in insertion order, and rebase high priority
8155// updates when preceding updates are skipped, the final result is deterministic
8156// regardless of priority. Intermediate state may vary according to system
8157// resources, but the final state is always the same.
8158
8159var UpdateState = 0;
8160var ReplaceState = 1;
8161var ForceUpdate = 2;
8162var CaptureUpdate = 3;
8163
8164// Global state that is reset at the beginning of calling `processUpdateQueue`.
8165// It should only be read right after calling `processUpdateQueue`, via
8166// `checkHasForceUpdateAfterProcessing`.
8167var hasForceUpdate = false;
8168
8169var didWarnUpdateInsideUpdate = void 0;
8170var currentlyProcessingQueue = void 0;
8171var resetCurrentlyProcessingQueue = void 0;
8172{
8173 didWarnUpdateInsideUpdate = false;
8174 currentlyProcessingQueue = null;
8175 resetCurrentlyProcessingQueue = function () {
8176 currentlyProcessingQueue = null;
8177 };
8178}
8179
8180function createUpdateQueue(baseState) {
8181 var queue = {
8182 baseState: baseState,
8183 firstUpdate: null,
8184 lastUpdate: null,
8185 firstCapturedUpdate: null,
8186 lastCapturedUpdate: null,
8187 firstEffect: null,
8188 lastEffect: null,
8189 firstCapturedEffect: null,
8190 lastCapturedEffect: null
8191 };
8192 return queue;
8193}
8194
8195function cloneUpdateQueue(currentQueue) {
8196 var queue = {
8197 baseState: currentQueue.baseState,
8198 firstUpdate: currentQueue.firstUpdate,
8199 lastUpdate: currentQueue.lastUpdate,
8200
8201 // TODO: With resuming, if we bail out and resuse the child tree, we should
8202 // keep these effects.
8203 firstCapturedUpdate: null,
8204 lastCapturedUpdate: null,
8205
8206 firstEffect: null,
8207 lastEffect: null,
8208
8209 firstCapturedEffect: null,
8210 lastCapturedEffect: null
8211 };
8212 return queue;
8213}
8214
8215function createUpdate(expirationTime) {
8216 return {
8217 expirationTime: expirationTime,
8218
8219 tag: UpdateState,
8220 payload: null,
8221 callback: null,
8222
8223 next: null,
8224 nextEffect: null
8225 };
8226}
8227
8228function appendUpdateToQueue(queue, update) {
8229 // Append the update to the end of the list.
8230 if (queue.lastUpdate === null) {
8231 // Queue is empty
8232 queue.firstUpdate = queue.lastUpdate = update;
8233 } else {
8234 queue.lastUpdate.next = update;
8235 queue.lastUpdate = update;
8236 }
8237}
8238
8239function enqueueUpdate(fiber, update) {
8240 // Update queues are created lazily.
8241 var alternate = fiber.alternate;
8242 var queue1 = void 0;
8243 var queue2 = void 0;
8244 if (alternate === null) {
8245 // There's only one fiber.
8246 queue1 = fiber.updateQueue;
8247 queue2 = null;
8248 if (queue1 === null) {
8249 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8250 }
8251 } else {
8252 // There are two owners.
8253 queue1 = fiber.updateQueue;
8254 queue2 = alternate.updateQueue;
8255 if (queue1 === null) {
8256 if (queue2 === null) {
8257 // Neither fiber has an update queue. Create new ones.
8258 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
8259 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
8260 } else {
8261 // Only one fiber has an update queue. Clone to create a new one.
8262 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
8263 }
8264 } else {
8265 if (queue2 === null) {
8266 // Only one fiber has an update queue. Clone to create a new one.
8267 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
8268 } else {
8269 // Both owners have an update queue.
8270 }
8271 }
8272 }
8273 if (queue2 === null || queue1 === queue2) {
8274 // There's only a single queue.
8275 appendUpdateToQueue(queue1, update);
8276 } else {
8277 // There are two queues. We need to append the update to both queues,
8278 // while accounting for the persistent structure of the list — we don't
8279 // want the same update to be added multiple times.
8280 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
8281 // One of the queues is not empty. We must add the update to both queues.
8282 appendUpdateToQueue(queue1, update);
8283 appendUpdateToQueue(queue2, update);
8284 } else {
8285 // Both queues are non-empty. The last update is the same in both lists,
8286 // because of structural sharing. So, only append to one of the lists.
8287 appendUpdateToQueue(queue1, update);
8288 // But we still need to update the `lastUpdate` pointer of queue2.
8289 queue2.lastUpdate = update;
8290 }
8291 }
8292
8293 {
8294 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
8295 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.');
8296 didWarnUpdateInsideUpdate = true;
8297 }
8298 }
8299}
8300
8301function enqueueCapturedUpdate(workInProgress, update) {
8302 // Captured updates go into a separate list, and only on the work-in-
8303 // progress queue.
8304 var workInProgressQueue = workInProgress.updateQueue;
8305 if (workInProgressQueue === null) {
8306 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
8307 } else {
8308 // TODO: I put this here rather than createWorkInProgress so that we don't
8309 // clone the queue unnecessarily. There's probably a better way to
8310 // structure this.
8311 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
8312 }
8313
8314 // Append the update to the end of the list.
8315 if (workInProgressQueue.lastCapturedUpdate === null) {
8316 // This is the first render phase update
8317 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
8318 } else {
8319 workInProgressQueue.lastCapturedUpdate.next = update;
8320 workInProgressQueue.lastCapturedUpdate = update;
8321 }
8322}
8323
8324function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
8325 var current = workInProgress.alternate;
8326 if (current !== null) {
8327 // If the work-in-progress queue is equal to the current queue,
8328 // we need to clone it first.
8329 if (queue === current.updateQueue) {
8330 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
8331 }
8332 }
8333 return queue;
8334}
8335
8336function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
8337 switch (update.tag) {
8338 case ReplaceState:
8339 {
8340 var _payload = update.payload;
8341 if (typeof _payload === 'function') {
8342 // Updater function
8343 {
8344 enterDisallowedContextReadInDEV();
8345 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8346 _payload.call(instance, prevState, nextProps);
8347 }
8348 }
8349 var nextState = _payload.call(instance, prevState, nextProps);
8350 {
8351 exitDisallowedContextReadInDEV();
8352 }
8353 return nextState;
8354 }
8355 // State object
8356 return _payload;
8357 }
8358 case CaptureUpdate:
8359 {
8360 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
8361 }
8362 // Intentional fallthrough
8363 case UpdateState:
8364 {
8365 var _payload2 = update.payload;
8366 var partialState = void 0;
8367 if (typeof _payload2 === 'function') {
8368 // Updater function
8369 {
8370 enterDisallowedContextReadInDEV();
8371 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8372 _payload2.call(instance, prevState, nextProps);
8373 }
8374 }
8375 partialState = _payload2.call(instance, prevState, nextProps);
8376 {
8377 exitDisallowedContextReadInDEV();
8378 }
8379 } else {
8380 // Partial state object
8381 partialState = _payload2;
8382 }
8383 if (partialState === null || partialState === undefined) {
8384 // Null and undefined are treated as no-ops.
8385 return prevState;
8386 }
8387 // Merge the partial state and the previous state.
8388 return _assign({}, prevState, partialState);
8389 }
8390 case ForceUpdate:
8391 {
8392 hasForceUpdate = true;
8393 return prevState;
8394 }
8395 }
8396 return prevState;
8397}
8398
8399function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
8400 hasForceUpdate = false;
8401
8402 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
8403
8404 {
8405 currentlyProcessingQueue = queue;
8406 }
8407
8408 // These values may change as we process the queue.
8409 var newBaseState = queue.baseState;
8410 var newFirstUpdate = null;
8411 var newExpirationTime = NoWork;
8412
8413 // Iterate through the list of updates to compute the result.
8414 var update = queue.firstUpdate;
8415 var resultState = newBaseState;
8416 while (update !== null) {
8417 var updateExpirationTime = update.expirationTime;
8418 if (updateExpirationTime < renderExpirationTime) {
8419 // This update does not have sufficient priority. Skip it.
8420 if (newFirstUpdate === null) {
8421 // This is the first skipped update. It will be the first update in
8422 // the new list.
8423 newFirstUpdate = update;
8424 // Since this is the first update that was skipped, the current result
8425 // is the new base state.
8426 newBaseState = resultState;
8427 }
8428 // Since this update will remain in the list, update the remaining
8429 // expiration time.
8430 if (newExpirationTime < updateExpirationTime) {
8431 newExpirationTime = updateExpirationTime;
8432 }
8433 } else {
8434 // This update does have sufficient priority. Process it and compute
8435 // a new result.
8436 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8437 var _callback = update.callback;
8438 if (_callback !== null) {
8439 workInProgress.effectTag |= Callback;
8440 // Set this to null, in case it was mutated during an aborted render.
8441 update.nextEffect = null;
8442 if (queue.lastEffect === null) {
8443 queue.firstEffect = queue.lastEffect = update;
8444 } else {
8445 queue.lastEffect.nextEffect = update;
8446 queue.lastEffect = update;
8447 }
8448 }
8449 }
8450 // Continue to the next update.
8451 update = update.next;
8452 }
8453
8454 // Separately, iterate though the list of captured updates.
8455 var newFirstCapturedUpdate = null;
8456 update = queue.firstCapturedUpdate;
8457 while (update !== null) {
8458 var _updateExpirationTime = update.expirationTime;
8459 if (_updateExpirationTime < renderExpirationTime) {
8460 // This update does not have sufficient priority. Skip it.
8461 if (newFirstCapturedUpdate === null) {
8462 // This is the first skipped captured update. It will be the first
8463 // update in the new list.
8464 newFirstCapturedUpdate = update;
8465 // If this is the first update that was skipped, the current result is
8466 // the new base state.
8467 if (newFirstUpdate === null) {
8468 newBaseState = resultState;
8469 }
8470 }
8471 // Since this update will remain in the list, update the remaining
8472 // expiration time.
8473 if (newExpirationTime < _updateExpirationTime) {
8474 newExpirationTime = _updateExpirationTime;
8475 }
8476 } else {
8477 // This update does have sufficient priority. Process it and compute
8478 // a new result.
8479 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
8480 var _callback2 = update.callback;
8481 if (_callback2 !== null) {
8482 workInProgress.effectTag |= Callback;
8483 // Set this to null, in case it was mutated during an aborted render.
8484 update.nextEffect = null;
8485 if (queue.lastCapturedEffect === null) {
8486 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
8487 } else {
8488 queue.lastCapturedEffect.nextEffect = update;
8489 queue.lastCapturedEffect = update;
8490 }
8491 }
8492 }
8493 update = update.next;
8494 }
8495
8496 if (newFirstUpdate === null) {
8497 queue.lastUpdate = null;
8498 }
8499 if (newFirstCapturedUpdate === null) {
8500 queue.lastCapturedUpdate = null;
8501 } else {
8502 workInProgress.effectTag |= Callback;
8503 }
8504 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
8505 // We processed every update, without skipping. That means the new base
8506 // state is the same as the result state.
8507 newBaseState = resultState;
8508 }
8509
8510 queue.baseState = newBaseState;
8511 queue.firstUpdate = newFirstUpdate;
8512 queue.firstCapturedUpdate = newFirstCapturedUpdate;
8513
8514 // Set the remaining expiration time to be whatever is remaining in the queue.
8515 // This should be fine because the only two other things that contribute to
8516 // expiration time are props and context. We're already in the middle of the
8517 // begin phase by the time we start processing the queue, so we've already
8518 // dealt with the props. Context in components that specify
8519 // shouldComponentUpdate is tricky; but we'll have to account for
8520 // that regardless.
8521 workInProgress.expirationTime = newExpirationTime;
8522 workInProgress.memoizedState = resultState;
8523
8524 {
8525 currentlyProcessingQueue = null;
8526 }
8527}
8528
8529function callCallback(callback, context) {
8530 !(typeof callback === 'function') ? invariant(false, 'Invalid argument passed as callback. Expected a function. Instead received: %s', callback) : void 0;
8531 callback.call(context);
8532}
8533
8534function resetHasForceUpdateBeforeProcessing() {
8535 hasForceUpdate = false;
8536}
8537
8538function checkHasForceUpdateAfterProcessing() {
8539 return hasForceUpdate;
8540}
8541
8542function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
8543 // If the finished render included captured updates, and there are still
8544 // lower priority updates left over, we need to keep the captured updates
8545 // in the queue so that they are rebased and not dropped once we process the
8546 // queue again at the lower priority.
8547 if (finishedQueue.firstCapturedUpdate !== null) {
8548 // Join the captured update list to the end of the normal list.
8549 if (finishedQueue.lastUpdate !== null) {
8550 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
8551 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
8552 }
8553 // Clear the list of captured updates.
8554 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
8555 }
8556
8557 // Commit the effects
8558 commitUpdateEffects(finishedQueue.firstEffect, instance);
8559 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
8560
8561 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
8562 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
8563}
8564
8565function commitUpdateEffects(effect, instance) {
8566 while (effect !== null) {
8567 var _callback3 = effect.callback;
8568 if (_callback3 !== null) {
8569 effect.callback = null;
8570 callCallback(_callback3, instance);
8571 }
8572 effect = effect.nextEffect;
8573 }
8574}
8575
8576function createCapturedValue(value, source) {
8577 // If the value is an error, call this function immediately after it is thrown
8578 // so the stack is accurate.
8579 return {
8580 value: value,
8581 source: source,
8582 stack: getStackByFiberInDevAndProd(source)
8583 };
8584}
8585
8586function markUpdate(workInProgress) {
8587 // Tag the fiber with an update effect. This turns a Placement into
8588 // a PlacementAndUpdate.
8589 workInProgress.effectTag |= Update;
8590}
8591
8592function markRef$1(workInProgress) {
8593 workInProgress.effectTag |= Ref;
8594}
8595
8596var appendAllChildren = void 0;
8597var updateHostContainer = void 0;
8598var updateHostComponent$1 = void 0;
8599var updateHostText$1 = void 0;
8600if (supportsMutation) {
8601 // Mutation mode
8602
8603 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8604 // We only have the top Fiber that was created but we need recurse down its
8605 // children to find all the terminal nodes.
8606 var node = workInProgress.child;
8607 while (node !== null) {
8608 if (node.tag === HostComponent || node.tag === HostText) {
8609 appendInitialChild(parent, node.stateNode);
8610 } else if (node.tag === HostPortal) {
8611 // If we have a portal child, then we don't want to traverse
8612 // down its children. Instead, we'll get insertions from each child in
8613 // the portal directly.
8614 } else if (node.child !== null) {
8615 node.child.return = node;
8616 node = node.child;
8617 continue;
8618 }
8619 if (node === workInProgress) {
8620 return;
8621 }
8622 while (node.sibling === null) {
8623 if (node.return === null || node.return === workInProgress) {
8624 return;
8625 }
8626 node = node.return;
8627 }
8628 node.sibling.return = node.return;
8629 node = node.sibling;
8630 }
8631 };
8632
8633 updateHostContainer = function (workInProgress) {
8634 // Noop
8635 };
8636 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8637 // If we have an alternate, that means this is an update and we need to
8638 // schedule a side-effect to do the updates.
8639 var oldProps = current.memoizedProps;
8640 if (oldProps === newProps) {
8641 // In mutation mode, this is sufficient for a bailout because
8642 // we won't touch this node even if children changed.
8643 return;
8644 }
8645
8646 // If we get updated because one of our children updated, we don't
8647 // have newProps so we'll have to reuse them.
8648 // TODO: Split the update API as separate for the props vs. children.
8649 // Even better would be if children weren't special cased at all tho.
8650 var instance = workInProgress.stateNode;
8651 var currentHostContext = getHostContext();
8652 // TODO: Experiencing an error where oldProps is null. Suggests a host
8653 // component is hitting the resume path. Figure out why. Possibly
8654 // related to `hidden`.
8655 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8656 // TODO: Type this specific to this type of component.
8657 workInProgress.updateQueue = updatePayload;
8658 // If the update payload indicates that there is a change or if there
8659 // is a new ref we mark this as an update. All the work is done in commitWork.
8660 if (updatePayload) {
8661 markUpdate(workInProgress);
8662 }
8663 };
8664 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8665 // If the text differs, mark it as an update. All the work in done in commitWork.
8666 if (oldText !== newText) {
8667 markUpdate(workInProgress);
8668 }
8669 };
8670} else if (supportsPersistence) {
8671 // Persistent host tree mode
8672
8673 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
8674 // We only have the top Fiber that was created but we need recurse down its
8675 // children to find all the terminal nodes.
8676 var node = workInProgress.child;
8677 while (node !== null) {
8678 // eslint-disable-next-line no-labels
8679 branches: if (node.tag === HostComponent) {
8680 var instance = node.stateNode;
8681 if (needsVisibilityToggle) {
8682 var props = node.memoizedProps;
8683 var type = node.type;
8684 if (isHidden) {
8685 // This child is inside a timed out tree. Hide it.
8686 instance = cloneHiddenInstance(instance, type, props, node);
8687 } else {
8688 // This child was previously inside a timed out tree. If it was not
8689 // updated during this render, it may need to be unhidden. Clone
8690 // again to be sure.
8691 instance = cloneUnhiddenInstance(instance, type, props, node);
8692 }
8693 node.stateNode = instance;
8694 }
8695 appendInitialChild(parent, instance);
8696 } else if (node.tag === HostText) {
8697 var _instance = node.stateNode;
8698 if (needsVisibilityToggle) {
8699 var text = node.memoizedProps;
8700 var rootContainerInstance = getRootHostContainer();
8701 var currentHostContext = getHostContext();
8702 if (isHidden) {
8703 _instance = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8704 } else {
8705 _instance = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8706 }
8707 node.stateNode = _instance;
8708 }
8709 appendInitialChild(parent, _instance);
8710 } else if (node.tag === HostPortal) {
8711 // If we have a portal child, then we don't want to traverse
8712 // down its children. Instead, we'll get insertions from each child in
8713 // the portal directly.
8714 } else if (node.tag === SuspenseComponent) {
8715 var current = node.alternate;
8716 if (current !== null) {
8717 var oldState = current.memoizedState;
8718 var newState = node.memoizedState;
8719 var oldIsHidden = oldState !== null;
8720 var newIsHidden = newState !== null;
8721 if (oldIsHidden !== newIsHidden) {
8722 // The placeholder either just timed out or switched back to the normal
8723 // children after having previously timed out. Toggle the visibility of
8724 // the direct host children.
8725 var primaryChildParent = newIsHidden ? node.child : node;
8726 if (primaryChildParent !== null) {
8727 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
8728 }
8729 // eslint-disable-next-line no-labels
8730 break branches;
8731 }
8732 }
8733 if (node.child !== null) {
8734 // Continue traversing like normal
8735 node.child.return = node;
8736 node = node.child;
8737 continue;
8738 }
8739 } else if (node.child !== null) {
8740 node.child.return = node;
8741 node = node.child;
8742 continue;
8743 }
8744 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8745 node = node;
8746 if (node === workInProgress) {
8747 return;
8748 }
8749 while (node.sibling === null) {
8750 if (node.return === null || node.return === workInProgress) {
8751 return;
8752 }
8753 node = node.return;
8754 }
8755 node.sibling.return = node.return;
8756 node = node.sibling;
8757 }
8758 };
8759
8760 // An unfortunate fork of appendAllChildren because we have two different parent types.
8761 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
8762 // We only have the top Fiber that was created but we need recurse down its
8763 // children to find all the terminal nodes.
8764 var node = workInProgress.child;
8765 while (node !== null) {
8766 // eslint-disable-next-line no-labels
8767 branches: if (node.tag === HostComponent) {
8768 var instance = node.stateNode;
8769 if (needsVisibilityToggle) {
8770 var props = node.memoizedProps;
8771 var type = node.type;
8772 if (isHidden) {
8773 // This child is inside a timed out tree. Hide it.
8774 instance = cloneHiddenInstance(instance, type, props, node);
8775 } else {
8776 // This child was previously inside a timed out tree. If it was not
8777 // updated during this render, it may need to be unhidden. Clone
8778 // again to be sure.
8779 instance = cloneUnhiddenInstance(instance, type, props, node);
8780 }
8781 node.stateNode = instance;
8782 }
8783 appendChildToContainerChildSet(containerChildSet, instance);
8784 } else if (node.tag === HostText) {
8785 var _instance2 = node.stateNode;
8786 if (needsVisibilityToggle) {
8787 var text = node.memoizedProps;
8788 var rootContainerInstance = getRootHostContainer();
8789 var currentHostContext = getHostContext();
8790 if (isHidden) {
8791 _instance2 = createHiddenTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8792 } else {
8793 _instance2 = createTextInstance(text, rootContainerInstance, currentHostContext, workInProgress);
8794 }
8795 node.stateNode = _instance2;
8796 }
8797 appendChildToContainerChildSet(containerChildSet, _instance2);
8798 } else if (node.tag === HostPortal) {
8799 // If we have a portal child, then we don't want to traverse
8800 // down its children. Instead, we'll get insertions from each child in
8801 // the portal directly.
8802 } else if (node.tag === SuspenseComponent) {
8803 var current = node.alternate;
8804 if (current !== null) {
8805 var oldState = current.memoizedState;
8806 var newState = node.memoizedState;
8807 var oldIsHidden = oldState !== null;
8808 var newIsHidden = newState !== null;
8809 if (oldIsHidden !== newIsHidden) {
8810 // The placeholder either just timed out or switched back to the normal
8811 // children after having previously timed out. Toggle the visibility of
8812 // the direct host children.
8813 var primaryChildParent = newIsHidden ? node.child : node;
8814 if (primaryChildParent !== null) {
8815 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
8816 }
8817 // eslint-disable-next-line no-labels
8818 break branches;
8819 }
8820 }
8821 if (node.child !== null) {
8822 // Continue traversing like normal
8823 node.child.return = node;
8824 node = node.child;
8825 continue;
8826 }
8827 } else if (node.child !== null) {
8828 node.child.return = node;
8829 node = node.child;
8830 continue;
8831 }
8832 // $FlowFixMe This is correct but Flow is confused by the labeled break.
8833 node = node;
8834 if (node === workInProgress) {
8835 return;
8836 }
8837 while (node.sibling === null) {
8838 if (node.return === null || node.return === workInProgress) {
8839 return;
8840 }
8841 node = node.return;
8842 }
8843 node.sibling.return = node.return;
8844 node = node.sibling;
8845 }
8846 };
8847 updateHostContainer = function (workInProgress) {
8848 var portalOrRoot = workInProgress.stateNode;
8849 var childrenUnchanged = workInProgress.firstEffect === null;
8850 if (childrenUnchanged) {
8851 // No changes, just reuse the existing instance.
8852 } else {
8853 var container = portalOrRoot.containerInfo;
8854 var newChildSet = createContainerChildSet(container);
8855 // If children might have changed, we have to add them all to the set.
8856 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
8857 portalOrRoot.pendingChildren = newChildSet;
8858 // Schedule an update on the container to swap out the container.
8859 markUpdate(workInProgress);
8860 finalizeContainerChildren(container, newChildSet);
8861 }
8862 };
8863 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8864 var currentInstance = current.stateNode;
8865 var oldProps = current.memoizedProps;
8866 // If there are no effects associated with this node, then none of our children had any updates.
8867 // This guarantees that we can reuse all of them.
8868 var childrenUnchanged = workInProgress.firstEffect === null;
8869 if (childrenUnchanged && oldProps === newProps) {
8870 // No changes, just reuse the existing instance.
8871 // Note that this might release a previous clone.
8872 workInProgress.stateNode = currentInstance;
8873 return;
8874 }
8875 var recyclableInstance = workInProgress.stateNode;
8876 var currentHostContext = getHostContext();
8877 var updatePayload = null;
8878 if (oldProps !== newProps) {
8879 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
8880 }
8881 if (childrenUnchanged && updatePayload === null) {
8882 // No changes, just reuse the existing instance.
8883 // Note that this might release a previous clone.
8884 workInProgress.stateNode = currentInstance;
8885 return;
8886 }
8887 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
8888 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
8889 markUpdate(workInProgress);
8890 }
8891 workInProgress.stateNode = newInstance;
8892 if (childrenUnchanged) {
8893 // If there are no other effects in this tree, we need to flag this node as having one.
8894 // Even though we're not going to use it for anything.
8895 // Otherwise parents won't know that there are new children to propagate upwards.
8896 markUpdate(workInProgress);
8897 } else {
8898 // If children might have changed, we have to add them all to the set.
8899 appendAllChildren(newInstance, workInProgress, false, false);
8900 }
8901 };
8902 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8903 if (oldText !== newText) {
8904 // If the text content differs, we'll create a new text instance for it.
8905 var rootContainerInstance = getRootHostContainer();
8906 var currentHostContext = getHostContext();
8907 workInProgress.stateNode = createTextInstance(newText, rootContainerInstance, currentHostContext, workInProgress);
8908 // We'll have to mark it as having an effect, even though we won't use the effect for anything.
8909 // This lets the parents know that at least one of their children has changed.
8910 markUpdate(workInProgress);
8911 }
8912 };
8913} else {
8914 // No host operations
8915 updateHostContainer = function (workInProgress) {
8916 // Noop
8917 };
8918 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
8919 // Noop
8920 };
8921 updateHostText$1 = function (current, workInProgress, oldText, newText) {
8922 // Noop
8923 };
8924}
8925
8926function completeWork(current, workInProgress, renderExpirationTime) {
8927 var newProps = workInProgress.pendingProps;
8928
8929 switch (workInProgress.tag) {
8930 case IndeterminateComponent:
8931 break;
8932 case LazyComponent:
8933 break;
8934 case SimpleMemoComponent:
8935 case FunctionComponent:
8936 break;
8937 case ClassComponent:
8938 {
8939 var Component = workInProgress.type;
8940 if (isContextProvider(Component)) {
8941 popContext(workInProgress);
8942 }
8943 break;
8944 }
8945 case HostRoot:
8946 {
8947 popHostContainer(workInProgress);
8948 popTopLevelContextObject(workInProgress);
8949 var fiberRoot = workInProgress.stateNode;
8950 if (fiberRoot.pendingContext) {
8951 fiberRoot.context = fiberRoot.pendingContext;
8952 fiberRoot.pendingContext = null;
8953 }
8954 if (current === null || current.child === null) {
8955 // If we hydrated, pop so that we can delete any remaining children
8956 // that weren't hydrated.
8957 popHydrationState(workInProgress);
8958 // This resets the hacky state to fix isMounted before committing.
8959 // TODO: Delete this when we delete isMounted and findDOMNode.
8960 workInProgress.effectTag &= ~Placement;
8961 }
8962 updateHostContainer(workInProgress);
8963 break;
8964 }
8965 case HostComponent:
8966 {
8967 popHostContext(workInProgress);
8968 var rootContainerInstance = getRootHostContainer();
8969 var type = workInProgress.type;
8970 if (current !== null && workInProgress.stateNode != null) {
8971 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
8972
8973 if (current.ref !== workInProgress.ref) {
8974 markRef$1(workInProgress);
8975 }
8976 } else {
8977 if (!newProps) {
8978 !(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;
8979 // This can happen when we abort work.
8980 break;
8981 }
8982
8983 var currentHostContext = getHostContext();
8984 // TODO: Move createInstance to beginWork and keep it on a context
8985 // "stack" as the parent. Then append children as we go in beginWork
8986 // or completeWork depending on we want to add then top->down or
8987 // bottom->up. Top->down is faster in IE11.
8988 var wasHydrated = popHydrationState(workInProgress);
8989 if (wasHydrated) {
8990 // TODO: Move this and createInstance step into the beginPhase
8991 // to consolidate.
8992 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
8993 // If changes to the hydrated node needs to be applied at the
8994 // commit-phase we mark this as such.
8995 markUpdate(workInProgress);
8996 }
8997 } else {
8998 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
8999
9000 appendAllChildren(instance, workInProgress, false, false);
9001
9002 // Certain renderers require commit-time effects for initial mount.
9003 // (eg DOM renderer supports auto-focus for certain elements).
9004 // Make sure such renderers get scheduled for later work.
9005 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
9006 markUpdate(workInProgress);
9007 }
9008 workInProgress.stateNode = instance;
9009 }
9010
9011 if (workInProgress.ref !== null) {
9012 // If there is a ref on a host node we need to schedule a callback
9013 markRef$1(workInProgress);
9014 }
9015 }
9016 break;
9017 }
9018 case HostText:
9019 {
9020 var newText = newProps;
9021 if (current && workInProgress.stateNode != null) {
9022 var oldText = current.memoizedProps;
9023 // If we have an alternate, that means this is an update and we need
9024 // to schedule a side-effect to do the updates.
9025 updateHostText$1(current, workInProgress, oldText, newText);
9026 } else {
9027 if (typeof newText !== 'string') {
9028 !(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;
9029 // This can happen when we abort work.
9030 }
9031 var _rootContainerInstance = getRootHostContainer();
9032 var _currentHostContext = getHostContext();
9033 var _wasHydrated = popHydrationState(workInProgress);
9034 if (_wasHydrated) {
9035 if (prepareToHydrateHostTextInstance(workInProgress)) {
9036 markUpdate(workInProgress);
9037 }
9038 } else {
9039 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
9040 }
9041 }
9042 break;
9043 }
9044 case ForwardRef:
9045 break;
9046 case SuspenseComponent:
9047 {
9048 var nextState = workInProgress.memoizedState;
9049 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
9050 // Something suspended. Re-render with the fallback children.
9051 workInProgress.expirationTime = renderExpirationTime;
9052 // Do not reset the effect list.
9053 return workInProgress;
9054 }
9055
9056 var nextDidTimeout = nextState !== null;
9057 var prevDidTimeout = current !== null && current.memoizedState !== null;
9058
9059 if (current !== null && !nextDidTimeout && prevDidTimeout) {
9060 // We just switched from the fallback to the normal children. Delete
9061 // the fallback.
9062 // TODO: Would it be better to store the fallback fragment on
9063 var currentFallbackChild = current.child.sibling;
9064 if (currentFallbackChild !== null) {
9065 // Deletions go at the beginning of the return fiber's effect list
9066 var first = workInProgress.firstEffect;
9067 if (first !== null) {
9068 workInProgress.firstEffect = currentFallbackChild;
9069 currentFallbackChild.nextEffect = first;
9070 } else {
9071 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
9072 currentFallbackChild.nextEffect = null;
9073 }
9074 currentFallbackChild.effectTag = Deletion;
9075 }
9076 }
9077
9078 if (nextDidTimeout || prevDidTimeout) {
9079 // If the children are hidden, or if they were previous hidden, schedule
9080 // an effect to toggle their visibility. This is also used to attach a
9081 // retry listener to the promise.
9082 workInProgress.effectTag |= Update;
9083 }
9084 break;
9085 }
9086 case Fragment:
9087 break;
9088 case Mode:
9089 break;
9090 case Profiler:
9091 break;
9092 case HostPortal:
9093 popHostContainer(workInProgress);
9094 updateHostContainer(workInProgress);
9095 break;
9096 case ContextProvider:
9097 // Pop provider fiber
9098 popProvider(workInProgress);
9099 break;
9100 case ContextConsumer:
9101 break;
9102 case MemoComponent:
9103 break;
9104 case IncompleteClassComponent:
9105 {
9106 // Same as class component case. I put it down here so that the tags are
9107 // sequential to ensure this switch is compiled to a jump table.
9108 var _Component = workInProgress.type;
9109 if (isContextProvider(_Component)) {
9110 popContext(workInProgress);
9111 }
9112 break;
9113 }
9114 case DehydratedSuspenseComponent:
9115 {
9116 if (enableSuspenseServerRenderer) {
9117 if (current === null) {
9118 var _wasHydrated2 = popHydrationState(workInProgress);
9119 !_wasHydrated2 ? invariant(false, 'A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React.') : void 0;
9120 skipPastDehydratedSuspenseInstance(workInProgress);
9121 } else if ((workInProgress.effectTag & DidCapture) === NoEffect) {
9122 // This boundary did not suspend so it's now hydrated.
9123 // To handle any future suspense cases, we're going to now upgrade it
9124 // to a Suspense component. We detach it from the existing current fiber.
9125 current.alternate = null;
9126 workInProgress.alternate = null;
9127 workInProgress.tag = SuspenseComponent;
9128 workInProgress.memoizedState = null;
9129 workInProgress.stateNode = null;
9130 }
9131 }
9132 break;
9133 }
9134 default:
9135 invariant(false, 'Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue.');
9136 }
9137
9138 return null;
9139}
9140
9141function shouldCaptureSuspense(workInProgress) {
9142 // In order to capture, the Suspense component must have a fallback prop.
9143 if (workInProgress.memoizedProps.fallback === undefined) {
9144 return false;
9145 }
9146 // If it was the primary children that just suspended, capture and render the
9147 // fallback. Otherwise, don't capture and bubble to the next boundary.
9148 var nextState = workInProgress.memoizedState;
9149 return nextState === null;
9150}
9151
9152// This module is forked in different environments.
9153// By default, return `true` to log errors to the console.
9154// Forks can return `false` if this isn't desirable.
9155function showErrorDialog(capturedError) {
9156 return true;
9157}
9158
9159function logCapturedError(capturedError) {
9160 var logError = showErrorDialog(capturedError);
9161
9162 // Allow injected showErrorDialog() to prevent default console.error logging.
9163 // This enables renderers like ReactNative to better manage redbox behavior.
9164 if (logError === false) {
9165 return;
9166 }
9167
9168 var error = capturedError.error;
9169 {
9170 var componentName = capturedError.componentName,
9171 componentStack = capturedError.componentStack,
9172 errorBoundaryName = capturedError.errorBoundaryName,
9173 errorBoundaryFound = capturedError.errorBoundaryFound,
9174 willRetry = capturedError.willRetry;
9175
9176 // Browsers support silencing uncaught errors by calling
9177 // `preventDefault()` in window `error` handler.
9178 // We record this information as an expando on the error.
9179
9180 if (error != null && error._suppressLogging) {
9181 if (errorBoundaryFound && willRetry) {
9182 // The error is recoverable and was silenced.
9183 // Ignore it and don't print the stack addendum.
9184 // This is handy for testing error boundaries without noise.
9185 return;
9186 }
9187 // The error is fatal. Since the silencing might have
9188 // been accidental, we'll surface it anyway.
9189 // However, the browser would have silenced the original error
9190 // so we'll print it first, and then print the stack addendum.
9191 console.error(error);
9192 // For a more detailed description of this block, see:
9193 // https://github.com/facebook/react/pull/13384
9194 }
9195
9196 var componentNameMessage = componentName ? 'The above error occurred in the <' + componentName + '> component:' : 'The above error occurred in one of your React components:';
9197
9198 var errorBoundaryMessage = void 0;
9199 // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
9200 if (errorBoundaryFound && errorBoundaryName) {
9201 if (willRetry) {
9202 errorBoundaryMessage = 'React will try to recreate this component tree from scratch ' + ('using the error boundary you provided, ' + errorBoundaryName + '.');
9203 } else {
9204 errorBoundaryMessage = 'This error was initially handled by the error boundary ' + errorBoundaryName + '.\n' + 'Recreating the tree from scratch failed so React will unmount the tree.';
9205 }
9206 } else {
9207 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.';
9208 }
9209 var combinedMessage = '' + componentNameMessage + componentStack + '\n\n' + ('' + errorBoundaryMessage);
9210
9211 // In development, we provide our own message with just the component stack.
9212 // We don't include the original error message and JS stack because the browser
9213 // has already printed it. Even if the application swallows the error, it is still
9214 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
9215 console.error(combinedMessage);
9216 }
9217}
9218
9219var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
9220{
9221 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
9222}
9223
9224var PossiblyWeakSet$1 = typeof WeakSet === 'function' ? WeakSet : Set;
9225
9226function logError(boundary, errorInfo) {
9227 var source = errorInfo.source;
9228 var stack = errorInfo.stack;
9229 if (stack === null && source !== null) {
9230 stack = getStackByFiberInDevAndProd(source);
9231 }
9232
9233 var capturedError = {
9234 componentName: source !== null ? getComponentName(source.type) : null,
9235 componentStack: stack !== null ? stack : '',
9236 error: errorInfo.value,
9237 errorBoundary: null,
9238 errorBoundaryName: null,
9239 errorBoundaryFound: false,
9240 willRetry: false
9241 };
9242
9243 if (boundary !== null && boundary.tag === ClassComponent) {
9244 capturedError.errorBoundary = boundary.stateNode;
9245 capturedError.errorBoundaryName = getComponentName(boundary.type);
9246 capturedError.errorBoundaryFound = true;
9247 capturedError.willRetry = true;
9248 }
9249
9250 try {
9251 logCapturedError(capturedError);
9252 } catch (e) {
9253 // This method must not throw, or React internal state will get messed up.
9254 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
9255 // we want to report this error outside of the normal stack as a last resort.
9256 // https://github.com/facebook/react/issues/13188
9257 setTimeout(function () {
9258 throw e;
9259 });
9260 }
9261}
9262
9263var callComponentWillUnmountWithTimer = function (current$$1, instance) {
9264 startPhaseTimer(current$$1, 'componentWillUnmount');
9265 instance.props = current$$1.memoizedProps;
9266 instance.state = current$$1.memoizedState;
9267 instance.componentWillUnmount();
9268 stopPhaseTimer();
9269};
9270
9271// Capture errors so they don't interrupt unmounting.
9272function safelyCallComponentWillUnmount(current$$1, instance) {
9273 {
9274 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
9275 if (hasCaughtError()) {
9276 var unmountError = clearCaughtError();
9277 captureCommitPhaseError(current$$1, unmountError);
9278 }
9279 }
9280}
9281
9282function safelyDetachRef(current$$1) {
9283 var ref = current$$1.ref;
9284 if (ref !== null) {
9285 if (typeof ref === 'function') {
9286 {
9287 invokeGuardedCallback(null, ref, null, null);
9288 if (hasCaughtError()) {
9289 var refError = clearCaughtError();
9290 captureCommitPhaseError(current$$1, refError);
9291 }
9292 }
9293 } else {
9294 ref.current = null;
9295 }
9296 }
9297}
9298
9299function safelyCallDestroy(current$$1, destroy) {
9300 {
9301 invokeGuardedCallback(null, destroy, null);
9302 if (hasCaughtError()) {
9303 var error = clearCaughtError();
9304 captureCommitPhaseError(current$$1, error);
9305 }
9306 }
9307}
9308
9309function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
9310 switch (finishedWork.tag) {
9311 case FunctionComponent:
9312 case ForwardRef:
9313 case SimpleMemoComponent:
9314 {
9315 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
9316 return;
9317 }
9318 case ClassComponent:
9319 {
9320 if (finishedWork.effectTag & Snapshot) {
9321 if (current$$1 !== null) {
9322 var prevProps = current$$1.memoizedProps;
9323 var prevState = current$$1.memoizedState;
9324 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
9325 var instance = finishedWork.stateNode;
9326 // We could update instance props and state here,
9327 // but instead we rely on them being set during last render.
9328 // TODO: revisit this when we implement resuming.
9329 {
9330 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9331 !(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;
9332 !(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;
9333 }
9334 }
9335 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
9336 {
9337 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
9338 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
9339 didWarnSet.add(finishedWork.type);
9340 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
9341 }
9342 }
9343 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
9344 stopPhaseTimer();
9345 }
9346 }
9347 return;
9348 }
9349 case HostRoot:
9350 case HostComponent:
9351 case HostText:
9352 case HostPortal:
9353 case IncompleteClassComponent:
9354 // Nothing to do for these component types
9355 return;
9356 default:
9357 {
9358 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.');
9359 }
9360 }
9361}
9362
9363function commitHookEffectList(unmountTag, mountTag, finishedWork) {
9364 var updateQueue = finishedWork.updateQueue;
9365 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
9366 if (lastEffect !== null) {
9367 var firstEffect = lastEffect.next;
9368 var effect = firstEffect;
9369 do {
9370 if ((effect.tag & unmountTag) !== NoEffect$1) {
9371 // Unmount
9372 var destroy = effect.destroy;
9373 effect.destroy = undefined;
9374 if (destroy !== undefined) {
9375 destroy();
9376 }
9377 }
9378 if ((effect.tag & mountTag) !== NoEffect$1) {
9379 // Mount
9380 var create = effect.create;
9381 effect.destroy = create();
9382
9383 {
9384 var _destroy = effect.destroy;
9385 if (_destroy !== undefined && typeof _destroy !== 'function') {
9386 var addendum = void 0;
9387 if (_destroy === null) {
9388 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
9389 } else if (typeof _destroy.then === 'function') {
9390 addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + '}, [someId]); // Or [] if effect doesn\'t need props or state\n\n' + 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching';
9391 } else {
9392 addendum = ' You returned: ' + _destroy;
9393 }
9394 warningWithoutStack$1(false, 'An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
9395 }
9396 }
9397 }
9398 effect = effect.next;
9399 } while (effect !== firstEffect);
9400 }
9401}
9402
9403function commitPassiveHookEffects(finishedWork) {
9404 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
9405 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
9406}
9407
9408function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
9409 switch (finishedWork.tag) {
9410 case FunctionComponent:
9411 case ForwardRef:
9412 case SimpleMemoComponent:
9413 {
9414 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
9415 break;
9416 }
9417 case ClassComponent:
9418 {
9419 var instance = finishedWork.stateNode;
9420 if (finishedWork.effectTag & Update) {
9421 if (current$$1 === null) {
9422 startPhaseTimer(finishedWork, 'componentDidMount');
9423 // We could update instance props and state here,
9424 // but instead we rely on them being set during last render.
9425 // TODO: revisit this when we implement resuming.
9426 {
9427 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9428 !(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;
9429 !(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;
9430 }
9431 }
9432 instance.componentDidMount();
9433 stopPhaseTimer();
9434 } else {
9435 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
9436 var prevState = current$$1.memoizedState;
9437 startPhaseTimer(finishedWork, 'componentDidUpdate');
9438 // We could update instance props and state here,
9439 // but instead we rely on them being set during last render.
9440 // TODO: revisit this when we implement resuming.
9441 {
9442 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9443 !(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;
9444 !(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;
9445 }
9446 }
9447 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
9448 stopPhaseTimer();
9449 }
9450 }
9451 var updateQueue = finishedWork.updateQueue;
9452 if (updateQueue !== null) {
9453 {
9454 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
9455 !(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;
9456 !(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;
9457 }
9458 }
9459 // We could update instance props and state here,
9460 // but instead we rely on them being set during last render.
9461 // TODO: revisit this when we implement resuming.
9462 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
9463 }
9464 return;
9465 }
9466 case HostRoot:
9467 {
9468 var _updateQueue = finishedWork.updateQueue;
9469 if (_updateQueue !== null) {
9470 var _instance = null;
9471 if (finishedWork.child !== null) {
9472 switch (finishedWork.child.tag) {
9473 case HostComponent:
9474 _instance = getPublicInstance(finishedWork.child.stateNode);
9475 break;
9476 case ClassComponent:
9477 _instance = finishedWork.child.stateNode;
9478 break;
9479 }
9480 }
9481 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
9482 }
9483 return;
9484 }
9485 case HostComponent:
9486 {
9487 var _instance2 = finishedWork.stateNode;
9488
9489 // Renderers may schedule work to be done after host components are mounted
9490 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
9491 // These effects should only be committed when components are first mounted,
9492 // aka when there is no current/alternate.
9493 if (current$$1 === null && finishedWork.effectTag & Update) {
9494 var type = finishedWork.type;
9495 var props = finishedWork.memoizedProps;
9496
9497 }
9498
9499 return;
9500 }
9501 case HostText:
9502 {
9503 // We have no life-cycles associated with text.
9504 return;
9505 }
9506 case HostPortal:
9507 {
9508 // We have no life-cycles associated with portals.
9509 return;
9510 }
9511 case Profiler:
9512 {
9513 if (enableProfilerTimer) {
9514 var onRender = finishedWork.memoizedProps.onRender;
9515
9516 if (enableSchedulerTracing) {
9517 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
9518 } else {
9519 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
9520 }
9521 }
9522 return;
9523 }
9524 case SuspenseComponent:
9525 break;
9526 case IncompleteClassComponent:
9527 break;
9528 default:
9529 {
9530 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.');
9531 }
9532 }
9533}
9534
9535function hideOrUnhideAllChildren(finishedWork, isHidden) {
9536 if (supportsMutation) {
9537 // We only have the top Fiber that was inserted but we need to recurse down its
9538 var node = finishedWork;
9539 while (true) {
9540 if (node.tag === HostComponent) {
9541 var instance = node.stateNode;
9542 if (isHidden) {
9543 hideInstance(instance);
9544 } else {
9545 unhideInstance(node.stateNode, node.memoizedProps);
9546 }
9547 } else if (node.tag === HostText) {
9548 var _instance3 = node.stateNode;
9549 if (isHidden) {
9550 hideTextInstance(_instance3);
9551 } else {
9552 unhideTextInstance(_instance3, node.memoizedProps);
9553 }
9554 } else if (node.tag === SuspenseComponent && node.memoizedState !== null) {
9555 // Found a nested Suspense component that timed out. Skip over the
9556 var fallbackChildFragment = node.child.sibling;
9557 fallbackChildFragment.return = node;
9558 node = fallbackChildFragment;
9559 continue;
9560 } else if (node.child !== null) {
9561 node.child.return = node;
9562 node = node.child;
9563 continue;
9564 }
9565 if (node === finishedWork) {
9566 return;
9567 }
9568 while (node.sibling === null) {
9569 if (node.return === null || node.return === finishedWork) {
9570 return;
9571 }
9572 node = node.return;
9573 }
9574 node.sibling.return = node.return;
9575 node = node.sibling;
9576 }
9577 }
9578}
9579
9580function commitAttachRef(finishedWork) {
9581 var ref = finishedWork.ref;
9582 if (ref !== null) {
9583 var instance = finishedWork.stateNode;
9584 var instanceToUse = void 0;
9585 switch (finishedWork.tag) {
9586 case HostComponent:
9587 instanceToUse = getPublicInstance(instance);
9588 break;
9589 default:
9590 instanceToUse = instance;
9591 }
9592 if (typeof ref === 'function') {
9593 ref(instanceToUse);
9594 } else {
9595 {
9596 if (!ref.hasOwnProperty('current')) {
9597 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
9598 }
9599 }
9600
9601 ref.current = instanceToUse;
9602 }
9603 }
9604}
9605
9606function commitDetachRef(current$$1) {
9607 var currentRef = current$$1.ref;
9608 if (currentRef !== null) {
9609 if (typeof currentRef === 'function') {
9610 currentRef(null);
9611 } else {
9612 currentRef.current = null;
9613 }
9614 }
9615}
9616
9617// User-originating errors (lifecycles and refs) should not interrupt
9618// deletion, so don't let them throw. Host-originating errors should
9619// interrupt deletion, so it's okay
9620function commitUnmount(current$$1) {
9621 onCommitUnmount(current$$1);
9622
9623 switch (current$$1.tag) {
9624 case FunctionComponent:
9625 case ForwardRef:
9626 case MemoComponent:
9627 case SimpleMemoComponent:
9628 {
9629 var updateQueue = current$$1.updateQueue;
9630 if (updateQueue !== null) {
9631 var lastEffect = updateQueue.lastEffect;
9632 if (lastEffect !== null) {
9633 var firstEffect = lastEffect.next;
9634 var effect = firstEffect;
9635 do {
9636 var destroy = effect.destroy;
9637 if (destroy !== undefined) {
9638 safelyCallDestroy(current$$1, destroy);
9639 }
9640 effect = effect.next;
9641 } while (effect !== firstEffect);
9642 }
9643 }
9644 break;
9645 }
9646 case ClassComponent:
9647 {
9648 safelyDetachRef(current$$1);
9649 var instance = current$$1.stateNode;
9650 if (typeof instance.componentWillUnmount === 'function') {
9651 safelyCallComponentWillUnmount(current$$1, instance);
9652 }
9653 return;
9654 }
9655 case HostComponent:
9656 {
9657 safelyDetachRef(current$$1);
9658 return;
9659 }
9660 case HostPortal:
9661 {
9662 // TODO: this is recursive.
9663 // We are also not using this parent because
9664 // the portal will get pushed immediately.
9665 if (supportsMutation) {
9666 unmountHostComponents(current$$1);
9667 } else if (supportsPersistence) {
9668 emptyPortalContainer(current$$1);
9669 }
9670 return;
9671 }
9672 }
9673}
9674
9675function commitNestedUnmounts(root) {
9676 // While we're inside a removed host node we don't want to call
9677 // removeChild on the inner nodes because they're removed by the top
9678 // call anyway. We also want to call componentWillUnmount on all
9679 // composites before this host node is removed from the tree. Therefore
9680 var node = root;
9681 while (true) {
9682 commitUnmount(node);
9683 // Visit children because they may contain more composite or host nodes.
9684 // Skip portals because commitUnmount() currently visits them recursively.
9685 if (node.child !== null && (
9686 // If we use mutation we drill down into portals using commitUnmount above.
9687 // If we don't use mutation we drill down into portals here instead.
9688 !supportsMutation || node.tag !== HostPortal)) {
9689 node.child.return = node;
9690 node = node.child;
9691 continue;
9692 }
9693 if (node === root) {
9694 return;
9695 }
9696 while (node.sibling === null) {
9697 if (node.return === null || node.return === root) {
9698 return;
9699 }
9700 node = node.return;
9701 }
9702 node.sibling.return = node.return;
9703 node = node.sibling;
9704 }
9705}
9706
9707function detachFiber(current$$1) {
9708 // Cut off the return pointers to disconnect it from the tree. Ideally, we
9709 // should clear the child pointer of the parent alternate to let this
9710 // get GC:ed but we don't know which for sure which parent is the current
9711 // one so we'll settle for GC:ing the subtree of this child. This child
9712 // itself will be GC:ed when the parent updates the next time.
9713 current$$1.return = null;
9714 current$$1.child = null;
9715 current$$1.memoizedState = null;
9716 current$$1.updateQueue = null;
9717 var alternate = current$$1.alternate;
9718 if (alternate !== null) {
9719 alternate.return = null;
9720 alternate.child = null;
9721 alternate.memoizedState = null;
9722 alternate.updateQueue = null;
9723 }
9724}
9725
9726function emptyPortalContainer(current$$1) {
9727 if (!supportsPersistence) {
9728 return;
9729 }
9730
9731 var portal = current$$1.stateNode;
9732 var containerInfo = portal.containerInfo;
9733
9734 var emptyChildSet = createContainerChildSet(containerInfo);
9735 replaceContainerChildren(containerInfo, emptyChildSet);
9736}
9737
9738function commitContainer(finishedWork) {
9739 if (!supportsPersistence) {
9740 return;
9741 }
9742
9743 switch (finishedWork.tag) {
9744 case ClassComponent:
9745 {
9746 return;
9747 }
9748 case HostComponent:
9749 {
9750 return;
9751 }
9752 case HostText:
9753 {
9754 return;
9755 }
9756 case HostRoot:
9757 case HostPortal:
9758 {
9759 var portalOrRoot = finishedWork.stateNode;
9760 var containerInfo = portalOrRoot.containerInfo,
9761 _pendingChildren = portalOrRoot.pendingChildren;
9762
9763 replaceContainerChildren(containerInfo, _pendingChildren);
9764 return;
9765 }
9766 default:
9767 {
9768 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.');
9769 }
9770 }
9771}
9772
9773function getHostParentFiber(fiber) {
9774 var parent = fiber.return;
9775 while (parent !== null) {
9776 if (isHostParent(parent)) {
9777 return parent;
9778 }
9779 parent = parent.return;
9780 }
9781 invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.');
9782}
9783
9784function isHostParent(fiber) {
9785 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
9786}
9787
9788function getHostSibling(fiber) {
9789 // We're going to search forward into the tree until we find a sibling host
9790 // node. Unfortunately, if multiple insertions are done in a row we have to
9791 // search past them. This leads to exponential search for the next sibling.
9792 var node = fiber;
9793 siblings: while (true) {
9794 // If we didn't find anything, let's try the next sibling.
9795 while (node.sibling === null) {
9796 if (node.return === null || isHostParent(node.return)) {
9797 // If we pop out of the root or hit the parent the fiber we are the
9798 // last sibling.
9799 return null;
9800 }
9801 node = node.return;
9802 }
9803 node.sibling.return = node.return;
9804 node = node.sibling;
9805 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedSuspenseComponent) {
9806 // If it is not host node and, we might have a host node inside it.
9807 // Try to search down until we find one.
9808 if (node.effectTag & Placement) {
9809 // If we don't have a child, try the siblings instead.
9810 continue siblings;
9811 }
9812 // If we don't have a child, try the siblings instead.
9813 // We also skip portals because they are not part of this host tree.
9814 if (node.child === null || node.tag === HostPortal) {
9815 continue siblings;
9816 } else {
9817 node.child.return = node;
9818 node = node.child;
9819 }
9820 }
9821 // Check if this host node is stable or about to be placed.
9822 if (!(node.effectTag & Placement)) {
9823 // Found it!
9824 return node.stateNode;
9825 }
9826 }
9827}
9828
9829function commitPlacement(finishedWork) {
9830 if (!supportsMutation) {
9831 return;
9832 }
9833
9834 // Recursively insert all host nodes into the parent.
9835 var parentFiber = getHostParentFiber(finishedWork);
9836
9837 // Note: these two variables *must* always be updated together.
9838 var parent = void 0;
9839 var isContainer = void 0;
9840
9841 switch (parentFiber.tag) {
9842 case HostComponent:
9843 parent = parentFiber.stateNode;
9844 isContainer = false;
9845 break;
9846 case HostRoot:
9847 parent = parentFiber.stateNode.containerInfo;
9848 isContainer = true;
9849 break;
9850 case HostPortal:
9851 parent = parentFiber.stateNode.containerInfo;
9852 isContainer = true;
9853 break;
9854 default:
9855 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
9856 }
9857 if (parentFiber.effectTag & ContentReset) {
9858 // Reset the text content of the parent before doing any insertions
9859 parentFiber.effectTag &= ~ContentReset;
9860 }
9861
9862 var before = getHostSibling(finishedWork);
9863 // We only have the top Fiber that was inserted but we need to recurse down its
9864 // children to find all the terminal nodes.
9865 var node = finishedWork;
9866 while (true) {
9867 if (node.tag === HostComponent || node.tag === HostText) {
9868 if (before) {
9869 if (isContainer) {
9870 insertInContainerBefore(parent, node.stateNode, before);
9871 } else {
9872 insertBefore(parent, node.stateNode, before);
9873 }
9874 } else {
9875 if (isContainer) {
9876 appendChildToContainer(parent, node.stateNode);
9877 } else {
9878 appendChild(parent, node.stateNode);
9879 }
9880 }
9881 } else if (node.tag === HostPortal) {
9882 // If the insertion itself is a portal, then we don't want to traverse
9883 // down its children. Instead, we'll get insertions from each child in
9884 // the portal directly.
9885 } else if (node.child !== null) {
9886 node.child.return = node;
9887 node = node.child;
9888 continue;
9889 }
9890 if (node === finishedWork) {
9891 return;
9892 }
9893 while (node.sibling === null) {
9894 if (node.return === null || node.return === finishedWork) {
9895 return;
9896 }
9897 node = node.return;
9898 }
9899 node.sibling.return = node.return;
9900 node = node.sibling;
9901 }
9902}
9903
9904function unmountHostComponents(current$$1) {
9905 // We only have the top Fiber that was deleted but we need to recurse down its
9906 var node = current$$1;
9907
9908 // Each iteration, currentParent is populated with node's host parent if not
9909 // currentParentIsValid.
9910 var currentParentIsValid = false;
9911
9912 // Note: these two variables *must* always be updated together.
9913 var currentParent = void 0;
9914 var currentParentIsContainer = void 0;
9915
9916 while (true) {
9917 if (!currentParentIsValid) {
9918 var parent = node.return;
9919 findParent: while (true) {
9920 !(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;
9921 switch (parent.tag) {
9922 case HostComponent:
9923 currentParent = parent.stateNode;
9924 currentParentIsContainer = false;
9925 break findParent;
9926 case HostRoot:
9927 currentParent = parent.stateNode.containerInfo;
9928 currentParentIsContainer = true;
9929 break findParent;
9930 case HostPortal:
9931 currentParent = parent.stateNode.containerInfo;
9932 currentParentIsContainer = true;
9933 break findParent;
9934 }
9935 parent = parent.return;
9936 }
9937 currentParentIsValid = true;
9938 }
9939
9940 if (node.tag === HostComponent || node.tag === HostText) {
9941 commitNestedUnmounts(node);
9942 // After all the children have unmounted, it is now safe to remove the
9943 // node from the tree.
9944 if (currentParentIsContainer) {
9945 removeChildFromContainer(currentParent, node.stateNode);
9946 } else {
9947 removeChild(currentParent, node.stateNode);
9948 }
9949 // Don't visit children because we already visited them.
9950 } else if (enableSuspenseServerRenderer && node.tag === DehydratedSuspenseComponent) {
9951 // Delete the dehydrated suspense boundary and all of its content.
9952 if (currentParentIsContainer) {
9953 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);
9954 } else {
9955 clearSuspenseBoundary(currentParent, node.stateNode);
9956 }
9957 } else if (node.tag === HostPortal) {
9958 if (node.child !== null) {
9959 // When we go into a portal, it becomes the parent to remove from.
9960 // We will reassign it back when we pop the portal on the way up.
9961 currentParent = node.stateNode.containerInfo;
9962 currentParentIsContainer = true;
9963 // Visit children because portals might contain host components.
9964 node.child.return = node;
9965 node = node.child;
9966 continue;
9967 }
9968 } else {
9969 commitUnmount(node);
9970 // Visit children because we may find more host components below.
9971 if (node.child !== null) {
9972 node.child.return = node;
9973 node = node.child;
9974 continue;
9975 }
9976 }
9977 if (node === current$$1) {
9978 return;
9979 }
9980 while (node.sibling === null) {
9981 if (node.return === null || node.return === current$$1) {
9982 return;
9983 }
9984 node = node.return;
9985 if (node.tag === HostPortal) {
9986 // When we go out of the portal, we need to restore the parent.
9987 // Since we don't keep a stack of them, we will search for it.
9988 currentParentIsValid = false;
9989 }
9990 }
9991 node.sibling.return = node.return;
9992 node = node.sibling;
9993 }
9994}
9995
9996function commitDeletion(current$$1) {
9997 if (supportsMutation) {
9998 // Recursively delete all host nodes from the parent.
9999 // Detach refs and call componentWillUnmount() on the whole subtree.
10000 unmountHostComponents(current$$1);
10001 } else {
10002 // Detach refs and call componentWillUnmount() on the whole subtree.
10003 commitNestedUnmounts(current$$1);
10004 }
10005 detachFiber(current$$1);
10006}
10007
10008function commitWork(current$$1, finishedWork) {
10009 if (!supportsMutation) {
10010 switch (finishedWork.tag) {
10011 case FunctionComponent:
10012 case ForwardRef:
10013 case MemoComponent:
10014 case SimpleMemoComponent:
10015 {
10016 // Note: We currently never use MountMutation, but useLayout uses
10017 // UnmountMutation.
10018 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
10019 return;
10020 }
10021 }
10022
10023 commitContainer(finishedWork);
10024 return;
10025 }
10026
10027 switch (finishedWork.tag) {
10028 case FunctionComponent:
10029 case ForwardRef:
10030 case MemoComponent:
10031 case SimpleMemoComponent:
10032 {
10033 // Note: We currently never use MountMutation, but useLayout uses
10034 // UnmountMutation.
10035 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
10036 return;
10037 }
10038 case ClassComponent:
10039 {
10040 return;
10041 }
10042 case HostComponent:
10043 {
10044 var instance = finishedWork.stateNode;
10045 if (instance != null) {
10046 // Commit the work prepared earlier.
10047 var newProps = finishedWork.memoizedProps;
10048 // For hydration we reuse the update path but we treat the oldProps
10049 // as the newProps. The updatePayload will contain the real change in
10050 // this case.
10051 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
10052 var type = finishedWork.type;
10053 // TODO: Type the updateQueue to be specific to host components.
10054 var updatePayload = finishedWork.updateQueue;
10055 finishedWork.updateQueue = null;
10056 if (updatePayload !== null) {
10057 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
10058 }
10059 }
10060 return;
10061 }
10062 case HostText:
10063 {
10064 !(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;
10065 var textInstance = finishedWork.stateNode;
10066 var newText = finishedWork.memoizedProps;
10067 // For hydration we reuse the update path but we treat the oldProps
10068 // as the newProps. The updatePayload will contain the real change in
10069 // this case.
10070 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
10071 commitTextUpdate(textInstance, oldText, newText);
10072 return;
10073 }
10074 case HostRoot:
10075 {
10076 return;
10077 }
10078 case Profiler:
10079 {
10080 return;
10081 }
10082 case SuspenseComponent:
10083 {
10084 var newState = finishedWork.memoizedState;
10085
10086 var newDidTimeout = void 0;
10087 var primaryChildParent = finishedWork;
10088 if (newState === null) {
10089 newDidTimeout = false;
10090 } else {
10091 newDidTimeout = true;
10092 primaryChildParent = finishedWork.child;
10093 if (newState.timedOutAt === NoWork) {
10094 // If the children had not already timed out, record the time.
10095 // This is used to compute the elapsed time during subsequent
10096 // attempts to render the children.
10097 newState.timedOutAt = requestCurrentTime();
10098 }
10099 }
10100
10101 if (primaryChildParent !== null) {
10102 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
10103 }
10104
10105 // If this boundary just timed out, then it will have a set of thenables.
10106 // For each thenable, attach a listener so that when it resolves, React
10107 // attempts to re-render the boundary in the primary (pre-timeout) state.
10108 var thenables = finishedWork.updateQueue;
10109 if (thenables !== null) {
10110 finishedWork.updateQueue = null;
10111 var retryCache = finishedWork.stateNode;
10112 if (retryCache === null) {
10113 retryCache = finishedWork.stateNode = new PossiblyWeakSet$1();
10114 }
10115 thenables.forEach(function (thenable) {
10116 // Memoize using the boundary fiber to prevent redundant listeners.
10117 var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable);
10118 if (enableSchedulerTracing) {
10119 retry = tracing.unstable_wrap(retry);
10120 }
10121 if (!retryCache.has(thenable)) {
10122 retryCache.add(thenable);
10123 thenable.then(retry, retry);
10124 }
10125 });
10126 }
10127
10128 return;
10129 }
10130 case IncompleteClassComponent:
10131 {
10132 return;
10133 }
10134 default:
10135 {
10136 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.');
10137 }
10138 }
10139}
10140
10141function commitResetTextContent(current$$1) {
10142 if (!supportsMutation) {
10143 return;
10144 }
10145 resetTextContent(current$$1.stateNode);
10146}
10147
10148var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
10149var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
10150
10151function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
10152 var update = createUpdate(expirationTime);
10153 // Unmount the root by rendering null.
10154 update.tag = CaptureUpdate;
10155 // Caution: React DevTools currently depends on this property
10156 // being called "element".
10157 update.payload = { element: null };
10158 var error = errorInfo.value;
10159 update.callback = function () {
10160 onUncaughtError(error);
10161 logError(fiber, errorInfo);
10162 };
10163 return update;
10164}
10165
10166function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
10167 var update = createUpdate(expirationTime);
10168 update.tag = CaptureUpdate;
10169 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
10170 if (typeof getDerivedStateFromError === 'function') {
10171 var error = errorInfo.value;
10172 update.payload = function () {
10173 return getDerivedStateFromError(error);
10174 };
10175 }
10176
10177 var inst = fiber.stateNode;
10178 if (inst !== null && typeof inst.componentDidCatch === 'function') {
10179 update.callback = function callback() {
10180 if (typeof getDerivedStateFromError !== 'function') {
10181 // To preserve the preexisting retry behavior of error boundaries,
10182 // we keep track of which ones already failed during this batch.
10183 // This gets reset before we yield back to the browser.
10184 // TODO: Warn in strict mode if getDerivedStateFromError is
10185 // not defined.
10186 markLegacyErrorBoundaryAsFailed(this);
10187 }
10188 var error = errorInfo.value;
10189 var stack = errorInfo.stack;
10190 logError(fiber, errorInfo);
10191 this.componentDidCatch(error, {
10192 componentStack: stack !== null ? stack : ''
10193 });
10194 {
10195 if (typeof getDerivedStateFromError !== 'function') {
10196 // If componentDidCatch is the only error boundary method defined,
10197 // then it needs to call setState to recover from errors.
10198 // If no state update is scheduled then the boundary will swallow the error.
10199 !(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;
10200 }
10201 }
10202 };
10203 }
10204 return update;
10205}
10206
10207function attachPingListener(root, renderExpirationTime, thenable) {
10208 // Attach a listener to the promise to "ping" the root and retry. But
10209 // only if one does not already exist for the current render expiration
10210 // time (which acts like a "thread ID" here).
10211 var pingCache = root.pingCache;
10212 var threadIDs = void 0;
10213 if (pingCache === null) {
10214 pingCache = root.pingCache = new PossiblyWeakMap();
10215 threadIDs = new Set();
10216 pingCache.set(thenable, threadIDs);
10217 } else {
10218 threadIDs = pingCache.get(thenable);
10219 if (threadIDs === undefined) {
10220 threadIDs = new Set();
10221 pingCache.set(thenable, threadIDs);
10222 }
10223 }
10224 if (!threadIDs.has(renderExpirationTime)) {
10225 // Memoize using the thread ID to prevent redundant listeners.
10226 threadIDs.add(renderExpirationTime);
10227 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
10228 if (enableSchedulerTracing) {
10229 ping = tracing.unstable_wrap(ping);
10230 }
10231 thenable.then(ping, ping);
10232 }
10233}
10234
10235function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
10236 // The source fiber did not complete.
10237 sourceFiber.effectTag |= Incomplete;
10238 // Its effect list is no longer valid.
10239 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
10240
10241 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
10242 // This is a thenable.
10243 var thenable = value;
10244
10245 // Find the earliest timeout threshold of all the placeholders in the
10246 // ancestor path. We could avoid this traversal by storing the thresholds on
10247 // the stack, but we choose not to because we only hit this path if we're
10248 // IO-bound (i.e. if something suspends). Whereas the stack is used even in
10249 // the non-IO- bound case.
10250 var _workInProgress = returnFiber;
10251 var earliestTimeoutMs = -1;
10252 var startTimeMs = -1;
10253 do {
10254 if (_workInProgress.tag === SuspenseComponent) {
10255 var current$$1 = _workInProgress.alternate;
10256 if (current$$1 !== null) {
10257 var currentState = current$$1.memoizedState;
10258 if (currentState !== null) {
10259 // Reached a boundary that already timed out. Do not search
10260 // any further.
10261 var timedOutAt = currentState.timedOutAt;
10262 startTimeMs = expirationTimeToMs(timedOutAt);
10263 // Do not search any further.
10264 break;
10265 }
10266 }
10267 var timeoutPropMs = _workInProgress.pendingProps.maxDuration;
10268 if (typeof timeoutPropMs === 'number') {
10269 if (timeoutPropMs <= 0) {
10270 earliestTimeoutMs = 0;
10271 } else if (earliestTimeoutMs === -1 || timeoutPropMs < earliestTimeoutMs) {
10272 earliestTimeoutMs = timeoutPropMs;
10273 }
10274 }
10275 }
10276 // If there is a DehydratedSuspenseComponent we don't have to do anything because
10277 // if something suspends inside it, we will simply leave that as dehydrated. It
10278 // will never timeout.
10279 _workInProgress = _workInProgress.return;
10280 } while (_workInProgress !== null);
10281
10282 // Schedule the nearest Suspense to re-render the timed out view.
10283 _workInProgress = returnFiber;
10284 do {
10285 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress)) {
10286 // Found the nearest boundary.
10287
10288 // Stash the promise on the boundary fiber. If the boundary times out, we'll
10289 var thenables = _workInProgress.updateQueue;
10290 if (thenables === null) {
10291 var updateQueue = new Set();
10292 updateQueue.add(thenable);
10293 _workInProgress.updateQueue = updateQueue;
10294 } else {
10295 thenables.add(thenable);
10296 }
10297
10298 // If the boundary is outside of concurrent mode, we should *not*
10299 // suspend the commit. Pretend as if the suspended component rendered
10300 // null and keep rendering. In the commit phase, we'll schedule a
10301 // subsequent synchronous update to re-render the Suspense.
10302 //
10303 // Note: It doesn't matter whether the component that suspended was
10304 // inside a concurrent mode tree. If the Suspense is outside of it, we
10305 // should *not* suspend the commit.
10306 if ((_workInProgress.mode & ConcurrentMode) === NoEffect) {
10307 _workInProgress.effectTag |= DidCapture;
10308
10309 // We're going to commit this fiber even though it didn't complete.
10310 // But we shouldn't call any lifecycle methods or callbacks. Remove
10311 // all lifecycle effect tags.
10312 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
10313
10314 if (sourceFiber.tag === ClassComponent) {
10315 var currentSourceFiber = sourceFiber.alternate;
10316 if (currentSourceFiber === null) {
10317 // This is a new mount. Change the tag so it's not mistaken for a
10318 // completed class component. For example, we should not call
10319 // componentWillUnmount if it is deleted.
10320 sourceFiber.tag = IncompleteClassComponent;
10321 } else {
10322 // When we try rendering again, we should not reuse the current fiber,
10323 // since it's known to be in an inconsistent state. Use a force updte to
10324 // prevent a bail out.
10325 var update = createUpdate(Sync);
10326 update.tag = ForceUpdate;
10327 enqueueUpdate(sourceFiber, update);
10328 }
10329 }
10330
10331 // The source fiber did not complete. Mark it with Sync priority to
10332 // indicate that it still has pending work.
10333 sourceFiber.expirationTime = Sync;
10334
10335 // Exit without suspending.
10336 return;
10337 }
10338
10339 // Confirmed that the boundary is in a concurrent mode tree. Continue
10340 // with the normal suspend path.
10341
10342 attachPingListener(root, renderExpirationTime, thenable);
10343
10344 var absoluteTimeoutMs = void 0;
10345 if (earliestTimeoutMs === -1) {
10346 // If no explicit threshold is given, default to an arbitrarily large
10347 // value. The actual size doesn't matter because the threshold for the
10348 // whole tree will be clamped to the expiration time.
10349 absoluteTimeoutMs = maxSigned31BitInt;
10350 } else {
10351 if (startTimeMs === -1) {
10352 // This suspend happened outside of any already timed-out
10353 // placeholders. We don't know exactly when the update was
10354 // scheduled, but we can infer an approximate start time from the
10355 // expiration time. First, find the earliest uncommitted expiration
10356 // time in the tree, including work that is suspended. Then subtract
10357 // the offset used to compute an async update's expiration time.
10358 // This will cause high priority (interactive) work to expire
10359 // earlier than necessary, but we can account for this by adjusting
10360 // for the Just Noticeable Difference.
10361 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, renderExpirationTime);
10362 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
10363 startTimeMs = earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
10364 }
10365 absoluteTimeoutMs = startTimeMs + earliestTimeoutMs;
10366 }
10367
10368 // Mark the earliest timeout in the suspended fiber's ancestor path.
10369 // After completing the root, we'll take the largest of all the
10370 // suspended fiber's timeouts and use it to compute a timeout for the
10371 // whole tree.
10372 renderDidSuspend(root, absoluteTimeoutMs, renderExpirationTime);
10373
10374 _workInProgress.effectTag |= ShouldCapture;
10375 _workInProgress.expirationTime = renderExpirationTime;
10376 return;
10377 } else if (enableSuspenseServerRenderer && _workInProgress.tag === DehydratedSuspenseComponent) {
10378 attachPingListener(root, renderExpirationTime, thenable);
10379
10380 // Since we already have a current fiber, we can eagerly add a retry listener.
10381 var retryCache = _workInProgress.memoizedState;
10382 if (retryCache === null) {
10383 retryCache = _workInProgress.memoizedState = new PossiblyWeakSet();
10384 var _current = _workInProgress.alternate;
10385 !_current ? invariant(false, 'A dehydrated suspense boundary must commit before trying to render. This is probably a bug in React.') : void 0;
10386 _current.memoizedState = retryCache;
10387 }
10388 // Memoize using the boundary fiber to prevent redundant listeners.
10389 if (!retryCache.has(thenable)) {
10390 retryCache.add(thenable);
10391 var retry = retryTimedOutBoundary.bind(null, _workInProgress, thenable);
10392 if (enableSchedulerTracing) {
10393 retry = tracing.unstable_wrap(retry);
10394 }
10395 thenable.then(retry, retry);
10396 }
10397 _workInProgress.effectTag |= ShouldCapture;
10398 _workInProgress.expirationTime = renderExpirationTime;
10399 return;
10400 }
10401 // This boundary already captured during this render. Continue to the next
10402 // boundary.
10403 _workInProgress = _workInProgress.return;
10404 } while (_workInProgress !== null);
10405 // No boundary was found. Fallthrough to error mode.
10406 // TODO: Use invariant so the message is stripped in prod?
10407 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));
10408 }
10409
10410 // We didn't find a boundary that could handle this type of exception. Start
10411 // over and traverse parent path again, this time treating the exception
10412 // as an error.
10413 renderDidError();
10414 value = createCapturedValue(value, sourceFiber);
10415 var workInProgress = returnFiber;
10416 do {
10417 switch (workInProgress.tag) {
10418 case HostRoot:
10419 {
10420 var _errorInfo = value;
10421 workInProgress.effectTag |= ShouldCapture;
10422 workInProgress.expirationTime = renderExpirationTime;
10423 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
10424 enqueueCapturedUpdate(workInProgress, _update);
10425 return;
10426 }
10427 case ClassComponent:
10428 // Capture and retry
10429 var errorInfo = value;
10430 var ctor = workInProgress.type;
10431 var instance = workInProgress.stateNode;
10432 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
10433 workInProgress.effectTag |= ShouldCapture;
10434 workInProgress.expirationTime = renderExpirationTime;
10435 // Schedule the error boundary to re-render using updated state
10436 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
10437 enqueueCapturedUpdate(workInProgress, _update2);
10438 return;
10439 }
10440 break;
10441 default:
10442 break;
10443 }
10444 workInProgress = workInProgress.return;
10445 } while (workInProgress !== null);
10446}
10447
10448function unwindWork(workInProgress, renderExpirationTime) {
10449 switch (workInProgress.tag) {
10450 case ClassComponent:
10451 {
10452 var Component = workInProgress.type;
10453 if (isContextProvider(Component)) {
10454 popContext(workInProgress);
10455 }
10456 var effectTag = workInProgress.effectTag;
10457 if (effectTag & ShouldCapture) {
10458 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
10459 return workInProgress;
10460 }
10461 return null;
10462 }
10463 case HostRoot:
10464 {
10465 popHostContainer(workInProgress);
10466 popTopLevelContextObject(workInProgress);
10467 var _effectTag = workInProgress.effectTag;
10468 !((_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;
10469 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
10470 return workInProgress;
10471 }
10472 case HostComponent:
10473 {
10474 // TODO: popHydrationState
10475 popHostContext(workInProgress);
10476 return null;
10477 }
10478 case SuspenseComponent:
10479 {
10480 var _effectTag2 = workInProgress.effectTag;
10481 if (_effectTag2 & ShouldCapture) {
10482 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture;
10483 // Captured a suspense effect. Re-render the boundary.
10484 return workInProgress;
10485 }
10486 return null;
10487 }
10488 case DehydratedSuspenseComponent:
10489 {
10490 if (enableSuspenseServerRenderer) {
10491 // TODO: popHydrationState
10492 var _effectTag3 = workInProgress.effectTag;
10493 if (_effectTag3 & ShouldCapture) {
10494 workInProgress.effectTag = _effectTag3 & ~ShouldCapture | DidCapture;
10495 // Captured a suspense effect. Re-render the boundary.
10496 return workInProgress;
10497 }
10498 }
10499 return null;
10500 }
10501 case HostPortal:
10502 popHostContainer(workInProgress);
10503 return null;
10504 case ContextProvider:
10505 popProvider(workInProgress);
10506 return null;
10507 default:
10508 return null;
10509 }
10510}
10511
10512function unwindInterruptedWork(interruptedWork) {
10513 switch (interruptedWork.tag) {
10514 case ClassComponent:
10515 {
10516 var childContextTypes = interruptedWork.type.childContextTypes;
10517 if (childContextTypes !== null && childContextTypes !== undefined) {
10518 popContext(interruptedWork);
10519 }
10520 break;
10521 }
10522 case HostRoot:
10523 {
10524 popHostContainer(interruptedWork);
10525 popTopLevelContextObject(interruptedWork);
10526 break;
10527 }
10528 case HostComponent:
10529 {
10530 popHostContext(interruptedWork);
10531 break;
10532 }
10533 case HostPortal:
10534 popHostContainer(interruptedWork);
10535 break;
10536 case ContextProvider:
10537 popProvider(interruptedWork);
10538 break;
10539 default:
10540 break;
10541 }
10542}
10543
10544var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
10545var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
10546
10547
10548var didWarnAboutStateTransition = void 0;
10549var didWarnSetStateChildContext = void 0;
10550var warnAboutUpdateOnUnmounted = void 0;
10551var warnAboutInvalidUpdates = void 0;
10552
10553if (enableSchedulerTracing) {
10554 // Provide explicit error message when production+profiling bundle of e.g. react-dom
10555 // is used with production (non-profiling) bundle of scheduler/tracing
10556 !(tracing.__interactionsRef != null && tracing.__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;
10557}
10558
10559{
10560 didWarnAboutStateTransition = false;
10561 didWarnSetStateChildContext = false;
10562 var didWarnStateUpdateForUnmountedComponent = {};
10563
10564 warnAboutUpdateOnUnmounted = function (fiber, isClass) {
10565 // We show the whole stack but dedupe on the top component's name because
10566 // the problematic code almost always lies inside that component.
10567 var componentName = getComponentName(fiber.type) || 'ReactComponent';
10568 if (didWarnStateUpdateForUnmountedComponent[componentName]) {
10569 return;
10570 }
10571 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));
10572 didWarnStateUpdateForUnmountedComponent[componentName] = true;
10573 };
10574
10575 warnAboutInvalidUpdates = function (instance) {
10576 switch (phase) {
10577 case 'getChildContext':
10578 if (didWarnSetStateChildContext) {
10579 return;
10580 }
10581 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
10582 didWarnSetStateChildContext = true;
10583 break;
10584 case 'render':
10585 if (didWarnAboutStateTransition) {
10586 return;
10587 }
10588 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.');
10589 didWarnAboutStateTransition = true;
10590 break;
10591 }
10592 };
10593}
10594
10595var isWorking = false;
10596
10597// The next work in progress fiber that we're currently working on.
10598var nextUnitOfWork = null;
10599var nextRoot = null;
10600// The time at which we're currently rendering work.
10601var nextRenderExpirationTime = NoWork;
10602var nextLatestAbsoluteTimeoutMs = -1;
10603var nextRenderDidError = false;
10604
10605// The next fiber with an effect that we're currently committing.
10606var nextEffect = null;
10607
10608var isCommitting$1 = false;
10609var rootWithPendingPassiveEffects = null;
10610var passiveEffectCallbackHandle = null;
10611var passiveEffectCallback = null;
10612
10613var legacyErrorBoundariesThatAlreadyFailed = null;
10614
10615// Used for performance tracking.
10616var interruptedBy = null;
10617
10618var stashedWorkInProgressProperties = void 0;
10619var replayUnitOfWork = void 0;
10620var mayReplayFailedUnitOfWork = void 0;
10621var isReplayingFailedUnitOfWork = void 0;
10622var originalReplayError = void 0;
10623var rethrowOriginalError = void 0;
10624if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
10625 stashedWorkInProgressProperties = null;
10626 mayReplayFailedUnitOfWork = true;
10627 isReplayingFailedUnitOfWork = false;
10628 originalReplayError = null;
10629 replayUnitOfWork = function (failedUnitOfWork, thrownValue, isYieldy) {
10630 if (thrownValue !== null && typeof thrownValue === 'object' && typeof thrownValue.then === 'function') {
10631 // Don't replay promises. Treat everything else like an error.
10632 // TODO: Need to figure out a different strategy if/when we add
10633 // support for catching other types.
10634 return;
10635 }
10636
10637 // Restore the original state of the work-in-progress
10638 if (stashedWorkInProgressProperties === null) {
10639 // This should never happen. Don't throw because this code is DEV-only.
10640 warningWithoutStack$1(false, 'Could not replay rendering after an error. This is likely a bug in React. ' + 'Please file an issue.');
10641 return;
10642 }
10643 assignFiberPropertiesInDEV(failedUnitOfWork, stashedWorkInProgressProperties);
10644
10645 switch (failedUnitOfWork.tag) {
10646 case HostRoot:
10647 popHostContainer(failedUnitOfWork);
10648 popTopLevelContextObject(failedUnitOfWork);
10649 break;
10650 case HostComponent:
10651 popHostContext(failedUnitOfWork);
10652 break;
10653 case ClassComponent:
10654 {
10655 var Component = failedUnitOfWork.type;
10656 if (isContextProvider(Component)) {
10657 popContext(failedUnitOfWork);
10658 }
10659 break;
10660 }
10661 case HostPortal:
10662 popHostContainer(failedUnitOfWork);
10663 break;
10664 case ContextProvider:
10665 popProvider(failedUnitOfWork);
10666 break;
10667 }
10668 // Replay the begin phase.
10669 isReplayingFailedUnitOfWork = true;
10670 originalReplayError = thrownValue;
10671 invokeGuardedCallback(null, workLoop, null, isYieldy);
10672 isReplayingFailedUnitOfWork = false;
10673 originalReplayError = null;
10674 if (hasCaughtError()) {
10675 var replayError = clearCaughtError();
10676 if (replayError != null && thrownValue != null) {
10677 try {
10678 // Reading the expando property is intentionally
10679 // inside `try` because it might be a getter or Proxy.
10680 if (replayError._suppressLogging) {
10681 // Also suppress logging for the original error.
10682 thrownValue._suppressLogging = true;
10683 }
10684 } catch (inner) {
10685 // Ignore.
10686 }
10687 }
10688 } else {
10689 // If the begin phase did not fail the second time, set this pointer
10690 // back to the original value.
10691 nextUnitOfWork = failedUnitOfWork;
10692 }
10693 };
10694 rethrowOriginalError = function () {
10695 throw originalReplayError;
10696 };
10697}
10698
10699function resetStack() {
10700 if (nextUnitOfWork !== null) {
10701 var interruptedWork = nextUnitOfWork.return;
10702 while (interruptedWork !== null) {
10703 unwindInterruptedWork(interruptedWork);
10704 interruptedWork = interruptedWork.return;
10705 }
10706 }
10707
10708 {
10709 ReactStrictModeWarnings.discardPendingWarnings();
10710 checkThatStackIsEmpty();
10711 }
10712
10713 nextRoot = null;
10714 nextRenderExpirationTime = NoWork;
10715 nextLatestAbsoluteTimeoutMs = -1;
10716 nextRenderDidError = false;
10717 nextUnitOfWork = null;
10718}
10719
10720function commitAllHostEffects() {
10721 while (nextEffect !== null) {
10722 {
10723 setCurrentFiber(nextEffect);
10724 }
10725 recordEffect();
10726
10727 var effectTag = nextEffect.effectTag;
10728
10729 if (effectTag & ContentReset) {
10730 commitResetTextContent(nextEffect);
10731 }
10732
10733 if (effectTag & Ref) {
10734 var current$$1 = nextEffect.alternate;
10735 if (current$$1 !== null) {
10736 commitDetachRef(current$$1);
10737 }
10738 }
10739
10740 // The following switch statement is only concerned about placement,
10741 // updates, and deletions. To avoid needing to add a case for every
10742 // possible bitmap value, we remove the secondary effects from the
10743 // effect tag and switch on that value.
10744 var primaryEffectTag = effectTag & (Placement | Update | Deletion);
10745 switch (primaryEffectTag) {
10746 case Placement:
10747 {
10748 commitPlacement(nextEffect);
10749 // Clear the "placement" from effect tag so that we know that this is inserted, before
10750 // any life-cycles like componentDidMount gets called.
10751 // TODO: findDOMNode doesn't rely on this any more but isMounted
10752 // does and isMounted is deprecated anyway so we should be able
10753 // to kill this.
10754 nextEffect.effectTag &= ~Placement;
10755 break;
10756 }
10757 case PlacementAndUpdate:
10758 {
10759 // Placement
10760 commitPlacement(nextEffect);
10761 // Clear the "placement" from effect tag so that we know that this is inserted, before
10762 // any life-cycles like componentDidMount gets called.
10763 nextEffect.effectTag &= ~Placement;
10764
10765 // Update
10766 var _current = nextEffect.alternate;
10767 commitWork(_current, nextEffect);
10768 break;
10769 }
10770 case Update:
10771 {
10772 var _current2 = nextEffect.alternate;
10773 commitWork(_current2, nextEffect);
10774 break;
10775 }
10776 case Deletion:
10777 {
10778 commitDeletion(nextEffect);
10779 break;
10780 }
10781 }
10782 nextEffect = nextEffect.nextEffect;
10783 }
10784
10785 {
10786 resetCurrentFiber();
10787 }
10788}
10789
10790function commitBeforeMutationLifecycles() {
10791 while (nextEffect !== null) {
10792 {
10793 setCurrentFiber(nextEffect);
10794 }
10795
10796 var effectTag = nextEffect.effectTag;
10797 if (effectTag & Snapshot) {
10798 recordEffect();
10799 var current$$1 = nextEffect.alternate;
10800 commitBeforeMutationLifeCycles(current$$1, nextEffect);
10801 }
10802
10803 nextEffect = nextEffect.nextEffect;
10804 }
10805
10806 {
10807 resetCurrentFiber();
10808 }
10809}
10810
10811function commitAllLifeCycles(finishedRoot, committedExpirationTime) {
10812 {
10813 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
10814 ReactStrictModeWarnings.flushLegacyContextWarning();
10815
10816 if (warnAboutDeprecatedLifecycles) {
10817 ReactStrictModeWarnings.flushPendingDeprecationWarnings();
10818 }
10819 }
10820 while (nextEffect !== null) {
10821 {
10822 setCurrentFiber(nextEffect);
10823 }
10824 var effectTag = nextEffect.effectTag;
10825
10826 if (effectTag & (Update | Callback)) {
10827 recordEffect();
10828 var current$$1 = nextEffect.alternate;
10829 commitLifeCycles(finishedRoot, current$$1, nextEffect, committedExpirationTime);
10830 }
10831
10832 if (effectTag & Ref) {
10833 recordEffect();
10834 commitAttachRef(nextEffect);
10835 }
10836
10837 if (effectTag & Passive) {
10838 rootWithPendingPassiveEffects = finishedRoot;
10839 }
10840
10841 nextEffect = nextEffect.nextEffect;
10842 }
10843 {
10844 resetCurrentFiber();
10845 }
10846}
10847
10848function commitPassiveEffects(root, firstEffect) {
10849 rootWithPendingPassiveEffects = null;
10850 passiveEffectCallbackHandle = null;
10851 passiveEffectCallback = null;
10852
10853 // Set this to true to prevent re-entrancy
10854 var previousIsRendering = isRendering;
10855 isRendering = true;
10856
10857 var effect = firstEffect;
10858 do {
10859 {
10860 setCurrentFiber(effect);
10861 }
10862
10863 if (effect.effectTag & Passive) {
10864 var didError = false;
10865 var error = void 0;
10866 {
10867 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
10868 if (hasCaughtError()) {
10869 didError = true;
10870 error = clearCaughtError();
10871 }
10872 }
10873 if (didError) {
10874 captureCommitPhaseError(effect, error);
10875 }
10876 }
10877 effect = effect.nextEffect;
10878 } while (effect !== null);
10879 {
10880 resetCurrentFiber();
10881 }
10882
10883 isRendering = previousIsRendering;
10884
10885 // Check if work was scheduled by one of the effects
10886 var rootExpirationTime = root.expirationTime;
10887 if (rootExpirationTime !== NoWork) {
10888 requestWork(root, rootExpirationTime);
10889 }
10890 // Flush any sync work that was scheduled by effects
10891 if (!isBatchingUpdates && !isRendering) {
10892 performSyncWork();
10893 }
10894}
10895
10896function isAlreadyFailedLegacyErrorBoundary(instance) {
10897 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
10898}
10899
10900function markLegacyErrorBoundaryAsFailed(instance) {
10901 if (legacyErrorBoundariesThatAlreadyFailed === null) {
10902 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
10903 } else {
10904 legacyErrorBoundariesThatAlreadyFailed.add(instance);
10905 }
10906}
10907
10908function flushPassiveEffects$1() {
10909 if (passiveEffectCallbackHandle !== null) {
10910 cancelPassiveEffects(passiveEffectCallbackHandle);
10911 }
10912 if (passiveEffectCallback !== null) {
10913 // We call the scheduled callback instead of commitPassiveEffects directly
10914 // to ensure tracing works correctly.
10915 passiveEffectCallback();
10916 }
10917}
10918
10919function commitRoot(root, finishedWork) {
10920 isWorking = true;
10921 isCommitting$1 = true;
10922 startCommitTimer();
10923
10924 !(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;
10925 var committedExpirationTime = root.pendingCommitExpirationTime;
10926 !(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;
10927 root.pendingCommitExpirationTime = NoWork;
10928
10929 // Update the pending priority levels to account for the work that we are
10930 // about to commit. This needs to happen before calling the lifecycles, since
10931 // they may schedule additional updates.
10932 var updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
10933 var childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
10934 var earliestRemainingTimeBeforeCommit = childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit ? childExpirationTimeBeforeCommit : updateExpirationTimeBeforeCommit;
10935 markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
10936
10937 var prevInteractions = null;
10938 if (enableSchedulerTracing) {
10939 // Restore any pending interactions at this point,
10940 // So that cascading work triggered during the render phase will be accounted for.
10941 prevInteractions = tracing.__interactionsRef.current;
10942 tracing.__interactionsRef.current = root.memoizedInteractions;
10943 }
10944
10945 // Reset this to null before calling lifecycles
10946 ReactCurrentOwner$1.current = null;
10947
10948 var firstEffect = void 0;
10949 if (finishedWork.effectTag > PerformedWork) {
10950 // A fiber's effect list consists only of its children, not itself. So if
10951 // the root has an effect, we need to add it to the end of the list. The
10952 // resulting list is the set that would belong to the root's parent, if
10953 // it had one; that is, all the effects in the tree including the root.
10954 if (finishedWork.lastEffect !== null) {
10955 finishedWork.lastEffect.nextEffect = finishedWork;
10956 firstEffect = finishedWork.firstEffect;
10957 } else {
10958 firstEffect = finishedWork;
10959 }
10960 } else {
10961 // There is no effect on the root.
10962 firstEffect = finishedWork.firstEffect;
10963 }
10964
10965 prepareForCommit(root.containerInfo);
10966
10967 // Invoke instances of getSnapshotBeforeUpdate before mutation.
10968 nextEffect = firstEffect;
10969 startCommitSnapshotEffectsTimer();
10970 while (nextEffect !== null) {
10971 var didError = false;
10972 var error = void 0;
10973 {
10974 invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
10975 if (hasCaughtError()) {
10976 didError = true;
10977 error = clearCaughtError();
10978 }
10979 }
10980 if (didError) {
10981 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
10982 captureCommitPhaseError(nextEffect, error);
10983 // Clean-up
10984 if (nextEffect !== null) {
10985 nextEffect = nextEffect.nextEffect;
10986 }
10987 }
10988 }
10989 stopCommitSnapshotEffectsTimer();
10990
10991 if (enableProfilerTimer) {
10992 // Mark the current commit time to be shared by all Profilers in this batch.
10993 // This enables them to be grouped later.
10994 recordCommitTime();
10995 }
10996
10997 // Commit all the side-effects within a tree. We'll do this in two passes.
10998 // The first pass performs all the host insertions, updates, deletions and
10999 // ref unmounts.
11000 nextEffect = firstEffect;
11001 startCommitHostEffectsTimer();
11002 while (nextEffect !== null) {
11003 var _didError = false;
11004 var _error = void 0;
11005 {
11006 invokeGuardedCallback(null, commitAllHostEffects, null);
11007 if (hasCaughtError()) {
11008 _didError = true;
11009 _error = clearCaughtError();
11010 }
11011 }
11012 if (_didError) {
11013 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11014 captureCommitPhaseError(nextEffect, _error);
11015 // Clean-up
11016 if (nextEffect !== null) {
11017 nextEffect = nextEffect.nextEffect;
11018 }
11019 }
11020 }
11021 stopCommitHostEffectsTimer();
11022
11023 resetAfterCommit(root.containerInfo);
11024
11025 // The work-in-progress tree is now the current tree. This must come after
11026 // the first pass of the commit phase, so that the previous tree is still
11027 // current during componentWillUnmount, but before the second pass, so that
11028 // the finished work is current during componentDidMount/Update.
11029 root.current = finishedWork;
11030
11031 // In the second pass we'll perform all life-cycles and ref callbacks.
11032 // Life-cycles happen as a separate pass so that all placements, updates,
11033 // and deletions in the entire tree have already been invoked.
11034 // This pass also triggers any renderer-specific initial effects.
11035 nextEffect = firstEffect;
11036 startCommitLifeCyclesTimer();
11037 while (nextEffect !== null) {
11038 var _didError2 = false;
11039 var _error2 = void 0;
11040 {
11041 invokeGuardedCallback(null, commitAllLifeCycles, null, root, committedExpirationTime);
11042 if (hasCaughtError()) {
11043 _didError2 = true;
11044 _error2 = clearCaughtError();
11045 }
11046 }
11047 if (_didError2) {
11048 !(nextEffect !== null) ? invariant(false, 'Should have next effect. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11049 captureCommitPhaseError(nextEffect, _error2);
11050 if (nextEffect !== null) {
11051 nextEffect = nextEffect.nextEffect;
11052 }
11053 }
11054 }
11055
11056 if (firstEffect !== null && rootWithPendingPassiveEffects !== null) {
11057 // This commit included a passive effect. These do not need to fire until
11058 // after the next paint. Schedule an callback to fire them in an async
11059 // event. To ensure serial execution, the callback will be flushed early if
11060 // we enter rootWithPendingPassiveEffects commit phase before then.
11061 var callback = commitPassiveEffects.bind(null, root, firstEffect);
11062 if (enableSchedulerTracing) {
11063 // TODO: Avoid this extra callback by mutating the tracing ref directly,
11064 // like we do at the beginning of commitRoot. I've opted not to do that
11065 // here because that code is still in flux.
11066 callback = tracing.unstable_wrap(callback);
11067 }
11068 passiveEffectCallbackHandle = scheduler.unstable_runWithPriority(scheduler.unstable_NormalPriority, function () {
11069 return schedulePassiveEffects(callback);
11070 });
11071 passiveEffectCallback = callback;
11072 }
11073
11074 isCommitting$1 = false;
11075 isWorking = false;
11076 stopCommitLifeCyclesTimer();
11077 stopCommitTimer();
11078 onCommitRoot(finishedWork.stateNode);
11079 if (true && ReactFiberInstrumentation_1.debugTool) {
11080 ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork);
11081 }
11082
11083 var updateExpirationTimeAfterCommit = finishedWork.expirationTime;
11084 var childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
11085 var earliestRemainingTimeAfterCommit = childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit ? childExpirationTimeAfterCommit : updateExpirationTimeAfterCommit;
11086 if (earliestRemainingTimeAfterCommit === NoWork) {
11087 // If there's no remaining work, we can clear the set of already failed
11088 // error boundaries.
11089 legacyErrorBoundariesThatAlreadyFailed = null;
11090 }
11091 onCommit(root, earliestRemainingTimeAfterCommit);
11092
11093 if (enableSchedulerTracing) {
11094 tracing.__interactionsRef.current = prevInteractions;
11095
11096 var subscriber = void 0;
11097
11098 try {
11099 subscriber = tracing.__subscriberRef.current;
11100 if (subscriber !== null && root.memoizedInteractions.size > 0) {
11101 var threadID = computeThreadID(committedExpirationTime, root.interactionThreadID);
11102 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
11103 }
11104 } catch (error) {
11105 // It's not safe for commitRoot() to throw.
11106 // Store the error for now and we'll re-throw in finishRendering().
11107 if (!hasUnhandledError) {
11108 hasUnhandledError = true;
11109 unhandledError = error;
11110 }
11111 } finally {
11112 // Clear completed interactions from the pending Map.
11113 // Unless the render was suspended or cascading work was scheduled,
11114 // In which case– leave pending interactions until the subsequent render.
11115 var pendingInteractionMap = root.pendingInteractionMap;
11116 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11117 // Only decrement the pending interaction count if we're done.
11118 // If there's still work at the current priority,
11119 // That indicates that we are waiting for suspense data.
11120 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
11121 pendingInteractionMap.delete(scheduledExpirationTime);
11122
11123 scheduledInteractions.forEach(function (interaction) {
11124 interaction.__count--;
11125
11126 if (subscriber !== null && interaction.__count === 0) {
11127 try {
11128 subscriber.onInteractionScheduledWorkCompleted(interaction);
11129 } catch (error) {
11130 // It's not safe for commitRoot() to throw.
11131 // Store the error for now and we'll re-throw in finishRendering().
11132 if (!hasUnhandledError) {
11133 hasUnhandledError = true;
11134 unhandledError = error;
11135 }
11136 }
11137 }
11138 });
11139 }
11140 });
11141 }
11142 }
11143}
11144
11145function resetChildExpirationTime(workInProgress, renderTime) {
11146 if (renderTime !== Never && workInProgress.childExpirationTime === Never) {
11147 // The children of this component are hidden. Don't bubble their
11148 // expiration times.
11149 return;
11150 }
11151
11152 var newChildExpirationTime = NoWork;
11153
11154 // Bubble up the earliest expiration time.
11155 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11156 // We're in profiling mode.
11157 // Let's use this same traversal to update the render durations.
11158 var actualDuration = workInProgress.actualDuration;
11159 var treeBaseDuration = workInProgress.selfBaseDuration;
11160
11161 // When a fiber is cloned, its actualDuration is reset to 0.
11162 // This value will only be updated if work is done on the fiber (i.e. it doesn't bailout).
11163 // When work is done, it should bubble to the parent's actualDuration.
11164 // If the fiber has not been cloned though, (meaning no work was done),
11165 // Then this value will reflect the amount of time spent working on a previous render.
11166 // In that case it should not bubble.
11167 // We determine whether it was cloned by comparing the child pointer.
11168 var shouldBubbleActualDurations = workInProgress.alternate === null || workInProgress.child !== workInProgress.alternate.child;
11169
11170 var child = workInProgress.child;
11171 while (child !== null) {
11172 var childUpdateExpirationTime = child.expirationTime;
11173 var childChildExpirationTime = child.childExpirationTime;
11174 if (childUpdateExpirationTime > newChildExpirationTime) {
11175 newChildExpirationTime = childUpdateExpirationTime;
11176 }
11177 if (childChildExpirationTime > newChildExpirationTime) {
11178 newChildExpirationTime = childChildExpirationTime;
11179 }
11180 if (shouldBubbleActualDurations) {
11181 actualDuration += child.actualDuration;
11182 }
11183 treeBaseDuration += child.treeBaseDuration;
11184 child = child.sibling;
11185 }
11186 workInProgress.actualDuration = actualDuration;
11187 workInProgress.treeBaseDuration = treeBaseDuration;
11188 } else {
11189 var _child = workInProgress.child;
11190 while (_child !== null) {
11191 var _childUpdateExpirationTime = _child.expirationTime;
11192 var _childChildExpirationTime = _child.childExpirationTime;
11193 if (_childUpdateExpirationTime > newChildExpirationTime) {
11194 newChildExpirationTime = _childUpdateExpirationTime;
11195 }
11196 if (_childChildExpirationTime > newChildExpirationTime) {
11197 newChildExpirationTime = _childChildExpirationTime;
11198 }
11199 _child = _child.sibling;
11200 }
11201 }
11202
11203 workInProgress.childExpirationTime = newChildExpirationTime;
11204}
11205
11206function completeUnitOfWork(workInProgress) {
11207 // Attempt to complete the current unit of work, then move to the
11208 // next sibling. If there are no more siblings, return to the
11209 // parent fiber.
11210 while (true) {
11211 // The current, flushed, state of this fiber is the alternate.
11212 // Ideally nothing should rely on this, but relying on it here
11213 // means that we don't need an additional field on the work in
11214 // progress.
11215 var current$$1 = workInProgress.alternate;
11216 {
11217 setCurrentFiber(workInProgress);
11218 }
11219
11220 var returnFiber = workInProgress.return;
11221 var siblingFiber = workInProgress.sibling;
11222
11223 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
11224 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11225 // Don't replay if it fails during completion phase.
11226 mayReplayFailedUnitOfWork = false;
11227 }
11228 // This fiber completed.
11229 // Remember we're completing this unit so we can find a boundary if it fails.
11230 nextUnitOfWork = workInProgress;
11231 if (enableProfilerTimer) {
11232 if (workInProgress.mode & ProfileMode) {
11233 startProfilerTimer(workInProgress);
11234 }
11235 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
11236 if (workInProgress.mode & ProfileMode) {
11237 // Update render duration assuming we didn't error.
11238 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11239 }
11240 } else {
11241 nextUnitOfWork = completeWork(current$$1, workInProgress, nextRenderExpirationTime);
11242 }
11243 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11244 // We're out of completion phase so replaying is fine now.
11245 mayReplayFailedUnitOfWork = true;
11246 }
11247 stopWorkTimer(workInProgress);
11248 resetChildExpirationTime(workInProgress, nextRenderExpirationTime);
11249 {
11250 resetCurrentFiber();
11251 }
11252
11253 if (nextUnitOfWork !== null) {
11254 // Completing this fiber spawned new work. Work on that next.
11255 return nextUnitOfWork;
11256 }
11257
11258 if (returnFiber !== null &&
11259 // Do not append effects to parents if a sibling failed to complete
11260 (returnFiber.effectTag & Incomplete) === NoEffect) {
11261 // Append all the effects of the subtree and this fiber onto the effect
11262 // list of the parent. The completion order of the children affects the
11263 // side-effect order.
11264 if (returnFiber.firstEffect === null) {
11265 returnFiber.firstEffect = workInProgress.firstEffect;
11266 }
11267 if (workInProgress.lastEffect !== null) {
11268 if (returnFiber.lastEffect !== null) {
11269 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
11270 }
11271 returnFiber.lastEffect = workInProgress.lastEffect;
11272 }
11273
11274 // If this fiber had side-effects, we append it AFTER the children's
11275 // side-effects. We can perform certain side-effects earlier if
11276 // needed, by doing multiple passes over the effect list. We don't want
11277 // to schedule our own side-effect on our own list because if end up
11278 // reusing children we'll schedule this effect onto itself since we're
11279 // at the end.
11280 var effectTag = workInProgress.effectTag;
11281 // Skip both NoWork and PerformedWork tags when creating the effect list.
11282 // PerformedWork effect is read by React DevTools but shouldn't be committed.
11283 if (effectTag > PerformedWork) {
11284 if (returnFiber.lastEffect !== null) {
11285 returnFiber.lastEffect.nextEffect = workInProgress;
11286 } else {
11287 returnFiber.firstEffect = workInProgress;
11288 }
11289 returnFiber.lastEffect = workInProgress;
11290 }
11291 }
11292
11293 if (true && ReactFiberInstrumentation_1.debugTool) {
11294 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11295 }
11296
11297 if (siblingFiber !== null) {
11298 // If there is more work to do in this returnFiber, do that next.
11299 return siblingFiber;
11300 } else if (returnFiber !== null) {
11301 // If there's no more work in this returnFiber. Complete the returnFiber.
11302 workInProgress = returnFiber;
11303 continue;
11304 } else {
11305 // We've reached the root.
11306 return null;
11307 }
11308 } else {
11309 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
11310 // Record the render duration for the fiber that errored.
11311 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
11312
11313 // Include the time spent working on failed children before continuing.
11314 var actualDuration = workInProgress.actualDuration;
11315 var child = workInProgress.child;
11316 while (child !== null) {
11317 actualDuration += child.actualDuration;
11318 child = child.sibling;
11319 }
11320 workInProgress.actualDuration = actualDuration;
11321 }
11322
11323 // This fiber did not complete because something threw. Pop values off
11324 // the stack without entering the complete phase. If this is a boundary,
11325 // capture values if possible.
11326 var next = unwindWork(workInProgress, nextRenderExpirationTime);
11327 // Because this fiber did not complete, don't reset its expiration time.
11328 if (workInProgress.effectTag & DidCapture) {
11329 // Restarting an error boundary
11330 stopFailedWorkTimer(workInProgress);
11331 } else {
11332 stopWorkTimer(workInProgress);
11333 }
11334
11335 {
11336 resetCurrentFiber();
11337 }
11338
11339 if (next !== null) {
11340 stopWorkTimer(workInProgress);
11341 if (true && ReactFiberInstrumentation_1.debugTool) {
11342 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11343 }
11344
11345 // If completing this work spawned new work, do that next. We'll come
11346 // back here again.
11347 // Since we're restarting, remove anything that is not a host effect
11348 // from the effect tag.
11349 next.effectTag &= HostEffectMask;
11350 return next;
11351 }
11352
11353 if (returnFiber !== null) {
11354 // Mark the parent fiber as incomplete and clear its effect list.
11355 returnFiber.firstEffect = returnFiber.lastEffect = null;
11356 returnFiber.effectTag |= Incomplete;
11357 }
11358
11359 if (true && ReactFiberInstrumentation_1.debugTool) {
11360 ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress);
11361 }
11362
11363 if (siblingFiber !== null) {
11364 // If there is more work to do in this returnFiber, do that next.
11365 return siblingFiber;
11366 } else if (returnFiber !== null) {
11367 // If there's no more work in this returnFiber. Complete the returnFiber.
11368 workInProgress = returnFiber;
11369 continue;
11370 } else {
11371 return null;
11372 }
11373 }
11374 }
11375
11376 // Without this explicit null return Flow complains of invalid return type
11377 // TODO Remove the above while(true) loop
11378 // eslint-disable-next-line no-unreachable
11379 return null;
11380}
11381
11382function performUnitOfWork(workInProgress) {
11383 // The current, flushed, state of this fiber is the alternate.
11384 // Ideally nothing should rely on this, but relying on it here
11385 // means that we don't need an additional field on the work in
11386 // progress.
11387 var current$$1 = workInProgress.alternate;
11388
11389 // See if beginning this work spawns more work.
11390 startWorkTimer(workInProgress);
11391 {
11392 setCurrentFiber(workInProgress);
11393 }
11394
11395 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11396 stashedWorkInProgressProperties = assignFiberPropertiesInDEV(stashedWorkInProgressProperties, workInProgress);
11397 }
11398
11399 var next = void 0;
11400 if (enableProfilerTimer) {
11401 if (workInProgress.mode & ProfileMode) {
11402 startProfilerTimer(workInProgress);
11403 }
11404
11405 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11406 workInProgress.memoizedProps = workInProgress.pendingProps;
11407
11408 if (workInProgress.mode & ProfileMode) {
11409 // Record the render duration assuming we didn't bailout (or error).
11410 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
11411 }
11412 } else {
11413 next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
11414 workInProgress.memoizedProps = workInProgress.pendingProps;
11415 }
11416
11417 {
11418 resetCurrentFiber();
11419 if (isReplayingFailedUnitOfWork) {
11420 // Currently replaying a failed unit of work. This should be unreachable,
11421 // because the render phase is meant to be idempotent, and it should
11422 // have thrown again. Since it didn't, rethrow the original error, so
11423 // React's internal stack is not misaligned.
11424 rethrowOriginalError();
11425 }
11426 }
11427 if (true && ReactFiberInstrumentation_1.debugTool) {
11428 ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress);
11429 }
11430
11431 if (next === null) {
11432 // If this doesn't spawn new work, complete the current work.
11433 next = completeUnitOfWork(workInProgress);
11434 }
11435
11436 ReactCurrentOwner$1.current = null;
11437
11438 return next;
11439}
11440
11441function workLoop(isYieldy) {
11442 if (!isYieldy) {
11443 // Flush work without yielding
11444 while (nextUnitOfWork !== null) {
11445 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11446 }
11447 } else {
11448 // Flush asynchronous work until there's a higher priority event
11449 while (nextUnitOfWork !== null && !shouldYieldToRenderer()) {
11450 nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
11451 }
11452 }
11453}
11454
11455function renderRoot(root, isYieldy) {
11456 !!isWorking ? invariant(false, 'renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11457
11458 flushPassiveEffects$1();
11459
11460 isWorking = true;
11461 var previousDispatcher = ReactCurrentDispatcher.current;
11462 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
11463
11464 var expirationTime = root.nextExpirationTimeToWorkOn;
11465
11466 // Check if we're starting from a fresh stack, or if we're resuming from
11467 // previously yielded work.
11468 if (expirationTime !== nextRenderExpirationTime || root !== nextRoot || nextUnitOfWork === null) {
11469 // Reset the stack and start working from the root.
11470 resetStack();
11471 nextRoot = root;
11472 nextRenderExpirationTime = expirationTime;
11473 nextUnitOfWork = createWorkInProgress(nextRoot.current, null, nextRenderExpirationTime);
11474 root.pendingCommitExpirationTime = NoWork;
11475
11476 if (enableSchedulerTracing) {
11477 // Determine which interactions this batch of work currently includes,
11478 // So that we can accurately attribute time spent working on it,
11479 var interactions = new Set();
11480 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
11481 if (scheduledExpirationTime >= expirationTime) {
11482 scheduledInteractions.forEach(function (interaction) {
11483 return interactions.add(interaction);
11484 });
11485 }
11486 });
11487
11488 // Store the current set of interactions on the FiberRoot for a few reasons:
11489 // We can re-use it in hot functions like renderRoot() without having to recalculate it.
11490 // We will also use it in commitWork() to pass to any Profiler onRender() hooks.
11491 // This also provides DevTools with a way to access it when the onCommitRoot() hook is called.
11492 root.memoizedInteractions = interactions;
11493
11494 if (interactions.size > 0) {
11495 var subscriber = tracing.__subscriberRef.current;
11496 if (subscriber !== null) {
11497 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11498 try {
11499 subscriber.onWorkStarted(interactions, threadID);
11500 } catch (error) {
11501 // Work thrown by an interaction tracing subscriber should be rethrown,
11502 // But only once it's safe (to avoid leaving the scheduler in an invalid state).
11503 // Store the error for now and we'll re-throw in finishRendering().
11504 if (!hasUnhandledError) {
11505 hasUnhandledError = true;
11506 unhandledError = error;
11507 }
11508 }
11509 }
11510 }
11511 }
11512 }
11513
11514 var prevInteractions = null;
11515 if (enableSchedulerTracing) {
11516 // We're about to start new traced work.
11517 // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
11518 prevInteractions = tracing.__interactionsRef.current;
11519 tracing.__interactionsRef.current = root.memoizedInteractions;
11520 }
11521
11522 var didFatal = false;
11523
11524 startWorkLoopTimer(nextUnitOfWork);
11525
11526 do {
11527 try {
11528 workLoop(isYieldy);
11529 } catch (thrownValue) {
11530 resetContextDependences();
11531 resetHooks();
11532
11533 // Reset in case completion throws.
11534 // This is only used in DEV and when replaying is on.
11535 var mayReplay = void 0;
11536 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11537 mayReplay = mayReplayFailedUnitOfWork;
11538 mayReplayFailedUnitOfWork = true;
11539 }
11540
11541 if (nextUnitOfWork === null) {
11542 // This is a fatal error.
11543 didFatal = true;
11544 onUncaughtError(thrownValue);
11545 } else {
11546 if (enableProfilerTimer && nextUnitOfWork.mode & ProfileMode) {
11547 // Record the time spent rendering before an error was thrown.
11548 // This avoids inaccurate Profiler durations in the case of a suspended render.
11549 stopProfilerTimerIfRunningAndRecordDelta(nextUnitOfWork, true);
11550 }
11551
11552 {
11553 // Reset global debug state
11554 // We assume this is defined in DEV
11555 resetCurrentlyProcessingQueue();
11556 }
11557
11558 if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
11559 if (mayReplay) {
11560 var failedUnitOfWork = nextUnitOfWork;
11561 replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
11562 }
11563 }
11564
11565 // TODO: we already know this isn't true in some cases.
11566 // At least this shows a nicer error message until we figure out the cause.
11567 // https://github.com/facebook/react/issues/12449#issuecomment-386727431
11568 !(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;
11569
11570 var sourceFiber = nextUnitOfWork;
11571 var returnFiber = sourceFiber.return;
11572 if (returnFiber === null) {
11573 // This is the root. The root could capture its own errors. However,
11574 // we don't know if it errors before or after we pushed the host
11575 // context. This information is needed to avoid a stack mismatch.
11576 // Because we're not sure, treat this as a fatal error. We could track
11577 // which phase it fails in, but doesn't seem worth it. At least
11578 // for now.
11579 didFatal = true;
11580 onUncaughtError(thrownValue);
11581 } else {
11582 throwException(root, returnFiber, sourceFiber, thrownValue, nextRenderExpirationTime);
11583 nextUnitOfWork = completeUnitOfWork(sourceFiber);
11584 continue;
11585 }
11586 }
11587 }
11588 break;
11589 } while (true);
11590
11591 if (enableSchedulerTracing) {
11592 // Traced work is done for now; restore the previous interactions.
11593 tracing.__interactionsRef.current = prevInteractions;
11594 }
11595
11596 // We're done performing work. Time to clean up.
11597 isWorking = false;
11598 ReactCurrentDispatcher.current = previousDispatcher;
11599 resetContextDependences();
11600 resetHooks();
11601
11602 // Yield back to main thread.
11603 if (didFatal) {
11604 var _didCompleteRoot = false;
11605 stopWorkLoopTimer(interruptedBy, _didCompleteRoot);
11606 interruptedBy = null;
11607 // There was a fatal error.
11608 {
11609 resetStackAfterFatalErrorInDev();
11610 }
11611 // `nextRoot` points to the in-progress root. A non-null value indicates
11612 // that we're in the middle of an async render. Set it to null to indicate
11613 // there's no more work to be done in the current batch.
11614 nextRoot = null;
11615 onFatal(root);
11616 return;
11617 }
11618
11619 if (nextUnitOfWork !== null) {
11620 // There's still remaining async work in this tree, but we ran out of time
11621 // in the current frame. Yield back to the renderer. Unless we're
11622 // interrupted by a higher priority update, we'll continue later from where
11623 // we left off.
11624 var _didCompleteRoot2 = false;
11625 stopWorkLoopTimer(interruptedBy, _didCompleteRoot2);
11626 interruptedBy = null;
11627 onYield(root);
11628 return;
11629 }
11630
11631 // We completed the whole tree.
11632 var didCompleteRoot = true;
11633 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
11634 var rootWorkInProgress = root.current.alternate;
11635 !(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;
11636
11637 // `nextRoot` points to the in-progress root. A non-null value indicates
11638 // that we're in the middle of an async render. Set it to null to indicate
11639 // there's no more work to be done in the current batch.
11640 nextRoot = null;
11641 interruptedBy = null;
11642
11643 if (nextRenderDidError) {
11644 // There was an error
11645 if (hasLowerPriorityWork(root, expirationTime)) {
11646 // There's lower priority work. If so, it may have the effect of fixing
11647 // the exception that was just thrown. Exit without committing. This is
11648 // similar to a suspend, but without a timeout because we're not waiting
11649 // for a promise to resolve. React will restart at the lower
11650 // priority level.
11651 markSuspendedPriorityLevel(root, expirationTime);
11652 var suspendedExpirationTime = expirationTime;
11653 var rootExpirationTime = root.expirationTime;
11654 onSuspend(root, rootWorkInProgress, suspendedExpirationTime, rootExpirationTime, -1 // Indicates no timeout
11655 );
11656 return;
11657 } else if (
11658 // There's no lower priority work, but we're rendering asynchronously.
11659 // Synchronously attempt to render the same level one more time. This is
11660 // similar to a suspend, but without a timeout because we're not waiting
11661 // for a promise to resolve.
11662 !root.didError && isYieldy) {
11663 root.didError = true;
11664 var _suspendedExpirationTime = root.nextExpirationTimeToWorkOn = expirationTime;
11665 var _rootExpirationTime = root.expirationTime = Sync;
11666 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime, _rootExpirationTime, -1 // Indicates no timeout
11667 );
11668 return;
11669 }
11670 }
11671
11672 if (isYieldy && nextLatestAbsoluteTimeoutMs !== -1) {
11673 // The tree was suspended.
11674 var _suspendedExpirationTime2 = expirationTime;
11675 markSuspendedPriorityLevel(root, _suspendedExpirationTime2);
11676
11677 // Find the earliest uncommitted expiration time in the tree, including
11678 // work that is suspended. The timeout threshold cannot be longer than
11679 // the overall expiration.
11680 var earliestExpirationTime = findEarliestOutstandingPriorityLevel(root, expirationTime);
11681 var earliestExpirationTimeMs = expirationTimeToMs(earliestExpirationTime);
11682 if (earliestExpirationTimeMs < nextLatestAbsoluteTimeoutMs) {
11683 nextLatestAbsoluteTimeoutMs = earliestExpirationTimeMs;
11684 }
11685
11686 // Subtract the current time from the absolute timeout to get the number
11687 // of milliseconds until the timeout. In other words, convert an absolute
11688 // timestamp to a relative time. This is the value that is passed
11689 // to `setTimeout`.
11690 var currentTimeMs = expirationTimeToMs(requestCurrentTime());
11691 var msUntilTimeout = nextLatestAbsoluteTimeoutMs - currentTimeMs;
11692 msUntilTimeout = msUntilTimeout < 0 ? 0 : msUntilTimeout;
11693
11694 // TODO: Account for the Just Noticeable Difference
11695
11696 var _rootExpirationTime2 = root.expirationTime;
11697 onSuspend(root, rootWorkInProgress, _suspendedExpirationTime2, _rootExpirationTime2, msUntilTimeout);
11698 return;
11699 }
11700
11701 // Ready to commit.
11702 onComplete(root, rootWorkInProgress, expirationTime);
11703}
11704
11705function captureCommitPhaseError(sourceFiber, value) {
11706 var expirationTime = Sync;
11707 var fiber = sourceFiber.return;
11708 while (fiber !== null) {
11709 switch (fiber.tag) {
11710 case ClassComponent:
11711 var ctor = fiber.type;
11712 var instance = fiber.stateNode;
11713 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
11714 var errorInfo = createCapturedValue(value, sourceFiber);
11715 var update = createClassErrorUpdate(fiber, errorInfo, expirationTime);
11716 enqueueUpdate(fiber, update);
11717 scheduleWork(fiber, expirationTime);
11718 return;
11719 }
11720 break;
11721 case HostRoot:
11722 {
11723 var _errorInfo = createCapturedValue(value, sourceFiber);
11724 var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime);
11725 enqueueUpdate(fiber, _update);
11726 scheduleWork(fiber, expirationTime);
11727 return;
11728 }
11729 }
11730 fiber = fiber.return;
11731 }
11732
11733 if (sourceFiber.tag === HostRoot) {
11734 // Error was thrown at the root. There is no parent, so the root
11735 // itself should capture it.
11736 var rootFiber = sourceFiber;
11737 var _errorInfo2 = createCapturedValue(value, rootFiber);
11738 var _update2 = createRootErrorUpdate(rootFiber, _errorInfo2, expirationTime);
11739 enqueueUpdate(rootFiber, _update2);
11740 scheduleWork(rootFiber, expirationTime);
11741 }
11742}
11743
11744function computeThreadID(expirationTime, interactionThreadID) {
11745 // Interaction threads are unique per root and expiration time.
11746 return expirationTime * 1000 + interactionThreadID;
11747}
11748
11749function computeExpirationForFiber(currentTime, fiber) {
11750 var priorityLevel = scheduler.unstable_getCurrentPriorityLevel();
11751
11752 var expirationTime = void 0;
11753 if ((fiber.mode & ConcurrentMode) === NoContext) {
11754 // Outside of concurrent mode, updates are always synchronous.
11755 expirationTime = Sync;
11756 } else if (isWorking && !isCommitting$1) {
11757 // During render phase, updates expire during as the current render.
11758 expirationTime = nextRenderExpirationTime;
11759 } else {
11760 switch (priorityLevel) {
11761 case scheduler.unstable_ImmediatePriority:
11762 expirationTime = Sync;
11763 break;
11764 case scheduler.unstable_UserBlockingPriority:
11765 expirationTime = computeInteractiveExpiration(currentTime);
11766 break;
11767 case scheduler.unstable_NormalPriority:
11768 // This is a normal, concurrent update
11769 expirationTime = computeAsyncExpiration(currentTime);
11770 break;
11771 case scheduler.unstable_LowPriority:
11772 case scheduler.unstable_IdlePriority:
11773 expirationTime = Never;
11774 break;
11775 default:
11776 invariant(false, 'Unknown priority level. This error is likely caused by a bug in React. Please file an issue.');
11777 }
11778
11779 // If we're in the middle of rendering a tree, do not update at the same
11780 // expiration time that is already rendering.
11781 if (nextRoot !== null && expirationTime === nextRenderExpirationTime) {
11782 expirationTime -= 1;
11783 }
11784 }
11785
11786 // Keep track of the lowest pending interactive expiration time. This
11787 // allows us to synchronously flush all interactive updates
11788 // when needed.
11789 // TODO: Move this to renderer?
11790 return expirationTime;
11791}
11792
11793function renderDidSuspend(root, absoluteTimeoutMs, suspendedTime) {
11794 // Schedule the timeout.
11795 if (absoluteTimeoutMs >= 0 && nextLatestAbsoluteTimeoutMs < absoluteTimeoutMs) {
11796 nextLatestAbsoluteTimeoutMs = absoluteTimeoutMs;
11797 }
11798}
11799
11800function renderDidError() {
11801 nextRenderDidError = true;
11802}
11803
11804function pingSuspendedRoot(root, thenable, pingTime) {
11805 // A promise that previously suspended React from committing has resolved.
11806 // If React is still suspended, try again at the previous level (pingTime).
11807
11808 var pingCache = root.pingCache;
11809 if (pingCache !== null) {
11810 // The thenable resolved, so we no longer need to memoize, because it will
11811 // never be thrown again.
11812 pingCache.delete(thenable);
11813 }
11814
11815 if (nextRoot !== null && nextRenderExpirationTime === pingTime) {
11816 // Received a ping at the same priority level at which we're currently
11817 // rendering. Restart from the root.
11818 nextRoot = null;
11819 } else {
11820 // Confirm that the root is still suspended at this level. Otherwise exit.
11821 if (isPriorityLevelSuspended(root, pingTime)) {
11822 // Ping at the original level
11823 markPingedPriorityLevel(root, pingTime);
11824 var rootExpirationTime = root.expirationTime;
11825 if (rootExpirationTime !== NoWork) {
11826 requestWork(root, rootExpirationTime);
11827 }
11828 }
11829 }
11830}
11831
11832function retryTimedOutBoundary(boundaryFiber, thenable) {
11833 // The boundary fiber (a Suspense component) previously timed out and was
11834 // rendered in its fallback state. One of the promises that suspended it has
11835 // resolved, which means at least part of the tree was likely unblocked. Try
11836 var retryCache = void 0;
11837 if (enableSuspenseServerRenderer) {
11838 switch (boundaryFiber.tag) {
11839 case SuspenseComponent:
11840 retryCache = boundaryFiber.stateNode;
11841 break;
11842 case DehydratedSuspenseComponent:
11843 retryCache = boundaryFiber.memoizedState;
11844 break;
11845 default:
11846 invariant(false, 'Pinged unknown suspense boundary type. This is probably a bug in React.');
11847 }
11848 } else {
11849 retryCache = boundaryFiber.stateNode;
11850 }
11851 if (retryCache !== null) {
11852 // The thenable resolved, so we no longer need to memoize, because it will
11853 // never be thrown again.
11854 retryCache.delete(thenable);
11855 }
11856
11857 var currentTime = requestCurrentTime();
11858 var retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
11859 var root = scheduleWorkToRoot(boundaryFiber, retryTime);
11860 if (root !== null) {
11861 markPendingPriorityLevel(root, retryTime);
11862 var rootExpirationTime = root.expirationTime;
11863 if (rootExpirationTime !== NoWork) {
11864 requestWork(root, rootExpirationTime);
11865 }
11866 }
11867}
11868
11869function scheduleWorkToRoot(fiber, expirationTime) {
11870 recordScheduleUpdate();
11871
11872 {
11873 if (fiber.tag === ClassComponent) {
11874 var instance = fiber.stateNode;
11875 warnAboutInvalidUpdates(instance);
11876 }
11877 }
11878
11879 // Update the source fiber's expiration time
11880 if (fiber.expirationTime < expirationTime) {
11881 fiber.expirationTime = expirationTime;
11882 }
11883 var alternate = fiber.alternate;
11884 if (alternate !== null && alternate.expirationTime < expirationTime) {
11885 alternate.expirationTime = expirationTime;
11886 }
11887 // Walk the parent path to the root and update the child expiration time.
11888 var node = fiber.return;
11889 var root = null;
11890 if (node === null && fiber.tag === HostRoot) {
11891 root = fiber.stateNode;
11892 } else {
11893 while (node !== null) {
11894 alternate = node.alternate;
11895 if (node.childExpirationTime < expirationTime) {
11896 node.childExpirationTime = expirationTime;
11897 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
11898 alternate.childExpirationTime = expirationTime;
11899 }
11900 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
11901 alternate.childExpirationTime = expirationTime;
11902 }
11903 if (node.return === null && node.tag === HostRoot) {
11904 root = node.stateNode;
11905 break;
11906 }
11907 node = node.return;
11908 }
11909 }
11910
11911 if (enableSchedulerTracing) {
11912 if (root !== null) {
11913 var interactions = tracing.__interactionsRef.current;
11914 if (interactions.size > 0) {
11915 var pendingInteractionMap = root.pendingInteractionMap;
11916 var pendingInteractions = pendingInteractionMap.get(expirationTime);
11917 if (pendingInteractions != null) {
11918 interactions.forEach(function (interaction) {
11919 if (!pendingInteractions.has(interaction)) {
11920 // Update the pending async work count for previously unscheduled interaction.
11921 interaction.__count++;
11922 }
11923
11924 pendingInteractions.add(interaction);
11925 });
11926 } else {
11927 pendingInteractionMap.set(expirationTime, new Set(interactions));
11928
11929 // Update the pending async work count for the current interactions.
11930 interactions.forEach(function (interaction) {
11931 interaction.__count++;
11932 });
11933 }
11934
11935 var subscriber = tracing.__subscriberRef.current;
11936 if (subscriber !== null) {
11937 var threadID = computeThreadID(expirationTime, root.interactionThreadID);
11938 subscriber.onWorkScheduled(interactions, threadID);
11939 }
11940 }
11941 }
11942 }
11943 return root;
11944}
11945
11946function warnIfNotCurrentlyBatchingInDev(fiber) {
11947 {
11948 if (isRendering === false && isBatchingUpdates === false) {
11949 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));
11950 }
11951 }
11952}
11953
11954function scheduleWork(fiber, expirationTime) {
11955 var root = scheduleWorkToRoot(fiber, expirationTime);
11956 if (root === null) {
11957 {
11958 switch (fiber.tag) {
11959 case ClassComponent:
11960 warnAboutUpdateOnUnmounted(fiber, true);
11961 break;
11962 case FunctionComponent:
11963 case ForwardRef:
11964 case MemoComponent:
11965 case SimpleMemoComponent:
11966 warnAboutUpdateOnUnmounted(fiber, false);
11967 break;
11968 }
11969 }
11970 return;
11971 }
11972
11973 if (!isWorking && nextRenderExpirationTime !== NoWork && expirationTime > nextRenderExpirationTime) {
11974 // This is an interruption. (Used for performance tracking.)
11975 interruptedBy = fiber;
11976 resetStack();
11977 }
11978 markPendingPriorityLevel(root, expirationTime);
11979 if (
11980 // If we're in the render phase, we don't need to schedule this root
11981 // for an update, because we'll do it before we exit...
11982 !isWorking || isCommitting$1 ||
11983 // ...unless this is a different root than the one we're rendering.
11984 nextRoot !== root) {
11985 var rootExpirationTime = root.expirationTime;
11986 requestWork(root, rootExpirationTime);
11987 }
11988 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
11989 // Reset this back to zero so subsequent updates don't throw.
11990 nestedUpdateCount = 0;
11991 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.');
11992 }
11993}
11994
11995function syncUpdates(fn, a, b, c, d) {
11996 return scheduler.unstable_runWithPriority(scheduler.unstable_ImmediatePriority, function () {
11997 return fn(a, b, c, d);
11998 });
11999}
12000
12001// TODO: Everything below this is written as if it has been lifted to the
12002// renderers. I'll do this in a follow-up.
12003
12004// Linked-list of roots
12005var firstScheduledRoot = null;
12006var lastScheduledRoot = null;
12007
12008var callbackExpirationTime = NoWork;
12009var callbackID = void 0;
12010var isRendering = false;
12011var nextFlushedRoot = null;
12012var nextFlushedExpirationTime = NoWork;
12013var hasUnhandledError = false;
12014var unhandledError = null;
12015
12016var isBatchingUpdates = false;
12017var isUnbatchingUpdates = false;
12018
12019var completedBatches = null;
12020
12021var originalStartTimeMs = now();
12022var currentRendererTime = msToExpirationTime(originalStartTimeMs);
12023var currentSchedulerTime = currentRendererTime;
12024
12025// Use these to prevent an infinite loop of nested updates
12026var NESTED_UPDATE_LIMIT = 50;
12027var nestedUpdateCount = 0;
12028var lastCommittedRootDuringThisBatch = null;
12029
12030function recomputeCurrentRendererTime() {
12031 var currentTimeMs = now() - originalStartTimeMs;
12032 currentRendererTime = msToExpirationTime(currentTimeMs);
12033}
12034
12035function scheduleCallbackWithExpirationTime(root, expirationTime) {
12036 if (callbackExpirationTime !== NoWork) {
12037 // A callback is already scheduled. Check its expiration time (timeout).
12038 if (expirationTime < callbackExpirationTime) {
12039 // Existing callback has sufficient timeout. Exit.
12040 return;
12041 } else {
12042 if (callbackID !== null) {
12043 // Existing callback has insufficient timeout. Cancel and schedule a
12044 // new one.
12045 cancelDeferredCallback$$1(callbackID);
12046 }
12047 }
12048 // The request callback timer is already running. Don't start a new one.
12049 } else {
12050 startRequestCallbackTimer();
12051 }
12052
12053 callbackExpirationTime = expirationTime;
12054 var currentMs = now() - originalStartTimeMs;
12055 var expirationTimeMs = expirationTimeToMs(expirationTime);
12056 var timeout = expirationTimeMs - currentMs;
12057 callbackID = scheduleDeferredCallback$$1(performAsyncWork, { timeout: timeout });
12058}
12059
12060// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and
12061// onYield is called upon exiting. We use these in lieu of returning a tuple.
12062// I've also chosen not to inline them into renderRoot because these will
12063// eventually be lifted into the renderer.
12064function onFatal(root) {
12065 root.finishedWork = null;
12066}
12067
12068function onComplete(root, finishedWork, expirationTime) {
12069 root.pendingCommitExpirationTime = expirationTime;
12070 root.finishedWork = finishedWork;
12071}
12072
12073function onSuspend(root, finishedWork, suspendedExpirationTime, rootExpirationTime, msUntilTimeout) {
12074 root.expirationTime = rootExpirationTime;
12075 if (msUntilTimeout === 0 && !shouldYieldToRenderer()) {
12076 // Don't wait an additional tick. Commit the tree immediately.
12077 root.pendingCommitExpirationTime = suspendedExpirationTime;
12078 root.finishedWork = finishedWork;
12079 } else if (msUntilTimeout > 0) {
12080 // Wait `msUntilTimeout` milliseconds before committing.
12081 root.timeoutHandle = scheduleTimeout(onTimeout.bind(null, root, finishedWork, suspendedExpirationTime), msUntilTimeout);
12082 }
12083}
12084
12085function onYield(root) {
12086 root.finishedWork = null;
12087}
12088
12089function onTimeout(root, finishedWork, suspendedExpirationTime) {
12090 // The root timed out. Commit it.
12091 root.pendingCommitExpirationTime = suspendedExpirationTime;
12092 root.finishedWork = finishedWork;
12093 // Read the current time before entering the commit phase. We can be
12094 // certain this won't cause tearing related to batching of event updates
12095 // because we're at the top of a timer event.
12096 recomputeCurrentRendererTime();
12097 currentSchedulerTime = currentRendererTime;
12098 flushRoot(root, suspendedExpirationTime);
12099}
12100
12101function onCommit(root, expirationTime) {
12102 root.expirationTime = expirationTime;
12103 root.finishedWork = null;
12104}
12105
12106function requestCurrentTime() {
12107 // requestCurrentTime is called by the scheduler to compute an expiration
12108 // time.
12109 //
12110 // Expiration times are computed by adding to the current time (the start
12111 // time). However, if two updates are scheduled within the same event, we
12112 // should treat their start times as simultaneous, even if the actual clock
12113 // time has advanced between the first and second call.
12114
12115 // In other words, because expiration times determine how updates are batched,
12116 // we want all updates of like priority that occur within the same event to
12117 // receive the same expiration time. Otherwise we get tearing.
12118 //
12119 // We keep track of two separate times: the current "renderer" time and the
12120 // current "scheduler" time. The renderer time can be updated whenever; it
12121 // only exists to minimize the calls performance.now.
12122 //
12123 // But the scheduler time can only be updated if there's no pending work, or
12124 // if we know for certain that we're not in the middle of an event.
12125
12126 if (isRendering) {
12127 // We're already rendering. Return the most recently read time.
12128 return currentSchedulerTime;
12129 }
12130 // Check if there's pending work.
12131 findHighestPriorityRoot();
12132 if (nextFlushedExpirationTime === NoWork || nextFlushedExpirationTime === Never) {
12133 // If there's no pending work, or if the pending work is offscreen, we can
12134 // read the current time without risk of tearing.
12135 recomputeCurrentRendererTime();
12136 currentSchedulerTime = currentRendererTime;
12137 return currentSchedulerTime;
12138 }
12139 // There's already pending work. We might be in the middle of a browser
12140 // event. If we were to read the current time, it could cause multiple updates
12141 // within the same event to receive different expiration times, leading to
12142 // tearing. Return the last read time. During the next idle callback, the
12143 // time will be updated.
12144 return currentSchedulerTime;
12145}
12146
12147// requestWork is called by the scheduler whenever a root receives an update.
12148// It's up to the renderer to call renderRoot at some point in the future.
12149function requestWork(root, expirationTime) {
12150 addRootToSchedule(root, expirationTime);
12151 if (isRendering) {
12152 // Prevent reentrancy. Remaining work will be scheduled at the end of
12153 // the currently rendering batch.
12154 return;
12155 }
12156
12157 if (isBatchingUpdates) {
12158 // Flush work at the end of the batch.
12159 if (isUnbatchingUpdates) {
12160 // ...unless we're inside unbatchedUpdates, in which case we should
12161 // flush it now.
12162 nextFlushedRoot = root;
12163 nextFlushedExpirationTime = Sync;
12164 performWorkOnRoot(root, Sync, false);
12165 }
12166 return;
12167 }
12168
12169 // TODO: Get rid of Sync and use current time?
12170 if (expirationTime === Sync) {
12171 performSyncWork();
12172 } else {
12173 scheduleCallbackWithExpirationTime(root, expirationTime);
12174 }
12175}
12176
12177function addRootToSchedule(root, expirationTime) {
12178 // Add the root to the schedule.
12179 // Check if this root is already part of the schedule.
12180 if (root.nextScheduledRoot === null) {
12181 // This root is not already scheduled. Add it.
12182 root.expirationTime = expirationTime;
12183 if (lastScheduledRoot === null) {
12184 firstScheduledRoot = lastScheduledRoot = root;
12185 root.nextScheduledRoot = root;
12186 } else {
12187 lastScheduledRoot.nextScheduledRoot = root;
12188 lastScheduledRoot = root;
12189 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12190 }
12191 } else {
12192 // This root is already scheduled, but its priority may have increased.
12193 var remainingExpirationTime = root.expirationTime;
12194 if (expirationTime > remainingExpirationTime) {
12195 // Update the priority.
12196 root.expirationTime = expirationTime;
12197 }
12198 }
12199}
12200
12201function findHighestPriorityRoot() {
12202 var highestPriorityWork = NoWork;
12203 var highestPriorityRoot = null;
12204 if (lastScheduledRoot !== null) {
12205 var previousScheduledRoot = lastScheduledRoot;
12206 var root = firstScheduledRoot;
12207 while (root !== null) {
12208 var remainingExpirationTime = root.expirationTime;
12209 if (remainingExpirationTime === NoWork) {
12210 // This root no longer has work. Remove it from the scheduler.
12211
12212 // TODO: This check is redudant, but Flow is confused by the branch
12213 // below where we set lastScheduledRoot to null, even though we break
12214 // from the loop right after.
12215 !(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;
12216 if (root === root.nextScheduledRoot) {
12217 // This is the only root in the list.
12218 root.nextScheduledRoot = null;
12219 firstScheduledRoot = lastScheduledRoot = null;
12220 break;
12221 } else if (root === firstScheduledRoot) {
12222 // This is the first root in the list.
12223 var next = root.nextScheduledRoot;
12224 firstScheduledRoot = next;
12225 lastScheduledRoot.nextScheduledRoot = next;
12226 root.nextScheduledRoot = null;
12227 } else if (root === lastScheduledRoot) {
12228 // This is the last root in the list.
12229 lastScheduledRoot = previousScheduledRoot;
12230 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12231 root.nextScheduledRoot = null;
12232 break;
12233 } else {
12234 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
12235 root.nextScheduledRoot = null;
12236 }
12237 root = previousScheduledRoot.nextScheduledRoot;
12238 } else {
12239 if (remainingExpirationTime > highestPriorityWork) {
12240 // Update the priority, if it's higher
12241 highestPriorityWork = remainingExpirationTime;
12242 highestPriorityRoot = root;
12243 }
12244 if (root === lastScheduledRoot) {
12245 break;
12246 }
12247 if (highestPriorityWork === Sync) {
12248 // Sync is highest priority by definition so
12249 // we can stop searching.
12250 break;
12251 }
12252 previousScheduledRoot = root;
12253 root = root.nextScheduledRoot;
12254 }
12255 }
12256 }
12257
12258 nextFlushedRoot = highestPriorityRoot;
12259 nextFlushedExpirationTime = highestPriorityWork;
12260}
12261
12262// TODO: This wrapper exists because many of the older tests (the ones that use
12263// flushDeferredPri) rely on the number of times `shouldYield` is called. We
12264// should get rid of it.
12265var didYield = false;
12266function shouldYieldToRenderer() {
12267 if (didYield) {
12268 return true;
12269 }
12270 if (shouldYield$$1()) {
12271 didYield = true;
12272 return true;
12273 }
12274 return false;
12275}
12276
12277function performAsyncWork() {
12278 try {
12279 if (!shouldYieldToRenderer()) {
12280 // The callback timed out. That means at least one update has expired.
12281 // Iterate through the root schedule. If they contain expired work, set
12282 // the next render expiration time to the current time. This has the effect
12283 // of flushing all expired work in a single batch, instead of flushing each
12284 // level one at a time.
12285 if (firstScheduledRoot !== null) {
12286 recomputeCurrentRendererTime();
12287 var root = firstScheduledRoot;
12288 do {
12289 didExpireAtExpirationTime(root, currentRendererTime);
12290 // The root schedule is circular, so this is never null.
12291 root = root.nextScheduledRoot;
12292 } while (root !== firstScheduledRoot);
12293 }
12294 }
12295 performWork(NoWork, true);
12296 } finally {
12297 didYield = false;
12298 }
12299}
12300
12301function performSyncWork() {
12302 performWork(Sync, false);
12303}
12304
12305function performWork(minExpirationTime, isYieldy) {
12306 // Keep working on roots until there's no more work, or until there's a higher
12307 // priority event.
12308 findHighestPriorityRoot();
12309
12310 if (isYieldy) {
12311 recomputeCurrentRendererTime();
12312 currentSchedulerTime = currentRendererTime;
12313
12314 if (enableUserTimingAPI) {
12315 var didExpire = nextFlushedExpirationTime > currentRendererTime;
12316 var timeout = expirationTimeToMs(nextFlushedExpirationTime);
12317 stopRequestCallbackTimer(didExpire, timeout);
12318 }
12319
12320 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime && !(didYield && currentRendererTime > nextFlushedExpirationTime)) {
12321 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, currentRendererTime > nextFlushedExpirationTime);
12322 findHighestPriorityRoot();
12323 recomputeCurrentRendererTime();
12324 currentSchedulerTime = currentRendererTime;
12325 }
12326 } else {
12327 while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime) {
12328 performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
12329 findHighestPriorityRoot();
12330 }
12331 }
12332
12333 // We're done flushing work. Either we ran out of time in this callback,
12334 // or there's no more work left with sufficient priority.
12335
12336 // If we're inside a callback, set this to false since we just completed it.
12337 if (isYieldy) {
12338 callbackExpirationTime = NoWork;
12339 callbackID = null;
12340 }
12341 // If there's work left over, schedule a new callback.
12342 if (nextFlushedExpirationTime !== NoWork) {
12343 scheduleCallbackWithExpirationTime(nextFlushedRoot, nextFlushedExpirationTime);
12344 }
12345
12346 // Clean-up.
12347 finishRendering();
12348}
12349
12350function flushRoot(root, expirationTime) {
12351 !!isRendering ? invariant(false, 'work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method.') : void 0;
12352 // Perform work on root as if the given expiration time is the current time.
12353 // This has the effect of synchronously flushing all work up to and
12354 // including the given time.
12355 nextFlushedRoot = root;
12356 nextFlushedExpirationTime = expirationTime;
12357 performWorkOnRoot(root, expirationTime, false);
12358 // Flush any sync work that was scheduled by lifecycles
12359 performSyncWork();
12360}
12361
12362function finishRendering() {
12363 nestedUpdateCount = 0;
12364 lastCommittedRootDuringThisBatch = null;
12365
12366 if (completedBatches !== null) {
12367 var batches = completedBatches;
12368 completedBatches = null;
12369 for (var i = 0; i < batches.length; i++) {
12370 var batch = batches[i];
12371 try {
12372 batch._onComplete();
12373 } catch (error) {
12374 if (!hasUnhandledError) {
12375 hasUnhandledError = true;
12376 unhandledError = error;
12377 }
12378 }
12379 }
12380 }
12381
12382 if (hasUnhandledError) {
12383 var error = unhandledError;
12384 unhandledError = null;
12385 hasUnhandledError = false;
12386 throw error;
12387 }
12388}
12389
12390function performWorkOnRoot(root, expirationTime, isYieldy) {
12391 !!isRendering ? invariant(false, 'performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue.') : void 0;
12392
12393 isRendering = true;
12394
12395 // Check if this is async work or sync/expired work.
12396 if (!isYieldy) {
12397 // Flush work without yielding.
12398 // TODO: Non-yieldy work does not necessarily imply expired work. A renderer
12399 // may want to perform some work without yielding, but also without
12400 // requiring the root to complete (by triggering placeholders).
12401
12402 var finishedWork = root.finishedWork;
12403 if (finishedWork !== null) {
12404 // This root is already complete. We can commit it.
12405 completeRoot(root, finishedWork, expirationTime);
12406 } else {
12407 root.finishedWork = null;
12408 // If this root previously suspended, clear its existing timeout, since
12409 // we're about to try rendering again.
12410 var timeoutHandle = root.timeoutHandle;
12411 if (timeoutHandle !== noTimeout) {
12412 root.timeoutHandle = noTimeout;
12413 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12414 cancelTimeout(timeoutHandle);
12415 }
12416 renderRoot(root, isYieldy);
12417 finishedWork = root.finishedWork;
12418 if (finishedWork !== null) {
12419 // We've completed the root. Commit it.
12420 completeRoot(root, finishedWork, expirationTime);
12421 }
12422 }
12423 } else {
12424 // Flush async work.
12425 var _finishedWork = root.finishedWork;
12426 if (_finishedWork !== null) {
12427 // This root is already complete. We can commit it.
12428 completeRoot(root, _finishedWork, expirationTime);
12429 } else {
12430 root.finishedWork = null;
12431 // If this root previously suspended, clear its existing timeout, since
12432 // we're about to try rendering again.
12433 var _timeoutHandle = root.timeoutHandle;
12434 if (_timeoutHandle !== noTimeout) {
12435 root.timeoutHandle = noTimeout;
12436 // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
12437 cancelTimeout(_timeoutHandle);
12438 }
12439 renderRoot(root, isYieldy);
12440 _finishedWork = root.finishedWork;
12441 if (_finishedWork !== null) {
12442 // We've completed the root. Check the if we should yield one more time
12443 // before committing.
12444 if (!shouldYieldToRenderer()) {
12445 // Still time left. Commit the root.
12446 completeRoot(root, _finishedWork, expirationTime);
12447 } else {
12448 // There's no time left. Mark this root as complete. We'll come
12449 // back and commit it later.
12450 root.finishedWork = _finishedWork;
12451 }
12452 }
12453 }
12454 }
12455
12456 isRendering = false;
12457}
12458
12459function completeRoot(root, finishedWork, expirationTime) {
12460 // Check if there's a batch that matches this expiration time.
12461 var firstBatch = root.firstBatch;
12462 if (firstBatch !== null && firstBatch._expirationTime >= expirationTime) {
12463 if (completedBatches === null) {
12464 completedBatches = [firstBatch];
12465 } else {
12466 completedBatches.push(firstBatch);
12467 }
12468 if (firstBatch._defer) {
12469 // This root is blocked from committing by a batch. Unschedule it until
12470 // we receive another update.
12471 root.finishedWork = finishedWork;
12472 root.expirationTime = NoWork;
12473 return;
12474 }
12475 }
12476
12477 // Commit the root.
12478 root.finishedWork = null;
12479
12480 // Check if this is a nested update (a sync update scheduled during the
12481 // commit phase).
12482 if (root === lastCommittedRootDuringThisBatch) {
12483 // If the next root is the same as the previous root, this is a nested
12484 // update. To prevent an infinite loop, increment the nested update count.
12485 nestedUpdateCount++;
12486 } else {
12487 // Reset whenever we switch roots.
12488 lastCommittedRootDuringThisBatch = root;
12489 nestedUpdateCount = 0;
12490 }
12491 scheduler.unstable_runWithPriority(scheduler.unstable_ImmediatePriority, function () {
12492 commitRoot(root, finishedWork);
12493 });
12494}
12495
12496function onUncaughtError(error) {
12497 !(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;
12498 // Unschedule this root so we don't work on it again until there's
12499 // another update.
12500 nextFlushedRoot.expirationTime = NoWork;
12501 if (!hasUnhandledError) {
12502 hasUnhandledError = true;
12503 unhandledError = error;
12504 }
12505}
12506
12507// TODO: Batching should be implemented at the renderer level, not inside
12508// the reconciler.
12509function batchedUpdates(fn, a) {
12510 var previousIsBatchingUpdates = isBatchingUpdates;
12511 isBatchingUpdates = true;
12512 try {
12513 return fn(a);
12514 } finally {
12515 isBatchingUpdates = previousIsBatchingUpdates;
12516 if (!isBatchingUpdates && !isRendering) {
12517 performSyncWork();
12518 }
12519 }
12520}
12521
12522// TODO: Batching should be implemented at the renderer level, not within
12523// the reconciler.
12524function flushSync(fn, a) {
12525 !!isRendering ? invariant(false, 'flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.') : void 0;
12526 var previousIsBatchingUpdates = isBatchingUpdates;
12527 isBatchingUpdates = true;
12528 try {
12529 return syncUpdates(fn, a);
12530 } finally {
12531 isBatchingUpdates = previousIsBatchingUpdates;
12532 performSyncWork();
12533 }
12534}
12535
12536// 0 is PROD, 1 is DEV.
12537// Might add PROFILE later.
12538
12539
12540var didWarnAboutNestedUpdates = void 0;
12541{
12542 didWarnAboutNestedUpdates = false;
12543
12544}
12545
12546function getContextForSubtree(parentComponent) {
12547 if (!parentComponent) {
12548 return emptyContextObject;
12549 }
12550
12551 var fiber = get(parentComponent);
12552 var parentContext = findCurrentUnmaskedContext(fiber);
12553
12554 if (fiber.tag === ClassComponent) {
12555 var Component = fiber.type;
12556 if (isContextProvider(Component)) {
12557 return processChildContext(fiber, Component, parentContext);
12558 }
12559 }
12560
12561 return parentContext;
12562}
12563
12564function scheduleRootUpdate(current$$1, element, expirationTime, callback) {
12565 {
12566 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
12567 didWarnAboutNestedUpdates = true;
12568 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');
12569 }
12570 }
12571
12572 var update = createUpdate(expirationTime);
12573 // Caution: React DevTools currently depends on this property
12574 // being called "element".
12575 update.payload = { element: element };
12576
12577 callback = callback === undefined ? null : callback;
12578 if (callback !== null) {
12579 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
12580 update.callback = callback;
12581 }
12582
12583 flushPassiveEffects$1();
12584 enqueueUpdate(current$$1, update);
12585 scheduleWork(current$$1, expirationTime);
12586
12587 return expirationTime;
12588}
12589
12590function updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback) {
12591 // TODO: If this is a nested container, this won't be the root.
12592 var current$$1 = container.current;
12593
12594 {
12595 if (ReactFiberInstrumentation_1.debugTool) {
12596 if (current$$1.alternate === null) {
12597 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
12598 } else if (element === null) {
12599 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
12600 } else {
12601 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
12602 }
12603 }
12604 }
12605
12606 var context = getContextForSubtree(parentComponent);
12607 if (container.context === null) {
12608 container.context = context;
12609 } else {
12610 container.pendingContext = context;
12611 }
12612
12613 return scheduleRootUpdate(current$$1, element, expirationTime, callback);
12614}
12615
12616function createContainer(containerInfo, isConcurrent, hydrate) {
12617 return createFiberRoot(containerInfo, isConcurrent, hydrate);
12618}
12619
12620function updateContainer(element, container, parentComponent, callback) {
12621 var current$$1 = container.current;
12622 var currentTime = requestCurrentTime();
12623 var expirationTime = computeExpirationForFiber(currentTime, current$$1);
12624 return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback);
12625}
12626
12627function getPublicRootInstance(container) {
12628 var containerFiber = container.current;
12629 if (!containerFiber.child) {
12630 return null;
12631 }
12632 switch (containerFiber.child.tag) {
12633 case HostComponent:
12634 return getPublicInstance(containerFiber.child.stateNode);
12635 default:
12636 return containerFiber.child.stateNode;
12637 }
12638}
12639
12640
12641
12642var overrideProps = null;
12643
12644{
12645 var copyWithSetImpl = function (obj, path, idx, value) {
12646 if (idx >= path.length) {
12647 return value;
12648 }
12649 var key = path[idx];
12650 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
12651 // $FlowFixMe number or string is fine here
12652 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
12653 return updated;
12654 };
12655
12656 var copyWithSet = function (obj, path, value) {
12657 return copyWithSetImpl(obj, path, 0, value);
12658 };
12659
12660 // Support DevTools props for function components, forwardRef, memo, host components, etc.
12661 overrideProps = function (fiber, path, value) {
12662 flushPassiveEffects$1();
12663 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
12664 if (fiber.alternate) {
12665 fiber.alternate.pendingProps = fiber.pendingProps;
12666 }
12667 scheduleWork(fiber, Sync);
12668 };
12669}
12670
12671function injectIntoDevTools(devToolsConfig) {
12672 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
12673 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
12674
12675
12676 return injectInternals(_assign({}, devToolsConfig, {
12677 overrideProps: overrideProps,
12678 currentDispatcherRef: ReactCurrentDispatcher,
12679 findHostInstanceByFiber: function (fiber) {
12680 var hostFiber = findCurrentHostFiber(fiber);
12681 if (hostFiber === null) {
12682 return null;
12683 }
12684 return hostFiber.stateNode;
12685 },
12686 findFiberByHostInstance: function (instance) {
12687 if (!findFiberByHostInstance) {
12688 // Might not be implemented by the renderer.
12689 return null;
12690 }
12691 return findFiberByHostInstance(instance);
12692 }
12693 }));
12694}
12695
12696// This file intentionally does *not* have the Flow annotation.
12697// Don't add it. See `./inline-typed.js` for an explanation.
12698
12699// TODO: this is special because it gets imported during build.
12700
12701var ReactVersion = '16.8.6';
12702
12703var _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; }; }();
12704
12705function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12706
12707function _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; }
12708
12709// for .act's return value
12710
12711
12712var defaultTestOptions = {
12713 createNodeMock: function () {
12714 return null;
12715 }
12716};
12717
12718function toJSON(inst) {
12719 if (inst.isHidden) {
12720 // Omit timed out children from output entirely. This seems like the least
12721 // surprising behavior. We could perhaps add a separate API that includes
12722 // them, if it turns out people need it.
12723 return null;
12724 }
12725 switch (inst.tag) {
12726 case 'TEXT':
12727 return inst.text;
12728 case 'INSTANCE':
12729 {
12730 /* eslint-disable no-unused-vars */
12731 // We don't include the `children` prop in JSON.
12732 // Instead, we will include the actual rendered children.
12733 var _inst$props = inst.props,
12734 _children = _inst$props.children,
12735 _props = _objectWithoutProperties(_inst$props, ['children']);
12736 /* eslint-enable */
12737
12738
12739 var renderedChildren = null;
12740 if (inst.children && inst.children.length) {
12741 for (var i = 0; i < inst.children.length; i++) {
12742 var renderedChild = toJSON(inst.children[i]);
12743 if (renderedChild !== null) {
12744 if (renderedChildren === null) {
12745 renderedChildren = [renderedChild];
12746 } else {
12747 renderedChildren.push(renderedChild);
12748 }
12749 }
12750 }
12751 }
12752 var json = {
12753 type: inst.type,
12754 props: _props,
12755 children: renderedChildren
12756 };
12757 Object.defineProperty(json, '$$typeof', {
12758 value: Symbol.for('react.test.json')
12759 });
12760 return json;
12761 }
12762 default:
12763 throw new Error('Unexpected node type in toJSON: ' + inst.tag);
12764 }
12765}
12766
12767function childrenToTree(node) {
12768 if (!node) {
12769 return null;
12770 }
12771 var children = nodeAndSiblingsArray(node);
12772 if (children.length === 0) {
12773 return null;
12774 } else if (children.length === 1) {
12775 return toTree(children[0]);
12776 }
12777 return flatten(children.map(toTree));
12778}
12779
12780function nodeAndSiblingsArray(nodeWithSibling) {
12781 var array = [];
12782 var node = nodeWithSibling;
12783 while (node != null) {
12784 array.push(node);
12785 node = node.sibling;
12786 }
12787 return array;
12788}
12789
12790function flatten(arr) {
12791 var result = [];
12792 var stack = [{ i: 0, array: arr }];
12793 while (stack.length) {
12794 var n = stack.pop();
12795 while (n.i < n.array.length) {
12796 var el = n.array[n.i];
12797 n.i += 1;
12798 if (Array.isArray(el)) {
12799 stack.push(n);
12800 stack.push({ i: 0, array: el });
12801 break;
12802 }
12803 result.push(el);
12804 }
12805 }
12806 return result;
12807}
12808
12809function toTree(node) {
12810 if (node == null) {
12811 return null;
12812 }
12813 switch (node.tag) {
12814 case HostRoot:
12815 return childrenToTree(node.child);
12816 case HostPortal:
12817 return childrenToTree(node.child);
12818 case ClassComponent:
12819 return {
12820 nodeType: 'component',
12821 type: node.type,
12822 props: _assign({}, node.memoizedProps),
12823 instance: node.stateNode,
12824 rendered: childrenToTree(node.child)
12825 };
12826 case FunctionComponent:
12827 case SimpleMemoComponent:
12828 return {
12829 nodeType: 'component',
12830 type: node.type,
12831 props: _assign({}, node.memoizedProps),
12832 instance: null,
12833 rendered: childrenToTree(node.child)
12834 };
12835 case HostComponent:
12836 {
12837 return {
12838 nodeType: 'host',
12839 type: node.type,
12840 props: _assign({}, node.memoizedProps),
12841 instance: null, // TODO: use createNodeMock here somehow?
12842 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
12843 };
12844 }
12845 case HostText:
12846 return node.stateNode.text;
12847 case Fragment:
12848 case ContextProvider:
12849 case ContextConsumer:
12850 case Mode:
12851 case Profiler:
12852 case ForwardRef:
12853 case MemoComponent:
12854 case IncompleteClassComponent:
12855 return childrenToTree(node.child);
12856 default:
12857 invariant(false, 'toTree() does not yet know how to handle nodes with tag=%s', node.tag);
12858 }
12859}
12860
12861var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent,
12862// Normally skipped, but used when there's more than one root child.
12863HostRoot]);
12864
12865function getChildren(parent) {
12866 var children = [];
12867 var startingNode = parent;
12868 var node = startingNode;
12869 if (node.child === null) {
12870 return children;
12871 }
12872 node.child.return = node;
12873 node = node.child;
12874 outer: while (true) {
12875 var descend = false;
12876 if (validWrapperTypes.has(node.tag)) {
12877 children.push(wrapFiber(node));
12878 } else if (node.tag === HostText) {
12879 children.push('' + node.memoizedProps);
12880 } else {
12881 descend = true;
12882 }
12883 if (descend && node.child !== null) {
12884 node.child.return = node;
12885 node = node.child;
12886 continue;
12887 }
12888 while (node.sibling === null) {
12889 if (node.return === startingNode) {
12890 break outer;
12891 }
12892 node = node.return;
12893 }
12894 node.sibling.return = node.return;
12895 node = node.sibling;
12896 }
12897 return children;
12898}
12899
12900var ReactTestInstance = function () {
12901 ReactTestInstance.prototype._currentFiber = function _currentFiber() {
12902 // Throws if this component has been unmounted.
12903 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
12904 !(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;
12905 return fiber;
12906 };
12907
12908 function ReactTestInstance(fiber) {
12909 _classCallCheck(this, ReactTestInstance);
12910
12911 !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;
12912 this._fiber = fiber;
12913 }
12914
12915 // Custom search functions
12916 ReactTestInstance.prototype.find = function find(predicate) {
12917 return expectOne(this.findAll(predicate, { deep: false }), 'matching custom predicate: ' + predicate.toString());
12918 };
12919
12920 ReactTestInstance.prototype.findByType = function findByType(type) {
12921 return expectOne(this.findAllByType(type, { deep: false }), 'with node type: "' + (type.displayName || type.name) + '"');
12922 };
12923
12924 ReactTestInstance.prototype.findByProps = function findByProps(props) {
12925 return expectOne(this.findAllByProps(props, { deep: false }), 'with props: ' + JSON.stringify(props));
12926 };
12927
12928 ReactTestInstance.prototype.findAll = function findAll(predicate) {
12929 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12930
12931 return _findAll(this, predicate, options);
12932 };
12933
12934 ReactTestInstance.prototype.findAllByType = function findAllByType(type) {
12935 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12936
12937 return _findAll(this, function (node) {
12938 return node.type === type;
12939 }, options);
12940 };
12941
12942 ReactTestInstance.prototype.findAllByProps = function findAllByProps(props) {
12943 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
12944
12945 return _findAll(this, function (node) {
12946 return node.props && propsMatch(node.props, props);
12947 }, options);
12948 };
12949
12950 _createClass(ReactTestInstance, [{
12951 key: 'instance',
12952 get: function () {
12953 if (this._fiber.tag === HostComponent) {
12954 return getPublicInstance(this._fiber.stateNode);
12955 } else {
12956 return this._fiber.stateNode;
12957 }
12958 }
12959 }, {
12960 key: 'type',
12961 get: function () {
12962 return this._fiber.type;
12963 }
12964 }, {
12965 key: 'props',
12966 get: function () {
12967 return this._currentFiber().memoizedProps;
12968 }
12969 }, {
12970 key: 'parent',
12971 get: function () {
12972 var parent = this._fiber.return;
12973 while (parent !== null) {
12974 if (validWrapperTypes.has(parent.tag)) {
12975 if (parent.tag === HostRoot) {
12976 // Special case: we only "materialize" instances for roots
12977 // if they have more than a single child. So we'll check that now.
12978 if (getChildren(parent).length < 2) {
12979 return null;
12980 }
12981 }
12982 return wrapFiber(parent);
12983 }
12984 parent = parent.return;
12985 }
12986 return null;
12987 }
12988 }, {
12989 key: 'children',
12990 get: function () {
12991 return getChildren(this._currentFiber());
12992 }
12993 }]);
12994
12995 return ReactTestInstance;
12996}();
12997
12998function _findAll(root, predicate, options) {
12999 var deep = options ? options.deep : true;
13000 var results = [];
13001
13002 if (predicate(root)) {
13003 results.push(root);
13004 if (!deep) {
13005 return results;
13006 }
13007 }
13008
13009 root.children.forEach(function (child) {
13010 if (typeof child === 'string') {
13011 return;
13012 }
13013 results.push.apply(results, _findAll(child, predicate, options));
13014 });
13015
13016 return results;
13017}
13018
13019function expectOne(all, message) {
13020 if (all.length === 1) {
13021 return all[0];
13022 }
13023
13024 var prefix = all.length === 0 ? 'No instances found ' : 'Expected 1 but found ' + all.length + ' instances ';
13025
13026 throw new Error(prefix + message);
13027}
13028
13029function propsMatch(props, filter) {
13030 for (var key in filter) {
13031 if (props[key] !== filter[key]) {
13032 return false;
13033 }
13034 }
13035 return true;
13036}
13037
13038var ReactTestRendererFiber = {
13039 create: function (element, options) {
13040 var createNodeMock = defaultTestOptions.createNodeMock;
13041 var isConcurrent = false;
13042 if (typeof options === 'object' && options !== null) {
13043 if (typeof options.createNodeMock === 'function') {
13044 createNodeMock = options.createNodeMock;
13045 }
13046 if (options.unstable_isConcurrent === true) {
13047 isConcurrent = true;
13048 }
13049 }
13050 var container = {
13051 children: [],
13052 createNodeMock: createNodeMock,
13053 tag: 'CONTAINER'
13054 };
13055 var root = createContainer(container, isConcurrent, false);
13056 !(root != null) ? invariant(false, 'something went wrong') : void 0;
13057 updateContainer(element, root, null, null);
13058
13059 var entry = {
13060 root: undefined, // makes flow happy
13061 // we define a 'getter' for 'root' below using 'Object.defineProperty'
13062 toJSON: function () {
13063 if (root == null || root.current == null || container == null) {
13064 return null;
13065 }
13066 if (container.children.length === 0) {
13067 return null;
13068 }
13069 if (container.children.length === 1) {
13070 return toJSON(container.children[0]);
13071 }
13072 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
13073 // Omit timed out children from output entirely, including the fact that we
13074 // temporarily wrap fallback and timed out children in an array.
13075 return toJSON(container.children[1]);
13076 }
13077 var renderedChildren = null;
13078 if (container.children && container.children.length) {
13079 for (var i = 0; i < container.children.length; i++) {
13080 var renderedChild = toJSON(container.children[i]);
13081 if (renderedChild !== null) {
13082 if (renderedChildren === null) {
13083 renderedChildren = [renderedChild];
13084 } else {
13085 renderedChildren.push(renderedChild);
13086 }
13087 }
13088 }
13089 }
13090 return renderedChildren;
13091 },
13092 toTree: function () {
13093 if (root == null || root.current == null) {
13094 return null;
13095 }
13096 return toTree(root.current);
13097 },
13098 update: function (newElement) {
13099 if (root == null || root.current == null) {
13100 return;
13101 }
13102 updateContainer(newElement, root, null, null);
13103 },
13104 unmount: function () {
13105 if (root == null || root.current == null) {
13106 return;
13107 }
13108 updateContainer(null, root, null, null);
13109 container = null;
13110 root = null;
13111 },
13112 getInstance: function () {
13113 if (root == null || root.current == null) {
13114 return null;
13115 }
13116 return getPublicRootInstance(root);
13117 },
13118
13119
13120 unstable_flushAll: flushAll,
13121 unstable_flushSync: function (fn) {
13122 clearYields();
13123 return flushSync(fn);
13124 },
13125
13126 unstable_flushNumberOfYields: flushNumberOfYields,
13127 unstable_clearYields: clearYields
13128 };
13129
13130 Object.defineProperty(entry, 'root', {
13131 configurable: true,
13132 enumerable: true,
13133 get: function () {
13134 if (root === null) {
13135 throw new Error("Can't access .root on unmounted test renderer");
13136 }
13137 var children = getChildren(root.current);
13138 if (children.length === 0) {
13139 throw new Error("Can't access .root on unmounted test renderer");
13140 } else if (children.length === 1) {
13141 // Normally, we skip the root and just give you the child.
13142 return children[0];
13143 } else {
13144 // However, we give you the root if there's more than one root child.
13145 // We could make this the behavior for all cases but it would be a breaking change.
13146 return wrapFiber(root.current);
13147 }
13148 }
13149 });
13150
13151 return entry;
13152 },
13153
13154
13155 unstable_yield: yieldValue,
13156 unstable_clearYields: clearYields,
13157
13158 /* eslint-disable camelcase */
13159 unstable_batchedUpdates: batchedUpdates,
13160 /* eslint-enable camelcase */
13161
13162 unstable_setNowImplementation: setNowImplementation,
13163
13164 act: function (callback) {
13165 // note: keep these warning messages in sync with
13166 // createNoop.js and ReactTestUtils.js
13167 var result = batchedUpdates(callback);
13168 {
13169 if (result !== undefined) {
13170 var addendum = void 0;
13171 if (result !== null && typeof result.then === 'function') {
13172 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';
13173 } else {
13174 addendum = ' You returned: ' + result;
13175 }
13176 warningWithoutStack$1(false, 'The callback passed to TestRenderer.act(...) function must not return anything.%s', addendum);
13177 }
13178 }
13179 flushPassiveEffects();
13180 // we want the user to not expect a return,
13181 // but we want to warn if they use it like they can await on it.
13182 return {
13183 then: function () {
13184 {
13185 warningWithoutStack$1(false, 'Do not await the result of calling TestRenderer.act(...), it is not a Promise.');
13186 }
13187 }
13188 };
13189 }
13190};
13191
13192// root used to flush effects during .act() calls
13193var actRoot = createContainer({
13194 children: [],
13195 createNodeMock: defaultTestOptions.createNodeMock,
13196 tag: 'CONTAINER'
13197}, true, false);
13198
13199function flushPassiveEffects() {
13200 // Trick to flush passive effects without exposing an internal API:
13201 // Create a throwaway root and schedule a dummy update on it.
13202 updateContainer(null, actRoot, null, null);
13203}
13204
13205var fiberToWrapper = new WeakMap();
13206function wrapFiber(fiber) {
13207 var wrapper = fiberToWrapper.get(fiber);
13208 if (wrapper === undefined && fiber.alternate !== null) {
13209 wrapper = fiberToWrapper.get(fiber.alternate);
13210 }
13211 if (wrapper === undefined) {
13212 wrapper = new ReactTestInstance(fiber);
13213 fiberToWrapper.set(fiber, wrapper);
13214 }
13215 return wrapper;
13216}
13217
13218// Enable ReactTestRenderer to be used to test DevTools integration.
13219injectIntoDevTools({
13220 findFiberByHostInstance: function () {
13221 throw new Error('TestRenderer does not support findFiberByHostInstance()');
13222 },
13223 bundleType: 1,
13224 version: ReactVersion,
13225 rendererPackageName: 'react-test-renderer'
13226});
13227
13228
13229
13230var ReactTestRenderer = Object.freeze({
13231 default: ReactTestRendererFiber
13232});
13233
13234var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
13235
13236// TODO: decide on the top-level export form.
13237// This is hacky but makes it work with both Rollup and Jest.
13238var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
13239
13240module.exports = reactTestRenderer;
13241 })();
13242}