UNPKG

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