UNPKG

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