diff --git a/Libraries/Renderer/REVISION b/Libraries/Renderer/REVISION index 347ba9d44caa00..b660dbcbc40f42 100644 --- a/Libraries/Renderer/REVISION +++ b/Libraries/Renderer/REVISION @@ -1 +1 @@ -55bc393f726ddf3def83ca5a43cfc38a45d2e421 \ No newline at end of file +85d05b3a4d439c504ee43652d586ee253a01faf6 \ No newline at end of file diff --git a/Libraries/Renderer/implementations/ReactFabric-dev.fb.js b/Libraries/Renderer/implementations/ReactFabric-dev.fb.js index 220395e35f439f..68b992fd50d5ea 100644 --- a/Libraries/Renderer/implementations/ReactFabric-dev.fb.js +++ b/Libraries/Renderer/implementations/ReactFabric-dev.fb.js @@ -2790,6 +2790,36 @@ var HostEffectMask = /* */ 1023; var Incomplete = /* */ 1024; var ShouldCapture = /* */ 2048; +// Re-export dynamic flags from the fbsource version. +var _require = require("../shims/ReactFeatureFlags"); + +var debugRenderPhaseSideEffects = _require.debugRenderPhaseSideEffects; + +var enableUserTimingAPI = true; +var enableProfilerTimer = true; +var enableSchedulerTracing = true; +var enableSuspenseServerRenderer = false; + +var debugRenderPhaseSideEffectsForStrictMode = true; + +var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; +var warnAboutDeprecatedLifecycles = true; +var warnAboutDeprecatedSetNativeProps = true; +var enableFlareAPI = false; +var enableFundamentalAPI = false; + +var warnAboutUnmockedScheduler = true; +var revertPassiveEffectsChange = false; +var flushSuspenseFallbacksInTests = true; +var enableUserBlockingEvents = false; +var enableSuspenseCallback = false; +var warnAboutDefaultPropsOnFunctionComponents = false; +var warnAboutStringRefs = false; +var disableLegacyContext = false; +var disableSchedulerTimeoutBasedOnReactExpirationTime = false; + +// Only used in www builds. + var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner; var MOUNTING = 1; @@ -3608,31 +3638,6 @@ function restoreStateIfNeeded() { } } -// Re-export dynamic flags from the fbsource version. -var _require = require("../shims/ReactFeatureFlags"); - -var debugRenderPhaseSideEffects = _require.debugRenderPhaseSideEffects; - -var enableUserTimingAPI = true; -var enableProfilerTimer = true; -var enableSchedulerTracing = true; -var enableSuspenseServerRenderer = false; - -var debugRenderPhaseSideEffectsForStrictMode = true; - -var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; -var warnAboutDeprecatedLifecycles = true; -var warnAboutDeprecatedSetNativeProps = true; -var enableFlareAPI = false; -var enableFundamentalAPI = false; - -var revertPassiveEffectsChange = false; -var enableUserBlockingEvents = false; -var enableSuspenseCallback = false; -var warnAboutDefaultPropsOnFunctionComponents = false; - -// Only used in www builds. - // Used as a way to call batchedUpdates when we don't have a reference to // the renderer. Such as when we're dispatching events or if third party // libraries need to call batchedUpdates. Eventually, this API will go away when @@ -3894,19 +3899,13 @@ var currentEventQueuePriority = ContinuousEvent; var currentTimerIDCounter = 0; var eventResponderContext = { - dispatchEvent: function(eventProp, eventValue, eventPriority) { + dispatchEvent: function(eventValue, eventListener, eventPriority) { validateResponderContext(); validateEventValue(eventValue); if (eventPriority < currentEventQueuePriority) { currentEventQueuePriority = eventPriority; } - var responderInstance = currentInstance; - var target = responderInstance.fiber; - var responder = responderInstance.responder; - var listeners = collectListeners(eventProp, responder, target); - if (listeners.length !== 0) { - currentEventQueue.push(createEventQueueItem(eventValue, listeners)); - } + currentEventQueue.push(createEventQueueItem(eventValue, eventListener)); }, isTargetWithinNode: function(childTarget, parentTarget) { validateResponderContext(); @@ -4003,10 +4002,10 @@ var eventResponderContext = { } }; -function createEventQueueItem(value, listeners) { +function createEventQueueItem(value, listener) { return { value: value, - listeners: listeners + listener: listener }; } @@ -4164,80 +4163,16 @@ function releaseOwnershipForEventResponderInstance(eventResponderInstance) { return false; } -// TODO this function is almost an exact copy of the DOM version, we should -// somehow share the logic -function collectListeners(eventProp, eventResponder, target) { - var eventListeners = []; - var node = target.return; - nodeTraversal: while (node !== null) { - switch (node.tag) { - case HostComponent: { - var dependencies = node.dependencies; - - if (dependencies !== null) { - var respondersMap = dependencies.responders; - - if (respondersMap !== null && respondersMap.has(eventResponder)) { - break nodeTraversal; - } - } - break; - } - case FunctionComponent: - case MemoComponent: - case ForwardRef: { - var _dependencies = node.dependencies; - - if (_dependencies !== null) { - var _listeners = _dependencies.listeners; - - if (_listeners !== null) { - for ( - var s = 0, listenersLength = _listeners.length; - s < listenersLength; - s++ - ) { - var listener = _listeners[s]; - var responder = listener.responder, - props = listener.props; - - var listenerFunc = props[eventProp]; - - if ( - responder === eventResponder && - typeof listenerFunc === "function" - ) { - eventListeners.push(listenerFunc); - } - } - } - } - } - } - node = node.return; - } - return eventListeners; -} - // TODO this function is almost an exact copy of the DOM version, we should // somehow share the logic function processEvents(eventQueue) { for (var i = 0, length = eventQueue.length; i < length; i++) { var _eventQueue$i = eventQueue[i], _value = _eventQueue$i.value, - _listeners2 = _eventQueue$i.listeners; + _listener = _eventQueue$i.listener; - for (var s = 0, length2 = _listeners2.length; s < length2; s++) { - var listener = _listeners2[s]; - var type = - typeof _value === "object" && _value !== null ? _value.type : ""; - invokeGuardedCallbackAndCatchFirstError( - type, - listener, - undefined, - _value - ); - } + var type = typeof _value === "object" && _value !== null ? _value.type : ""; + invokeGuardedCallbackAndCatchFirstError(type, _listener, undefined, _value); } } @@ -5653,262 +5588,310 @@ function getUnmaskedContext( Component, didPushOwnContextIfProvider ) { - if (didPushOwnContextIfProvider && isContextProvider(Component)) { - // If the fiber is a context provider itself, when we read its context - // we may have already pushed its own child context on the stack. A context - // provider should not "see" its own child context. Therefore we read the - // previous (parent) context instead for a context provider. - return previousContext; + if (disableLegacyContext) { + return emptyContextObject; + } else { + if (didPushOwnContextIfProvider && isContextProvider(Component)) { + // If the fiber is a context provider itself, when we read its context + // we may have already pushed its own child context on the stack. A context + // provider should not "see" its own child context. Therefore we read the + // previous (parent) context instead for a context provider. + return previousContext; + } + return contextStackCursor.current; } - return contextStackCursor.current; } function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + } } function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { + if (disableLegacyContext) { return emptyContextObject; - } + } else { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyContextObject; + } - // Avoid recreating masked context unless unmasked context has changed. - // Failing to do this will result in unnecessary calls to componentWillReceiveProps. - // This may trigger infinite loops if componentWillReceiveProps calls setState. - var instance = workInProgress.stateNode; - if ( - instance && - instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext - ) { - return instance.__reactInternalMemoizedMaskedChildContext; - } + // Avoid recreating masked context unless unmasked context has changed. + // Failing to do this will result in unnecessary calls to componentWillReceiveProps. + // This may trigger infinite loops if componentWillReceiveProps calls setState. + var instance = workInProgress.stateNode; + if ( + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext + ) { + return instance.__reactInternalMemoizedMaskedChildContext; + } - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - getCurrentFiberStackInDev - ); - } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + getCurrentFiberStackInDev + ); + } - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // Context is created before the class component is instantiated so check for instance. - if (instance) { - cacheContext(workInProgress, unmaskedContext, context); - } + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // Context is created before the class component is instantiated so check for instance. + if (instance) { + cacheContext(workInProgress, unmaskedContext, context); + } - return context; + return context; + } } function hasContextChanged() { - return didPerformWorkStackCursor.current; + if (disableLegacyContext) { + return false; + } else { + return didPerformWorkStackCursor.current; + } } function isContextProvider(type) { - var childContextTypes = type.childContextTypes; - return childContextTypes !== null && childContextTypes !== undefined; + if (disableLegacyContext) { + return false; + } else { + var childContextTypes = type.childContextTypes; + return childContextTypes !== null && childContextTypes !== undefined; + } } function popContext(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function pushTopLevelContextObject(fiber, context, didChange) { - (function() { - if (!(contextStackCursor.current === emptyContextObject)) { - throw ReactError( - Error( - "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return; + } else { + (function() { + if (!(contextStackCursor.current === emptyContextObject)) { + throw ReactError( + Error( + "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - push(contextStackCursor, context, fiber); - push(didPerformWorkStackCursor, didChange, fiber); + push(contextStackCursor, context, fiber); + push(didPerformWorkStackCursor, didChange, fiber); + } } function processChildContext(fiber, type, parentContext) { - var instance = fiber.stateNode; - var childContextTypes = type.childContextTypes; + if (disableLegacyContext) { + return parentContext; + } else { + var instance = fiber.stateNode; + var childContextTypes = type.childContextTypes; - // TODO (bvaughn) Replace this behavior with an invariant() in the future. - // It has only been added in Fiber to match the (unintentional) behavior in Stack. - if (typeof instance.getChildContext !== "function") { - { - var componentName = getComponentName(type) || "Unknown"; + // TODO (bvaughn) Replace this behavior with an invariant() in the future. + // It has only been added in Fiber to match the (unintentional) behavior in Stack. + if (typeof instance.getChildContext !== "function") { + { + var componentName = getComponentName(type) || "Unknown"; - if (!warnedAboutMissingGetChildContext[componentName]) { - warnedAboutMissingGetChildContext[componentName] = true; - 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 - ); + if (!warnedAboutMissingGetChildContext[componentName]) { + warnedAboutMissingGetChildContext[componentName] = true; + 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 + ); + } } + return parentContext; } - return parentContext; - } - var childContext = void 0; - { - setCurrentPhase("getChildContext"); + var childContext = void 0; + { + setCurrentPhase("getChildContext"); + } + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + setCurrentPhase(null); + } + for (var contextKey in childContext) { + (function() { + if (!(contextKey in childContextTypes)) { + throw ReactError( + Error( + (getComponentName(type) || "Unknown") + + '.getChildContext(): key "' + + contextKey + + '" is not defined in childContextTypes.' + ) + ); + } + })(); + } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + childContextTypes, + childContext, + "child context", + name, + // In practice, there is one case in which we won't get a stack. It's when + // somebody calls unstable_renderSubtreeIntoContainer() and we process + // context from the parent component instance. The stack will be missing + // because it's outside of the reconciliation, and so the pointer has not + // been set. This is rare and doesn't matter. We'll also remove that API. + getCurrentFiberStackInDev + ); + } + + return Object.assign({}, parentContext, childContext); } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - setCurrentPhase(null); +} + +function pushContextProvider(workInProgress) { + if (disableLegacyContext) { + return false; + } else { + var instance = workInProgress.stateNode; + // We push the context as early as possible to ensure stack integrity. + // If the instance does not exist yet, we will push null at first, + // and replace it on the stack later when invalidating the context. + var memoizedMergedChildContext = + (instance && instance.__reactInternalMemoizedMergedChildContext) || + emptyContextObject; + + // Remember the parent context so we can merge with it later. + // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. + previousContext = contextStackCursor.current; + push(contextStackCursor, memoizedMergedChildContext, workInProgress); + push( + didPerformWorkStackCursor, + didPerformWorkStackCursor.current, + workInProgress + ); + + return true; } - for (var contextKey in childContext) { +} + +function invalidateContextProvider(workInProgress, type, didChange) { + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; (function() { - if (!(contextKey in childContextTypes)) { + if (!instance) { throw ReactError( Error( - (getComponentName(type) || "Unknown") + - '.getChildContext(): key "' + - contextKey + - '" is not defined in childContextTypes.' + "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." ) ); } })(); - } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - childContextTypes, - childContext, - "child context", - name, - // In practice, there is one case in which we won't get a stack. It's when - // somebody calls unstable_renderSubtreeIntoContainer() and we process - // context from the parent component instance. The stack will be missing - // because it's outside of the reconciliation, and so the pointer has not - // been set. This is rare and doesn't matter. We'll also remove that API. - getCurrentFiberStackInDev - ); - } - return Object.assign({}, parentContext, childContext); -} - -function pushContextProvider(workInProgress) { - var instance = workInProgress.stateNode; - // We push the context as early as possible to ensure stack integrity. - // If the instance does not exist yet, we will push null at first, - // and replace it on the stack later when invalidating the context. - var memoizedMergedChildContext = - (instance && instance.__reactInternalMemoizedMergedChildContext) || - emptyContextObject; - - // Remember the parent context so we can merge with it later. - // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. - previousContext = contextStackCursor.current; - push(contextStackCursor, memoizedMergedChildContext, workInProgress); - push( - didPerformWorkStackCursor, - didPerformWorkStackCursor.current, - workInProgress - ); - - return true; -} - -function invalidateContextProvider(workInProgress, type, didChange) { - var instance = workInProgress.stateNode; - (function() { - if (!instance) { - throw ReactError( - Error( - "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." - ) + if (didChange) { + // Merge parent and own context. + // Skip this if we're not updating due to sCU. + // This avoids unnecessarily recomputing memoized values. + var mergedContext = processChildContext( + workInProgress, + type, + previousContext ); + instance.__reactInternalMemoizedMergedChildContext = mergedContext; + + // Replace the old (or empty) context with the new one. + // It is important to unwind the context in the reverse order. + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); + // Now push the new context and mark that it has changed. + push(contextStackCursor, mergedContext, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } else { + pop(didPerformWorkStackCursor, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); } - })(); - - if (didChange) { - // Merge parent and own context. - // Skip this if we're not updating due to sCU. - // This avoids unnecessarily recomputing memoized values. - var mergedContext = processChildContext( - workInProgress, - type, - previousContext - ); - instance.__reactInternalMemoizedMergedChildContext = mergedContext; - - // Replace the old (or empty) context with the new one. - // It is important to unwind the context in the reverse order. - pop(didPerformWorkStackCursor, workInProgress); - pop(contextStackCursor, workInProgress); - // Now push the new context and mark that it has changed. - push(contextStackCursor, mergedContext, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } else { - pop(didPerformWorkStackCursor, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); } } function findCurrentUnmaskedContext(fiber) { - // Currently this is only used with renderSubtreeIntoContainer; not sure if it - // makes sense elsewhere - (function() { - if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { - throw ReactError( - Error( - "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return emptyContextObject; + } else { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere + (function() { + if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { + throw ReactError( + Error( + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - var node = fiber; - do { - switch (node.tag) { - case HostRoot: - return node.stateNode.context; - case ClassComponent: { - var Component = node.type; - if (isContextProvider(Component)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; + var node = fiber; + do { + switch (node.tag) { + case HostRoot: + return node.stateNode.context; + case ClassComponent: { + var Component = node.type; + if (isContextProvider(Component)) { + return node.stateNode.__reactInternalMemoizedMergedChildContext; + } + break; } - break; } - } - node = node.return; - } while (node !== null); - (function() { - { - throw ReactError( - Error( - "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + node = node.return; + } while (node !== null); + (function() { + { + throw ReactError( + Error( + "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); + } } var LegacyRoot = 0; @@ -5962,6 +5945,7 @@ var NormalPriority = 97; var LowPriority = 96; var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only. +var NoPriority = 90; var shouldYield = Scheduler_shouldYield; var requestPaint = @@ -7502,7 +7486,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: NoWork, firstContext: contextItem, - listeners: null, responders: null }; } else { @@ -8402,28 +8385,48 @@ function checkClassInstance(workInProgress, ctor, newProps) { name ) : void 0; - var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warningWithoutStack$1( + + if (disableLegacyContext) { + if (ctor.childContextTypes) { + warningWithoutStack$1( false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", + "%s uses the legacy childContextTypes API which is no longer supported. " + + "Use React.createContext() instead.", name - ) - : void 0; + ); + } + if (ctor.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with static contextType instead.", + name + ); + } + } else { + var noInstanceContextTypes = !instance.contextTypes; + !noInstanceContextTypes + ? warningWithoutStack$1( + false, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ) + : void 0; - if ( - ctor.contextType && - ctor.contextTypes && - !didWarnAboutContextTypeAndContextTypes.has(ctor) - ) { - didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack$1( - false, - "%s declares both contextTypes and contextType static properties. " + - "The legacy contextTypes property will be ignored.", - name - ); + if ( + ctor.contextType && + ctor.contextTypes && + !didWarnAboutContextTypeAndContextTypes.has(ctor) + ) { + didWarnAboutContextTypeAndContextTypes.add(ctor); + warningWithoutStack$1( + false, + "%s declares both contextTypes and contextType static properties. " + + "The legacy contextTypes property will be ignored.", + name + ); + } } var noComponentShouldUpdate = @@ -8599,7 +8602,7 @@ function constructClassInstance( ) { var isLegacyContextConsumer = false; var unmaskedContext = emptyContextObject; - var context = null; + var context = emptyContextObject; var contextType = ctor.contextType; { @@ -8647,7 +8650,7 @@ function constructClassInstance( if (typeof contextType === "object" && contextType !== null) { context = readContext(contextType); - } else { + } else if (!disableLegacyContext) { unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); var contextTypes = ctor.contextTypes; isLegacyContextConsumer = @@ -8849,6 +8852,8 @@ function mountClassInstance( var contextType = ctor.contextType; if (typeof contextType === "object" && contextType !== null) { instance.context = readContext(contextType); + } else if (disableLegacyContext) { + instance.context = emptyContextObject; } else { var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); instance.context = getMaskedContext(workInProgress, unmaskedContext); @@ -8949,10 +8954,10 @@ function resumeMountClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextLegacyUnmaskedContext = getUnmaskedContext( workInProgress, ctor, @@ -9098,10 +9103,10 @@ function updateClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); } @@ -9257,7 +9262,7 @@ function updateClassInstance( var didWarnAboutMaps = void 0; var didWarnAboutGenerators = void 0; -var didWarnAboutStringRefInStrictMode = void 0; +var didWarnAboutStringRefs = void 0; var ownerHasKeyUseWarning = void 0; var ownerHasFunctionTypeWarning = void 0; var warnForMissingKey = function(child) {}; @@ -9265,7 +9270,7 @@ var warnForMissingKey = function(child) {}; { didWarnAboutMaps = false; didWarnAboutGenerators = false; - didWarnAboutStringRefInStrictMode = {}; + didWarnAboutStringRefs = {}; /** * Warn if there's no key explicitly set on dynamic arrays of children or @@ -9322,21 +9327,38 @@ function coerceRef(returnFiber, current$$1, element) { typeof mixedRef !== "object" ) { { - if (returnFiber.mode & StrictMode) { + // TODO: Clean this up once we turn on the string ref warning for + // everyone, because the strict mode case will no longer be relevant + if (returnFiber.mode & StrictMode || warnAboutStringRefs) { var componentName = getComponentName(returnFiber.type) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - 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) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; + if (!didWarnAboutStringRefs[componentName]) { + if (warnAboutStringRefs) { + warningWithoutStack$1( + false, + 'Component "%s" contains the string ref "%s". Support for string refs ' + + "will be removed in a future major release. We recommend using " + + "useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + componentName, + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } else { + 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 useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } + didWarnAboutStringRefs[componentName] = true; } } } @@ -10801,45 +10823,15 @@ function findFirstSuspended(row) { return null; } -var currentlyRenderingFiber$2 = null; -var currentListenerHookIndex = 0; - -function prepareToReadListenerHooks(workInProgress) { - currentlyRenderingFiber$2 = workInProgress; - currentListenerHookIndex = 0; -} - -function getListenerHooks() { - var listeners = void 0; - var dependencies = currentlyRenderingFiber$2.dependencies; - if (dependencies === null) { - dependencies = currentlyRenderingFiber$2.dependencies = { - expirationTime: NoWork, - firstContext: null, - listeners: [], - responders: null - }; - } - listeners = dependencies.listeners; - if (listeners === null) { - dependencies.listeners = listeners = []; - } - return listeners; -} - -function updateListenerHook(responder, props) { - var listeners = getListenerHooks(); - if (listeners.length === currentListenerHookIndex) { - listeners.push({ - responder: responder, - props: props - }); - currentListenerHookIndex++; - } else { - var currentListenerHook = listeners[currentListenerHookIndex++]; - currentListenerHook.responder = responder; - currentListenerHook.props = props; +function createResponderListener(responder, props) { + var eventResponderListener = { + responder: responder, + props: props + }; + { + Object.freeze(eventResponderListener); } + return eventResponderListener; } function createResponderInstance( @@ -11924,7 +11916,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }; var HooksDispatcherOnMountInDEV = null; @@ -12031,10 +12023,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12110,10 +12102,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12189,10 +12181,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12279,11 +12271,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12370,11 +12362,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; } @@ -12437,6 +12429,17 @@ var hydrationParentFiber = null; var nextHydratableInstance = null; var isHydrating = false; +function warnIfHydrating() { + { + !!isHydrating + ? warning$1( + false, + "We should not be hydrating here. This is a bug in React. Please file a bug." + ) + : void 0; + } +} + function enterHydrationState(fiber) { if (!supportsHydration) { return false; @@ -12945,9 +12948,6 @@ function updateForwardRef( // The rest is a fork of updateFunctionComponent var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -12966,9 +12966,6 @@ function updateForwardRef( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -13248,14 +13245,14 @@ function updateFunctionComponent( } } - var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); + context = getMaskedContext(workInProgress, unmaskedContext); + } var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -13274,9 +13271,6 @@ function updateFunctionComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -13868,13 +13862,13 @@ function mountIndeterminateComponent( } var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); + context = getMaskedContext(workInProgress, unmaskedContext); + } prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } var value = void 0; { @@ -13981,6 +13975,15 @@ function mountIndeterminateComponent( // Proceed under the assumption that this is a function component workInProgress.tag = FunctionComponent; { + if (disableLegacyContext && Component.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with React.useContext() instead.", + getComponentName(Component) || "Unknown" + ); + } + if ( debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && @@ -13988,9 +13991,6 @@ function mountIndeterminateComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } value = renderWithHooks( null, workInProgress, @@ -14520,12 +14520,18 @@ function updateDehydratedSuspenseComponent( } return null; } + if ((workInProgress.effectTag & DidCapture) !== NoEffect) { // Something suspended. Leave the existing children in place. // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far? workInProgress.child = null; return null; } + + // We should never be hydrating at this point because it is the first pass, + // but after we've already committed once. + warnIfHydrating(); + if (isSuspenseInstanceFallback(suspenseInstance)) { // This boundary is in a permanent fallback state. In this case, we'll never // get an update and we'll never be able to hydrate the final content. Let's just try the @@ -15384,29 +15390,26 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect; - var childExpirationTime = workInProgress.childExpirationTime; - if (childExpirationTime < renderExpirationTime) { + var hasChildWork = + workInProgress.childExpirationTime >= renderExpirationTime; + + if (didSuspendBefore) { + if (hasChildWork) { + // If something was in fallback state last time, and we have all the + // same children then we're still in progressive loading state. + // Something might get unblocked by state updates or retries in the + // tree which will affect the tail. So we need to use the normal + // path to compute the correct tail. + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + } // If none of the children had any work, that means that none of // them got retried so they'll still be blocked in the same way // as before. We can fast bail out. - pushSuspenseContext(workInProgress, suspenseStackCursor.current); - if (didSuspendBefore) { - workInProgress.effectTag |= DidCapture; - } - return null; - } - - if (didSuspendBefore) { - // If something was in fallback state last time, and we have all the - // same children then we're still in progressive loading state. - // Something might get unblocked by state updates or retries in the - // tree which will affect the tail. So we need to use the normal - // path to compute the correct tail. - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); + workInProgress.effectTag |= DidCapture; } // If nothing suspended before and we're rendering the same children, @@ -15420,7 +15423,15 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { renderState.tail = null; } pushSuspenseContext(workInProgress, suspenseStackCursor.current); - break; + + if (hasChildWork) { + break; + } else { + // If none of the children had any work, that means that none of + // them got retried so they'll still be blocked in the same way + // as before. We can fast bail out. + return null; + } } } return bailoutOnAlreadyFinishedWork( @@ -15676,7 +15687,7 @@ if (supportsMutation) { while (node !== null) { if (node.tag === HostComponent || node.tag === HostText) { appendInitialChild(parent, node.stateNode); - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { appendInitialChild(parent, node.stateNode.instance); } else if (node.tag === HostPortal) { // If we have a portal child, then we don't want to traverse @@ -16174,12 +16185,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { ); if (enableFlareAPI) { - var prevResponders = current.memoizedProps.responders; - var nextResponders = newProps.responders; + var prevListeners = current.memoizedProps.listeners; + var nextListeners = newProps.listeners; var instance = workInProgress.stateNode; - if (prevResponders !== nextResponders) { - updateEventResponders( - nextResponders, + if (prevListeners !== nextListeners) { + updateEventListeners( + nextListeners, instance, rootContainerInstance, workInProgress @@ -16225,8 +16236,20 @@ function completeWork(current, workInProgress, renderExpirationTime) { // commit-phase we mark this as such. markUpdate(workInProgress); } + if (enableFlareAPI) { + var _instance5 = workInProgress.stateNode; + var listeners = newProps.listeners; + if (listeners != null) { + updateEventListeners( + listeners, + _instance5, + rootContainerInstance, + workInProgress + ); + } + } } else { - var _instance5 = createInstance( + var _instance6 = createInstance( type, newProps, rootContainerInstance, @@ -16234,14 +16257,14 @@ function completeWork(current, workInProgress, renderExpirationTime) { workInProgress ); - appendAllChildren(_instance5, workInProgress, false, false); + appendAllChildren(_instance6, workInProgress, false, false); if (enableFlareAPI) { - var responders = newProps.responders; - if (responders != null) { - updateEventResponders( - responders, - _instance5, + var _listeners = newProps.listeners; + if (_listeners != null) { + updateEventListeners( + _listeners, + _instance6, rootContainerInstance, workInProgress ); @@ -16253,7 +16276,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { // Make sure such renderers get scheduled for later work. if ( finalizeInitialChildren( - _instance5, + _instance6, type, newProps, rootContainerInstance, @@ -16262,7 +16285,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { ) { markUpdate(workInProgress); } - workInProgress.stateNode = _instance5; + workInProgress.stateNode = _instance6; } if (workInProgress.ref !== null) { @@ -16462,15 +16485,22 @@ function completeWork(current, workInProgress, renderExpirationTime) { markSpawnedWork(Never); } skipPastDehydratedSuspenseInstance(workInProgress); - } else if ((workInProgress.effectTag & DidCapture) === NoEffect) { - // This boundary did not suspend so it's now hydrated. - // To handle any future suspense cases, we're going to now upgrade it - // to a Suspense component. We detach it from the existing current fiber. - current.alternate = null; - workInProgress.alternate = null; - workInProgress.tag = SuspenseComponent; - workInProgress.memoizedState = null; - workInProgress.stateNode = null; + } else { + // We should never have been in a hydration state if we didn't have a current. + // However, in some of those paths, we might have reentered a hydration state + // and then we might be inside a hydration state. In that case, we'll need to + // exit out of it. + resetHydrationState(); + if ((workInProgress.effectTag & DidCapture) === NoEffect) { + // This boundary did not suspend so it's now hydrated. + // To handle any future suspense cases, we're going to now upgrade it + // to a Suspense component. We detach it from the existing current fiber. + current.alternate = null; + workInProgress.alternate = null; + workInProgress.tag = SuspenseComponent; + workInProgress.memoizedState = null; + workInProgress.stateNode = null; + } } } break; @@ -16684,12 +16714,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalImpl, fundamentalState || {} ); - var _instance6 = getFundamentalComponentInstance(fundamentalInstance); - fundamentalInstance.instance = _instance6; + var _instance7 = getFundamentalComponentInstance(fundamentalInstance); + fundamentalInstance.instance = _instance7; if (fundamentalImpl.reconcileChildren === false) { return null; } - appendAllChildren(_instance6, workInProgress, false, false); + appendAllChildren(_instance7, workInProgress, false, false); mountFundamentalComponent(fundamentalInstance); } else { // We fire update in commit phase @@ -16698,9 +16728,9 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalInstance.props = newProps; fundamentalInstance.currentFiber = workInProgress; if (supportsPersistence) { - var _instance7 = cloneFundamentalInstance(fundamentalInstance); - fundamentalInstance.instance = _instance7; - appendAllChildren(_instance7, workInProgress, false, false); + var _instance8 = cloneFundamentalInstance(fundamentalInstance); + fundamentalInstance.instance = _instance8; + appendAllChildren(_instance8, workInProgress, false, false); } var shouldUpdate = shouldUpdateFundamentalComponent( fundamentalInstance @@ -16758,26 +16788,41 @@ function mountEventResponder$1( respondersMap.set(responder, responderInstance); } -function updateEventResponder( - responder, - props, +function updateEventListener( + listener, fiber, visistedResponders, respondersMap, instance, rootContainerInstance ) { + var responder = void 0; + var props = void 0; + + if (listener) { + responder = listener.responder; + props = listener.props; + } (function() { if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) { throw ReactError( Error( - "An invalid value was used as an event responder. Expect one or many event responders created via React.unstable_createResponer()." + "An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponer()." ) ); } })(); + var listenerProps = props; if (visistedResponders.has(responder)) { // show warning + { + warning$1( + false, + 'Duplicate event responder "%s" found in event listeners. ' + + "Event listeners passed to elements cannot use the same event responder more than once.", + responder.displayName + ); + } return; } visistedResponders.add(responder); @@ -16787,7 +16832,7 @@ function updateEventResponder( // Mount mountEventResponder$1( responder, - props, + listenerProps, instance, rootContainerInstance, fiber, @@ -16795,25 +16840,24 @@ function updateEventResponder( ); } else { // Update - responderInstance.props = props; + responderInstance.props = listenerProps; responderInstance.fiber = fiber; } } -function updateEventResponders( - responders, +function updateEventListeners( + listeners, instance, rootContainerInstance, fiber ) { var visistedResponders = new Set(); var dependencies = fiber.dependencies; - if (responders != null) { + if (listeners != null) { if (dependencies === null) { dependencies = fiber.dependencies = { expirationTime: NoWork, firstContext: null, - listeners: null, responders: new Map() }; } @@ -16821,15 +16865,11 @@ function updateEventResponders( if (respondersMap === null) { respondersMap = new Map(); } - if (isArray$2(responders)) { - for (var i = 0, length = responders.length; i < length; i++) { - var _responders$i = responders[i], - type = _responders$i.type, - props = _responders$i.props; - - updateEventResponder( - type, - props, + if (isArray$2(listeners)) { + for (var i = 0, length = listeners.length; i < length; i++) { + var listener = listeners[i]; + updateEventListener( + listener, fiber, visistedResponders, respondersMap, @@ -16838,12 +16878,8 @@ function updateEventResponders( ); } } else { - var type = responders.type, - props = responders.props; - - updateEventResponder( - type, - props, + updateEventListener( + listeners, fiber, visistedResponders, respondersMap, @@ -16916,8 +16952,12 @@ function unwindWork(workInProgress, renderExpirationTime) { } case DehydratedSuspenseComponent: { if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(workInProgress); + if (workInProgress.alternate === null) { + // TODO: popHydrationState + } else { + resetHydrationState(); + } var _effectTag3 = workInProgress.effectTag; if (_effectTag3 & ShouldCapture) { workInProgress.effectTag = @@ -16971,7 +17011,6 @@ function unwindInterruptedWork(interruptedWork) { break; case DehydratedSuspenseComponent: if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(interruptedWork); } break; @@ -17688,7 +17727,7 @@ function commitDetachRef(current$$1) { // User-originating errors (lifecycles and refs) should not interrupt // deletion, so don't let them throw. Host-originating errors should // interrupt deletion, so it's okay -function commitUnmount(current$$1) { +function commitUnmount(current$$1, renderPriorityLevel) { onCommitUnmount(current$$1); switch (current$$1.tag) { @@ -17701,14 +17740,33 @@ function commitUnmount(current$$1) { var lastEffect = updateQueue.lastEffect; if (lastEffect !== null) { var firstEffect = lastEffect.next; - var effect = firstEffect; - do { - var destroy = effect.destroy; - if (destroy !== undefined) { - safelyCallDestroy(current$$1, destroy); - } - effect = effect.next; - } while (effect !== firstEffect); + + // When the owner fiber is deleted, the destroy function of a passive + // effect hook is called during the synchronous commit phase. This is + // a concession to implementation complexity. Calling it in the + // passive effect phase (like they usually are, when dependencies + // change during an update) would require either traversing the + // children of the deleted fiber again, or including unmount effects + // as part of the fiber effect list. + // + // Because this is during the sync commit phase, we need to change + // the priority. + // + // TODO: Reconsider this implementation trade off. + var priorityLevel = + renderPriorityLevel > NormalPriority + ? NormalPriority + : renderPriorityLevel; + runWithPriority$1(priorityLevel, function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (destroy !== undefined) { + safelyCallDestroy(current$$1, destroy); + } + effect = effect.next; + } while (effect !== firstEffect); + }); } } break; @@ -17749,7 +17807,7 @@ function commitUnmount(current$$1) { // We are also not using this parent because // the portal will get pushed immediately. if (supportsMutation) { - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else if (supportsPersistence) { emptyPortalContainer(current$$1); } @@ -17767,14 +17825,14 @@ function commitUnmount(current$$1) { } } -function commitNestedUnmounts(root) { +function commitNestedUnmounts(root, renderPriorityLevel) { // While we're inside a removed host node we don't want to call // removeChild on the inner nodes because they're removed by the top // call anyway. We also want to call componentWillUnmount on all // composites before this host node is removed from the tree. Therefore var node = root; while (true) { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes. // Skip portals because commitUnmount() currently visits them recursively. if ( @@ -17994,7 +18052,7 @@ function commitPlacement(finishedWork) { var node = finishedWork; while (true) { var isHost = node.tag === HostComponent || node.tag === HostText; - if (isHost || node.tag === FundamentalComponent) { + if (isHost || (enableFundamentalAPI && node.tag === FundamentalComponent)) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (before) { if (isContainer) { @@ -18032,7 +18090,7 @@ function commitPlacement(finishedWork) { } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel) { // We only have the top Fiber that was deleted but we need to recurse down its var node = current$$1; @@ -18083,7 +18141,7 @@ function unmountHostComponents(current$$1) { } if (node.tag === HostComponent || node.tag === HostText) { - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -18092,9 +18150,9 @@ function unmountHostComponents(current$$1) { removeChild(currentParent, node.stateNode); } // Don't visit children because we already visited them. - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { var fundamentalNode = node.stateNode.instance; - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -18124,7 +18182,7 @@ function unmountHostComponents(current$$1) { continue; } } else { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because we may find more host components below. if (node.child !== null) { node.child.return = node; @@ -18151,14 +18209,14 @@ function unmountHostComponents(current$$1) { } } -function commitDeletion(current$$1) { +function commitDeletion(current$$1, renderPriorityLevel) { if (supportsMutation) { // Recursively delete all host nodes from the parent. // Detach refs and call componentWillUnmount() on the whole subtree. - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else { // Detach refs and call componentWillUnmount() on the whole subtree. - commitNestedUnmounts(current$$1); + commitNestedUnmounts(current$$1, renderPriorityLevel); } detachFiber(current$$1); } @@ -18704,6 +18762,7 @@ function throwException( } while (workInProgress !== null); } +// The scheduler is imported here *only* to detect whether it's been mocked // DEV stuff var ceil = Math.ceil; @@ -18758,6 +18817,7 @@ var legacyErrorBoundariesThatAlreadyFailed = null; var rootDoesHavePassiveEffects = false; var rootWithPendingPassiveEffects = null; +var pendingPassiveEffectsRenderPriority = NoPriority; var pendingPassiveEffectsExpirationTime = NoWork; var rootsWithPendingDiscreteUpdates = null; @@ -19026,7 +19086,10 @@ function scheduleCallbackForRoot(root, priorityLevel, expirationTime) { ); } else { var options = null; - if (expirationTime !== Never) { + if ( + !disableSchedulerTimeoutBasedOnReactExpirationTime && + expirationTime !== Never + ) { var timeout = expirationTimeToMs(expirationTime) - now(); options = { timeout: timeout }; } @@ -19242,7 +19305,6 @@ function prepareFreshStack(root, expirationTime) { { ReactStrictModeWarnings.discardPendingWarnings(); - componentsThatSuspendedAtHighPri = null; componentsThatTriggeredHighPriSuspend = null; } } @@ -19425,8 +19487,6 @@ function renderRoot(root, expirationTime, isSync) { // Set this to null to indicate there's no in-progress render. workInProgressRoot = null; - flushSuspensePriorityWarningInDEV(); - switch (workInProgressRootExitStatus) { case RootIncomplete: { (function() { @@ -19435,7 +19495,7 @@ function renderRoot(root, expirationTime, isSync) { } })(); } - // Flow knows about invariant, so it compains if I add a break statement, + // Flow knows about invariant, so it complains if I add a break statement, // but eslint doesn't know about invariant, so it complains if I do. // eslint-disable-next-line no-fallthrough case RootErrored: { @@ -19461,6 +19521,8 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspended: { + flushSuspensePriorityWarningInDEV(); + // We have an acceptable loading state. We need to figure out if we should // immediately commit it or wait a bit. @@ -19469,7 +19531,12 @@ function renderRoot(root, expirationTime, isSync) { // possible. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync; - if (hasNotProcessedNewUpdates && !isSync) { + if ( + hasNotProcessedNewUpdates && + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // If we have not processed any new updates during this pass, then this is // either a retry of an existing fallback state or a hidden tree. // Hidden trees shouldn't be batched with other work and after that's @@ -19506,7 +19573,13 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspendedWithDelay: { - if (!isSync) { + flushSuspensePriorityWarningInDEV(); + + if ( + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // We're suspended in a state that should be avoided. We'll try to avoid committing // it for as long as the timeouts let us. if (workInProgressRootHasPendingPing) { @@ -19576,6 +19649,12 @@ function renderRoot(root, expirationTime, isSync) { // The work completed. Ready to commit. if ( !isSync && + // do not delay if we're inside an act() scope + !( + true && + flushSuspenseFallbacksInTests && + IsThisRendererActing.current + ) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null ) { @@ -19924,12 +20003,15 @@ function resetChildExpirationTime(completedWork) { } function commitRoot(root) { - runWithPriority$1(ImmediatePriority, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority$1( + ImmediatePriority, + commitRootImpl.bind(null, root, renderPriorityLevel) + ); // If there are passive effects, schedule a callback to flush them. This goes // outside commitRootImpl so that it inherits the priority of the render. if (rootWithPendingPassiveEffects !== null) { - var priorityLevel = getCurrentPriorityLevel(); - scheduleCallback(priorityLevel, function() { + scheduleCallback(NormalPriority, function() { flushPassiveEffects(); return null; }); @@ -19937,7 +20019,7 @@ function commitRoot(root) { return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); flushRenderPhaseStrictModeWarningsInDEV(); @@ -20066,7 +20148,12 @@ function commitRootImpl(root) { nextEffect = firstEffect; do { { - invokeGuardedCallback(null, commitMutationEffects, null); + invokeGuardedCallback( + null, + commitMutationEffects, + null, + renderPriorityLevel + ); if (hasCaughtError()) { (function() { if (!(nextEffect !== null)) { @@ -20153,6 +20240,7 @@ function commitRootImpl(root) { rootDoesHavePassiveEffects = false; rootWithPendingPassiveEffects = root; pendingPassiveEffectsExpirationTime = expirationTime; + pendingPassiveEffectsRenderPriority = renderPriorityLevel; } else { // We are done with the effect chain at this point so let's clear the // nextEffect pointers to assist with GC. If we have passive effects, we'll @@ -20255,7 +20343,7 @@ function commitBeforeMutationEffects() { } } -function commitMutationEffects() { +function commitMutationEffects(renderPriorityLevel) { // TODO: Should probably move the bulk of this function to commitWork. while (nextEffect !== null) { setCurrentFiber(nextEffect); @@ -20306,7 +20394,7 @@ function commitMutationEffects() { break; } case Deletion: { - commitDeletion(nextEffect); + commitDeletion(nextEffect, renderPriorityLevel); break; } } @@ -20352,9 +20440,19 @@ function flushPassiveEffects() { } var root = rootWithPendingPassiveEffects; var expirationTime = pendingPassiveEffectsExpirationTime; + var renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = NoWork; + pendingPassiveEffectsRenderPriority = NoPriority; + var priorityLevel = + renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel; + return runWithPriority$1( + priorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = null; if (enableSchedulerTracing) { prevInteractions = tracing.__interactionsRef.current; @@ -20861,6 +20959,7 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) { } } +// a 'shared' variable that changes when act() opens/closes in tests. var IsThisRendererActing = { current: false }; function warnIfNotScopedWithMatchingAct(fiber) { @@ -20876,12 +20975,12 @@ function warnIfNotScopedWithMatchingAct(fiber) { "Be sure to use the matching version of act() corresponding to your renderer:\n\n" + "// for react-dom:\n" + "import {act} from 'react-dom/test-utils';\n" + - "//...\n" + + "// ...\n" + "act(() => ...);\n\n" + "// for react-test-renderer:\n" + "import TestRenderer from 'react-test-renderer';\n" + "const {act} = TestRenderer;\n" + - "//...\n" + + "// ...\n" + "act(() => ...);" + "%s", getStackByFiberInDevAndProd(fiber) @@ -20948,7 +21047,44 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber) { var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; -var componentsThatSuspendedAtHighPri = null; +// In tests, we want to enforce a mocked scheduler. +var didWarnAboutUnmockedScheduler = false; +// TODO Before we release concurrent mode, revisit this and decide whether a mocked +// scheduler is the actual recommendation. The alternative could be a testing build, +// a new lib, or whatever; we dunno just yet. This message is for early adopters +// to get their tests right. + +function warnIfUnmockedScheduler(fiber) { + { + if ( + didWarnAboutUnmockedScheduler === false && + Scheduler.unstable_flushAllWithoutAsserting === undefined + ) { + if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } else if (warnAboutUnmockedScheduler === true) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'Starting from React v17, the "scheduler" module will need to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } + } + } +} + var componentsThatTriggeredHighPriSuspend = null; function checkForWrongSuspensePriorityInDEV(sourceFiber) { { @@ -21035,70 +21171,34 @@ function checkForWrongSuspensePriorityInDEV(sourceFiber) { } workInProgressNode = workInProgressNode.return; } - - // Add the component name to a set. - var componentName = getComponentName(sourceFiber.type); - if (componentsThatSuspendedAtHighPri === null) { - componentsThatSuspendedAtHighPri = new Set([componentName]); - } else { - componentsThatSuspendedAtHighPri.add(componentName); - } } } } function flushSuspensePriorityWarningInDEV() { { - if (componentsThatSuspendedAtHighPri !== null) { + if (componentsThatTriggeredHighPriSuspend !== null) { var componentNames = []; - componentsThatSuspendedAtHighPri.forEach(function(name) { - componentNames.push(name); + componentsThatTriggeredHighPriSuspend.forEach(function(name) { + return componentNames.push(name); }); - componentsThatSuspendedAtHighPri = null; - - var componentsThatTriggeredSuspendNames = []; - if (componentsThatTriggeredHighPriSuspend !== null) { - componentsThatTriggeredHighPriSuspend.forEach(function(name) { - return componentsThatTriggeredSuspendNames.push(name); - }); - } - componentsThatTriggeredHighPriSuspend = null; - var componentNamesString = componentNames.sort().join(", "); - var componentThatTriggeredSuspenseError = ""; - if (componentsThatTriggeredSuspendNames.length > 0) { - componentThatTriggeredSuspenseError = - "The following components triggered a user-blocking update:" + - "\n\n" + - " " + - componentsThatTriggeredSuspendNames.sort().join(", ") + - "\n\n" + - "that was then suspended by:" + - "\n\n" + - " " + - componentNamesString; - } else { - componentThatTriggeredSuspenseError = - "A user-blocking update was suspended by:" + - "\n\n" + - " " + - componentNamesString; + if (componentNames.length > 0) { + warningWithoutStack$1( + false, + "%s triggered a user-blocking update that suspended." + + "\n\n" + + "The fix is to split the update into multiple parts: a user-blocking " + + "update to provide immediate feedback, and another update that " + + "triggers the bulk of the changes." + + "\n\n" + + "Refer to the documentation for useSuspenseTransition to learn how " + + "to implement this pattern.", + // TODO: Add link to React docs with more information, once it exists + componentNames.sort().join(", ") + ); } - - warningWithoutStack$1( - false, - "%s" + - "\n\n" + - "The fix is to split the update into multiple parts: a user-blocking " + - "update to provide immediate feedback, and another update that " + - "triggers the bulk of the changes." + - "\n\n" + - "Refer to the documentation for useSuspenseTransition to learn how " + - "to implement this pattern.", - // TODO: Add link to React docs with more information, once it exists - componentThatTriggeredSuspenseError - ); } } } @@ -21577,7 +21677,6 @@ function createWorkInProgress(current, pendingProps, expirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -21670,7 +21769,6 @@ function resetWorkInProgress(workInProgress, renderExpirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -22293,6 +22391,7 @@ function updateContainer(element, container, parentComponent, callback) { { // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests if ("undefined" !== typeof jest) { + warnIfUnmockedScheduler(current$$1); warnIfNotScopedWithMatchingAct(current$$1); } } diff --git a/Libraries/Renderer/implementations/ReactFabric-dev.js b/Libraries/Renderer/implementations/ReactFabric-dev.js index 6baec3d6a0dc18..ad2a1b865b9341 100644 --- a/Libraries/Renderer/implementations/ReactFabric-dev.js +++ b/Libraries/Renderer/implementations/ReactFabric-dev.js @@ -2791,6 +2791,31 @@ var HostEffectMask = /* */ 1023; var Incomplete = /* */ 1024; var ShouldCapture = /* */ 2048; +var debugRenderPhaseSideEffects = false; +var debugRenderPhaseSideEffectsForStrictMode = false; +var enableUserTimingAPI = true; +var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; +var warnAboutDeprecatedLifecycles = true; +var enableProfilerTimer = true; +var enableSchedulerTracing = true; +var enableSuspenseServerRenderer = false; + +var warnAboutDeprecatedSetNativeProps = false; +var enableFlareAPI = false; +var enableFundamentalAPI = false; + +var warnAboutUnmockedScheduler = false; +var revertPassiveEffectsChange = false; +var flushSuspenseFallbacksInTests = true; +var enableUserBlockingEvents = false; +var enableSuspenseCallback = false; +var warnAboutDefaultPropsOnFunctionComponents = false; +var warnAboutStringRefs = false; +var disableLegacyContext = false; +var disableSchedulerTimeoutBasedOnReactExpirationTime = false; + +// Only used in www builds. + var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner; var MOUNTING = 1; @@ -3609,26 +3634,6 @@ function restoreStateIfNeeded() { } } -var debugRenderPhaseSideEffects = false; -var debugRenderPhaseSideEffectsForStrictMode = false; -var enableUserTimingAPI = true; -var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; -var warnAboutDeprecatedLifecycles = true; -var enableProfilerTimer = true; -var enableSchedulerTracing = true; -var enableSuspenseServerRenderer = false; - -var warnAboutDeprecatedSetNativeProps = false; -var enableFlareAPI = false; -var enableFundamentalAPI = false; - -var revertPassiveEffectsChange = false; -var enableUserBlockingEvents = false; -var enableSuspenseCallback = false; -var warnAboutDefaultPropsOnFunctionComponents = false; - -// Only used in www builds. - // Used as a way to call batchedUpdates when we don't have a reference to // the renderer. Such as when we're dispatching events or if third party // libraries need to call batchedUpdates. Eventually, this API will go away when @@ -3890,19 +3895,13 @@ var currentEventQueuePriority = ContinuousEvent; var currentTimerIDCounter = 0; var eventResponderContext = { - dispatchEvent: function(eventProp, eventValue, eventPriority) { + dispatchEvent: function(eventValue, eventListener, eventPriority) { validateResponderContext(); validateEventValue(eventValue); if (eventPriority < currentEventQueuePriority) { currentEventQueuePriority = eventPriority; } - var responderInstance = currentInstance; - var target = responderInstance.fiber; - var responder = responderInstance.responder; - var listeners = collectListeners(eventProp, responder, target); - if (listeners.length !== 0) { - currentEventQueue.push(createEventQueueItem(eventValue, listeners)); - } + currentEventQueue.push(createEventQueueItem(eventValue, eventListener)); }, isTargetWithinNode: function(childTarget, parentTarget) { validateResponderContext(); @@ -3999,10 +3998,10 @@ var eventResponderContext = { } }; -function createEventQueueItem(value, listeners) { +function createEventQueueItem(value, listener) { return { value: value, - listeners: listeners + listener: listener }; } @@ -4160,80 +4159,16 @@ function releaseOwnershipForEventResponderInstance(eventResponderInstance) { return false; } -// TODO this function is almost an exact copy of the DOM version, we should -// somehow share the logic -function collectListeners(eventProp, eventResponder, target) { - var eventListeners = []; - var node = target.return; - nodeTraversal: while (node !== null) { - switch (node.tag) { - case HostComponent: { - var dependencies = node.dependencies; - - if (dependencies !== null) { - var respondersMap = dependencies.responders; - - if (respondersMap !== null && respondersMap.has(eventResponder)) { - break nodeTraversal; - } - } - break; - } - case FunctionComponent: - case MemoComponent: - case ForwardRef: { - var _dependencies = node.dependencies; - - if (_dependencies !== null) { - var _listeners = _dependencies.listeners; - - if (_listeners !== null) { - for ( - var s = 0, listenersLength = _listeners.length; - s < listenersLength; - s++ - ) { - var listener = _listeners[s]; - var responder = listener.responder, - props = listener.props; - - var listenerFunc = props[eventProp]; - - if ( - responder === eventResponder && - typeof listenerFunc === "function" - ) { - eventListeners.push(listenerFunc); - } - } - } - } - } - } - node = node.return; - } - return eventListeners; -} - // TODO this function is almost an exact copy of the DOM version, we should // somehow share the logic function processEvents(eventQueue) { for (var i = 0, length = eventQueue.length; i < length; i++) { var _eventQueue$i = eventQueue[i], _value = _eventQueue$i.value, - _listeners2 = _eventQueue$i.listeners; + _listener = _eventQueue$i.listener; - for (var s = 0, length2 = _listeners2.length; s < length2; s++) { - var listener = _listeners2[s]; - var type = - typeof _value === "object" && _value !== null ? _value.type : ""; - invokeGuardedCallbackAndCatchFirstError( - type, - listener, - undefined, - _value - ); - } + var type = typeof _value === "object" && _value !== null ? _value.type : ""; + invokeGuardedCallbackAndCatchFirstError(type, _listener, undefined, _value); } } @@ -5649,262 +5584,310 @@ function getUnmaskedContext( Component, didPushOwnContextIfProvider ) { - if (didPushOwnContextIfProvider && isContextProvider(Component)) { - // If the fiber is a context provider itself, when we read its context - // we may have already pushed its own child context on the stack. A context - // provider should not "see" its own child context. Therefore we read the - // previous (parent) context instead for a context provider. - return previousContext; + if (disableLegacyContext) { + return emptyContextObject; + } else { + if (didPushOwnContextIfProvider && isContextProvider(Component)) { + // If the fiber is a context provider itself, when we read its context + // we may have already pushed its own child context on the stack. A context + // provider should not "see" its own child context. Therefore we read the + // previous (parent) context instead for a context provider. + return previousContext; + } + return contextStackCursor.current; } - return contextStackCursor.current; } function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + } } function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { + if (disableLegacyContext) { return emptyContextObject; - } + } else { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyContextObject; + } - // Avoid recreating masked context unless unmasked context has changed. - // Failing to do this will result in unnecessary calls to componentWillReceiveProps. - // This may trigger infinite loops if componentWillReceiveProps calls setState. - var instance = workInProgress.stateNode; - if ( - instance && - instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext - ) { - return instance.__reactInternalMemoizedMaskedChildContext; - } + // Avoid recreating masked context unless unmasked context has changed. + // Failing to do this will result in unnecessary calls to componentWillReceiveProps. + // This may trigger infinite loops if componentWillReceiveProps calls setState. + var instance = workInProgress.stateNode; + if ( + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext + ) { + return instance.__reactInternalMemoizedMaskedChildContext; + } - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - getCurrentFiberStackInDev - ); - } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + getCurrentFiberStackInDev + ); + } - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // Context is created before the class component is instantiated so check for instance. - if (instance) { - cacheContext(workInProgress, unmaskedContext, context); - } + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // Context is created before the class component is instantiated so check for instance. + if (instance) { + cacheContext(workInProgress, unmaskedContext, context); + } - return context; + return context; + } } function hasContextChanged() { - return didPerformWorkStackCursor.current; + if (disableLegacyContext) { + return false; + } else { + return didPerformWorkStackCursor.current; + } } function isContextProvider(type) { - var childContextTypes = type.childContextTypes; - return childContextTypes !== null && childContextTypes !== undefined; + if (disableLegacyContext) { + return false; + } else { + var childContextTypes = type.childContextTypes; + return childContextTypes !== null && childContextTypes !== undefined; + } } function popContext(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function pushTopLevelContextObject(fiber, context, didChange) { - (function() { - if (!(contextStackCursor.current === emptyContextObject)) { - throw ReactError( - Error( - "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return; + } else { + (function() { + if (!(contextStackCursor.current === emptyContextObject)) { + throw ReactError( + Error( + "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - push(contextStackCursor, context, fiber); - push(didPerformWorkStackCursor, didChange, fiber); + push(contextStackCursor, context, fiber); + push(didPerformWorkStackCursor, didChange, fiber); + } } function processChildContext(fiber, type, parentContext) { - var instance = fiber.stateNode; - var childContextTypes = type.childContextTypes; + if (disableLegacyContext) { + return parentContext; + } else { + var instance = fiber.stateNode; + var childContextTypes = type.childContextTypes; - // TODO (bvaughn) Replace this behavior with an invariant() in the future. - // It has only been added in Fiber to match the (unintentional) behavior in Stack. - if (typeof instance.getChildContext !== "function") { - { - var componentName = getComponentName(type) || "Unknown"; + // TODO (bvaughn) Replace this behavior with an invariant() in the future. + // It has only been added in Fiber to match the (unintentional) behavior in Stack. + if (typeof instance.getChildContext !== "function") { + { + var componentName = getComponentName(type) || "Unknown"; - if (!warnedAboutMissingGetChildContext[componentName]) { - warnedAboutMissingGetChildContext[componentName] = true; - 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 - ); + if (!warnedAboutMissingGetChildContext[componentName]) { + warnedAboutMissingGetChildContext[componentName] = true; + 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 + ); + } } + return parentContext; } - return parentContext; - } - var childContext = void 0; - { - setCurrentPhase("getChildContext"); + var childContext = void 0; + { + setCurrentPhase("getChildContext"); + } + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + setCurrentPhase(null); + } + for (var contextKey in childContext) { + (function() { + if (!(contextKey in childContextTypes)) { + throw ReactError( + Error( + (getComponentName(type) || "Unknown") + + '.getChildContext(): key "' + + contextKey + + '" is not defined in childContextTypes.' + ) + ); + } + })(); + } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + childContextTypes, + childContext, + "child context", + name, + // In practice, there is one case in which we won't get a stack. It's when + // somebody calls unstable_renderSubtreeIntoContainer() and we process + // context from the parent component instance. The stack will be missing + // because it's outside of the reconciliation, and so the pointer has not + // been set. This is rare and doesn't matter. We'll also remove that API. + getCurrentFiberStackInDev + ); + } + + return Object.assign({}, parentContext, childContext); } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - setCurrentPhase(null); +} + +function pushContextProvider(workInProgress) { + if (disableLegacyContext) { + return false; + } else { + var instance = workInProgress.stateNode; + // We push the context as early as possible to ensure stack integrity. + // If the instance does not exist yet, we will push null at first, + // and replace it on the stack later when invalidating the context. + var memoizedMergedChildContext = + (instance && instance.__reactInternalMemoizedMergedChildContext) || + emptyContextObject; + + // Remember the parent context so we can merge with it later. + // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. + previousContext = contextStackCursor.current; + push(contextStackCursor, memoizedMergedChildContext, workInProgress); + push( + didPerformWorkStackCursor, + didPerformWorkStackCursor.current, + workInProgress + ); + + return true; } - for (var contextKey in childContext) { +} + +function invalidateContextProvider(workInProgress, type, didChange) { + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; (function() { - if (!(contextKey in childContextTypes)) { + if (!instance) { throw ReactError( Error( - (getComponentName(type) || "Unknown") + - '.getChildContext(): key "' + - contextKey + - '" is not defined in childContextTypes.' + "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." ) ); } })(); - } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - childContextTypes, - childContext, - "child context", - name, - // In practice, there is one case in which we won't get a stack. It's when - // somebody calls unstable_renderSubtreeIntoContainer() and we process - // context from the parent component instance. The stack will be missing - // because it's outside of the reconciliation, and so the pointer has not - // been set. This is rare and doesn't matter. We'll also remove that API. - getCurrentFiberStackInDev - ); - } - - return Object.assign({}, parentContext, childContext); -} - -function pushContextProvider(workInProgress) { - var instance = workInProgress.stateNode; - // We push the context as early as possible to ensure stack integrity. - // If the instance does not exist yet, we will push null at first, - // and replace it on the stack later when invalidating the context. - var memoizedMergedChildContext = - (instance && instance.__reactInternalMemoizedMergedChildContext) || - emptyContextObject; - - // Remember the parent context so we can merge with it later. - // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. - previousContext = contextStackCursor.current; - push(contextStackCursor, memoizedMergedChildContext, workInProgress); - push( - didPerformWorkStackCursor, - didPerformWorkStackCursor.current, - workInProgress - ); - - return true; -} -function invalidateContextProvider(workInProgress, type, didChange) { - var instance = workInProgress.stateNode; - (function() { - if (!instance) { - throw ReactError( - Error( - "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." - ) + if (didChange) { + // Merge parent and own context. + // Skip this if we're not updating due to sCU. + // This avoids unnecessarily recomputing memoized values. + var mergedContext = processChildContext( + workInProgress, + type, + previousContext ); + instance.__reactInternalMemoizedMergedChildContext = mergedContext; + + // Replace the old (or empty) context with the new one. + // It is important to unwind the context in the reverse order. + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); + // Now push the new context and mark that it has changed. + push(contextStackCursor, mergedContext, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } else { + pop(didPerformWorkStackCursor, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); } - })(); - - if (didChange) { - // Merge parent and own context. - // Skip this if we're not updating due to sCU. - // This avoids unnecessarily recomputing memoized values. - var mergedContext = processChildContext( - workInProgress, - type, - previousContext - ); - instance.__reactInternalMemoizedMergedChildContext = mergedContext; - - // Replace the old (or empty) context with the new one. - // It is important to unwind the context in the reverse order. - pop(didPerformWorkStackCursor, workInProgress); - pop(contextStackCursor, workInProgress); - // Now push the new context and mark that it has changed. - push(contextStackCursor, mergedContext, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } else { - pop(didPerformWorkStackCursor, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); } } function findCurrentUnmaskedContext(fiber) { - // Currently this is only used with renderSubtreeIntoContainer; not sure if it - // makes sense elsewhere - (function() { - if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { - throw ReactError( - Error( - "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return emptyContextObject; + } else { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere + (function() { + if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { + throw ReactError( + Error( + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - var node = fiber; - do { - switch (node.tag) { - case HostRoot: - return node.stateNode.context; - case ClassComponent: { - var Component = node.type; - if (isContextProvider(Component)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; + var node = fiber; + do { + switch (node.tag) { + case HostRoot: + return node.stateNode.context; + case ClassComponent: { + var Component = node.type; + if (isContextProvider(Component)) { + return node.stateNode.__reactInternalMemoizedMergedChildContext; + } + break; } - break; } - } - node = node.return; - } while (node !== null); - (function() { - { - throw ReactError( - Error( - "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + node = node.return; + } while (node !== null); + (function() { + { + throw ReactError( + Error( + "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); + } } var LegacyRoot = 0; @@ -5958,6 +5941,7 @@ var NormalPriority = 97; var LowPriority = 96; var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only. +var NoPriority = 90; var shouldYield = Scheduler_shouldYield; var requestPaint = @@ -7498,7 +7482,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: NoWork, firstContext: contextItem, - listeners: null, responders: null }; } else { @@ -8398,28 +8381,48 @@ function checkClassInstance(workInProgress, ctor, newProps) { name ) : void 0; - var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warningWithoutStack$1( + + if (disableLegacyContext) { + if (ctor.childContextTypes) { + warningWithoutStack$1( false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", + "%s uses the legacy childContextTypes API which is no longer supported. " + + "Use React.createContext() instead.", name - ) - : void 0; + ); + } + if (ctor.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with static contextType instead.", + name + ); + } + } else { + var noInstanceContextTypes = !instance.contextTypes; + !noInstanceContextTypes + ? warningWithoutStack$1( + false, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ) + : void 0; - if ( - ctor.contextType && - ctor.contextTypes && - !didWarnAboutContextTypeAndContextTypes.has(ctor) - ) { - didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack$1( - false, - "%s declares both contextTypes and contextType static properties. " + - "The legacy contextTypes property will be ignored.", - name - ); + if ( + ctor.contextType && + ctor.contextTypes && + !didWarnAboutContextTypeAndContextTypes.has(ctor) + ) { + didWarnAboutContextTypeAndContextTypes.add(ctor); + warningWithoutStack$1( + false, + "%s declares both contextTypes and contextType static properties. " + + "The legacy contextTypes property will be ignored.", + name + ); + } } var noComponentShouldUpdate = @@ -8595,7 +8598,7 @@ function constructClassInstance( ) { var isLegacyContextConsumer = false; var unmaskedContext = emptyContextObject; - var context = null; + var context = emptyContextObject; var contextType = ctor.contextType; { @@ -8643,7 +8646,7 @@ function constructClassInstance( if (typeof contextType === "object" && contextType !== null) { context = readContext(contextType); - } else { + } else if (!disableLegacyContext) { unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); var contextTypes = ctor.contextTypes; isLegacyContextConsumer = @@ -8845,6 +8848,8 @@ function mountClassInstance( var contextType = ctor.contextType; if (typeof contextType === "object" && contextType !== null) { instance.context = readContext(contextType); + } else if (disableLegacyContext) { + instance.context = emptyContextObject; } else { var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); instance.context = getMaskedContext(workInProgress, unmaskedContext); @@ -8945,10 +8950,10 @@ function resumeMountClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextLegacyUnmaskedContext = getUnmaskedContext( workInProgress, ctor, @@ -9094,10 +9099,10 @@ function updateClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); } @@ -9253,7 +9258,7 @@ function updateClassInstance( var didWarnAboutMaps = void 0; var didWarnAboutGenerators = void 0; -var didWarnAboutStringRefInStrictMode = void 0; +var didWarnAboutStringRefs = void 0; var ownerHasKeyUseWarning = void 0; var ownerHasFunctionTypeWarning = void 0; var warnForMissingKey = function(child) {}; @@ -9261,7 +9266,7 @@ var warnForMissingKey = function(child) {}; { didWarnAboutMaps = false; didWarnAboutGenerators = false; - didWarnAboutStringRefInStrictMode = {}; + didWarnAboutStringRefs = {}; /** * Warn if there's no key explicitly set on dynamic arrays of children or @@ -9318,21 +9323,38 @@ function coerceRef(returnFiber, current$$1, element) { typeof mixedRef !== "object" ) { { - if (returnFiber.mode & StrictMode) { + // TODO: Clean this up once we turn on the string ref warning for + // everyone, because the strict mode case will no longer be relevant + if (returnFiber.mode & StrictMode || warnAboutStringRefs) { var componentName = getComponentName(returnFiber.type) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - 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) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; + if (!didWarnAboutStringRefs[componentName]) { + if (warnAboutStringRefs) { + warningWithoutStack$1( + false, + 'Component "%s" contains the string ref "%s". Support for string refs ' + + "will be removed in a future major release. We recommend using " + + "useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + componentName, + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } else { + 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 useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } + didWarnAboutStringRefs[componentName] = true; } } } @@ -10797,45 +10819,15 @@ function findFirstSuspended(row) { return null; } -var currentlyRenderingFiber$2 = null; -var currentListenerHookIndex = 0; - -function prepareToReadListenerHooks(workInProgress) { - currentlyRenderingFiber$2 = workInProgress; - currentListenerHookIndex = 0; -} - -function getListenerHooks() { - var listeners = void 0; - var dependencies = currentlyRenderingFiber$2.dependencies; - if (dependencies === null) { - dependencies = currentlyRenderingFiber$2.dependencies = { - expirationTime: NoWork, - firstContext: null, - listeners: [], - responders: null - }; - } - listeners = dependencies.listeners; - if (listeners === null) { - dependencies.listeners = listeners = []; - } - return listeners; -} - -function updateListenerHook(responder, props) { - var listeners = getListenerHooks(); - if (listeners.length === currentListenerHookIndex) { - listeners.push({ - responder: responder, - props: props - }); - currentListenerHookIndex++; - } else { - var currentListenerHook = listeners[currentListenerHookIndex++]; - currentListenerHook.responder = responder; - currentListenerHook.props = props; +function createResponderListener(responder, props) { + var eventResponderListener = { + responder: responder, + props: props + }; + { + Object.freeze(eventResponderListener); } + return eventResponderListener; } function createResponderInstance( @@ -11920,7 +11912,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }; var HooksDispatcherOnMountInDEV = null; @@ -12027,10 +12019,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12106,10 +12098,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12185,10 +12177,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12275,11 +12267,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -12366,11 +12358,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; } @@ -12433,6 +12425,17 @@ var hydrationParentFiber = null; var nextHydratableInstance = null; var isHydrating = false; +function warnIfHydrating() { + { + !!isHydrating + ? warning$1( + false, + "We should not be hydrating here. This is a bug in React. Please file a bug." + ) + : void 0; + } +} + function enterHydrationState(fiber) { if (!supportsHydration) { return false; @@ -12941,9 +12944,6 @@ function updateForwardRef( // The rest is a fork of updateFunctionComponent var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -12962,9 +12962,6 @@ function updateForwardRef( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -13244,14 +13241,14 @@ function updateFunctionComponent( } } - var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); + context = getMaskedContext(workInProgress, unmaskedContext); + } var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -13270,9 +13267,6 @@ function updateFunctionComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -13864,13 +13858,13 @@ function mountIndeterminateComponent( } var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); + context = getMaskedContext(workInProgress, unmaskedContext); + } prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } var value = void 0; { @@ -13977,6 +13971,15 @@ function mountIndeterminateComponent( // Proceed under the assumption that this is a function component workInProgress.tag = FunctionComponent; { + if (disableLegacyContext && Component.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with React.useContext() instead.", + getComponentName(Component) || "Unknown" + ); + } + if ( debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && @@ -13984,9 +13987,6 @@ function mountIndeterminateComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } value = renderWithHooks( null, workInProgress, @@ -14516,12 +14516,18 @@ function updateDehydratedSuspenseComponent( } return null; } + if ((workInProgress.effectTag & DidCapture) !== NoEffect) { // Something suspended. Leave the existing children in place. // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far? workInProgress.child = null; return null; } + + // We should never be hydrating at this point because it is the first pass, + // but after we've already committed once. + warnIfHydrating(); + if (isSuspenseInstanceFallback(suspenseInstance)) { // This boundary is in a permanent fallback state. In this case, we'll never // get an update and we'll never be able to hydrate the final content. Let's just try the @@ -15380,29 +15386,26 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect; - var childExpirationTime = workInProgress.childExpirationTime; - if (childExpirationTime < renderExpirationTime) { + var hasChildWork = + workInProgress.childExpirationTime >= renderExpirationTime; + + if (didSuspendBefore) { + if (hasChildWork) { + // If something was in fallback state last time, and we have all the + // same children then we're still in progressive loading state. + // Something might get unblocked by state updates or retries in the + // tree which will affect the tail. So we need to use the normal + // path to compute the correct tail. + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + } // If none of the children had any work, that means that none of // them got retried so they'll still be blocked in the same way // as before. We can fast bail out. - pushSuspenseContext(workInProgress, suspenseStackCursor.current); - if (didSuspendBefore) { - workInProgress.effectTag |= DidCapture; - } - return null; - } - - if (didSuspendBefore) { - // If something was in fallback state last time, and we have all the - // same children then we're still in progressive loading state. - // Something might get unblocked by state updates or retries in the - // tree which will affect the tail. So we need to use the normal - // path to compute the correct tail. - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); + workInProgress.effectTag |= DidCapture; } // If nothing suspended before and we're rendering the same children, @@ -15416,7 +15419,15 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { renderState.tail = null; } pushSuspenseContext(workInProgress, suspenseStackCursor.current); - break; + + if (hasChildWork) { + break; + } else { + // If none of the children had any work, that means that none of + // them got retried so they'll still be blocked in the same way + // as before. We can fast bail out. + return null; + } } } return bailoutOnAlreadyFinishedWork( @@ -15672,7 +15683,7 @@ if (supportsMutation) { while (node !== null) { if (node.tag === HostComponent || node.tag === HostText) { appendInitialChild(parent, node.stateNode); - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { appendInitialChild(parent, node.stateNode.instance); } else if (node.tag === HostPortal) { // If we have a portal child, then we don't want to traverse @@ -16170,12 +16181,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { ); if (enableFlareAPI) { - var prevResponders = current.memoizedProps.responders; - var nextResponders = newProps.responders; + var prevListeners = current.memoizedProps.listeners; + var nextListeners = newProps.listeners; var instance = workInProgress.stateNode; - if (prevResponders !== nextResponders) { - updateEventResponders( - nextResponders, + if (prevListeners !== nextListeners) { + updateEventListeners( + nextListeners, instance, rootContainerInstance, workInProgress @@ -16221,8 +16232,20 @@ function completeWork(current, workInProgress, renderExpirationTime) { // commit-phase we mark this as such. markUpdate(workInProgress); } + if (enableFlareAPI) { + var _instance5 = workInProgress.stateNode; + var listeners = newProps.listeners; + if (listeners != null) { + updateEventListeners( + listeners, + _instance5, + rootContainerInstance, + workInProgress + ); + } + } } else { - var _instance5 = createInstance( + var _instance6 = createInstance( type, newProps, rootContainerInstance, @@ -16230,14 +16253,14 @@ function completeWork(current, workInProgress, renderExpirationTime) { workInProgress ); - appendAllChildren(_instance5, workInProgress, false, false); + appendAllChildren(_instance6, workInProgress, false, false); if (enableFlareAPI) { - var responders = newProps.responders; - if (responders != null) { - updateEventResponders( - responders, - _instance5, + var _listeners = newProps.listeners; + if (_listeners != null) { + updateEventListeners( + _listeners, + _instance6, rootContainerInstance, workInProgress ); @@ -16249,7 +16272,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { // Make sure such renderers get scheduled for later work. if ( finalizeInitialChildren( - _instance5, + _instance6, type, newProps, rootContainerInstance, @@ -16258,7 +16281,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { ) { markUpdate(workInProgress); } - workInProgress.stateNode = _instance5; + workInProgress.stateNode = _instance6; } if (workInProgress.ref !== null) { @@ -16458,15 +16481,22 @@ function completeWork(current, workInProgress, renderExpirationTime) { markSpawnedWork(Never); } skipPastDehydratedSuspenseInstance(workInProgress); - } else if ((workInProgress.effectTag & DidCapture) === NoEffect) { - // This boundary did not suspend so it's now hydrated. - // To handle any future suspense cases, we're going to now upgrade it - // to a Suspense component. We detach it from the existing current fiber. - current.alternate = null; - workInProgress.alternate = null; - workInProgress.tag = SuspenseComponent; - workInProgress.memoizedState = null; - workInProgress.stateNode = null; + } else { + // We should never have been in a hydration state if we didn't have a current. + // However, in some of those paths, we might have reentered a hydration state + // and then we might be inside a hydration state. In that case, we'll need to + // exit out of it. + resetHydrationState(); + if ((workInProgress.effectTag & DidCapture) === NoEffect) { + // This boundary did not suspend so it's now hydrated. + // To handle any future suspense cases, we're going to now upgrade it + // to a Suspense component. We detach it from the existing current fiber. + current.alternate = null; + workInProgress.alternate = null; + workInProgress.tag = SuspenseComponent; + workInProgress.memoizedState = null; + workInProgress.stateNode = null; + } } } break; @@ -16680,12 +16710,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalImpl, fundamentalState || {} ); - var _instance6 = getFundamentalComponentInstance(fundamentalInstance); - fundamentalInstance.instance = _instance6; + var _instance7 = getFundamentalComponentInstance(fundamentalInstance); + fundamentalInstance.instance = _instance7; if (fundamentalImpl.reconcileChildren === false) { return null; } - appendAllChildren(_instance6, workInProgress, false, false); + appendAllChildren(_instance7, workInProgress, false, false); mountFundamentalComponent(fundamentalInstance); } else { // We fire update in commit phase @@ -16694,9 +16724,9 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalInstance.props = newProps; fundamentalInstance.currentFiber = workInProgress; if (supportsPersistence) { - var _instance7 = cloneFundamentalInstance(fundamentalInstance); - fundamentalInstance.instance = _instance7; - appendAllChildren(_instance7, workInProgress, false, false); + var _instance8 = cloneFundamentalInstance(fundamentalInstance); + fundamentalInstance.instance = _instance8; + appendAllChildren(_instance8, workInProgress, false, false); } var shouldUpdate = shouldUpdateFundamentalComponent( fundamentalInstance @@ -16754,26 +16784,41 @@ function mountEventResponder$1( respondersMap.set(responder, responderInstance); } -function updateEventResponder( - responder, - props, +function updateEventListener( + listener, fiber, visistedResponders, respondersMap, instance, rootContainerInstance ) { + var responder = void 0; + var props = void 0; + + if (listener) { + responder = listener.responder; + props = listener.props; + } (function() { if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) { throw ReactError( Error( - "An invalid value was used as an event responder. Expect one or many event responders created via React.unstable_createResponer()." + "An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponer()." ) ); } })(); + var listenerProps = props; if (visistedResponders.has(responder)) { // show warning + { + warning$1( + false, + 'Duplicate event responder "%s" found in event listeners. ' + + "Event listeners passed to elements cannot use the same event responder more than once.", + responder.displayName + ); + } return; } visistedResponders.add(responder); @@ -16783,7 +16828,7 @@ function updateEventResponder( // Mount mountEventResponder$1( responder, - props, + listenerProps, instance, rootContainerInstance, fiber, @@ -16791,25 +16836,24 @@ function updateEventResponder( ); } else { // Update - responderInstance.props = props; + responderInstance.props = listenerProps; responderInstance.fiber = fiber; } } -function updateEventResponders( - responders, +function updateEventListeners( + listeners, instance, rootContainerInstance, fiber ) { var visistedResponders = new Set(); var dependencies = fiber.dependencies; - if (responders != null) { + if (listeners != null) { if (dependencies === null) { dependencies = fiber.dependencies = { expirationTime: NoWork, firstContext: null, - listeners: null, responders: new Map() }; } @@ -16817,15 +16861,11 @@ function updateEventResponders( if (respondersMap === null) { respondersMap = new Map(); } - if (isArray$2(responders)) { - for (var i = 0, length = responders.length; i < length; i++) { - var _responders$i = responders[i], - type = _responders$i.type, - props = _responders$i.props; - - updateEventResponder( - type, - props, + if (isArray$2(listeners)) { + for (var i = 0, length = listeners.length; i < length; i++) { + var listener = listeners[i]; + updateEventListener( + listener, fiber, visistedResponders, respondersMap, @@ -16834,12 +16874,8 @@ function updateEventResponders( ); } } else { - var type = responders.type, - props = responders.props; - - updateEventResponder( - type, - props, + updateEventListener( + listeners, fiber, visistedResponders, respondersMap, @@ -16912,8 +16948,12 @@ function unwindWork(workInProgress, renderExpirationTime) { } case DehydratedSuspenseComponent: { if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(workInProgress); + if (workInProgress.alternate === null) { + // TODO: popHydrationState + } else { + resetHydrationState(); + } var _effectTag3 = workInProgress.effectTag; if (_effectTag3 & ShouldCapture) { workInProgress.effectTag = @@ -16967,7 +17007,6 @@ function unwindInterruptedWork(interruptedWork) { break; case DehydratedSuspenseComponent: if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(interruptedWork); } break; @@ -17684,7 +17723,7 @@ function commitDetachRef(current$$1) { // User-originating errors (lifecycles and refs) should not interrupt // deletion, so don't let them throw. Host-originating errors should // interrupt deletion, so it's okay -function commitUnmount(current$$1) { +function commitUnmount(current$$1, renderPriorityLevel) { onCommitUnmount(current$$1); switch (current$$1.tag) { @@ -17697,14 +17736,33 @@ function commitUnmount(current$$1) { var lastEffect = updateQueue.lastEffect; if (lastEffect !== null) { var firstEffect = lastEffect.next; - var effect = firstEffect; - do { - var destroy = effect.destroy; - if (destroy !== undefined) { - safelyCallDestroy(current$$1, destroy); - } - effect = effect.next; - } while (effect !== firstEffect); + + // When the owner fiber is deleted, the destroy function of a passive + // effect hook is called during the synchronous commit phase. This is + // a concession to implementation complexity. Calling it in the + // passive effect phase (like they usually are, when dependencies + // change during an update) would require either traversing the + // children of the deleted fiber again, or including unmount effects + // as part of the fiber effect list. + // + // Because this is during the sync commit phase, we need to change + // the priority. + // + // TODO: Reconsider this implementation trade off. + var priorityLevel = + renderPriorityLevel > NormalPriority + ? NormalPriority + : renderPriorityLevel; + runWithPriority$1(priorityLevel, function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (destroy !== undefined) { + safelyCallDestroy(current$$1, destroy); + } + effect = effect.next; + } while (effect !== firstEffect); + }); } } break; @@ -17745,7 +17803,7 @@ function commitUnmount(current$$1) { // We are also not using this parent because // the portal will get pushed immediately. if (supportsMutation) { - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else if (supportsPersistence) { emptyPortalContainer(current$$1); } @@ -17763,14 +17821,14 @@ function commitUnmount(current$$1) { } } -function commitNestedUnmounts(root) { +function commitNestedUnmounts(root, renderPriorityLevel) { // While we're inside a removed host node we don't want to call // removeChild on the inner nodes because they're removed by the top // call anyway. We also want to call componentWillUnmount on all // composites before this host node is removed from the tree. Therefore var node = root; while (true) { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes. // Skip portals because commitUnmount() currently visits them recursively. if ( @@ -17990,7 +18048,7 @@ function commitPlacement(finishedWork) { var node = finishedWork; while (true) { var isHost = node.tag === HostComponent || node.tag === HostText; - if (isHost || node.tag === FundamentalComponent) { + if (isHost || (enableFundamentalAPI && node.tag === FundamentalComponent)) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (before) { if (isContainer) { @@ -18028,7 +18086,7 @@ function commitPlacement(finishedWork) { } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel) { // We only have the top Fiber that was deleted but we need to recurse down its var node = current$$1; @@ -18079,7 +18137,7 @@ function unmountHostComponents(current$$1) { } if (node.tag === HostComponent || node.tag === HostText) { - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -18088,9 +18146,9 @@ function unmountHostComponents(current$$1) { removeChild(currentParent, node.stateNode); } // Don't visit children because we already visited them. - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { var fundamentalNode = node.stateNode.instance; - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -18120,7 +18178,7 @@ function unmountHostComponents(current$$1) { continue; } } else { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because we may find more host components below. if (node.child !== null) { node.child.return = node; @@ -18147,14 +18205,14 @@ function unmountHostComponents(current$$1) { } } -function commitDeletion(current$$1) { +function commitDeletion(current$$1, renderPriorityLevel) { if (supportsMutation) { // Recursively delete all host nodes from the parent. // Detach refs and call componentWillUnmount() on the whole subtree. - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else { // Detach refs and call componentWillUnmount() on the whole subtree. - commitNestedUnmounts(current$$1); + commitNestedUnmounts(current$$1, renderPriorityLevel); } detachFiber(current$$1); } @@ -18700,6 +18758,7 @@ function throwException( } while (workInProgress !== null); } +// The scheduler is imported here *only* to detect whether it's been mocked // DEV stuff var ceil = Math.ceil; @@ -18754,6 +18813,7 @@ var legacyErrorBoundariesThatAlreadyFailed = null; var rootDoesHavePassiveEffects = false; var rootWithPendingPassiveEffects = null; +var pendingPassiveEffectsRenderPriority = NoPriority; var pendingPassiveEffectsExpirationTime = NoWork; var rootsWithPendingDiscreteUpdates = null; @@ -19022,7 +19082,10 @@ function scheduleCallbackForRoot(root, priorityLevel, expirationTime) { ); } else { var options = null; - if (expirationTime !== Never) { + if ( + !disableSchedulerTimeoutBasedOnReactExpirationTime && + expirationTime !== Never + ) { var timeout = expirationTimeToMs(expirationTime) - now(); options = { timeout: timeout }; } @@ -19238,7 +19301,6 @@ function prepareFreshStack(root, expirationTime) { { ReactStrictModeWarnings.discardPendingWarnings(); - componentsThatSuspendedAtHighPri = null; componentsThatTriggeredHighPriSuspend = null; } } @@ -19421,8 +19483,6 @@ function renderRoot(root, expirationTime, isSync) { // Set this to null to indicate there's no in-progress render. workInProgressRoot = null; - flushSuspensePriorityWarningInDEV(); - switch (workInProgressRootExitStatus) { case RootIncomplete: { (function() { @@ -19431,7 +19491,7 @@ function renderRoot(root, expirationTime, isSync) { } })(); } - // Flow knows about invariant, so it compains if I add a break statement, + // Flow knows about invariant, so it complains if I add a break statement, // but eslint doesn't know about invariant, so it complains if I do. // eslint-disable-next-line no-fallthrough case RootErrored: { @@ -19457,6 +19517,8 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspended: { + flushSuspensePriorityWarningInDEV(); + // We have an acceptable loading state. We need to figure out if we should // immediately commit it or wait a bit. @@ -19465,7 +19527,12 @@ function renderRoot(root, expirationTime, isSync) { // possible. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync; - if (hasNotProcessedNewUpdates && !isSync) { + if ( + hasNotProcessedNewUpdates && + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // If we have not processed any new updates during this pass, then this is // either a retry of an existing fallback state or a hidden tree. // Hidden trees shouldn't be batched with other work and after that's @@ -19502,7 +19569,13 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspendedWithDelay: { - if (!isSync) { + flushSuspensePriorityWarningInDEV(); + + if ( + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // We're suspended in a state that should be avoided. We'll try to avoid committing // it for as long as the timeouts let us. if (workInProgressRootHasPendingPing) { @@ -19572,6 +19645,12 @@ function renderRoot(root, expirationTime, isSync) { // The work completed. Ready to commit. if ( !isSync && + // do not delay if we're inside an act() scope + !( + true && + flushSuspenseFallbacksInTests && + IsThisRendererActing.current + ) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null ) { @@ -19920,12 +19999,15 @@ function resetChildExpirationTime(completedWork) { } function commitRoot(root) { - runWithPriority$1(ImmediatePriority, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority$1( + ImmediatePriority, + commitRootImpl.bind(null, root, renderPriorityLevel) + ); // If there are passive effects, schedule a callback to flush them. This goes // outside commitRootImpl so that it inherits the priority of the render. if (rootWithPendingPassiveEffects !== null) { - var priorityLevel = getCurrentPriorityLevel(); - scheduleCallback(priorityLevel, function() { + scheduleCallback(NormalPriority, function() { flushPassiveEffects(); return null; }); @@ -19933,7 +20015,7 @@ function commitRoot(root) { return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); flushRenderPhaseStrictModeWarningsInDEV(); @@ -20062,7 +20144,12 @@ function commitRootImpl(root) { nextEffect = firstEffect; do { { - invokeGuardedCallback(null, commitMutationEffects, null); + invokeGuardedCallback( + null, + commitMutationEffects, + null, + renderPriorityLevel + ); if (hasCaughtError()) { (function() { if (!(nextEffect !== null)) { @@ -20149,6 +20236,7 @@ function commitRootImpl(root) { rootDoesHavePassiveEffects = false; rootWithPendingPassiveEffects = root; pendingPassiveEffectsExpirationTime = expirationTime; + pendingPassiveEffectsRenderPriority = renderPriorityLevel; } else { // We are done with the effect chain at this point so let's clear the // nextEffect pointers to assist with GC. If we have passive effects, we'll @@ -20251,7 +20339,7 @@ function commitBeforeMutationEffects() { } } -function commitMutationEffects() { +function commitMutationEffects(renderPriorityLevel) { // TODO: Should probably move the bulk of this function to commitWork. while (nextEffect !== null) { setCurrentFiber(nextEffect); @@ -20302,7 +20390,7 @@ function commitMutationEffects() { break; } case Deletion: { - commitDeletion(nextEffect); + commitDeletion(nextEffect, renderPriorityLevel); break; } } @@ -20348,9 +20436,19 @@ function flushPassiveEffects() { } var root = rootWithPendingPassiveEffects; var expirationTime = pendingPassiveEffectsExpirationTime; + var renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = NoWork; + pendingPassiveEffectsRenderPriority = NoPriority; + var priorityLevel = + renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel; + return runWithPriority$1( + priorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = null; if (enableSchedulerTracing) { prevInteractions = tracing.__interactionsRef.current; @@ -20857,6 +20955,7 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) { } } +// a 'shared' variable that changes when act() opens/closes in tests. var IsThisRendererActing = { current: false }; function warnIfNotScopedWithMatchingAct(fiber) { @@ -20872,12 +20971,12 @@ function warnIfNotScopedWithMatchingAct(fiber) { "Be sure to use the matching version of act() corresponding to your renderer:\n\n" + "// for react-dom:\n" + "import {act} from 'react-dom/test-utils';\n" + - "//...\n" + + "// ...\n" + "act(() => ...);\n\n" + "// for react-test-renderer:\n" + "import TestRenderer from 'react-test-renderer';\n" + "const {act} = TestRenderer;\n" + - "//...\n" + + "// ...\n" + "act(() => ...);" + "%s", getStackByFiberInDevAndProd(fiber) @@ -20944,7 +21043,44 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber) { var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; -var componentsThatSuspendedAtHighPri = null; +// In tests, we want to enforce a mocked scheduler. +var didWarnAboutUnmockedScheduler = false; +// TODO Before we release concurrent mode, revisit this and decide whether a mocked +// scheduler is the actual recommendation. The alternative could be a testing build, +// a new lib, or whatever; we dunno just yet. This message is for early adopters +// to get their tests right. + +function warnIfUnmockedScheduler(fiber) { + { + if ( + didWarnAboutUnmockedScheduler === false && + Scheduler.unstable_flushAllWithoutAsserting === undefined + ) { + if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } else if (warnAboutUnmockedScheduler === true) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'Starting from React v17, the "scheduler" module will need to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } + } + } +} + var componentsThatTriggeredHighPriSuspend = null; function checkForWrongSuspensePriorityInDEV(sourceFiber) { { @@ -21031,70 +21167,34 @@ function checkForWrongSuspensePriorityInDEV(sourceFiber) { } workInProgressNode = workInProgressNode.return; } - - // Add the component name to a set. - var componentName = getComponentName(sourceFiber.type); - if (componentsThatSuspendedAtHighPri === null) { - componentsThatSuspendedAtHighPri = new Set([componentName]); - } else { - componentsThatSuspendedAtHighPri.add(componentName); - } } } } function flushSuspensePriorityWarningInDEV() { { - if (componentsThatSuspendedAtHighPri !== null) { + if (componentsThatTriggeredHighPriSuspend !== null) { var componentNames = []; - componentsThatSuspendedAtHighPri.forEach(function(name) { - componentNames.push(name); + componentsThatTriggeredHighPriSuspend.forEach(function(name) { + return componentNames.push(name); }); - componentsThatSuspendedAtHighPri = null; - - var componentsThatTriggeredSuspendNames = []; - if (componentsThatTriggeredHighPriSuspend !== null) { - componentsThatTriggeredHighPriSuspend.forEach(function(name) { - return componentsThatTriggeredSuspendNames.push(name); - }); - } - componentsThatTriggeredHighPriSuspend = null; - var componentNamesString = componentNames.sort().join(", "); - var componentThatTriggeredSuspenseError = ""; - if (componentsThatTriggeredSuspendNames.length > 0) { - componentThatTriggeredSuspenseError = - "The following components triggered a user-blocking update:" + - "\n\n" + - " " + - componentsThatTriggeredSuspendNames.sort().join(", ") + - "\n\n" + - "that was then suspended by:" + - "\n\n" + - " " + - componentNamesString; - } else { - componentThatTriggeredSuspenseError = - "A user-blocking update was suspended by:" + - "\n\n" + - " " + - componentNamesString; + if (componentNames.length > 0) { + warningWithoutStack$1( + false, + "%s triggered a user-blocking update that suspended." + + "\n\n" + + "The fix is to split the update into multiple parts: a user-blocking " + + "update to provide immediate feedback, and another update that " + + "triggers the bulk of the changes." + + "\n\n" + + "Refer to the documentation for useSuspenseTransition to learn how " + + "to implement this pattern.", + // TODO: Add link to React docs with more information, once it exists + componentNames.sort().join(", ") + ); } - - warningWithoutStack$1( - false, - "%s" + - "\n\n" + - "The fix is to split the update into multiple parts: a user-blocking " + - "update to provide immediate feedback, and another update that " + - "triggers the bulk of the changes." + - "\n\n" + - "Refer to the documentation for useSuspenseTransition to learn how " + - "to implement this pattern.", - // TODO: Add link to React docs with more information, once it exists - componentThatTriggeredSuspenseError - ); } } } @@ -21573,7 +21673,6 @@ function createWorkInProgress(current, pendingProps, expirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -21666,7 +21765,6 @@ function resetWorkInProgress(workInProgress, renderExpirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -22289,6 +22387,7 @@ function updateContainer(element, container, parentComponent, callback) { { // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests if ("undefined" !== typeof jest) { + warnIfUnmockedScheduler(current$$1); warnIfNotScopedWithMatchingAct(current$$1); } } diff --git a/Libraries/Renderer/implementations/ReactFabric-prod.fb.js b/Libraries/Renderer/implementations/ReactFabric-prod.fb.js index 543906e39c31f7..35fbfdae532a68 100644 --- a/Libraries/Renderer/implementations/ReactFabric-prod.fb.js +++ b/Libraries/Renderer/implementations/ReactFabric-prod.fb.js @@ -1102,6 +1102,7 @@ function getComponentName(type) { } return null; } +require("../shims/ReactFeatureFlags"); function isFiberMountedImpl(fiber) { var node = fiber; if (fiber.alternate) for (; node.return; ) node = node.return; @@ -1451,7 +1452,6 @@ function restoreStateOfTarget(target) { ) ); } -require("../shims/ReactFeatureFlags"); function batchedUpdatesImpl(fn, bookkeeping) { return fn(bookkeeping); } @@ -2065,7 +2065,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3282,24 +3281,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3650,7 +3633,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3724,7 +3707,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3779,7 +3762,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, hydrationParentFiber = null, nextHydratableInstance = null, @@ -3998,17 +3981,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -4932,6 +4915,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -4960,6 +4952,56 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { + "function" === typeof onCommitFiberUnmount && + onCommitFiberUnmount(current$$1$jscomp$0); + switch (current$$1$jscomp$0.tag) { + case 0: + case 11: + case 14: + case 15: + var updateQueue = current$$1$jscomp$0.updateQueue; + if ( + null !== updateQueue && + ((updateQueue = updateQueue.lastEffect), null !== updateQueue) + ) { + var firstEffect = updateQueue.next; + runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); + } + ); + } + break; + case 1: + safelyDetachRef(current$$1$jscomp$0); + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); + break; + case 5: + safelyDetachRef(current$$1$jscomp$0); + break; + case 4: + createChildNodeSet(current$$1$jscomp$0.stateNode.containerInfo); + } +} function commitWork(current$$1, finishedWork) { switch (finishedWork.tag) { case 0: @@ -5078,6 +5120,8 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, + pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, rootWithNestedUpdates = null, @@ -5903,7 +5947,6 @@ function completeUnitOfWork(unitOfWork) { : { expirationTime: type.expirationTime, firstContext: type.firstContext, - listeners: type.listeners, responders: type.responders })), (renderExpirationTime$jscomp$0 = @@ -6035,16 +6078,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority$1(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority$1(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6146,7 +6189,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6170,84 +6213,38 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - a: for (prevState = prevProps = current$$1; ; ) { - instance = prevState; - "function" === typeof onCommitFiberUnmount && - onCommitFiberUnmount(instance); - switch (instance.tag) { - case 0: - case 11: - case 14: - case 15: - var updateQueue = instance.updateQueue; - if (null !== updateQueue) { - var lastEffect = updateQueue.lastEffect; - if (null !== lastEffect) { - var firstEffect = lastEffect.next; - snapshot = firstEffect; - do { - var destroy = snapshot.destroy; - if (void 0 !== destroy) { - finishedWork$jscomp$0 = instance; - try { - destroy(); - } catch (error) { - captureCommitPhaseError( - finishedWork$jscomp$0, - error - ); - } - } - snapshot = snapshot.next; - } while (snapshot !== firstEffect); - } - } - break; - case 1: - safelyDetachRef(instance); - var instance$jscomp$0 = instance.stateNode; - if ( - "function" === - typeof instance$jscomp$0.componentWillUnmount - ) - try { - (instance$jscomp$0.props = instance.memoizedProps), - (instance$jscomp$0.state = instance.memoizedState), - instance$jscomp$0.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(instance, unmountError); - } - break; - case 5: - safelyDetachRef(instance); - break; - case 4: - createChildNodeSet(instance.stateNode.containerInfo); - } - if (null !== prevState.child) - (prevState.child.return = prevState), - (prevState = prevState.child); + prevProps = nextEffect; + a: for ( + prevState = prevProps, + instance = current$$1, + snapshot = prevState; + ; + + ) + if ( + (commitUnmount(snapshot, instance), null !== snapshot.child) + ) + (snapshot.child.return = snapshot), + (snapshot = snapshot.child); else { - if (prevState === prevProps) break; - for (; null === prevState.sibling; ) { + if (snapshot === prevState) break; + for (; null === snapshot.sibling; ) { if ( - null === prevState.return || - prevState.return === prevProps + null === snapshot.return || + snapshot.return === prevState ) break a; - prevState = prevState.return; + snapshot = snapshot.return; } - prevState.sibling.return = prevState.return; - prevState = prevState.sibling; + snapshot.sibling.return = snapshot.return; + snapshot = snapshot.sibling; } - } - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6285,10 +6282,10 @@ function commitRootImpl(root) { ); break; case 1: - var instance$jscomp$1 = current$$1$jscomp$0.stateNode; + var instance$jscomp$0 = current$$1$jscomp$0.stateNode; if (current$$1$jscomp$0.effectTag & 4) if (null === current$$1$jscomp$1) - instance$jscomp$1.componentDidMount(); + instance$jscomp$0.componentDidMount(); else { var prevProps$jscomp$0 = current$$1$jscomp$0.elementType === @@ -6298,38 +6295,38 @@ function commitRootImpl(root) { current$$1$jscomp$0.type, current$$1$jscomp$1.memoizedProps ); - instance$jscomp$1.componentDidUpdate( + instance$jscomp$0.componentDidUpdate( prevProps$jscomp$0, current$$1$jscomp$1.memoizedState, - instance$jscomp$1.__reactInternalSnapshotBeforeUpdate + instance$jscomp$0.__reactInternalSnapshotBeforeUpdate ); } - var updateQueue$jscomp$0 = current$$1$jscomp$0.updateQueue; - null !== updateQueue$jscomp$0 && + var updateQueue = current$$1$jscomp$0.updateQueue; + null !== updateQueue && commitUpdateQueue( current$$1$jscomp$0, - updateQueue$jscomp$0, - instance$jscomp$1, + updateQueue, + instance$jscomp$0, currentRef ); break; case 3: var _updateQueue = current$$1$jscomp$0.updateQueue; if (null !== _updateQueue) { - updateQueue = null; + alternate = null; if (null !== current$$1$jscomp$0.child) switch (current$$1$jscomp$0.child.tag) { case 5: - updateQueue = + alternate = current$$1$jscomp$0.child.stateNode.canonical; break; case 1: - updateQueue = current$$1$jscomp$0.child.stateNode; + alternate = current$$1$jscomp$0.child.stateNode; } commitUpdateQueue( current$$1$jscomp$0, _updateQueue, - updateQueue, + alternate, currentRef ); } @@ -6367,13 +6364,13 @@ function commitRootImpl(root) { if (effectTag$jscomp$0 & 128) { var ref = nextEffect.ref; if (null !== ref) { - var instance$jscomp$2 = nextEffect.stateNode; + var instance$jscomp$1 = nextEffect.stateNode; switch (nextEffect.tag) { case 5: - var instanceToUse = instance$jscomp$2.canonical; + var instanceToUse = instance$jscomp$1.canonical; break; default: - instanceToUse = instance$jscomp$2; + instanceToUse = instance$jscomp$1; } "function" === typeof ref ? ref(instanceToUse) @@ -6395,24 +6392,27 @@ function commitRootImpl(root) { executionContext = childExpirationTimeBeforeCommit; } else root.current = finishedWork; if (rootDoesHavePassiveEffects) - (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root); + (rootDoesHavePassiveEffects = !1), + (rootWithPendingPassiveEffects = root), + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (effectTag$jscomp$0 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = effectTag$jscomp$0); - effectTag$jscomp$0 = root.firstPendingTime; - 0 !== effectTag$jscomp$0 - ? ((current$$1$jscomp$1 = requestCurrentTime()), - (current$$1$jscomp$1 = inferPriorityFromExpirationTime( - current$$1$jscomp$1, - effectTag$jscomp$0 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + 0 !== renderPriorityLevel + ? ((effectTag$jscomp$0 = requestCurrentTime()), + (effectTag$jscomp$0 = inferPriorityFromExpirationTime( + effectTag$jscomp$0, + renderPriorityLevel )), - scheduleCallbackForRoot(root, current$$1$jscomp$1, effectTag$jscomp$0)) + scheduleCallbackForRoot(root, effectTag$jscomp$0, renderPriorityLevel)) : (legacyErrorBoundariesThatAlreadyFailed = null); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === effectTag$jscomp$0 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6428,8 +6428,18 @@ function commitRootImpl(root) { } function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; - var root = rootWithPendingPassiveEffects; + var root = rootWithPendingPassiveEffects, + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; + pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root) { if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError( Error("Cannot flush passive effects while already rendering.") @@ -6587,32 +6597,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6631,25 +6635,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6658,8 +6662,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6670,9 +6674,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -6692,28 +6696,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6722,7 +6726,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6731,7 +6735,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6740,8 +6744,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -6750,7 +6754,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -6759,32 +6763,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6797,8 +6801,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -6807,7 +6811,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -6871,16 +6875,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6917,9 +6921,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -6933,7 +6937,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7015,7 +7019,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7023,12 +7027,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7040,16 +7047,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7067,11 +7074,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7084,13 +7091,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7204,7 +7211,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactFabric-prod.js b/Libraries/Renderer/implementations/ReactFabric-prod.js index 88bd68a54c22b2..b10ca758ec0c87 100644 --- a/Libraries/Renderer/implementations/ReactFabric-prod.js +++ b/Libraries/Renderer/implementations/ReactFabric-prod.js @@ -2065,7 +2065,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3282,24 +3281,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3650,7 +3633,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3724,7 +3707,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3779,7 +3762,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, hydrationParentFiber = null, nextHydratableInstance = null, @@ -3998,17 +3981,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -4932,6 +4915,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -4960,6 +4952,56 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { + "function" === typeof onCommitFiberUnmount && + onCommitFiberUnmount(current$$1$jscomp$0); + switch (current$$1$jscomp$0.tag) { + case 0: + case 11: + case 14: + case 15: + var updateQueue = current$$1$jscomp$0.updateQueue; + if ( + null !== updateQueue && + ((updateQueue = updateQueue.lastEffect), null !== updateQueue) + ) { + var firstEffect = updateQueue.next; + runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); + } + ); + } + break; + case 1: + safelyDetachRef(current$$1$jscomp$0); + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); + break; + case 5: + safelyDetachRef(current$$1$jscomp$0); + break; + case 4: + createChildNodeSet(current$$1$jscomp$0.stateNode.containerInfo); + } +} function commitWork(current$$1, finishedWork) { switch (finishedWork.tag) { case 0: @@ -5078,6 +5120,8 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, + pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, rootWithNestedUpdates = null, @@ -5903,7 +5947,6 @@ function completeUnitOfWork(unitOfWork) { : { expirationTime: type.expirationTime, firstContext: type.firstContext, - listeners: type.listeners, responders: type.responders })), (renderExpirationTime$jscomp$0 = @@ -6035,16 +6078,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority$1(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority$1(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6146,7 +6189,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6170,84 +6213,38 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - a: for (prevState = prevProps = current$$1; ; ) { - instance = prevState; - "function" === typeof onCommitFiberUnmount && - onCommitFiberUnmount(instance); - switch (instance.tag) { - case 0: - case 11: - case 14: - case 15: - var updateQueue = instance.updateQueue; - if (null !== updateQueue) { - var lastEffect = updateQueue.lastEffect; - if (null !== lastEffect) { - var firstEffect = lastEffect.next; - snapshot = firstEffect; - do { - var destroy = snapshot.destroy; - if (void 0 !== destroy) { - finishedWork$jscomp$0 = instance; - try { - destroy(); - } catch (error) { - captureCommitPhaseError( - finishedWork$jscomp$0, - error - ); - } - } - snapshot = snapshot.next; - } while (snapshot !== firstEffect); - } - } - break; - case 1: - safelyDetachRef(instance); - var instance$jscomp$0 = instance.stateNode; - if ( - "function" === - typeof instance$jscomp$0.componentWillUnmount - ) - try { - (instance$jscomp$0.props = instance.memoizedProps), - (instance$jscomp$0.state = instance.memoizedState), - instance$jscomp$0.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(instance, unmountError); - } - break; - case 5: - safelyDetachRef(instance); - break; - case 4: - createChildNodeSet(instance.stateNode.containerInfo); - } - if (null !== prevState.child) - (prevState.child.return = prevState), - (prevState = prevState.child); + prevProps = nextEffect; + a: for ( + prevState = prevProps, + instance = current$$1, + snapshot = prevState; + ; + + ) + if ( + (commitUnmount(snapshot, instance), null !== snapshot.child) + ) + (snapshot.child.return = snapshot), + (snapshot = snapshot.child); else { - if (prevState === prevProps) break; - for (; null === prevState.sibling; ) { + if (snapshot === prevState) break; + for (; null === snapshot.sibling; ) { if ( - null === prevState.return || - prevState.return === prevProps + null === snapshot.return || + snapshot.return === prevState ) break a; - prevState = prevState.return; + snapshot = snapshot.return; } - prevState.sibling.return = prevState.return; - prevState = prevState.sibling; + snapshot.sibling.return = snapshot.return; + snapshot = snapshot.sibling; } - } - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6285,10 +6282,10 @@ function commitRootImpl(root) { ); break; case 1: - var instance$jscomp$1 = current$$1$jscomp$0.stateNode; + var instance$jscomp$0 = current$$1$jscomp$0.stateNode; if (current$$1$jscomp$0.effectTag & 4) if (null === current$$1$jscomp$1) - instance$jscomp$1.componentDidMount(); + instance$jscomp$0.componentDidMount(); else { var prevProps$jscomp$0 = current$$1$jscomp$0.elementType === @@ -6298,38 +6295,38 @@ function commitRootImpl(root) { current$$1$jscomp$0.type, current$$1$jscomp$1.memoizedProps ); - instance$jscomp$1.componentDidUpdate( + instance$jscomp$0.componentDidUpdate( prevProps$jscomp$0, current$$1$jscomp$1.memoizedState, - instance$jscomp$1.__reactInternalSnapshotBeforeUpdate + instance$jscomp$0.__reactInternalSnapshotBeforeUpdate ); } - var updateQueue$jscomp$0 = current$$1$jscomp$0.updateQueue; - null !== updateQueue$jscomp$0 && + var updateQueue = current$$1$jscomp$0.updateQueue; + null !== updateQueue && commitUpdateQueue( current$$1$jscomp$0, - updateQueue$jscomp$0, - instance$jscomp$1, + updateQueue, + instance$jscomp$0, currentRef ); break; case 3: var _updateQueue = current$$1$jscomp$0.updateQueue; if (null !== _updateQueue) { - updateQueue = null; + alternate = null; if (null !== current$$1$jscomp$0.child) switch (current$$1$jscomp$0.child.tag) { case 5: - updateQueue = + alternate = current$$1$jscomp$0.child.stateNode.canonical; break; case 1: - updateQueue = current$$1$jscomp$0.child.stateNode; + alternate = current$$1$jscomp$0.child.stateNode; } commitUpdateQueue( current$$1$jscomp$0, _updateQueue, - updateQueue, + alternate, currentRef ); } @@ -6367,13 +6364,13 @@ function commitRootImpl(root) { if (effectTag$jscomp$0 & 128) { var ref = nextEffect.ref; if (null !== ref) { - var instance$jscomp$2 = nextEffect.stateNode; + var instance$jscomp$1 = nextEffect.stateNode; switch (nextEffect.tag) { case 5: - var instanceToUse = instance$jscomp$2.canonical; + var instanceToUse = instance$jscomp$1.canonical; break; default: - instanceToUse = instance$jscomp$2; + instanceToUse = instance$jscomp$1; } "function" === typeof ref ? ref(instanceToUse) @@ -6395,24 +6392,27 @@ function commitRootImpl(root) { executionContext = childExpirationTimeBeforeCommit; } else root.current = finishedWork; if (rootDoesHavePassiveEffects) - (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root); + (rootDoesHavePassiveEffects = !1), + (rootWithPendingPassiveEffects = root), + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (effectTag$jscomp$0 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = effectTag$jscomp$0); - effectTag$jscomp$0 = root.firstPendingTime; - 0 !== effectTag$jscomp$0 - ? ((current$$1$jscomp$1 = requestCurrentTime()), - (current$$1$jscomp$1 = inferPriorityFromExpirationTime( - current$$1$jscomp$1, - effectTag$jscomp$0 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + 0 !== renderPriorityLevel + ? ((effectTag$jscomp$0 = requestCurrentTime()), + (effectTag$jscomp$0 = inferPriorityFromExpirationTime( + effectTag$jscomp$0, + renderPriorityLevel )), - scheduleCallbackForRoot(root, current$$1$jscomp$1, effectTag$jscomp$0)) + scheduleCallbackForRoot(root, effectTag$jscomp$0, renderPriorityLevel)) : (legacyErrorBoundariesThatAlreadyFailed = null); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === effectTag$jscomp$0 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6428,8 +6428,18 @@ function commitRootImpl(root) { } function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; - var root = rootWithPendingPassiveEffects; + var root = rootWithPendingPassiveEffects, + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; + pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root) { if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError( Error("Cannot flush passive effects while already rendering.") @@ -6587,32 +6597,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6631,25 +6635,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6658,8 +6662,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6670,9 +6674,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -6692,28 +6696,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6722,7 +6726,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6731,7 +6735,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6740,8 +6744,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -6750,7 +6754,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -6759,32 +6763,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6797,8 +6801,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -6807,7 +6811,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -6871,16 +6875,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6917,9 +6921,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -6933,7 +6937,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7015,7 +7019,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7023,12 +7027,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7040,16 +7047,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7067,11 +7074,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7084,13 +7091,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7204,7 +7211,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js b/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js index c4f8f3fd2b1ee8..071f92097b6ce7 100644 --- a/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js +++ b/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js @@ -1103,6 +1103,7 @@ function getComponentName(type) { } return null; } +require("../shims/ReactFeatureFlags"); function isFiberMountedImpl(fiber) { var node = fiber; if (fiber.alternate) for (; node.return; ) node = node.return; @@ -1452,7 +1453,6 @@ function restoreStateOfTarget(target) { ) ); } -require("../shims/ReactFeatureFlags"); function batchedUpdatesImpl(fn, bookkeeping) { return fn(bookkeeping); } @@ -2075,7 +2075,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3292,24 +3291,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3660,7 +3643,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3734,7 +3717,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3789,7 +3772,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, now$1 = Scheduler.unstable_now, commitTime = 0, @@ -4019,17 +4002,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -5105,7 +5088,6 @@ function completeWork(current, workInProgress, renderExpirationTime) { : { expirationTime: updatePayload.expirationTime, firstContext: updatePayload.firstContext, - listeners: updatePayload.listeners, responders: updatePayload.responders }), (rootContainerInstance.selfBaseDuration = @@ -5285,6 +5267,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -5313,6 +5304,56 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { + "function" === typeof onCommitFiberUnmount && + onCommitFiberUnmount(current$$1$jscomp$0); + switch (current$$1$jscomp$0.tag) { + case 0: + case 11: + case 14: + case 15: + var updateQueue = current$$1$jscomp$0.updateQueue; + if ( + null !== updateQueue && + ((updateQueue = updateQueue.lastEffect), null !== updateQueue) + ) { + var firstEffect = updateQueue.next; + runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); + } + ); + } + break; + case 1: + safelyDetachRef(current$$1$jscomp$0); + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); + break; + case 5: + safelyDetachRef(current$$1$jscomp$0); + break; + case 4: + createChildNodeSet(current$$1$jscomp$0.stateNode.containerInfo); + } +} function commitWork(current$$1, finishedWork) { switch (finishedWork.tag) { case 0: @@ -5433,6 +5474,7 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, @@ -6139,16 +6181,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority$1(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority$1(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6253,7 +6295,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6277,84 +6319,38 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - a: for (prevState = prevProps = current$$1; ; ) { - instance = prevState; - "function" === typeof onCommitFiberUnmount && - onCommitFiberUnmount(instance); - switch (instance.tag) { - case 0: - case 11: - case 14: - case 15: - var updateQueue = instance.updateQueue; - if (null !== updateQueue) { - var lastEffect = updateQueue.lastEffect; - if (null !== lastEffect) { - var firstEffect = lastEffect.next; - snapshot = firstEffect; - do { - var destroy = snapshot.destroy; - if (void 0 !== destroy) { - finishedWork$jscomp$0 = instance; - try { - destroy(); - } catch (error) { - captureCommitPhaseError( - finishedWork$jscomp$0, - error - ); - } - } - snapshot = snapshot.next; - } while (snapshot !== firstEffect); - } - } - break; - case 1: - safelyDetachRef(instance); - var instance$jscomp$0 = instance.stateNode; - if ( - "function" === - typeof instance$jscomp$0.componentWillUnmount - ) - try { - (instance$jscomp$0.props = instance.memoizedProps), - (instance$jscomp$0.state = instance.memoizedState), - instance$jscomp$0.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(instance, unmountError); - } - break; - case 5: - safelyDetachRef(instance); - break; - case 4: - createChildNodeSet(instance.stateNode.containerInfo); - } - if (null !== prevState.child) - (prevState.child.return = prevState), - (prevState = prevState.child); + prevProps = nextEffect; + a: for ( + prevState = prevProps, + instance = current$$1, + snapshot = prevState; + ; + + ) + if ( + (commitUnmount(snapshot, instance), null !== snapshot.child) + ) + (snapshot.child.return = snapshot), + (snapshot = snapshot.child); else { - if (prevState === prevProps) break; - for (; null === prevState.sibling; ) { + if (snapshot === prevState) break; + for (; null === snapshot.sibling; ) { if ( - null === prevState.return || - prevState.return === prevProps + null === snapshot.return || + snapshot.return === prevState ) break a; - prevState = prevState.return; + snapshot = snapshot.return; } - prevState.sibling.return = prevState.return; - prevState = prevState.sibling; + snapshot.sibling.return = snapshot.return; + snapshot = snapshot.sibling; } - } - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6382,10 +6378,10 @@ function commitRootImpl(root) { ) { var effectTag$jscomp$0 = nextEffect.effectTag; if (effectTag$jscomp$0 & 36) { - lastEffect = effectTag; + current$$1 = effectTag; var current$$1$jscomp$1 = nextEffect.alternate; currentRef = nextEffect; - updateQueue = current$$1$jscomp$0; + alternate = current$$1$jscomp$0; switch (currentRef.tag) { case 0: case 11: @@ -6393,10 +6389,10 @@ function commitRootImpl(root) { commitHookEffectList(UnmountLayout, MountLayout, currentRef); break; case 1: - var instance$jscomp$1 = currentRef.stateNode; + var instance$jscomp$0 = currentRef.stateNode; if (currentRef.effectTag & 4) if (null === current$$1$jscomp$1) - instance$jscomp$1.componentDidMount(); + instance$jscomp$0.componentDidMount(); else { var prevProps$jscomp$0 = currentRef.elementType === currentRef.type @@ -6405,38 +6401,38 @@ function commitRootImpl(root) { currentRef.type, current$$1$jscomp$1.memoizedProps ); - instance$jscomp$1.componentDidUpdate( + instance$jscomp$0.componentDidUpdate( prevProps$jscomp$0, current$$1$jscomp$1.memoizedState, - instance$jscomp$1.__reactInternalSnapshotBeforeUpdate + instance$jscomp$0.__reactInternalSnapshotBeforeUpdate ); } - var updateQueue$jscomp$0 = currentRef.updateQueue; - null !== updateQueue$jscomp$0 && + var updateQueue = currentRef.updateQueue; + null !== updateQueue && commitUpdateQueue( currentRef, - updateQueue$jscomp$0, - instance$jscomp$1, - updateQueue + updateQueue, + instance$jscomp$0, + alternate ); break; case 3: var _updateQueue = currentRef.updateQueue; if (null !== _updateQueue) { - lastEffect = null; + current$$1 = null; if (null !== currentRef.child) switch (currentRef.child.tag) { case 5: - lastEffect = currentRef.child.stateNode.canonical; + current$$1 = currentRef.child.stateNode.canonical; break; case 1: - lastEffect = currentRef.child.stateNode; + current$$1 = currentRef.child.stateNode; } commitUpdateQueue( currentRef, _updateQueue, - lastEffect, - updateQueue + current$$1, + alternate ); } break; @@ -6462,7 +6458,7 @@ function commitRootImpl(root) { currentRef.treeBaseDuration, currentRef.actualStartTime, commitTime, - lastEffect.memoizedInteractions + current$$1.memoizedInteractions ); break; case 13: @@ -6481,13 +6477,13 @@ function commitRootImpl(root) { if (effectTag$jscomp$0 & 128) { var ref = nextEffect.ref; if (null !== ref) { - var instance$jscomp$2 = nextEffect.stateNode; + var instance$jscomp$1 = nextEffect.stateNode; switch (nextEffect.tag) { case 5: - var instanceToUse = instance$jscomp$2.canonical; + var instanceToUse = instance$jscomp$1.canonical; break; default: - instanceToUse = instance$jscomp$2; + instanceToUse = instance$jscomp$1; } "function" === typeof ref ? ref(instanceToUse) @@ -6512,38 +6508,39 @@ function commitRootImpl(root) { if ((effectTag$jscomp$0 = rootDoesHavePassiveEffects)) (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root), - (pendingPassiveEffectsExpirationTime = expirationTime); + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (current$$1$jscomp$1 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = current$$1$jscomp$1); - current$$1$jscomp$1 = root.firstPendingTime; - if (0 !== current$$1$jscomp$1) { - instance$jscomp$1 = requestCurrentTime(); - instance$jscomp$1 = inferPriorityFromExpirationTime( - instance$jscomp$1, - current$$1$jscomp$1 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + if (0 !== renderPriorityLevel) { + current$$1$jscomp$1 = requestCurrentTime(); + current$$1$jscomp$1 = inferPriorityFromExpirationTime( + current$$1$jscomp$1, + renderPriorityLevel ); if (null !== spawnedWorkDuringRender) for ( - prevProps$jscomp$0 = spawnedWorkDuringRender, + instance$jscomp$0 = spawnedWorkDuringRender, spawnedWorkDuringRender = null, - updateQueue$jscomp$0 = 0; - updateQueue$jscomp$0 < prevProps$jscomp$0.length; - updateQueue$jscomp$0++ + prevProps$jscomp$0 = 0; + prevProps$jscomp$0 < instance$jscomp$0.length; + prevProps$jscomp$0++ ) scheduleInteractions( root, - prevProps$jscomp$0[updateQueue$jscomp$0], + instance$jscomp$0[prevProps$jscomp$0], root.memoizedInteractions ); - scheduleCallbackForRoot(root, instance$jscomp$1, current$$1$jscomp$1); + scheduleCallbackForRoot(root, current$$1$jscomp$1, renderPriorityLevel); } else legacyErrorBoundariesThatAlreadyFailed = null; effectTag$jscomp$0 || finishPendingInteractions(root, expirationTime); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === current$$1$jscomp$1 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6560,9 +6557,17 @@ function commitRootImpl(root) { function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; var root = rootWithPendingPassiveEffects, - expirationTime = pendingPassiveEffectsExpirationTime; + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = tracing.__interactionsRef.current; tracing.__interactionsRef.current = root.memoizedInteractions; if ((executionContext & (RenderContext | CommitContext)) !== NoContext) @@ -6727,32 +6732,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6771,25 +6770,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6798,8 +6797,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6810,9 +6809,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -6832,28 +6831,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6862,7 +6861,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6871,7 +6870,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6880,8 +6879,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -6890,7 +6889,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -6899,32 +6898,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6937,8 +6936,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -6947,7 +6946,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -7011,16 +7010,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7058,9 +7057,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -7074,7 +7073,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7156,7 +7155,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7164,12 +7163,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7181,16 +7183,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7208,11 +7210,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7225,13 +7227,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7437,7 +7439,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactFabric-profiling.js b/Libraries/Renderer/implementations/ReactFabric-profiling.js index 8fad29f2f8c173..1de09047ecc9a7 100644 --- a/Libraries/Renderer/implementations/ReactFabric-profiling.js +++ b/Libraries/Renderer/implementations/ReactFabric-profiling.js @@ -2075,7 +2075,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3292,24 +3291,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3660,7 +3643,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3734,7 +3717,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3789,7 +3772,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, now$1 = Scheduler.unstable_now, commitTime = 0, @@ -4019,17 +4002,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -5105,7 +5088,6 @@ function completeWork(current, workInProgress, renderExpirationTime) { : { expirationTime: updatePayload.expirationTime, firstContext: updatePayload.firstContext, - listeners: updatePayload.listeners, responders: updatePayload.responders }), (rootContainerInstance.selfBaseDuration = @@ -5285,6 +5267,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -5313,6 +5304,56 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { + "function" === typeof onCommitFiberUnmount && + onCommitFiberUnmount(current$$1$jscomp$0); + switch (current$$1$jscomp$0.tag) { + case 0: + case 11: + case 14: + case 15: + var updateQueue = current$$1$jscomp$0.updateQueue; + if ( + null !== updateQueue && + ((updateQueue = updateQueue.lastEffect), null !== updateQueue) + ) { + var firstEffect = updateQueue.next; + runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); + } + ); + } + break; + case 1: + safelyDetachRef(current$$1$jscomp$0); + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); + break; + case 5: + safelyDetachRef(current$$1$jscomp$0); + break; + case 4: + createChildNodeSet(current$$1$jscomp$0.stateNode.containerInfo); + } +} function commitWork(current$$1, finishedWork) { switch (finishedWork.tag) { case 0: @@ -5433,6 +5474,7 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, @@ -6139,16 +6181,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority$1(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority$1(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6253,7 +6295,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6277,84 +6319,38 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - a: for (prevState = prevProps = current$$1; ; ) { - instance = prevState; - "function" === typeof onCommitFiberUnmount && - onCommitFiberUnmount(instance); - switch (instance.tag) { - case 0: - case 11: - case 14: - case 15: - var updateQueue = instance.updateQueue; - if (null !== updateQueue) { - var lastEffect = updateQueue.lastEffect; - if (null !== lastEffect) { - var firstEffect = lastEffect.next; - snapshot = firstEffect; - do { - var destroy = snapshot.destroy; - if (void 0 !== destroy) { - finishedWork$jscomp$0 = instance; - try { - destroy(); - } catch (error) { - captureCommitPhaseError( - finishedWork$jscomp$0, - error - ); - } - } - snapshot = snapshot.next; - } while (snapshot !== firstEffect); - } - } - break; - case 1: - safelyDetachRef(instance); - var instance$jscomp$0 = instance.stateNode; - if ( - "function" === - typeof instance$jscomp$0.componentWillUnmount - ) - try { - (instance$jscomp$0.props = instance.memoizedProps), - (instance$jscomp$0.state = instance.memoizedState), - instance$jscomp$0.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(instance, unmountError); - } - break; - case 5: - safelyDetachRef(instance); - break; - case 4: - createChildNodeSet(instance.stateNode.containerInfo); - } - if (null !== prevState.child) - (prevState.child.return = prevState), - (prevState = prevState.child); + prevProps = nextEffect; + a: for ( + prevState = prevProps, + instance = current$$1, + snapshot = prevState; + ; + + ) + if ( + (commitUnmount(snapshot, instance), null !== snapshot.child) + ) + (snapshot.child.return = snapshot), + (snapshot = snapshot.child); else { - if (prevState === prevProps) break; - for (; null === prevState.sibling; ) { + if (snapshot === prevState) break; + for (; null === snapshot.sibling; ) { if ( - null === prevState.return || - prevState.return === prevProps + null === snapshot.return || + snapshot.return === prevState ) break a; - prevState = prevState.return; + snapshot = snapshot.return; } - prevState.sibling.return = prevState.return; - prevState = prevState.sibling; + snapshot.sibling.return = snapshot.return; + snapshot = snapshot.sibling; } - } - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6382,10 +6378,10 @@ function commitRootImpl(root) { ) { var effectTag$jscomp$0 = nextEffect.effectTag; if (effectTag$jscomp$0 & 36) { - lastEffect = effectTag; + current$$1 = effectTag; var current$$1$jscomp$1 = nextEffect.alternate; currentRef = nextEffect; - updateQueue = current$$1$jscomp$0; + alternate = current$$1$jscomp$0; switch (currentRef.tag) { case 0: case 11: @@ -6393,10 +6389,10 @@ function commitRootImpl(root) { commitHookEffectList(UnmountLayout, MountLayout, currentRef); break; case 1: - var instance$jscomp$1 = currentRef.stateNode; + var instance$jscomp$0 = currentRef.stateNode; if (currentRef.effectTag & 4) if (null === current$$1$jscomp$1) - instance$jscomp$1.componentDidMount(); + instance$jscomp$0.componentDidMount(); else { var prevProps$jscomp$0 = currentRef.elementType === currentRef.type @@ -6405,38 +6401,38 @@ function commitRootImpl(root) { currentRef.type, current$$1$jscomp$1.memoizedProps ); - instance$jscomp$1.componentDidUpdate( + instance$jscomp$0.componentDidUpdate( prevProps$jscomp$0, current$$1$jscomp$1.memoizedState, - instance$jscomp$1.__reactInternalSnapshotBeforeUpdate + instance$jscomp$0.__reactInternalSnapshotBeforeUpdate ); } - var updateQueue$jscomp$0 = currentRef.updateQueue; - null !== updateQueue$jscomp$0 && + var updateQueue = currentRef.updateQueue; + null !== updateQueue && commitUpdateQueue( currentRef, - updateQueue$jscomp$0, - instance$jscomp$1, - updateQueue + updateQueue, + instance$jscomp$0, + alternate ); break; case 3: var _updateQueue = currentRef.updateQueue; if (null !== _updateQueue) { - lastEffect = null; + current$$1 = null; if (null !== currentRef.child) switch (currentRef.child.tag) { case 5: - lastEffect = currentRef.child.stateNode.canonical; + current$$1 = currentRef.child.stateNode.canonical; break; case 1: - lastEffect = currentRef.child.stateNode; + current$$1 = currentRef.child.stateNode; } commitUpdateQueue( currentRef, _updateQueue, - lastEffect, - updateQueue + current$$1, + alternate ); } break; @@ -6462,7 +6458,7 @@ function commitRootImpl(root) { currentRef.treeBaseDuration, currentRef.actualStartTime, commitTime, - lastEffect.memoizedInteractions + current$$1.memoizedInteractions ); break; case 13: @@ -6481,13 +6477,13 @@ function commitRootImpl(root) { if (effectTag$jscomp$0 & 128) { var ref = nextEffect.ref; if (null !== ref) { - var instance$jscomp$2 = nextEffect.stateNode; + var instance$jscomp$1 = nextEffect.stateNode; switch (nextEffect.tag) { case 5: - var instanceToUse = instance$jscomp$2.canonical; + var instanceToUse = instance$jscomp$1.canonical; break; default: - instanceToUse = instance$jscomp$2; + instanceToUse = instance$jscomp$1; } "function" === typeof ref ? ref(instanceToUse) @@ -6512,38 +6508,39 @@ function commitRootImpl(root) { if ((effectTag$jscomp$0 = rootDoesHavePassiveEffects)) (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root), - (pendingPassiveEffectsExpirationTime = expirationTime); + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (current$$1$jscomp$1 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = current$$1$jscomp$1); - current$$1$jscomp$1 = root.firstPendingTime; - if (0 !== current$$1$jscomp$1) { - instance$jscomp$1 = requestCurrentTime(); - instance$jscomp$1 = inferPriorityFromExpirationTime( - instance$jscomp$1, - current$$1$jscomp$1 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + if (0 !== renderPriorityLevel) { + current$$1$jscomp$1 = requestCurrentTime(); + current$$1$jscomp$1 = inferPriorityFromExpirationTime( + current$$1$jscomp$1, + renderPriorityLevel ); if (null !== spawnedWorkDuringRender) for ( - prevProps$jscomp$0 = spawnedWorkDuringRender, + instance$jscomp$0 = spawnedWorkDuringRender, spawnedWorkDuringRender = null, - updateQueue$jscomp$0 = 0; - updateQueue$jscomp$0 < prevProps$jscomp$0.length; - updateQueue$jscomp$0++ + prevProps$jscomp$0 = 0; + prevProps$jscomp$0 < instance$jscomp$0.length; + prevProps$jscomp$0++ ) scheduleInteractions( root, - prevProps$jscomp$0[updateQueue$jscomp$0], + instance$jscomp$0[prevProps$jscomp$0], root.memoizedInteractions ); - scheduleCallbackForRoot(root, instance$jscomp$1, current$$1$jscomp$1); + scheduleCallbackForRoot(root, current$$1$jscomp$1, renderPriorityLevel); } else legacyErrorBoundariesThatAlreadyFailed = null; effectTag$jscomp$0 || finishPendingInteractions(root, expirationTime); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === current$$1$jscomp$1 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6560,9 +6557,17 @@ function commitRootImpl(root) { function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; var root = rootWithPendingPassiveEffects, - expirationTime = pendingPassiveEffectsExpirationTime; + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority$1( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = tracing.__interactionsRef.current; tracing.__interactionsRef.current = root.memoizedInteractions; if ((executionContext & (RenderContext | CommitContext)) !== NoContext) @@ -6727,32 +6732,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6771,25 +6770,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6798,8 +6797,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6810,9 +6809,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -6832,28 +6831,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6862,7 +6861,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6871,7 +6870,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6880,8 +6879,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -6890,7 +6889,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -6899,32 +6898,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6937,8 +6936,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -6947,7 +6946,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -7011,16 +7010,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7058,9 +7057,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -7074,7 +7073,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7156,7 +7155,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7164,12 +7163,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7181,16 +7183,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7208,11 +7210,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7225,13 +7227,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7437,7 +7439,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js b/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js index e439de16a08195..4d155951884124 100644 --- a/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js +++ b/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js @@ -2662,10 +2662,15 @@ var warnAboutDeprecatedSetNativeProps = true; var enableFlareAPI = false; var enableFundamentalAPI = false; +var warnAboutUnmockedScheduler = true; var revertPassiveEffectsChange = false; +var flushSuspenseFallbacksInTests = true; var enableSuspenseCallback = false; var warnAboutDefaultPropsOnFunctionComponents = false; +var warnAboutStringRefs = false; +var disableLegacyContext = false; +var disableSchedulerTimeoutBasedOnReactExpirationTime = false; // Only used in www builds. @@ -5123,262 +5128,310 @@ function getUnmaskedContext( Component, didPushOwnContextIfProvider ) { - if (didPushOwnContextIfProvider && isContextProvider(Component)) { - // If the fiber is a context provider itself, when we read its context - // we may have already pushed its own child context on the stack. A context - // provider should not "see" its own child context. Therefore we read the - // previous (parent) context instead for a context provider. - return previousContext; + if (disableLegacyContext) { + return emptyContextObject; + } else { + if (didPushOwnContextIfProvider && isContextProvider(Component)) { + // If the fiber is a context provider itself, when we read its context + // we may have already pushed its own child context on the stack. A context + // provider should not "see" its own child context. Therefore we read the + // previous (parent) context instead for a context provider. + return previousContext; + } + return contextStackCursor.current; } - return contextStackCursor.current; } function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + } } function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { + if (disableLegacyContext) { return emptyContextObject; - } + } else { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyContextObject; + } - // Avoid recreating masked context unless unmasked context has changed. - // Failing to do this will result in unnecessary calls to componentWillReceiveProps. - // This may trigger infinite loops if componentWillReceiveProps calls setState. - var instance = workInProgress.stateNode; - if ( - instance && - instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext - ) { - return instance.__reactInternalMemoizedMaskedChildContext; - } + // Avoid recreating masked context unless unmasked context has changed. + // Failing to do this will result in unnecessary calls to componentWillReceiveProps. + // This may trigger infinite loops if componentWillReceiveProps calls setState. + var instance = workInProgress.stateNode; + if ( + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext + ) { + return instance.__reactInternalMemoizedMaskedChildContext; + } - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - getCurrentFiberStackInDev - ); - } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + getCurrentFiberStackInDev + ); + } - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // Context is created before the class component is instantiated so check for instance. - if (instance) { - cacheContext(workInProgress, unmaskedContext, context); - } + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // Context is created before the class component is instantiated so check for instance. + if (instance) { + cacheContext(workInProgress, unmaskedContext, context); + } - return context; + return context; + } } function hasContextChanged() { - return didPerformWorkStackCursor.current; + if (disableLegacyContext) { + return false; + } else { + return didPerformWorkStackCursor.current; + } } function isContextProvider(type) { - var childContextTypes = type.childContextTypes; - return childContextTypes !== null && childContextTypes !== undefined; + if (disableLegacyContext) { + return false; + } else { + var childContextTypes = type.childContextTypes; + return childContextTypes !== null && childContextTypes !== undefined; + } } function popContext(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function pushTopLevelContextObject(fiber, context, didChange) { - (function() { - if (!(contextStackCursor.current === emptyContextObject)) { - throw ReactError( - Error( - "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return; + } else { + (function() { + if (!(contextStackCursor.current === emptyContextObject)) { + throw ReactError( + Error( + "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - push(contextStackCursor, context, fiber); - push(didPerformWorkStackCursor, didChange, fiber); + push(contextStackCursor, context, fiber); + push(didPerformWorkStackCursor, didChange, fiber); + } } function processChildContext(fiber, type, parentContext) { - var instance = fiber.stateNode; - var childContextTypes = type.childContextTypes; + if (disableLegacyContext) { + return parentContext; + } else { + var instance = fiber.stateNode; + var childContextTypes = type.childContextTypes; - // TODO (bvaughn) Replace this behavior with an invariant() in the future. - // It has only been added in Fiber to match the (unintentional) behavior in Stack. - if (typeof instance.getChildContext !== "function") { - { - var componentName = getComponentName(type) || "Unknown"; + // TODO (bvaughn) Replace this behavior with an invariant() in the future. + // It has only been added in Fiber to match the (unintentional) behavior in Stack. + if (typeof instance.getChildContext !== "function") { + { + var componentName = getComponentName(type) || "Unknown"; - if (!warnedAboutMissingGetChildContext[componentName]) { - warnedAboutMissingGetChildContext[componentName] = true; - 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 - ); + if (!warnedAboutMissingGetChildContext[componentName]) { + warnedAboutMissingGetChildContext[componentName] = true; + 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 + ); + } } + return parentContext; } - return parentContext; - } - var childContext = void 0; - { - setCurrentPhase("getChildContext"); + var childContext = void 0; + { + setCurrentPhase("getChildContext"); + } + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + setCurrentPhase(null); + } + for (var contextKey in childContext) { + (function() { + if (!(contextKey in childContextTypes)) { + throw ReactError( + Error( + (getComponentName(type) || "Unknown") + + '.getChildContext(): key "' + + contextKey + + '" is not defined in childContextTypes.' + ) + ); + } + })(); + } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + childContextTypes, + childContext, + "child context", + name, + // In practice, there is one case in which we won't get a stack. It's when + // somebody calls unstable_renderSubtreeIntoContainer() and we process + // context from the parent component instance. The stack will be missing + // because it's outside of the reconciliation, and so the pointer has not + // been set. This is rare and doesn't matter. We'll also remove that API. + getCurrentFiberStackInDev + ); + } + + return Object.assign({}, parentContext, childContext); } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - setCurrentPhase(null); +} + +function pushContextProvider(workInProgress) { + if (disableLegacyContext) { + return false; + } else { + var instance = workInProgress.stateNode; + // We push the context as early as possible to ensure stack integrity. + // If the instance does not exist yet, we will push null at first, + // and replace it on the stack later when invalidating the context. + var memoizedMergedChildContext = + (instance && instance.__reactInternalMemoizedMergedChildContext) || + emptyContextObject; + + // Remember the parent context so we can merge with it later. + // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. + previousContext = contextStackCursor.current; + push(contextStackCursor, memoizedMergedChildContext, workInProgress); + push( + didPerformWorkStackCursor, + didPerformWorkStackCursor.current, + workInProgress + ); + + return true; } - for (var contextKey in childContext) { +} + +function invalidateContextProvider(workInProgress, type, didChange) { + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; (function() { - if (!(contextKey in childContextTypes)) { + if (!instance) { throw ReactError( Error( - (getComponentName(type) || "Unknown") + - '.getChildContext(): key "' + - contextKey + - '" is not defined in childContextTypes.' + "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." ) ); } })(); - } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - childContextTypes, - childContext, - "child context", - name, - // In practice, there is one case in which we won't get a stack. It's when - // somebody calls unstable_renderSubtreeIntoContainer() and we process - // context from the parent component instance. The stack will be missing - // because it's outside of the reconciliation, and so the pointer has not - // been set. This is rare and doesn't matter. We'll also remove that API. - getCurrentFiberStackInDev - ); - } - - return Object.assign({}, parentContext, childContext); -} - -function pushContextProvider(workInProgress) { - var instance = workInProgress.stateNode; - // We push the context as early as possible to ensure stack integrity. - // If the instance does not exist yet, we will push null at first, - // and replace it on the stack later when invalidating the context. - var memoizedMergedChildContext = - (instance && instance.__reactInternalMemoizedMergedChildContext) || - emptyContextObject; - - // Remember the parent context so we can merge with it later. - // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. - previousContext = contextStackCursor.current; - push(contextStackCursor, memoizedMergedChildContext, workInProgress); - push( - didPerformWorkStackCursor, - didPerformWorkStackCursor.current, - workInProgress - ); - - return true; -} -function invalidateContextProvider(workInProgress, type, didChange) { - var instance = workInProgress.stateNode; - (function() { - if (!instance) { - throw ReactError( - Error( - "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." - ) + if (didChange) { + // Merge parent and own context. + // Skip this if we're not updating due to sCU. + // This avoids unnecessarily recomputing memoized values. + var mergedContext = processChildContext( + workInProgress, + type, + previousContext ); + instance.__reactInternalMemoizedMergedChildContext = mergedContext; + + // Replace the old (or empty) context with the new one. + // It is important to unwind the context in the reverse order. + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); + // Now push the new context and mark that it has changed. + push(contextStackCursor, mergedContext, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } else { + pop(didPerformWorkStackCursor, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); } - })(); - - if (didChange) { - // Merge parent and own context. - // Skip this if we're not updating due to sCU. - // This avoids unnecessarily recomputing memoized values. - var mergedContext = processChildContext( - workInProgress, - type, - previousContext - ); - instance.__reactInternalMemoizedMergedChildContext = mergedContext; - - // Replace the old (or empty) context with the new one. - // It is important to unwind the context in the reverse order. - pop(didPerformWorkStackCursor, workInProgress); - pop(contextStackCursor, workInProgress); - // Now push the new context and mark that it has changed. - push(contextStackCursor, mergedContext, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } else { - pop(didPerformWorkStackCursor, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); } } function findCurrentUnmaskedContext(fiber) { - // Currently this is only used with renderSubtreeIntoContainer; not sure if it - // makes sense elsewhere - (function() { - if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { - throw ReactError( - Error( - "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return emptyContextObject; + } else { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere + (function() { + if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { + throw ReactError( + Error( + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - var node = fiber; - do { - switch (node.tag) { - case HostRoot: - return node.stateNode.context; - case ClassComponent: { - var Component = node.type; - if (isContextProvider(Component)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; + var node = fiber; + do { + switch (node.tag) { + case HostRoot: + return node.stateNode.context; + case ClassComponent: { + var Component = node.type; + if (isContextProvider(Component)) { + return node.stateNode.__reactInternalMemoizedMergedChildContext; + } + break; } - break; } - } - node = node.return; - } while (node !== null); - (function() { - { - throw ReactError( - Error( - "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + node = node.return; + } while (node !== null); + (function() { + { + throw ReactError( + Error( + "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); + } } var LegacyRoot = 0; @@ -5469,6 +5522,7 @@ var NormalPriority = 97; var LowPriority = 96; var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only. +var NoPriority = 90; var shouldYield = Scheduler_shouldYield; var requestPaint = @@ -7009,7 +7063,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: NoWork, firstContext: contextItem, - listeners: null, responders: null }; } else { @@ -7909,28 +7962,48 @@ function checkClassInstance(workInProgress, ctor, newProps) { name ) : void 0; - var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warningWithoutStack$1( + + if (disableLegacyContext) { + if (ctor.childContextTypes) { + warningWithoutStack$1( false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", + "%s uses the legacy childContextTypes API which is no longer supported. " + + "Use React.createContext() instead.", name - ) - : void 0; + ); + } + if (ctor.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with static contextType instead.", + name + ); + } + } else { + var noInstanceContextTypes = !instance.contextTypes; + !noInstanceContextTypes + ? warningWithoutStack$1( + false, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ) + : void 0; - if ( - ctor.contextType && - ctor.contextTypes && - !didWarnAboutContextTypeAndContextTypes.has(ctor) - ) { - didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack$1( - false, - "%s declares both contextTypes and contextType static properties. " + - "The legacy contextTypes property will be ignored.", - name - ); + if ( + ctor.contextType && + ctor.contextTypes && + !didWarnAboutContextTypeAndContextTypes.has(ctor) + ) { + didWarnAboutContextTypeAndContextTypes.add(ctor); + warningWithoutStack$1( + false, + "%s declares both contextTypes and contextType static properties. " + + "The legacy contextTypes property will be ignored.", + name + ); + } } var noComponentShouldUpdate = @@ -8106,7 +8179,7 @@ function constructClassInstance( ) { var isLegacyContextConsumer = false; var unmaskedContext = emptyContextObject; - var context = null; + var context = emptyContextObject; var contextType = ctor.contextType; { @@ -8154,7 +8227,7 @@ function constructClassInstance( if (typeof contextType === "object" && contextType !== null) { context = readContext(contextType); - } else { + } else if (!disableLegacyContext) { unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); var contextTypes = ctor.contextTypes; isLegacyContextConsumer = @@ -8356,6 +8429,8 @@ function mountClassInstance( var contextType = ctor.contextType; if (typeof contextType === "object" && contextType !== null) { instance.context = readContext(contextType); + } else if (disableLegacyContext) { + instance.context = emptyContextObject; } else { var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); instance.context = getMaskedContext(workInProgress, unmaskedContext); @@ -8456,10 +8531,10 @@ function resumeMountClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextLegacyUnmaskedContext = getUnmaskedContext( workInProgress, ctor, @@ -8605,10 +8680,10 @@ function updateClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); } @@ -8764,7 +8839,7 @@ function updateClassInstance( var didWarnAboutMaps = void 0; var didWarnAboutGenerators = void 0; -var didWarnAboutStringRefInStrictMode = void 0; +var didWarnAboutStringRefs = void 0; var ownerHasKeyUseWarning = void 0; var ownerHasFunctionTypeWarning = void 0; var warnForMissingKey = function(child) {}; @@ -8772,7 +8847,7 @@ var warnForMissingKey = function(child) {}; { didWarnAboutMaps = false; didWarnAboutGenerators = false; - didWarnAboutStringRefInStrictMode = {}; + didWarnAboutStringRefs = {}; /** * Warn if there's no key explicitly set on dynamic arrays of children or @@ -8829,21 +8904,38 @@ function coerceRef(returnFiber, current$$1, element) { typeof mixedRef !== "object" ) { { - if (returnFiber.mode & StrictMode) { + // TODO: Clean this up once we turn on the string ref warning for + // everyone, because the strict mode case will no longer be relevant + if (returnFiber.mode & StrictMode || warnAboutStringRefs) { var componentName = getComponentName(returnFiber.type) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - 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) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; + if (!didWarnAboutStringRefs[componentName]) { + if (warnAboutStringRefs) { + warningWithoutStack$1( + false, + 'Component "%s" contains the string ref "%s". Support for string refs ' + + "will be removed in a future major release. We recommend using " + + "useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + componentName, + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } else { + 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 useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } + didWarnAboutStringRefs[componentName] = true; } } } @@ -10308,45 +10400,15 @@ function findFirstSuspended(row) { return null; } -var currentlyRenderingFiber$2 = null; -var currentListenerHookIndex = 0; - -function prepareToReadListenerHooks(workInProgress) { - currentlyRenderingFiber$2 = workInProgress; - currentListenerHookIndex = 0; -} - -function getListenerHooks() { - var listeners = void 0; - var dependencies = currentlyRenderingFiber$2.dependencies; - if (dependencies === null) { - dependencies = currentlyRenderingFiber$2.dependencies = { - expirationTime: NoWork, - firstContext: null, - listeners: [], - responders: null - }; - } - listeners = dependencies.listeners; - if (listeners === null) { - dependencies.listeners = listeners = []; - } - return listeners; -} - -function updateListenerHook(responder, props) { - var listeners = getListenerHooks(); - if (listeners.length === currentListenerHookIndex) { - listeners.push({ - responder: responder, - props: props - }); - currentListenerHookIndex++; - } else { - var currentListenerHook = listeners[currentListenerHookIndex++]; - currentListenerHook.responder = responder; - currentListenerHook.props = props; +function createResponderListener(responder, props) { + var eventResponderListener = { + responder: responder, + props: props + }; + { + Object.freeze(eventResponderListener); } + return eventResponderListener; } function createResponderInstance( @@ -11431,7 +11493,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }; var HooksDispatcherOnMountInDEV = null; @@ -11538,10 +11600,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11617,10 +11679,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11696,10 +11758,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11786,11 +11848,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11877,11 +11939,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; } @@ -11944,6 +12006,17 @@ var hydrationParentFiber = null; var nextHydratableInstance = null; var isHydrating = false; +function warnIfHydrating() { + { + !!isHydrating + ? warning$1( + false, + "We should not be hydrating here. This is a bug in React. Please file a bug." + ) + : void 0; + } +} + function enterHydrationState(fiber) { if (!supportsHydration) { return false; @@ -12452,9 +12525,6 @@ function updateForwardRef( // The rest is a fork of updateFunctionComponent var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -12473,9 +12543,6 @@ function updateForwardRef( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -12755,14 +12822,14 @@ function updateFunctionComponent( } } - var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); + context = getMaskedContext(workInProgress, unmaskedContext); + } var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -12781,9 +12848,6 @@ function updateFunctionComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -13375,13 +13439,13 @@ function mountIndeterminateComponent( } var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); + context = getMaskedContext(workInProgress, unmaskedContext); + } prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } var value = void 0; { @@ -13488,6 +13552,15 @@ function mountIndeterminateComponent( // Proceed under the assumption that this is a function component workInProgress.tag = FunctionComponent; { + if (disableLegacyContext && Component.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with React.useContext() instead.", + getComponentName(Component) || "Unknown" + ); + } + if ( debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && @@ -13495,9 +13568,6 @@ function mountIndeterminateComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } value = renderWithHooks( null, workInProgress, @@ -14027,12 +14097,18 @@ function updateDehydratedSuspenseComponent( } return null; } + if ((workInProgress.effectTag & DidCapture) !== NoEffect) { // Something suspended. Leave the existing children in place. // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far? workInProgress.child = null; return null; } + + // We should never be hydrating at this point because it is the first pass, + // but after we've already committed once. + warnIfHydrating(); + if (isSuspenseInstanceFallback(suspenseInstance)) { // This boundary is in a permanent fallback state. In this case, we'll never // get an update and we'll never be able to hydrate the final content. Let's just try the @@ -14891,29 +14967,26 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect; - var childExpirationTime = workInProgress.childExpirationTime; - if (childExpirationTime < renderExpirationTime) { + var hasChildWork = + workInProgress.childExpirationTime >= renderExpirationTime; + + if (didSuspendBefore) { + if (hasChildWork) { + // If something was in fallback state last time, and we have all the + // same children then we're still in progressive loading state. + // Something might get unblocked by state updates or retries in the + // tree which will affect the tail. So we need to use the normal + // path to compute the correct tail. + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + } // If none of the children had any work, that means that none of // them got retried so they'll still be blocked in the same way // as before. We can fast bail out. - pushSuspenseContext(workInProgress, suspenseStackCursor.current); - if (didSuspendBefore) { - workInProgress.effectTag |= DidCapture; - } - return null; - } - - if (didSuspendBefore) { - // If something was in fallback state last time, and we have all the - // same children then we're still in progressive loading state. - // Something might get unblocked by state updates or retries in the - // tree which will affect the tail. So we need to use the normal - // path to compute the correct tail. - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); + workInProgress.effectTag |= DidCapture; } // If nothing suspended before and we're rendering the same children, @@ -14927,7 +15000,15 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { renderState.tail = null; } pushSuspenseContext(workInProgress, suspenseStackCursor.current); - break; + + if (hasChildWork) { + break; + } else { + // If none of the children had any work, that means that none of + // them got retried so they'll still be blocked in the same way + // as before. We can fast bail out. + return null; + } } } return bailoutOnAlreadyFinishedWork( @@ -15183,7 +15264,7 @@ if (supportsMutation) { while (node !== null) { if (node.tag === HostComponent || node.tag === HostText) { appendInitialChild(parent, node.stateNode); - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { appendInitialChild(parent, node.stateNode.instance); } else if (node.tag === HostPortal) { // If we have a portal child, then we don't want to traverse @@ -15681,12 +15762,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { ); if (enableFlareAPI) { - var prevResponders = current.memoizedProps.responders; - var nextResponders = newProps.responders; + var prevListeners = current.memoizedProps.listeners; + var nextListeners = newProps.listeners; var instance = workInProgress.stateNode; - if (prevResponders !== nextResponders) { - updateEventResponders( - nextResponders, + if (prevListeners !== nextListeners) { + updateEventListeners( + nextListeners, instance, rootContainerInstance, workInProgress @@ -15732,8 +15813,20 @@ function completeWork(current, workInProgress, renderExpirationTime) { // commit-phase we mark this as such. markUpdate(workInProgress); } + if (enableFlareAPI) { + var _instance5 = workInProgress.stateNode; + var listeners = newProps.listeners; + if (listeners != null) { + updateEventListeners( + listeners, + _instance5, + rootContainerInstance, + workInProgress + ); + } + } } else { - var _instance5 = createInstance( + var _instance6 = createInstance( type, newProps, rootContainerInstance, @@ -15741,14 +15834,14 @@ function completeWork(current, workInProgress, renderExpirationTime) { workInProgress ); - appendAllChildren(_instance5, workInProgress, false, false); + appendAllChildren(_instance6, workInProgress, false, false); if (enableFlareAPI) { - var responders = newProps.responders; - if (responders != null) { - updateEventResponders( - responders, - _instance5, + var _listeners = newProps.listeners; + if (_listeners != null) { + updateEventListeners( + _listeners, + _instance6, rootContainerInstance, workInProgress ); @@ -15760,7 +15853,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { // Make sure such renderers get scheduled for later work. if ( finalizeInitialChildren( - _instance5, + _instance6, type, newProps, rootContainerInstance, @@ -15769,7 +15862,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { ) { markUpdate(workInProgress); } - workInProgress.stateNode = _instance5; + workInProgress.stateNode = _instance6; } if (workInProgress.ref !== null) { @@ -15969,15 +16062,22 @@ function completeWork(current, workInProgress, renderExpirationTime) { markSpawnedWork(Never); } skipPastDehydratedSuspenseInstance(workInProgress); - } else if ((workInProgress.effectTag & DidCapture) === NoEffect) { - // This boundary did not suspend so it's now hydrated. - // To handle any future suspense cases, we're going to now upgrade it - // to a Suspense component. We detach it from the existing current fiber. - current.alternate = null; - workInProgress.alternate = null; - workInProgress.tag = SuspenseComponent; - workInProgress.memoizedState = null; - workInProgress.stateNode = null; + } else { + // We should never have been in a hydration state if we didn't have a current. + // However, in some of those paths, we might have reentered a hydration state + // and then we might be inside a hydration state. In that case, we'll need to + // exit out of it. + resetHydrationState(); + if ((workInProgress.effectTag & DidCapture) === NoEffect) { + // This boundary did not suspend so it's now hydrated. + // To handle any future suspense cases, we're going to now upgrade it + // to a Suspense component. We detach it from the existing current fiber. + current.alternate = null; + workInProgress.alternate = null; + workInProgress.tag = SuspenseComponent; + workInProgress.memoizedState = null; + workInProgress.stateNode = null; + } } } break; @@ -16191,12 +16291,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalImpl, fundamentalState || {} ); - var _instance6 = getFundamentalComponentInstance(fundamentalInstance); - fundamentalInstance.instance = _instance6; + var _instance7 = getFundamentalComponentInstance(fundamentalInstance); + fundamentalInstance.instance = _instance7; if (fundamentalImpl.reconcileChildren === false) { return null; } - appendAllChildren(_instance6, workInProgress, false, false); + appendAllChildren(_instance7, workInProgress, false, false); mountFundamentalComponent(fundamentalInstance); } else { // We fire update in commit phase @@ -16205,9 +16305,9 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalInstance.props = newProps; fundamentalInstance.currentFiber = workInProgress; if (supportsPersistence) { - var _instance7 = cloneFundamentalInstance(fundamentalInstance); - fundamentalInstance.instance = _instance7; - appendAllChildren(_instance7, workInProgress, false, false); + var _instance8 = cloneFundamentalInstance(fundamentalInstance); + fundamentalInstance.instance = _instance8; + appendAllChildren(_instance8, workInProgress, false, false); } var shouldUpdate = shouldUpdateFundamentalComponent( fundamentalInstance @@ -16265,26 +16365,41 @@ function mountEventResponder( respondersMap.set(responder, responderInstance); } -function updateEventResponder( - responder, - props, +function updateEventListener( + listener, fiber, visistedResponders, respondersMap, instance, rootContainerInstance ) { + var responder = void 0; + var props = void 0; + + if (listener) { + responder = listener.responder; + props = listener.props; + } (function() { if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) { throw ReactError( Error( - "An invalid value was used as an event responder. Expect one or many event responders created via React.unstable_createResponer()." + "An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponer()." ) ); } })(); + var listenerProps = props; if (visistedResponders.has(responder)) { // show warning + { + warning$1( + false, + 'Duplicate event responder "%s" found in event listeners. ' + + "Event listeners passed to elements cannot use the same event responder more than once.", + responder.displayName + ); + } return; } visistedResponders.add(responder); @@ -16294,7 +16409,7 @@ function updateEventResponder( // Mount mountEventResponder( responder, - props, + listenerProps, instance, rootContainerInstance, fiber, @@ -16302,25 +16417,24 @@ function updateEventResponder( ); } else { // Update - responderInstance.props = props; + responderInstance.props = listenerProps; responderInstance.fiber = fiber; } } -function updateEventResponders( - responders, +function updateEventListeners( + listeners, instance, rootContainerInstance, fiber ) { var visistedResponders = new Set(); var dependencies = fiber.dependencies; - if (responders != null) { + if (listeners != null) { if (dependencies === null) { dependencies = fiber.dependencies = { expirationTime: NoWork, firstContext: null, - listeners: null, responders: new Map() }; } @@ -16328,15 +16442,11 @@ function updateEventResponders( if (respondersMap === null) { respondersMap = new Map(); } - if (isArray$2(responders)) { - for (var i = 0, length = responders.length; i < length; i++) { - var _responders$i = responders[i], - type = _responders$i.type, - props = _responders$i.props; - - updateEventResponder( - type, - props, + if (isArray$2(listeners)) { + for (var i = 0, length = listeners.length; i < length; i++) { + var listener = listeners[i]; + updateEventListener( + listener, fiber, visistedResponders, respondersMap, @@ -16345,12 +16455,8 @@ function updateEventResponders( ); } } else { - var type = responders.type, - props = responders.props; - - updateEventResponder( - type, - props, + updateEventListener( + listeners, fiber, visistedResponders, respondersMap, @@ -16423,8 +16529,12 @@ function unwindWork(workInProgress, renderExpirationTime) { } case DehydratedSuspenseComponent: { if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(workInProgress); + if (workInProgress.alternate === null) { + // TODO: popHydrationState + } else { + resetHydrationState(); + } var _effectTag3 = workInProgress.effectTag; if (_effectTag3 & ShouldCapture) { workInProgress.effectTag = @@ -16478,7 +16588,6 @@ function unwindInterruptedWork(interruptedWork) { break; case DehydratedSuspenseComponent: if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(interruptedWork); } break; @@ -17194,7 +17303,7 @@ function commitDetachRef(current$$1) { // User-originating errors (lifecycles and refs) should not interrupt // deletion, so don't let them throw. Host-originating errors should // interrupt deletion, so it's okay -function commitUnmount(current$$1) { +function commitUnmount(current$$1, renderPriorityLevel) { onCommitUnmount(current$$1); switch (current$$1.tag) { @@ -17207,14 +17316,33 @@ function commitUnmount(current$$1) { var lastEffect = updateQueue.lastEffect; if (lastEffect !== null) { var firstEffect = lastEffect.next; - var effect = firstEffect; - do { - var destroy = effect.destroy; - if (destroy !== undefined) { - safelyCallDestroy(current$$1, destroy); - } - effect = effect.next; - } while (effect !== firstEffect); + + // When the owner fiber is deleted, the destroy function of a passive + // effect hook is called during the synchronous commit phase. This is + // a concession to implementation complexity. Calling it in the + // passive effect phase (like they usually are, when dependencies + // change during an update) would require either traversing the + // children of the deleted fiber again, or including unmount effects + // as part of the fiber effect list. + // + // Because this is during the sync commit phase, we need to change + // the priority. + // + // TODO: Reconsider this implementation trade off. + var priorityLevel = + renderPriorityLevel > NormalPriority + ? NormalPriority + : renderPriorityLevel; + runWithPriority(priorityLevel, function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (destroy !== undefined) { + safelyCallDestroy(current$$1, destroy); + } + effect = effect.next; + } while (effect !== firstEffect); + }); } } break; @@ -17255,7 +17383,7 @@ function commitUnmount(current$$1) { // We are also not using this parent because // the portal will get pushed immediately. if (supportsMutation) { - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else if (supportsPersistence) { emptyPortalContainer(current$$1); } @@ -17273,14 +17401,14 @@ function commitUnmount(current$$1) { } } -function commitNestedUnmounts(root) { +function commitNestedUnmounts(root, renderPriorityLevel) { // While we're inside a removed host node we don't want to call // removeChild on the inner nodes because they're removed by the top // call anyway. We also want to call componentWillUnmount on all // composites before this host node is removed from the tree. Therefore var node = root; while (true) { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes. // Skip portals because commitUnmount() currently visits them recursively. if ( @@ -17500,7 +17628,7 @@ function commitPlacement(finishedWork) { var node = finishedWork; while (true) { var isHost = node.tag === HostComponent || node.tag === HostText; - if (isHost || node.tag === FundamentalComponent) { + if (isHost || (enableFundamentalAPI && node.tag === FundamentalComponent)) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (before) { if (isContainer) { @@ -17538,7 +17666,7 @@ function commitPlacement(finishedWork) { } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel) { // We only have the top Fiber that was deleted but we need to recurse down its var node = current$$1; @@ -17589,7 +17717,7 @@ function unmountHostComponents(current$$1) { } if (node.tag === HostComponent || node.tag === HostText) { - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -17598,9 +17726,9 @@ function unmountHostComponents(current$$1) { removeChild(currentParent, node.stateNode); } // Don't visit children because we already visited them. - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { var fundamentalNode = node.stateNode.instance; - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -17630,7 +17758,7 @@ function unmountHostComponents(current$$1) { continue; } } else { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because we may find more host components below. if (node.child !== null) { node.child.return = node; @@ -17657,14 +17785,14 @@ function unmountHostComponents(current$$1) { } } -function commitDeletion(current$$1) { +function commitDeletion(current$$1, renderPriorityLevel) { if (supportsMutation) { // Recursively delete all host nodes from the parent. // Detach refs and call componentWillUnmount() on the whole subtree. - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else { // Detach refs and call componentWillUnmount() on the whole subtree. - commitNestedUnmounts(current$$1); + commitNestedUnmounts(current$$1, renderPriorityLevel); } detachFiber(current$$1); } @@ -18210,6 +18338,7 @@ function throwException( } while (workInProgress !== null); } +// The scheduler is imported here *only* to detect whether it's been mocked // DEV stuff var ceil = Math.ceil; @@ -18264,6 +18393,7 @@ var legacyErrorBoundariesThatAlreadyFailed = null; var rootDoesHavePassiveEffects = false; var rootWithPendingPassiveEffects = null; +var pendingPassiveEffectsRenderPriority = NoPriority; var pendingPassiveEffectsExpirationTime = NoWork; var rootsWithPendingDiscreteUpdates = null; @@ -18532,7 +18662,10 @@ function scheduleCallbackForRoot(root, priorityLevel, expirationTime) { ); } else { var options = null; - if (expirationTime !== Never) { + if ( + !disableSchedulerTimeoutBasedOnReactExpirationTime && + expirationTime !== Never + ) { var timeout = expirationTimeToMs(expirationTime) - now(); options = { timeout: timeout }; } @@ -18748,7 +18881,6 @@ function prepareFreshStack(root, expirationTime) { { ReactStrictModeWarnings.discardPendingWarnings(); - componentsThatSuspendedAtHighPri = null; componentsThatTriggeredHighPriSuspend = null; } } @@ -18931,8 +19063,6 @@ function renderRoot(root, expirationTime, isSync) { // Set this to null to indicate there's no in-progress render. workInProgressRoot = null; - flushSuspensePriorityWarningInDEV(); - switch (workInProgressRootExitStatus) { case RootIncomplete: { (function() { @@ -18941,7 +19071,7 @@ function renderRoot(root, expirationTime, isSync) { } })(); } - // Flow knows about invariant, so it compains if I add a break statement, + // Flow knows about invariant, so it complains if I add a break statement, // but eslint doesn't know about invariant, so it complains if I do. // eslint-disable-next-line no-fallthrough case RootErrored: { @@ -18967,6 +19097,8 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspended: { + flushSuspensePriorityWarningInDEV(); + // We have an acceptable loading state. We need to figure out if we should // immediately commit it or wait a bit. @@ -18975,7 +19107,12 @@ function renderRoot(root, expirationTime, isSync) { // possible. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync; - if (hasNotProcessedNewUpdates && !isSync) { + if ( + hasNotProcessedNewUpdates && + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // If we have not processed any new updates during this pass, then this is // either a retry of an existing fallback state or a hidden tree. // Hidden trees shouldn't be batched with other work and after that's @@ -19012,7 +19149,13 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspendedWithDelay: { - if (!isSync) { + flushSuspensePriorityWarningInDEV(); + + if ( + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // We're suspended in a state that should be avoided. We'll try to avoid committing // it for as long as the timeouts let us. if (workInProgressRootHasPendingPing) { @@ -19082,6 +19225,12 @@ function renderRoot(root, expirationTime, isSync) { // The work completed. Ready to commit. if ( !isSync && + // do not delay if we're inside an act() scope + !( + true && + flushSuspenseFallbacksInTests && + IsThisRendererActing.current + ) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null ) { @@ -19430,12 +19579,15 @@ function resetChildExpirationTime(completedWork) { } function commitRoot(root) { - runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority( + ImmediatePriority, + commitRootImpl.bind(null, root, renderPriorityLevel) + ); // If there are passive effects, schedule a callback to flush them. This goes // outside commitRootImpl so that it inherits the priority of the render. if (rootWithPendingPassiveEffects !== null) { - var priorityLevel = getCurrentPriorityLevel(); - scheduleCallback(priorityLevel, function() { + scheduleCallback(NormalPriority, function() { flushPassiveEffects(); return null; }); @@ -19443,7 +19595,7 @@ function commitRoot(root) { return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); flushRenderPhaseStrictModeWarningsInDEV(); @@ -19572,7 +19724,12 @@ function commitRootImpl(root) { nextEffect = firstEffect; do { { - invokeGuardedCallback(null, commitMutationEffects, null); + invokeGuardedCallback( + null, + commitMutationEffects, + null, + renderPriorityLevel + ); if (hasCaughtError()) { (function() { if (!(nextEffect !== null)) { @@ -19659,6 +19816,7 @@ function commitRootImpl(root) { rootDoesHavePassiveEffects = false; rootWithPendingPassiveEffects = root; pendingPassiveEffectsExpirationTime = expirationTime; + pendingPassiveEffectsRenderPriority = renderPriorityLevel; } else { // We are done with the effect chain at this point so let's clear the // nextEffect pointers to assist with GC. If we have passive effects, we'll @@ -19761,7 +19919,7 @@ function commitBeforeMutationEffects() { } } -function commitMutationEffects() { +function commitMutationEffects(renderPriorityLevel) { // TODO: Should probably move the bulk of this function to commitWork. while (nextEffect !== null) { setCurrentFiber(nextEffect); @@ -19812,7 +19970,7 @@ function commitMutationEffects() { break; } case Deletion: { - commitDeletion(nextEffect); + commitDeletion(nextEffect, renderPriorityLevel); break; } } @@ -19858,9 +20016,19 @@ function flushPassiveEffects() { } var root = rootWithPendingPassiveEffects; var expirationTime = pendingPassiveEffectsExpirationTime; + var renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = NoWork; + pendingPassiveEffectsRenderPriority = NoPriority; + var priorityLevel = + renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel; + return runWithPriority( + priorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = null; if (enableSchedulerTracing) { prevInteractions = tracing.__interactionsRef.current; @@ -20367,6 +20535,7 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) { } } +// a 'shared' variable that changes when act() opens/closes in tests. var IsThisRendererActing = { current: false }; function warnIfNotScopedWithMatchingAct(fiber) { @@ -20382,12 +20551,12 @@ function warnIfNotScopedWithMatchingAct(fiber) { "Be sure to use the matching version of act() corresponding to your renderer:\n\n" + "// for react-dom:\n" + "import {act} from 'react-dom/test-utils';\n" + - "//...\n" + + "// ...\n" + "act(() => ...);\n\n" + "// for react-test-renderer:\n" + "import TestRenderer from 'react-test-renderer';\n" + "const {act} = TestRenderer;\n" + - "//...\n" + + "// ...\n" + "act(() => ...);" + "%s", getStackByFiberInDevAndProd(fiber) @@ -20454,7 +20623,44 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber) { var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; -var componentsThatSuspendedAtHighPri = null; +// In tests, we want to enforce a mocked scheduler. +var didWarnAboutUnmockedScheduler = false; +// TODO Before we release concurrent mode, revisit this and decide whether a mocked +// scheduler is the actual recommendation. The alternative could be a testing build, +// a new lib, or whatever; we dunno just yet. This message is for early adopters +// to get their tests right. + +function warnIfUnmockedScheduler(fiber) { + { + if ( + didWarnAboutUnmockedScheduler === false && + Scheduler.unstable_flushAllWithoutAsserting === undefined + ) { + if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } else if (warnAboutUnmockedScheduler === true) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'Starting from React v17, the "scheduler" module will need to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } + } + } +} + var componentsThatTriggeredHighPriSuspend = null; function checkForWrongSuspensePriorityInDEV(sourceFiber) { { @@ -20541,70 +20747,34 @@ function checkForWrongSuspensePriorityInDEV(sourceFiber) { } workInProgressNode = workInProgressNode.return; } - - // Add the component name to a set. - var componentName = getComponentName(sourceFiber.type); - if (componentsThatSuspendedAtHighPri === null) { - componentsThatSuspendedAtHighPri = new Set([componentName]); - } else { - componentsThatSuspendedAtHighPri.add(componentName); - } } } } function flushSuspensePriorityWarningInDEV() { { - if (componentsThatSuspendedAtHighPri !== null) { + if (componentsThatTriggeredHighPriSuspend !== null) { var componentNames = []; - componentsThatSuspendedAtHighPri.forEach(function(name) { - componentNames.push(name); + componentsThatTriggeredHighPriSuspend.forEach(function(name) { + return componentNames.push(name); }); - componentsThatSuspendedAtHighPri = null; - - var componentsThatTriggeredSuspendNames = []; - if (componentsThatTriggeredHighPriSuspend !== null) { - componentsThatTriggeredHighPriSuspend.forEach(function(name) { - return componentsThatTriggeredSuspendNames.push(name); - }); - } - componentsThatTriggeredHighPriSuspend = null; - var componentNamesString = componentNames.sort().join(", "); - var componentThatTriggeredSuspenseError = ""; - if (componentsThatTriggeredSuspendNames.length > 0) { - componentThatTriggeredSuspenseError = - "The following components triggered a user-blocking update:" + - "\n\n" + - " " + - componentsThatTriggeredSuspendNames.sort().join(", ") + - "\n\n" + - "that was then suspended by:" + - "\n\n" + - " " + - componentNamesString; - } else { - componentThatTriggeredSuspenseError = - "A user-blocking update was suspended by:" + - "\n\n" + - " " + - componentNamesString; + if (componentNames.length > 0) { + warningWithoutStack$1( + false, + "%s triggered a user-blocking update that suspended." + + "\n\n" + + "The fix is to split the update into multiple parts: a user-blocking " + + "update to provide immediate feedback, and another update that " + + "triggers the bulk of the changes." + + "\n\n" + + "Refer to the documentation for useSuspenseTransition to learn how " + + "to implement this pattern.", + // TODO: Add link to React docs with more information, once it exists + componentNames.sort().join(", ") + ); } - - warningWithoutStack$1( - false, - "%s" + - "\n\n" + - "The fix is to split the update into multiple parts: a user-blocking " + - "update to provide immediate feedback, and another update that " + - "triggers the bulk of the changes." + - "\n\n" + - "Refer to the documentation for useSuspenseTransition to learn how " + - "to implement this pattern.", - // TODO: Add link to React docs with more information, once it exists - componentThatTriggeredSuspenseError - ); } } } @@ -21083,7 +21253,6 @@ function createWorkInProgress(current, pendingProps, expirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -21176,7 +21345,6 @@ function resetWorkInProgress(workInProgress, renderExpirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -21799,6 +21967,7 @@ function updateContainer(element, container, parentComponent, callback) { { // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests if ("undefined" !== typeof jest) { + warnIfUnmockedScheduler(current$$1); warnIfNotScopedWithMatchingAct(current$$1); } } diff --git a/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js b/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js index 932146e9d9a381..b38efdcb4ed9f4 100644 --- a/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +++ b/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js @@ -2658,10 +2658,15 @@ var warnAboutDeprecatedSetNativeProps = false; var enableFlareAPI = false; var enableFundamentalAPI = false; +var warnAboutUnmockedScheduler = false; var revertPassiveEffectsChange = false; +var flushSuspenseFallbacksInTests = true; var enableSuspenseCallback = false; var warnAboutDefaultPropsOnFunctionComponents = false; +var warnAboutStringRefs = false; +var disableLegacyContext = false; +var disableSchedulerTimeoutBasedOnReactExpirationTime = false; // Only used in www builds. @@ -5119,262 +5124,310 @@ function getUnmaskedContext( Component, didPushOwnContextIfProvider ) { - if (didPushOwnContextIfProvider && isContextProvider(Component)) { - // If the fiber is a context provider itself, when we read its context - // we may have already pushed its own child context on the stack. A context - // provider should not "see" its own child context. Therefore we read the - // previous (parent) context instead for a context provider. - return previousContext; + if (disableLegacyContext) { + return emptyContextObject; + } else { + if (didPushOwnContextIfProvider && isContextProvider(Component)) { + // If the fiber is a context provider itself, when we read its context + // we may have already pushed its own child context on the stack. A context + // provider should not "see" its own child context. Therefore we read the + // previous (parent) context instead for a context provider. + return previousContext; + } + return contextStackCursor.current; } - return contextStackCursor.current; } function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; + } } function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { + if (disableLegacyContext) { return emptyContextObject; - } + } else { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyContextObject; + } - // Avoid recreating masked context unless unmasked context has changed. - // Failing to do this will result in unnecessary calls to componentWillReceiveProps. - // This may trigger infinite loops if componentWillReceiveProps calls setState. - var instance = workInProgress.stateNode; - if ( - instance && - instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext - ) { - return instance.__reactInternalMemoizedMaskedChildContext; - } + // Avoid recreating masked context unless unmasked context has changed. + // Failing to do this will result in unnecessary calls to componentWillReceiveProps. + // This may trigger infinite loops if componentWillReceiveProps calls setState. + var instance = workInProgress.stateNode; + if ( + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext + ) { + return instance.__reactInternalMemoizedMaskedChildContext; + } - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - getCurrentFiberStackInDev - ); - } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + getCurrentFiberStackInDev + ); + } - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // Context is created before the class component is instantiated so check for instance. - if (instance) { - cacheContext(workInProgress, unmaskedContext, context); - } + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // Context is created before the class component is instantiated so check for instance. + if (instance) { + cacheContext(workInProgress, unmaskedContext, context); + } - return context; + return context; + } } function hasContextChanged() { - return didPerformWorkStackCursor.current; + if (disableLegacyContext) { + return false; + } else { + return didPerformWorkStackCursor.current; + } } function isContextProvider(type) { - var childContextTypes = type.childContextTypes; - return childContextTypes !== null && childContextTypes !== undefined; + if (disableLegacyContext) { + return false; + } else { + var childContextTypes = type.childContextTypes; + return childContextTypes !== null && childContextTypes !== undefined; + } } function popContext(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (disableLegacyContext) { + return; + } else { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); + } } function pushTopLevelContextObject(fiber, context, didChange) { - (function() { - if (!(contextStackCursor.current === emptyContextObject)) { - throw ReactError( - Error( - "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return; + } else { + (function() { + if (!(contextStackCursor.current === emptyContextObject)) { + throw ReactError( + Error( + "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - push(contextStackCursor, context, fiber); - push(didPerformWorkStackCursor, didChange, fiber); + push(contextStackCursor, context, fiber); + push(didPerformWorkStackCursor, didChange, fiber); + } } function processChildContext(fiber, type, parentContext) { - var instance = fiber.stateNode; - var childContextTypes = type.childContextTypes; + if (disableLegacyContext) { + return parentContext; + } else { + var instance = fiber.stateNode; + var childContextTypes = type.childContextTypes; - // TODO (bvaughn) Replace this behavior with an invariant() in the future. - // It has only been added in Fiber to match the (unintentional) behavior in Stack. - if (typeof instance.getChildContext !== "function") { - { - var componentName = getComponentName(type) || "Unknown"; + // TODO (bvaughn) Replace this behavior with an invariant() in the future. + // It has only been added in Fiber to match the (unintentional) behavior in Stack. + if (typeof instance.getChildContext !== "function") { + { + var componentName = getComponentName(type) || "Unknown"; - if (!warnedAboutMissingGetChildContext[componentName]) { - warnedAboutMissingGetChildContext[componentName] = true; - 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 - ); + if (!warnedAboutMissingGetChildContext[componentName]) { + warnedAboutMissingGetChildContext[componentName] = true; + 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 + ); + } } + return parentContext; } - return parentContext; - } - var childContext = void 0; - { - setCurrentPhase("getChildContext"); + var childContext = void 0; + { + setCurrentPhase("getChildContext"); + } + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + setCurrentPhase(null); + } + for (var contextKey in childContext) { + (function() { + if (!(contextKey in childContextTypes)) { + throw ReactError( + Error( + (getComponentName(type) || "Unknown") + + '.getChildContext(): key "' + + contextKey + + '" is not defined in childContextTypes.' + ) + ); + } + })(); + } + { + var name = getComponentName(type) || "Unknown"; + checkPropTypes( + childContextTypes, + childContext, + "child context", + name, + // In practice, there is one case in which we won't get a stack. It's when + // somebody calls unstable_renderSubtreeIntoContainer() and we process + // context from the parent component instance. The stack will be missing + // because it's outside of the reconciliation, and so the pointer has not + // been set. This is rare and doesn't matter. We'll also remove that API. + getCurrentFiberStackInDev + ); + } + + return Object.assign({}, parentContext, childContext); } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - setCurrentPhase(null); +} + +function pushContextProvider(workInProgress) { + if (disableLegacyContext) { + return false; + } else { + var instance = workInProgress.stateNode; + // We push the context as early as possible to ensure stack integrity. + // If the instance does not exist yet, we will push null at first, + // and replace it on the stack later when invalidating the context. + var memoizedMergedChildContext = + (instance && instance.__reactInternalMemoizedMergedChildContext) || + emptyContextObject; + + // Remember the parent context so we can merge with it later. + // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. + previousContext = contextStackCursor.current; + push(contextStackCursor, memoizedMergedChildContext, workInProgress); + push( + didPerformWorkStackCursor, + didPerformWorkStackCursor.current, + workInProgress + ); + + return true; } - for (var contextKey in childContext) { +} + +function invalidateContextProvider(workInProgress, type, didChange) { + if (disableLegacyContext) { + return; + } else { + var instance = workInProgress.stateNode; (function() { - if (!(contextKey in childContextTypes)) { + if (!instance) { throw ReactError( Error( - (getComponentName(type) || "Unknown") + - '.getChildContext(): key "' + - contextKey + - '" is not defined in childContextTypes.' + "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." ) ); } })(); - } - { - var name = getComponentName(type) || "Unknown"; - checkPropTypes( - childContextTypes, - childContext, - "child context", - name, - // In practice, there is one case in which we won't get a stack. It's when - // somebody calls unstable_renderSubtreeIntoContainer() and we process - // context from the parent component instance. The stack will be missing - // because it's outside of the reconciliation, and so the pointer has not - // been set. This is rare and doesn't matter. We'll also remove that API. - getCurrentFiberStackInDev - ); - } - - return Object.assign({}, parentContext, childContext); -} - -function pushContextProvider(workInProgress) { - var instance = workInProgress.stateNode; - // We push the context as early as possible to ensure stack integrity. - // If the instance does not exist yet, we will push null at first, - // and replace it on the stack later when invalidating the context. - var memoizedMergedChildContext = - (instance && instance.__reactInternalMemoizedMergedChildContext) || - emptyContextObject; - - // Remember the parent context so we can merge with it later. - // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. - previousContext = contextStackCursor.current; - push(contextStackCursor, memoizedMergedChildContext, workInProgress); - push( - didPerformWorkStackCursor, - didPerformWorkStackCursor.current, - workInProgress - ); - - return true; -} -function invalidateContextProvider(workInProgress, type, didChange) { - var instance = workInProgress.stateNode; - (function() { - if (!instance) { - throw ReactError( - Error( - "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." - ) + if (didChange) { + // Merge parent and own context. + // Skip this if we're not updating due to sCU. + // This avoids unnecessarily recomputing memoized values. + var mergedContext = processChildContext( + workInProgress, + type, + previousContext ); + instance.__reactInternalMemoizedMergedChildContext = mergedContext; + + // Replace the old (or empty) context with the new one. + // It is important to unwind the context in the reverse order. + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); + // Now push the new context and mark that it has changed. + push(contextStackCursor, mergedContext, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } else { + pop(didPerformWorkStackCursor, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); } - })(); - - if (didChange) { - // Merge parent and own context. - // Skip this if we're not updating due to sCU. - // This avoids unnecessarily recomputing memoized values. - var mergedContext = processChildContext( - workInProgress, - type, - previousContext - ); - instance.__reactInternalMemoizedMergedChildContext = mergedContext; - - // Replace the old (or empty) context with the new one. - // It is important to unwind the context in the reverse order. - pop(didPerformWorkStackCursor, workInProgress); - pop(contextStackCursor, workInProgress); - // Now push the new context and mark that it has changed. - push(contextStackCursor, mergedContext, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } else { - pop(didPerformWorkStackCursor, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); } } function findCurrentUnmaskedContext(fiber) { - // Currently this is only used with renderSubtreeIntoContainer; not sure if it - // makes sense elsewhere - (function() { - if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { - throw ReactError( - Error( - "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + if (disableLegacyContext) { + return emptyContextObject; + } else { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere + (function() { + if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) { + throw ReactError( + Error( + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); - var node = fiber; - do { - switch (node.tag) { - case HostRoot: - return node.stateNode.context; - case ClassComponent: { - var Component = node.type; - if (isContextProvider(Component)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; + var node = fiber; + do { + switch (node.tag) { + case HostRoot: + return node.stateNode.context; + case ClassComponent: { + var Component = node.type; + if (isContextProvider(Component)) { + return node.stateNode.__reactInternalMemoizedMergedChildContext; + } + break; } - break; } - } - node = node.return; - } while (node !== null); - (function() { - { - throw ReactError( - Error( - "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." - ) - ); - } - })(); + node = node.return; + } while (node !== null); + (function() { + { + throw ReactError( + Error( + "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." + ) + ); + } + })(); + } } var LegacyRoot = 0; @@ -5465,6 +5518,7 @@ var NormalPriority = 97; var LowPriority = 96; var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only. +var NoPriority = 90; var shouldYield = Scheduler_shouldYield; var requestPaint = @@ -7005,7 +7059,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: NoWork, firstContext: contextItem, - listeners: null, responders: null }; } else { @@ -7905,28 +7958,48 @@ function checkClassInstance(workInProgress, ctor, newProps) { name ) : void 0; - var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warningWithoutStack$1( + + if (disableLegacyContext) { + if (ctor.childContextTypes) { + warningWithoutStack$1( false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", + "%s uses the legacy childContextTypes API which is no longer supported. " + + "Use React.createContext() instead.", name - ) - : void 0; + ); + } + if (ctor.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with static contextType instead.", + name + ); + } + } else { + var noInstanceContextTypes = !instance.contextTypes; + !noInstanceContextTypes + ? warningWithoutStack$1( + false, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ) + : void 0; - if ( - ctor.contextType && - ctor.contextTypes && - !didWarnAboutContextTypeAndContextTypes.has(ctor) - ) { - didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack$1( - false, - "%s declares both contextTypes and contextType static properties. " + - "The legacy contextTypes property will be ignored.", - name - ); + if ( + ctor.contextType && + ctor.contextTypes && + !didWarnAboutContextTypeAndContextTypes.has(ctor) + ) { + didWarnAboutContextTypeAndContextTypes.add(ctor); + warningWithoutStack$1( + false, + "%s declares both contextTypes and contextType static properties. " + + "The legacy contextTypes property will be ignored.", + name + ); + } } var noComponentShouldUpdate = @@ -8102,7 +8175,7 @@ function constructClassInstance( ) { var isLegacyContextConsumer = false; var unmaskedContext = emptyContextObject; - var context = null; + var context = emptyContextObject; var contextType = ctor.contextType; { @@ -8150,7 +8223,7 @@ function constructClassInstance( if (typeof contextType === "object" && contextType !== null) { context = readContext(contextType); - } else { + } else if (!disableLegacyContext) { unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); var contextTypes = ctor.contextTypes; isLegacyContextConsumer = @@ -8352,6 +8425,8 @@ function mountClassInstance( var contextType = ctor.contextType; if (typeof contextType === "object" && contextType !== null) { instance.context = readContext(contextType); + } else if (disableLegacyContext) { + instance.context = emptyContextObject; } else { var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); instance.context = getMaskedContext(workInProgress, unmaskedContext); @@ -8452,10 +8527,10 @@ function resumeMountClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextLegacyUnmaskedContext = getUnmaskedContext( workInProgress, ctor, @@ -8601,10 +8676,10 @@ function updateClassInstance( var oldContext = instance.context; var contextType = ctor.contextType; - var nextContext = void 0; + var nextContext = emptyContextObject; if (typeof contextType === "object" && contextType !== null) { nextContext = readContext(contextType); - } else { + } else if (!disableLegacyContext) { var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); } @@ -8760,7 +8835,7 @@ function updateClassInstance( var didWarnAboutMaps = void 0; var didWarnAboutGenerators = void 0; -var didWarnAboutStringRefInStrictMode = void 0; +var didWarnAboutStringRefs = void 0; var ownerHasKeyUseWarning = void 0; var ownerHasFunctionTypeWarning = void 0; var warnForMissingKey = function(child) {}; @@ -8768,7 +8843,7 @@ var warnForMissingKey = function(child) {}; { didWarnAboutMaps = false; didWarnAboutGenerators = false; - didWarnAboutStringRefInStrictMode = {}; + didWarnAboutStringRefs = {}; /** * Warn if there's no key explicitly set on dynamic arrays of children or @@ -8825,21 +8900,38 @@ function coerceRef(returnFiber, current$$1, element) { typeof mixedRef !== "object" ) { { - if (returnFiber.mode & StrictMode) { + // TODO: Clean this up once we turn on the string ref warning for + // everyone, because the strict mode case will no longer be relevant + if (returnFiber.mode & StrictMode || warnAboutStringRefs) { var componentName = getComponentName(returnFiber.type) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - 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) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; + if (!didWarnAboutStringRefs[componentName]) { + if (warnAboutStringRefs) { + warningWithoutStack$1( + false, + 'Component "%s" contains the string ref "%s". Support for string refs ' + + "will be removed in a future major release. We recommend using " + + "useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + componentName, + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } else { + 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 useRef() or createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + mixedRef, + getStackByFiberInDevAndProd(returnFiber) + ); + } + didWarnAboutStringRefs[componentName] = true; } } } @@ -10304,45 +10396,15 @@ function findFirstSuspended(row) { return null; } -var currentlyRenderingFiber$2 = null; -var currentListenerHookIndex = 0; - -function prepareToReadListenerHooks(workInProgress) { - currentlyRenderingFiber$2 = workInProgress; - currentListenerHookIndex = 0; -} - -function getListenerHooks() { - var listeners = void 0; - var dependencies = currentlyRenderingFiber$2.dependencies; - if (dependencies === null) { - dependencies = currentlyRenderingFiber$2.dependencies = { - expirationTime: NoWork, - firstContext: null, - listeners: [], - responders: null - }; - } - listeners = dependencies.listeners; - if (listeners === null) { - dependencies.listeners = listeners = []; - } - return listeners; -} - -function updateListenerHook(responder, props) { - var listeners = getListenerHooks(); - if (listeners.length === currentListenerHookIndex) { - listeners.push({ - responder: responder, - props: props - }); - currentListenerHookIndex++; - } else { - var currentListenerHook = listeners[currentListenerHookIndex++]; - currentListenerHook.responder = responder; - currentListenerHook.props = props; +function createResponderListener(responder, props) { + var eventResponderListener = { + responder: responder, + props: props + }; + { + Object.freeze(eventResponderListener); } + return eventResponderListener; } function createResponderInstance( @@ -11427,7 +11489,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }; var HooksDispatcherOnMountInDEV = null; @@ -11534,10 +11596,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11613,10 +11675,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11692,10 +11754,10 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11782,11 +11844,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; mountHookTypesDev(); return mountDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); mountHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; @@ -11873,11 +11935,11 @@ var InvalidNestedHooksDispatcherOnUpdateInDEV = null; updateHookTypesDev(); return updateDebugValue(value, formatterFn); }, - useListener: function(responder, props) { - currentHookNameInDev = "useListener"; + useResponder: function(responder, props) { + currentHookNameInDev = "useResponder"; warnInvalidHookAccess(); updateHookTypesDev(); - updateListenerHook(responder, props); + return createResponderListener(responder, props); } }; } @@ -11940,6 +12002,17 @@ var hydrationParentFiber = null; var nextHydratableInstance = null; var isHydrating = false; +function warnIfHydrating() { + { + !!isHydrating + ? warning$1( + false, + "We should not be hydrating here. This is a bug in React. Please file a bug." + ) + : void 0; + } +} + function enterHydrationState(fiber) { if (!supportsHydration) { return false; @@ -12448,9 +12521,6 @@ function updateForwardRef( // The rest is a fork of updateFunctionComponent var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -12469,9 +12539,6 @@ function updateForwardRef( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -12751,14 +12818,14 @@ function updateFunctionComponent( } } - var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, true); + context = getMaskedContext(workInProgress, unmaskedContext); + } var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); @@ -12777,9 +12844,6 @@ function updateFunctionComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } nextChildren = renderWithHooks( current$$1, workInProgress, @@ -13371,13 +13435,13 @@ function mountIndeterminateComponent( } var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); - var context = getMaskedContext(workInProgress, unmaskedContext); + var context = void 0; + if (!disableLegacyContext) { + var unmaskedContext = getUnmaskedContext(workInProgress, Component, false); + context = getMaskedContext(workInProgress, unmaskedContext); + } prepareToReadContext(workInProgress, renderExpirationTime); - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } var value = void 0; { @@ -13484,6 +13548,15 @@ function mountIndeterminateComponent( // Proceed under the assumption that this is a function component workInProgress.tag = FunctionComponent; { + if (disableLegacyContext && Component.contextTypes) { + warningWithoutStack$1( + false, + "%s uses the legacy contextTypes API which is no longer supported. " + + "Use React.createContext() with React.useContext() instead.", + getComponentName(Component) || "Unknown" + ); + } + if ( debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && @@ -13491,9 +13564,6 @@ function mountIndeterminateComponent( ) { // Only double-render components with Hooks if (workInProgress.memoizedState !== null) { - if (enableFlareAPI) { - prepareToReadListenerHooks(workInProgress); - } value = renderWithHooks( null, workInProgress, @@ -14023,12 +14093,18 @@ function updateDehydratedSuspenseComponent( } return null; } + if ((workInProgress.effectTag & DidCapture) !== NoEffect) { // Something suspended. Leave the existing children in place. // TODO: In non-concurrent mode, should we commit the nodes we have hydrated so far? workInProgress.child = null; return null; } + + // We should never be hydrating at this point because it is the first pass, + // but after we've already committed once. + warnIfHydrating(); + if (isSuspenseInstanceFallback(suspenseInstance)) { // This boundary is in a permanent fallback state. In this case, we'll never // get an update and we'll never be able to hydrate the final content. Let's just try the @@ -14887,29 +14963,26 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect; - var childExpirationTime = workInProgress.childExpirationTime; - if (childExpirationTime < renderExpirationTime) { + var hasChildWork = + workInProgress.childExpirationTime >= renderExpirationTime; + + if (didSuspendBefore) { + if (hasChildWork) { + // If something was in fallback state last time, and we have all the + // same children then we're still in progressive loading state. + // Something might get unblocked by state updates or retries in the + // tree which will affect the tail. So we need to use the normal + // path to compute the correct tail. + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + } // If none of the children had any work, that means that none of // them got retried so they'll still be blocked in the same way // as before. We can fast bail out. - pushSuspenseContext(workInProgress, suspenseStackCursor.current); - if (didSuspendBefore) { - workInProgress.effectTag |= DidCapture; - } - return null; - } - - if (didSuspendBefore) { - // If something was in fallback state last time, and we have all the - // same children then we're still in progressive loading state. - // Something might get unblocked by state updates or retries in the - // tree which will affect the tail. So we need to use the normal - // path to compute the correct tail. - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); + workInProgress.effectTag |= DidCapture; } // If nothing suspended before and we're rendering the same children, @@ -14923,7 +14996,15 @@ function beginWork$1(current$$1, workInProgress, renderExpirationTime) { renderState.tail = null; } pushSuspenseContext(workInProgress, suspenseStackCursor.current); - break; + + if (hasChildWork) { + break; + } else { + // If none of the children had any work, that means that none of + // them got retried so they'll still be blocked in the same way + // as before. We can fast bail out. + return null; + } } } return bailoutOnAlreadyFinishedWork( @@ -15179,7 +15260,7 @@ if (supportsMutation) { while (node !== null) { if (node.tag === HostComponent || node.tag === HostText) { appendInitialChild(parent, node.stateNode); - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { appendInitialChild(parent, node.stateNode.instance); } else if (node.tag === HostPortal) { // If we have a portal child, then we don't want to traverse @@ -15677,12 +15758,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { ); if (enableFlareAPI) { - var prevResponders = current.memoizedProps.responders; - var nextResponders = newProps.responders; + var prevListeners = current.memoizedProps.listeners; + var nextListeners = newProps.listeners; var instance = workInProgress.stateNode; - if (prevResponders !== nextResponders) { - updateEventResponders( - nextResponders, + if (prevListeners !== nextListeners) { + updateEventListeners( + nextListeners, instance, rootContainerInstance, workInProgress @@ -15728,8 +15809,20 @@ function completeWork(current, workInProgress, renderExpirationTime) { // commit-phase we mark this as such. markUpdate(workInProgress); } + if (enableFlareAPI) { + var _instance5 = workInProgress.stateNode; + var listeners = newProps.listeners; + if (listeners != null) { + updateEventListeners( + listeners, + _instance5, + rootContainerInstance, + workInProgress + ); + } + } } else { - var _instance5 = createInstance( + var _instance6 = createInstance( type, newProps, rootContainerInstance, @@ -15737,14 +15830,14 @@ function completeWork(current, workInProgress, renderExpirationTime) { workInProgress ); - appendAllChildren(_instance5, workInProgress, false, false); + appendAllChildren(_instance6, workInProgress, false, false); if (enableFlareAPI) { - var responders = newProps.responders; - if (responders != null) { - updateEventResponders( - responders, - _instance5, + var _listeners = newProps.listeners; + if (_listeners != null) { + updateEventListeners( + _listeners, + _instance6, rootContainerInstance, workInProgress ); @@ -15756,7 +15849,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { // Make sure such renderers get scheduled for later work. if ( finalizeInitialChildren( - _instance5, + _instance6, type, newProps, rootContainerInstance, @@ -15765,7 +15858,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { ) { markUpdate(workInProgress); } - workInProgress.stateNode = _instance5; + workInProgress.stateNode = _instance6; } if (workInProgress.ref !== null) { @@ -15965,15 +16058,22 @@ function completeWork(current, workInProgress, renderExpirationTime) { markSpawnedWork(Never); } skipPastDehydratedSuspenseInstance(workInProgress); - } else if ((workInProgress.effectTag & DidCapture) === NoEffect) { - // This boundary did not suspend so it's now hydrated. - // To handle any future suspense cases, we're going to now upgrade it - // to a Suspense component. We detach it from the existing current fiber. - current.alternate = null; - workInProgress.alternate = null; - workInProgress.tag = SuspenseComponent; - workInProgress.memoizedState = null; - workInProgress.stateNode = null; + } else { + // We should never have been in a hydration state if we didn't have a current. + // However, in some of those paths, we might have reentered a hydration state + // and then we might be inside a hydration state. In that case, we'll need to + // exit out of it. + resetHydrationState(); + if ((workInProgress.effectTag & DidCapture) === NoEffect) { + // This boundary did not suspend so it's now hydrated. + // To handle any future suspense cases, we're going to now upgrade it + // to a Suspense component. We detach it from the existing current fiber. + current.alternate = null; + workInProgress.alternate = null; + workInProgress.tag = SuspenseComponent; + workInProgress.memoizedState = null; + workInProgress.stateNode = null; + } } } break; @@ -16187,12 +16287,12 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalImpl, fundamentalState || {} ); - var _instance6 = getFundamentalComponentInstance(fundamentalInstance); - fundamentalInstance.instance = _instance6; + var _instance7 = getFundamentalComponentInstance(fundamentalInstance); + fundamentalInstance.instance = _instance7; if (fundamentalImpl.reconcileChildren === false) { return null; } - appendAllChildren(_instance6, workInProgress, false, false); + appendAllChildren(_instance7, workInProgress, false, false); mountFundamentalComponent(fundamentalInstance); } else { // We fire update in commit phase @@ -16201,9 +16301,9 @@ function completeWork(current, workInProgress, renderExpirationTime) { fundamentalInstance.props = newProps; fundamentalInstance.currentFiber = workInProgress; if (supportsPersistence) { - var _instance7 = cloneFundamentalInstance(fundamentalInstance); - fundamentalInstance.instance = _instance7; - appendAllChildren(_instance7, workInProgress, false, false); + var _instance8 = cloneFundamentalInstance(fundamentalInstance); + fundamentalInstance.instance = _instance8; + appendAllChildren(_instance8, workInProgress, false, false); } var shouldUpdate = shouldUpdateFundamentalComponent( fundamentalInstance @@ -16261,26 +16361,41 @@ function mountEventResponder( respondersMap.set(responder, responderInstance); } -function updateEventResponder( - responder, - props, +function updateEventListener( + listener, fiber, visistedResponders, respondersMap, instance, rootContainerInstance ) { + var responder = void 0; + var props = void 0; + + if (listener) { + responder = listener.responder; + props = listener.props; + } (function() { if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) { throw ReactError( Error( - "An invalid value was used as an event responder. Expect one or many event responders created via React.unstable_createResponer()." + "An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponer()." ) ); } })(); + var listenerProps = props; if (visistedResponders.has(responder)) { // show warning + { + warning$1( + false, + 'Duplicate event responder "%s" found in event listeners. ' + + "Event listeners passed to elements cannot use the same event responder more than once.", + responder.displayName + ); + } return; } visistedResponders.add(responder); @@ -16290,7 +16405,7 @@ function updateEventResponder( // Mount mountEventResponder( responder, - props, + listenerProps, instance, rootContainerInstance, fiber, @@ -16298,25 +16413,24 @@ function updateEventResponder( ); } else { // Update - responderInstance.props = props; + responderInstance.props = listenerProps; responderInstance.fiber = fiber; } } -function updateEventResponders( - responders, +function updateEventListeners( + listeners, instance, rootContainerInstance, fiber ) { var visistedResponders = new Set(); var dependencies = fiber.dependencies; - if (responders != null) { + if (listeners != null) { if (dependencies === null) { dependencies = fiber.dependencies = { expirationTime: NoWork, firstContext: null, - listeners: null, responders: new Map() }; } @@ -16324,15 +16438,11 @@ function updateEventResponders( if (respondersMap === null) { respondersMap = new Map(); } - if (isArray$2(responders)) { - for (var i = 0, length = responders.length; i < length; i++) { - var _responders$i = responders[i], - type = _responders$i.type, - props = _responders$i.props; - - updateEventResponder( - type, - props, + if (isArray$2(listeners)) { + for (var i = 0, length = listeners.length; i < length; i++) { + var listener = listeners[i]; + updateEventListener( + listener, fiber, visistedResponders, respondersMap, @@ -16341,12 +16451,8 @@ function updateEventResponders( ); } } else { - var type = responders.type, - props = responders.props; - - updateEventResponder( - type, - props, + updateEventListener( + listeners, fiber, visistedResponders, respondersMap, @@ -16419,8 +16525,12 @@ function unwindWork(workInProgress, renderExpirationTime) { } case DehydratedSuspenseComponent: { if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(workInProgress); + if (workInProgress.alternate === null) { + // TODO: popHydrationState + } else { + resetHydrationState(); + } var _effectTag3 = workInProgress.effectTag; if (_effectTag3 & ShouldCapture) { workInProgress.effectTag = @@ -16474,7 +16584,6 @@ function unwindInterruptedWork(interruptedWork) { break; case DehydratedSuspenseComponent: if (enableSuspenseServerRenderer) { - // TODO: popHydrationState popSuspenseContext(interruptedWork); } break; @@ -17190,7 +17299,7 @@ function commitDetachRef(current$$1) { // User-originating errors (lifecycles and refs) should not interrupt // deletion, so don't let them throw. Host-originating errors should // interrupt deletion, so it's okay -function commitUnmount(current$$1) { +function commitUnmount(current$$1, renderPriorityLevel) { onCommitUnmount(current$$1); switch (current$$1.tag) { @@ -17203,14 +17312,33 @@ function commitUnmount(current$$1) { var lastEffect = updateQueue.lastEffect; if (lastEffect !== null) { var firstEffect = lastEffect.next; - var effect = firstEffect; - do { - var destroy = effect.destroy; - if (destroy !== undefined) { - safelyCallDestroy(current$$1, destroy); - } - effect = effect.next; - } while (effect !== firstEffect); + + // When the owner fiber is deleted, the destroy function of a passive + // effect hook is called during the synchronous commit phase. This is + // a concession to implementation complexity. Calling it in the + // passive effect phase (like they usually are, when dependencies + // change during an update) would require either traversing the + // children of the deleted fiber again, or including unmount effects + // as part of the fiber effect list. + // + // Because this is during the sync commit phase, we need to change + // the priority. + // + // TODO: Reconsider this implementation trade off. + var priorityLevel = + renderPriorityLevel > NormalPriority + ? NormalPriority + : renderPriorityLevel; + runWithPriority(priorityLevel, function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (destroy !== undefined) { + safelyCallDestroy(current$$1, destroy); + } + effect = effect.next; + } while (effect !== firstEffect); + }); } } break; @@ -17251,7 +17379,7 @@ function commitUnmount(current$$1) { // We are also not using this parent because // the portal will get pushed immediately. if (supportsMutation) { - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else if (supportsPersistence) { emptyPortalContainer(current$$1); } @@ -17269,14 +17397,14 @@ function commitUnmount(current$$1) { } } -function commitNestedUnmounts(root) { +function commitNestedUnmounts(root, renderPriorityLevel) { // While we're inside a removed host node we don't want to call // removeChild on the inner nodes because they're removed by the top // call anyway. We also want to call componentWillUnmount on all // composites before this host node is removed from the tree. Therefore var node = root; while (true) { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes. // Skip portals because commitUnmount() currently visits them recursively. if ( @@ -17496,7 +17624,7 @@ function commitPlacement(finishedWork) { var node = finishedWork; while (true) { var isHost = node.tag === HostComponent || node.tag === HostText; - if (isHost || node.tag === FundamentalComponent) { + if (isHost || (enableFundamentalAPI && node.tag === FundamentalComponent)) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (before) { if (isContainer) { @@ -17534,7 +17662,7 @@ function commitPlacement(finishedWork) { } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel) { // We only have the top Fiber that was deleted but we need to recurse down its var node = current$$1; @@ -17585,7 +17713,7 @@ function unmountHostComponents(current$$1) { } if (node.tag === HostComponent || node.tag === HostText) { - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -17594,9 +17722,9 @@ function unmountHostComponents(current$$1) { removeChild(currentParent, node.stateNode); } // Don't visit children because we already visited them. - } else if (node.tag === FundamentalComponent) { + } else if (enableFundamentalAPI && node.tag === FundamentalComponent) { var fundamentalNode = node.stateNode.instance; - commitNestedUnmounts(node); + commitNestedUnmounts(node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the // node from the tree. if (currentParentIsContainer) { @@ -17626,7 +17754,7 @@ function unmountHostComponents(current$$1) { continue; } } else { - commitUnmount(node); + commitUnmount(node, renderPriorityLevel); // Visit children because we may find more host components below. if (node.child !== null) { node.child.return = node; @@ -17653,14 +17781,14 @@ function unmountHostComponents(current$$1) { } } -function commitDeletion(current$$1) { +function commitDeletion(current$$1, renderPriorityLevel) { if (supportsMutation) { // Recursively delete all host nodes from the parent. // Detach refs and call componentWillUnmount() on the whole subtree. - unmountHostComponents(current$$1); + unmountHostComponents(current$$1, renderPriorityLevel); } else { // Detach refs and call componentWillUnmount() on the whole subtree. - commitNestedUnmounts(current$$1); + commitNestedUnmounts(current$$1, renderPriorityLevel); } detachFiber(current$$1); } @@ -18206,6 +18334,7 @@ function throwException( } while (workInProgress !== null); } +// The scheduler is imported here *only* to detect whether it's been mocked // DEV stuff var ceil = Math.ceil; @@ -18260,6 +18389,7 @@ var legacyErrorBoundariesThatAlreadyFailed = null; var rootDoesHavePassiveEffects = false; var rootWithPendingPassiveEffects = null; +var pendingPassiveEffectsRenderPriority = NoPriority; var pendingPassiveEffectsExpirationTime = NoWork; var rootsWithPendingDiscreteUpdates = null; @@ -18528,7 +18658,10 @@ function scheduleCallbackForRoot(root, priorityLevel, expirationTime) { ); } else { var options = null; - if (expirationTime !== Never) { + if ( + !disableSchedulerTimeoutBasedOnReactExpirationTime && + expirationTime !== Never + ) { var timeout = expirationTimeToMs(expirationTime) - now(); options = { timeout: timeout }; } @@ -18744,7 +18877,6 @@ function prepareFreshStack(root, expirationTime) { { ReactStrictModeWarnings.discardPendingWarnings(); - componentsThatSuspendedAtHighPri = null; componentsThatTriggeredHighPriSuspend = null; } } @@ -18927,8 +19059,6 @@ function renderRoot(root, expirationTime, isSync) { // Set this to null to indicate there's no in-progress render. workInProgressRoot = null; - flushSuspensePriorityWarningInDEV(); - switch (workInProgressRootExitStatus) { case RootIncomplete: { (function() { @@ -18937,7 +19067,7 @@ function renderRoot(root, expirationTime, isSync) { } })(); } - // Flow knows about invariant, so it compains if I add a break statement, + // Flow knows about invariant, so it complains if I add a break statement, // but eslint doesn't know about invariant, so it complains if I do. // eslint-disable-next-line no-fallthrough case RootErrored: { @@ -18963,6 +19093,8 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspended: { + flushSuspensePriorityWarningInDEV(); + // We have an acceptable loading state. We need to figure out if we should // immediately commit it or wait a bit. @@ -18971,7 +19103,12 @@ function renderRoot(root, expirationTime, isSync) { // possible. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync; - if (hasNotProcessedNewUpdates && !isSync) { + if ( + hasNotProcessedNewUpdates && + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // If we have not processed any new updates during this pass, then this is // either a retry of an existing fallback state or a hidden tree. // Hidden trees shouldn't be batched with other work and after that's @@ -19008,7 +19145,13 @@ function renderRoot(root, expirationTime, isSync) { return commitRoot.bind(null, root); } case RootSuspendedWithDelay: { - if (!isSync) { + flushSuspensePriorityWarningInDEV(); + + if ( + !isSync && + // do not delay if we're inside an act() scope + !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) + ) { // We're suspended in a state that should be avoided. We'll try to avoid committing // it for as long as the timeouts let us. if (workInProgressRootHasPendingPing) { @@ -19078,6 +19221,12 @@ function renderRoot(root, expirationTime, isSync) { // The work completed. Ready to commit. if ( !isSync && + // do not delay if we're inside an act() scope + !( + true && + flushSuspenseFallbacksInTests && + IsThisRendererActing.current + ) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null ) { @@ -19426,12 +19575,15 @@ function resetChildExpirationTime(completedWork) { } function commitRoot(root) { - runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority( + ImmediatePriority, + commitRootImpl.bind(null, root, renderPriorityLevel) + ); // If there are passive effects, schedule a callback to flush them. This goes // outside commitRootImpl so that it inherits the priority of the render. if (rootWithPendingPassiveEffects !== null) { - var priorityLevel = getCurrentPriorityLevel(); - scheduleCallback(priorityLevel, function() { + scheduleCallback(NormalPriority, function() { flushPassiveEffects(); return null; }); @@ -19439,7 +19591,7 @@ function commitRoot(root) { return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); flushRenderPhaseStrictModeWarningsInDEV(); @@ -19568,7 +19720,12 @@ function commitRootImpl(root) { nextEffect = firstEffect; do { { - invokeGuardedCallback(null, commitMutationEffects, null); + invokeGuardedCallback( + null, + commitMutationEffects, + null, + renderPriorityLevel + ); if (hasCaughtError()) { (function() { if (!(nextEffect !== null)) { @@ -19655,6 +19812,7 @@ function commitRootImpl(root) { rootDoesHavePassiveEffects = false; rootWithPendingPassiveEffects = root; pendingPassiveEffectsExpirationTime = expirationTime; + pendingPassiveEffectsRenderPriority = renderPriorityLevel; } else { // We are done with the effect chain at this point so let's clear the // nextEffect pointers to assist with GC. If we have passive effects, we'll @@ -19757,7 +19915,7 @@ function commitBeforeMutationEffects() { } } -function commitMutationEffects() { +function commitMutationEffects(renderPriorityLevel) { // TODO: Should probably move the bulk of this function to commitWork. while (nextEffect !== null) { setCurrentFiber(nextEffect); @@ -19808,7 +19966,7 @@ function commitMutationEffects() { break; } case Deletion: { - commitDeletion(nextEffect); + commitDeletion(nextEffect, renderPriorityLevel); break; } } @@ -19854,9 +20012,19 @@ function flushPassiveEffects() { } var root = rootWithPendingPassiveEffects; var expirationTime = pendingPassiveEffectsExpirationTime; + var renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = NoWork; + pendingPassiveEffectsRenderPriority = NoPriority; + var priorityLevel = + renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel; + return runWithPriority( + priorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = null; if (enableSchedulerTracing) { prevInteractions = tracing.__interactionsRef.current; @@ -20363,6 +20531,7 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) { } } +// a 'shared' variable that changes when act() opens/closes in tests. var IsThisRendererActing = { current: false }; function warnIfNotScopedWithMatchingAct(fiber) { @@ -20378,12 +20547,12 @@ function warnIfNotScopedWithMatchingAct(fiber) { "Be sure to use the matching version of act() corresponding to your renderer:\n\n" + "// for react-dom:\n" + "import {act} from 'react-dom/test-utils';\n" + - "//...\n" + + "// ...\n" + "act(() => ...);\n\n" + "// for react-test-renderer:\n" + "import TestRenderer from 'react-test-renderer';\n" + "const {act} = TestRenderer;\n" + - "//...\n" + + "// ...\n" + "act(() => ...);" + "%s", getStackByFiberInDevAndProd(fiber) @@ -20450,7 +20619,44 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber) { var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; -var componentsThatSuspendedAtHighPri = null; +// In tests, we want to enforce a mocked scheduler. +var didWarnAboutUnmockedScheduler = false; +// TODO Before we release concurrent mode, revisit this and decide whether a mocked +// scheduler is the actual recommendation. The alternative could be a testing build, +// a new lib, or whatever; we dunno just yet. This message is for early adopters +// to get their tests right. + +function warnIfUnmockedScheduler(fiber) { + { + if ( + didWarnAboutUnmockedScheduler === false && + Scheduler.unstable_flushAllWithoutAsserting === undefined + ) { + if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } else if (warnAboutUnmockedScheduler === true) { + didWarnAboutUnmockedScheduler = true; + warningWithoutStack$1( + false, + 'Starting from React v17, the "scheduler" module will need to be mocked ' + + "to guarantee consistent behaviour across tests and browsers. " + + "For example, with jest: \n" + + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + + "For more info, visit https://fb.me/react-mock-scheduler" + ); + } + } + } +} + var componentsThatTriggeredHighPriSuspend = null; function checkForWrongSuspensePriorityInDEV(sourceFiber) { { @@ -20537,70 +20743,34 @@ function checkForWrongSuspensePriorityInDEV(sourceFiber) { } workInProgressNode = workInProgressNode.return; } - - // Add the component name to a set. - var componentName = getComponentName(sourceFiber.type); - if (componentsThatSuspendedAtHighPri === null) { - componentsThatSuspendedAtHighPri = new Set([componentName]); - } else { - componentsThatSuspendedAtHighPri.add(componentName); - } } } } function flushSuspensePriorityWarningInDEV() { { - if (componentsThatSuspendedAtHighPri !== null) { + if (componentsThatTriggeredHighPriSuspend !== null) { var componentNames = []; - componentsThatSuspendedAtHighPri.forEach(function(name) { - componentNames.push(name); + componentsThatTriggeredHighPriSuspend.forEach(function(name) { + return componentNames.push(name); }); - componentsThatSuspendedAtHighPri = null; - - var componentsThatTriggeredSuspendNames = []; - if (componentsThatTriggeredHighPriSuspend !== null) { - componentsThatTriggeredHighPriSuspend.forEach(function(name) { - return componentsThatTriggeredSuspendNames.push(name); - }); - } - componentsThatTriggeredHighPriSuspend = null; - var componentNamesString = componentNames.sort().join(", "); - var componentThatTriggeredSuspenseError = ""; - if (componentsThatTriggeredSuspendNames.length > 0) { - componentThatTriggeredSuspenseError = - "The following components triggered a user-blocking update:" + - "\n\n" + - " " + - componentsThatTriggeredSuspendNames.sort().join(", ") + - "\n\n" + - "that was then suspended by:" + - "\n\n" + - " " + - componentNamesString; - } else { - componentThatTriggeredSuspenseError = - "A user-blocking update was suspended by:" + - "\n\n" + - " " + - componentNamesString; + if (componentNames.length > 0) { + warningWithoutStack$1( + false, + "%s triggered a user-blocking update that suspended." + + "\n\n" + + "The fix is to split the update into multiple parts: a user-blocking " + + "update to provide immediate feedback, and another update that " + + "triggers the bulk of the changes." + + "\n\n" + + "Refer to the documentation for useSuspenseTransition to learn how " + + "to implement this pattern.", + // TODO: Add link to React docs with more information, once it exists + componentNames.sort().join(", ") + ); } - - warningWithoutStack$1( - false, - "%s" + - "\n\n" + - "The fix is to split the update into multiple parts: a user-blocking " + - "update to provide immediate feedback, and another update that " + - "triggers the bulk of the changes." + - "\n\n" + - "Refer to the documentation for useSuspenseTransition to learn how " + - "to implement this pattern.", - // TODO: Add link to React docs with more information, once it exists - componentThatTriggeredSuspenseError - ); } } } @@ -21079,7 +21249,6 @@ function createWorkInProgress(current, pendingProps, expirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -21172,7 +21341,6 @@ function resetWorkInProgress(workInProgress, renderExpirationTime) { : { expirationTime: currentDependencies.expirationTime, firstContext: currentDependencies.firstContext, - listeners: currentDependencies.listeners, responders: currentDependencies.responders }; @@ -21795,6 +21963,7 @@ function updateContainer(element, container, parentComponent, callback) { { // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests if ("undefined" !== typeof jest) { + warnIfUnmockedScheduler(current$$1); warnIfNotScopedWithMatchingAct(current$$1); } } diff --git a/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js b/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js index 9437badd089b1c..d5c1cabad48d05 100644 --- a/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js +++ b/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js @@ -1661,22 +1661,8 @@ function finalizeInitialChildren(parentInstance) { return !1; } var scheduleTimeout = setTimeout, - cancelTimeout = clearTimeout; -function removeChild(parentInstance, child) { - recursivelyUncacheFiberNode(child); - var children = parentInstance._children; - child = children.indexOf(child); - children.splice(child, 1); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - [], - [], - [child] - ); -} -var BEFORE_SLASH_RE = /^(.*)[\\\/]/; + cancelTimeout = clearTimeout, + BEFORE_SLASH_RE = /^(.*)[\\\/]/; function getStackByFiberInDevAndProd(workInProgress) { var info = ""; do { @@ -2070,7 +2056,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3287,24 +3272,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3655,7 +3624,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3729,7 +3698,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3784,7 +3753,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, hydrationParentFiber = null, nextHydratableInstance = null, @@ -4003,17 +3972,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -4640,7 +4609,6 @@ var appendAllChildren = void 0, appendAllChildren = function(parent, workInProgress) { for (var node = workInProgress.child; null !== node; ) { if (5 === node.tag || 6 === node.tag) parent._children.push(node.stateNode); - else if (20 === node.tag) parent._children.push(node.stateNode.instance); else if (4 !== node.tag && null !== node.child) { node.child.return = node; node = node.child; @@ -4783,6 +4751,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -4811,7 +4788,7 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } -function commitUnmount(current$$1$jscomp$0) { +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(current$$1$jscomp$0); switch (current$$1$jscomp$0.tag) { @@ -4824,54 +4801,43 @@ function commitUnmount(current$$1$jscomp$0) { null !== updateQueue && ((updateQueue = updateQueue.lastEffect), null !== updateQueue) ) { - var effect = (updateQueue = updateQueue.next); - do { - var destroy = effect.destroy; - if (void 0 !== destroy) { - var current$$1 = current$$1$jscomp$0; - try { - destroy(); - } catch (error) { - captureCommitPhaseError(current$$1, error); - } + var firstEffect = updateQueue.next; + runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); } - effect = effect.next; - } while (effect !== updateQueue); + ); } break; case 1: safelyDetachRef(current$$1$jscomp$0); - updateQueue = current$$1$jscomp$0.stateNode; - if ("function" === typeof updateQueue.componentWillUnmount) - try { - (updateQueue.props = current$$1$jscomp$0.memoizedProps), - (updateQueue.state = current$$1$jscomp$0.memoizedState), - updateQueue.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(current$$1$jscomp$0, unmountError); - } + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); break; case 5: safelyDetachRef(current$$1$jscomp$0); break; case 4: - unmountHostComponents(current$$1$jscomp$0); + unmountHostComponents(current$$1$jscomp$0, renderPriorityLevel); } } -function commitNestedUnmounts(root) { - for (var node = root; ; ) - if ((commitUnmount(node), null !== node.child && 4 !== node.tag)) - (node.child.return = node), (node = node.child); - else { - if (node === root) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === root) return; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } -} function isHostParent(fiber) { return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; } @@ -4938,7 +4904,7 @@ function commitPlacement(finishedWork) { } for (var node = finishedWork; ; ) { var isHost = 5 === node.tag || 6 === node.tag; - if (isHost || 20 === node.tag) { + if (isHost) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (parentFiber) if (isContainer) { @@ -5022,7 +4988,7 @@ function commitPlacement(finishedWork) { node = node.sibling; } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel$jscomp$0) { for ( var node = current$$1, currentParentIsValid = !1, @@ -5058,37 +5024,56 @@ function unmountHostComponents(current$$1) { } currentParentIsValid = !0; } - if (5 === node.tag || 6 === node.tag) - if ((commitNestedUnmounts(node), currentParentIsContainer)) { - var parentInstance = currentParent; - recursivelyUncacheFiberNode(node.stateNode); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, node.stateNode); - else if (20 === node.tag) - if ( - ((parentInstance = node.stateNode.instance), - commitNestedUnmounts(node), - currentParentIsContainer) - ) { - var parentInstance$jscomp$0 = currentParent; - recursivelyUncacheFiberNode(parentInstance); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance$jscomp$0, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, parentInstance); - else if (4 === node.tag) { + if (5 === node.tag || 6 === node.tag) { + a: for ( + var root = node, + renderPriorityLevel = renderPriorityLevel$jscomp$0, + node$jscomp$0 = root; + ; + + ) + if ( + (commitUnmount(node$jscomp$0, renderPriorityLevel), + null !== node$jscomp$0.child && 4 !== node$jscomp$0.tag) + ) + (node$jscomp$0.child.return = node$jscomp$0), + (node$jscomp$0 = node$jscomp$0.child); + else { + if (node$jscomp$0 === root) break; + for (; null === node$jscomp$0.sibling; ) { + if (null === node$jscomp$0.return || node$jscomp$0.return === root) + break a; + node$jscomp$0 = node$jscomp$0.return; + } + node$jscomp$0.sibling.return = node$jscomp$0.return; + node$jscomp$0 = node$jscomp$0.sibling; + } + currentParentIsContainer + ? ((root = currentParent), + recursivelyUncacheFiberNode(node.stateNode), + ReactNativePrivateInterface.UIManager.manageChildren( + root, + [], + [], + [], + [], + [0] + )) + : ((root = currentParent), + (node$jscomp$0 = node.stateNode), + recursivelyUncacheFiberNode(node$jscomp$0), + (renderPriorityLevel = root._children), + (node$jscomp$0 = renderPriorityLevel.indexOf(node$jscomp$0)), + renderPriorityLevel.splice(node$jscomp$0, 1), + ReactNativePrivateInterface.UIManager.manageChildren( + root._nativeTag, + [], + [], + [], + [], + [node$jscomp$0] + )); + } else if (4 === node.tag) { if (null !== node.child) { currentParent = node.stateNode.containerInfo; currentParentIsContainer = !0; @@ -5096,7 +5081,9 @@ function unmountHostComponents(current$$1) { node = node.child; continue; } - } else if ((commitUnmount(node), null !== node.child)) { + } else if ( + (commitUnmount(node, renderPriorityLevel$jscomp$0), null !== node.child) + ) { node.child.return = node; node = node.child; continue; @@ -5325,6 +5312,8 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, + pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, rootWithNestedUpdates = null, @@ -5958,7 +5947,7 @@ function completeUnitOfWork(unitOfWork) { else if (newProps) { current = requiredContext(contextStackCursor$1.current); var type$jscomp$0 = type; - var _instance5 = newProps; + var _instance6 = newProps; var rootContainerInstance = renderExpirationTime$jscomp$0, internalInstanceHandle = current$$1, tag = allocateTag(); @@ -5966,7 +5955,7 @@ function completeUnitOfWork(unitOfWork) { var updatePayload = diffProperties( null, emptyObject, - _instance5, + _instance6, type$jscomp$0.validAttributes ); ReactNativePrivateInterface.UIManager.createView( @@ -5980,17 +5969,17 @@ function completeUnitOfWork(unitOfWork) { type$jscomp$0 ); instanceCache.set(tag, internalInstanceHandle); - instanceProps.set(tag, _instance5); - _instance5 = rootContainerInstance; - appendAllChildren(_instance5, current$$1, !1, !1); + instanceProps.set(tag, _instance6); + _instance6 = rootContainerInstance; + appendAllChildren(_instance6, current$$1, !1, !1); finalizeInitialChildren( - _instance5, + _instance6, type, newProps, renderExpirationTime$jscomp$0, current ) && (current$$1.effectTag |= 4); - current$$1.stateNode = _instance5; + current$$1.stateNode = _instance6; null !== current$$1.ref && (current$$1.effectTag |= 128); } else if (null === current$$1.stateNode) throw ReactError( @@ -6054,10 +6043,10 @@ function completeUnitOfWork(unitOfWork) { null === type || ((type = current.child.sibling), null !== type && - ((_instance5 = current$$1.firstEffect), - null !== _instance5 + ((_instance6 = current$$1.firstEffect), + null !== _instance6 ? ((current$$1.firstEffect = type), - (type.nextEffect = _instance5)) + (type.nextEffect = _instance6)) : ((current$$1.firstEffect = current$$1.lastEffect = type), (type.nextEffect = null)), (type.effectTag = 8)))); @@ -6109,8 +6098,8 @@ function completeUnitOfWork(unitOfWork) { newProps = current$$1.memoizedState; if (null === newProps) break; type = 0 !== (current$$1.effectTag & 64); - _instance5 = newProps.rendering; - if (null === _instance5) + _instance6 = newProps.rendering; + if (null === _instance6) if (type) cutOffTailIfNeeded(newProps, !1); else { if ( @@ -6118,11 +6107,11 @@ function completeUnitOfWork(unitOfWork) { (null !== current && 0 !== (current.effectTag & 64)) ) for (current = current$$1.child; null !== current; ) { - _instance5 = findFirstSuspended(current); - if (null !== _instance5) { + _instance6 = findFirstSuspended(current); + if (null !== _instance6) { current$$1.effectTag |= 64; cutOffTailIfNeeded(newProps, !1); - newProps = _instance5.updateQueue; + newProps = _instance6.updateQueue; null !== newProps && ((current$$1.updateQueue = newProps), (current$$1.effectTag |= 4)); @@ -6135,9 +6124,9 @@ function completeUnitOfWork(unitOfWork) { (renderExpirationTime$jscomp$0.nextEffect = null), (renderExpirationTime$jscomp$0.firstEffect = null), (renderExpirationTime$jscomp$0.lastEffect = null), - (_instance5 = + (_instance6 = renderExpirationTime$jscomp$0.alternate), - null === _instance5 + null === _instance6 ? ((renderExpirationTime$jscomp$0.childExpirationTime = 0), (renderExpirationTime$jscomp$0.expirationTime = type), (renderExpirationTime$jscomp$0.child = null), @@ -6146,25 +6135,24 @@ function completeUnitOfWork(unitOfWork) { (renderExpirationTime$jscomp$0.updateQueue = null), (renderExpirationTime$jscomp$0.dependencies = null)) : ((renderExpirationTime$jscomp$0.childExpirationTime = - _instance5.childExpirationTime), + _instance6.childExpirationTime), (renderExpirationTime$jscomp$0.expirationTime = - _instance5.expirationTime), + _instance6.expirationTime), (renderExpirationTime$jscomp$0.child = - _instance5.child), + _instance6.child), (renderExpirationTime$jscomp$0.memoizedProps = - _instance5.memoizedProps), + _instance6.memoizedProps), (renderExpirationTime$jscomp$0.memoizedState = - _instance5.memoizedState), + _instance6.memoizedState), (renderExpirationTime$jscomp$0.updateQueue = - _instance5.updateQueue), - (type = _instance5.dependencies), + _instance6.updateQueue), + (type = _instance6.dependencies), (renderExpirationTime$jscomp$0.dependencies = null === type ? null : { expirationTime: type.expirationTime, firstContext: type.firstContext, - listeners: type.listeners, responders: type.responders })), (current = current.sibling); @@ -6184,7 +6172,7 @@ function completeUnitOfWork(unitOfWork) { else { if (!type) if ( - ((current = findFirstSuspended(_instance5)), null !== current) + ((current = findFirstSuspended(_instance6)), null !== current) ) { if ( ((current$$1.effectTag |= 64), @@ -6209,13 +6197,13 @@ function completeUnitOfWork(unitOfWork) { (current$$1.expirationTime = current$$1.childExpirationTime = renderExpirationTime$jscomp$0 - 1)); newProps.isBackwards - ? ((_instance5.sibling = current$$1.child), - (current$$1.child = _instance5)) + ? ((_instance6.sibling = current$$1.child), + (current$$1.child = _instance6)) : ((current = newProps.last), null !== current - ? (current.sibling = _instance5) - : (current$$1.child = _instance5), - (newProps.last = _instance5)); + ? (current.sibling = _instance6) + : (current$$1.child = _instance6), + (newProps.last = _instance6)); } if (null !== newProps.tail) { 0 === newProps.tailExpiration && @@ -6255,9 +6243,9 @@ function completeUnitOfWork(unitOfWork) { ) (type = renderExpirationTime$jscomp$0.expirationTime), - (_instance5 = renderExpirationTime$jscomp$0.childExpirationTime), + (_instance6 = renderExpirationTime$jscomp$0.childExpirationTime), type > current && (current = type), - _instance5 > current && (current = _instance5), + _instance6 > current && (current = _instance6), (renderExpirationTime$jscomp$0 = renderExpirationTime$jscomp$0.sibling); newProps.childExpirationTime = current; @@ -6293,16 +6281,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6404,7 +6392,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6430,14 +6418,14 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - unmountHostComponents(current$$1); - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps = nextEffect; + unmountHostComponents(prevProps, current$$1); + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6575,24 +6563,27 @@ function commitRootImpl(root) { executionContext = childExpirationTimeBeforeCommit; } else root.current = finishedWork; if (rootDoesHavePassiveEffects) - (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root); + (rootDoesHavePassiveEffects = !1), + (rootWithPendingPassiveEffects = root), + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (effectTag$jscomp$0 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = effectTag$jscomp$0); - effectTag$jscomp$0 = root.firstPendingTime; - 0 !== effectTag$jscomp$0 - ? ((current$$1$jscomp$1 = requestCurrentTime()), - (current$$1$jscomp$1 = inferPriorityFromExpirationTime( - current$$1$jscomp$1, - effectTag$jscomp$0 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + 0 !== renderPriorityLevel + ? ((effectTag$jscomp$0 = requestCurrentTime()), + (effectTag$jscomp$0 = inferPriorityFromExpirationTime( + effectTag$jscomp$0, + renderPriorityLevel )), - scheduleCallbackForRoot(root, current$$1$jscomp$1, effectTag$jscomp$0)) + scheduleCallbackForRoot(root, effectTag$jscomp$0, renderPriorityLevel)) : (legacyErrorBoundariesThatAlreadyFailed = null); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === effectTag$jscomp$0 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6608,8 +6599,18 @@ function commitRootImpl(root) { } function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; - var root = rootWithPendingPassiveEffects; + var root = rootWithPendingPassiveEffects, + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; + pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root) { if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError( Error("Cannot flush passive effects while already rendering.") @@ -6767,32 +6768,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6811,25 +6806,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6838,8 +6833,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6850,9 +6845,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -6872,28 +6867,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6902,7 +6897,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6911,7 +6906,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6920,8 +6915,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -6930,7 +6925,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -6939,32 +6934,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6977,8 +6972,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -6987,7 +6982,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -7051,16 +7046,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7097,9 +7092,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -7113,7 +7108,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7195,7 +7190,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7203,12 +7198,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7220,16 +7218,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7247,11 +7245,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7264,13 +7262,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7384,7 +7382,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js b/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js index 097f5c59a48e11..0d953540edf3e1 100644 --- a/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +++ b/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js @@ -1661,22 +1661,8 @@ function finalizeInitialChildren(parentInstance) { return !1; } var scheduleTimeout = setTimeout, - cancelTimeout = clearTimeout; -function removeChild(parentInstance, child) { - recursivelyUncacheFiberNode(child); - var children = parentInstance._children; - child = children.indexOf(child); - children.splice(child, 1); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - [], - [], - [child] - ); -} -var BEFORE_SLASH_RE = /^(.*)[\\\/]/; + cancelTimeout = clearTimeout, + BEFORE_SLASH_RE = /^(.*)[\\\/]/; function getStackByFiberInDevAndProd(workInProgress) { var info = ""; do { @@ -2070,7 +2056,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3287,24 +3272,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3655,7 +3624,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3729,7 +3698,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3784,7 +3753,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, hydrationParentFiber = null, nextHydratableInstance = null, @@ -4003,17 +3972,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -4640,7 +4609,6 @@ var appendAllChildren = void 0, appendAllChildren = function(parent, workInProgress) { for (var node = workInProgress.child; null !== node; ) { if (5 === node.tag || 6 === node.tag) parent._children.push(node.stateNode); - else if (20 === node.tag) parent._children.push(node.stateNode.instance); else if (4 !== node.tag && null !== node.child) { node.child.return = node; node = node.child; @@ -4783,6 +4751,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -4811,7 +4788,7 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } -function commitUnmount(current$$1$jscomp$0) { +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(current$$1$jscomp$0); switch (current$$1$jscomp$0.tag) { @@ -4824,54 +4801,43 @@ function commitUnmount(current$$1$jscomp$0) { null !== updateQueue && ((updateQueue = updateQueue.lastEffect), null !== updateQueue) ) { - var effect = (updateQueue = updateQueue.next); - do { - var destroy = effect.destroy; - if (void 0 !== destroy) { - var current$$1 = current$$1$jscomp$0; - try { - destroy(); - } catch (error) { - captureCommitPhaseError(current$$1, error); - } + var firstEffect = updateQueue.next; + runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); } - effect = effect.next; - } while (effect !== updateQueue); + ); } break; case 1: safelyDetachRef(current$$1$jscomp$0); - updateQueue = current$$1$jscomp$0.stateNode; - if ("function" === typeof updateQueue.componentWillUnmount) - try { - (updateQueue.props = current$$1$jscomp$0.memoizedProps), - (updateQueue.state = current$$1$jscomp$0.memoizedState), - updateQueue.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(current$$1$jscomp$0, unmountError); - } + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); break; case 5: safelyDetachRef(current$$1$jscomp$0); break; case 4: - unmountHostComponents(current$$1$jscomp$0); + unmountHostComponents(current$$1$jscomp$0, renderPriorityLevel); } } -function commitNestedUnmounts(root) { - for (var node = root; ; ) - if ((commitUnmount(node), null !== node.child && 4 !== node.tag)) - (node.child.return = node), (node = node.child); - else { - if (node === root) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === root) return; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } -} function isHostParent(fiber) { return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; } @@ -4938,7 +4904,7 @@ function commitPlacement(finishedWork) { } for (var node = finishedWork; ; ) { var isHost = 5 === node.tag || 6 === node.tag; - if (isHost || 20 === node.tag) { + if (isHost) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (parentFiber) if (isContainer) { @@ -5022,7 +4988,7 @@ function commitPlacement(finishedWork) { node = node.sibling; } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel$jscomp$0) { for ( var node = current$$1, currentParentIsValid = !1, @@ -5058,37 +5024,56 @@ function unmountHostComponents(current$$1) { } currentParentIsValid = !0; } - if (5 === node.tag || 6 === node.tag) - if ((commitNestedUnmounts(node), currentParentIsContainer)) { - var parentInstance = currentParent; - recursivelyUncacheFiberNode(node.stateNode); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, node.stateNode); - else if (20 === node.tag) - if ( - ((parentInstance = node.stateNode.instance), - commitNestedUnmounts(node), - currentParentIsContainer) - ) { - var parentInstance$jscomp$0 = currentParent; - recursivelyUncacheFiberNode(parentInstance); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance$jscomp$0, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, parentInstance); - else if (4 === node.tag) { + if (5 === node.tag || 6 === node.tag) { + a: for ( + var root = node, + renderPriorityLevel = renderPriorityLevel$jscomp$0, + node$jscomp$0 = root; + ; + + ) + if ( + (commitUnmount(node$jscomp$0, renderPriorityLevel), + null !== node$jscomp$0.child && 4 !== node$jscomp$0.tag) + ) + (node$jscomp$0.child.return = node$jscomp$0), + (node$jscomp$0 = node$jscomp$0.child); + else { + if (node$jscomp$0 === root) break; + for (; null === node$jscomp$0.sibling; ) { + if (null === node$jscomp$0.return || node$jscomp$0.return === root) + break a; + node$jscomp$0 = node$jscomp$0.return; + } + node$jscomp$0.sibling.return = node$jscomp$0.return; + node$jscomp$0 = node$jscomp$0.sibling; + } + currentParentIsContainer + ? ((root = currentParent), + recursivelyUncacheFiberNode(node.stateNode), + ReactNativePrivateInterface.UIManager.manageChildren( + root, + [], + [], + [], + [], + [0] + )) + : ((root = currentParent), + (node$jscomp$0 = node.stateNode), + recursivelyUncacheFiberNode(node$jscomp$0), + (renderPriorityLevel = root._children), + (node$jscomp$0 = renderPriorityLevel.indexOf(node$jscomp$0)), + renderPriorityLevel.splice(node$jscomp$0, 1), + ReactNativePrivateInterface.UIManager.manageChildren( + root._nativeTag, + [], + [], + [], + [], + [node$jscomp$0] + )); + } else if (4 === node.tag) { if (null !== node.child) { currentParent = node.stateNode.containerInfo; currentParentIsContainer = !0; @@ -5096,7 +5081,9 @@ function unmountHostComponents(current$$1) { node = node.child; continue; } - } else if ((commitUnmount(node), null !== node.child)) { + } else if ( + (commitUnmount(node, renderPriorityLevel$jscomp$0), null !== node.child) + ) { node.child.return = node; node = node.child; continue; @@ -5325,6 +5312,8 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, + pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, rootWithNestedUpdates = null, @@ -5958,7 +5947,7 @@ function completeUnitOfWork(unitOfWork) { else if (newProps) { current = requiredContext(contextStackCursor$1.current); var type$jscomp$0 = type; - var _instance5 = newProps; + var _instance6 = newProps; var rootContainerInstance = renderExpirationTime$jscomp$0, internalInstanceHandle = current$$1, tag = allocateTag(); @@ -5966,7 +5955,7 @@ function completeUnitOfWork(unitOfWork) { var updatePayload = diffProperties( null, emptyObject, - _instance5, + _instance6, type$jscomp$0.validAttributes ); ReactNativePrivateInterface.UIManager.createView( @@ -5980,17 +5969,17 @@ function completeUnitOfWork(unitOfWork) { type$jscomp$0 ); instanceCache.set(tag, internalInstanceHandle); - instanceProps.set(tag, _instance5); - _instance5 = rootContainerInstance; - appendAllChildren(_instance5, current$$1, !1, !1); + instanceProps.set(tag, _instance6); + _instance6 = rootContainerInstance; + appendAllChildren(_instance6, current$$1, !1, !1); finalizeInitialChildren( - _instance5, + _instance6, type, newProps, renderExpirationTime$jscomp$0, current ) && (current$$1.effectTag |= 4); - current$$1.stateNode = _instance5; + current$$1.stateNode = _instance6; null !== current$$1.ref && (current$$1.effectTag |= 128); } else if (null === current$$1.stateNode) throw ReactError( @@ -6054,10 +6043,10 @@ function completeUnitOfWork(unitOfWork) { null === type || ((type = current.child.sibling), null !== type && - ((_instance5 = current$$1.firstEffect), - null !== _instance5 + ((_instance6 = current$$1.firstEffect), + null !== _instance6 ? ((current$$1.firstEffect = type), - (type.nextEffect = _instance5)) + (type.nextEffect = _instance6)) : ((current$$1.firstEffect = current$$1.lastEffect = type), (type.nextEffect = null)), (type.effectTag = 8)))); @@ -6109,8 +6098,8 @@ function completeUnitOfWork(unitOfWork) { newProps = current$$1.memoizedState; if (null === newProps) break; type = 0 !== (current$$1.effectTag & 64); - _instance5 = newProps.rendering; - if (null === _instance5) + _instance6 = newProps.rendering; + if (null === _instance6) if (type) cutOffTailIfNeeded(newProps, !1); else { if ( @@ -6118,11 +6107,11 @@ function completeUnitOfWork(unitOfWork) { (null !== current && 0 !== (current.effectTag & 64)) ) for (current = current$$1.child; null !== current; ) { - _instance5 = findFirstSuspended(current); - if (null !== _instance5) { + _instance6 = findFirstSuspended(current); + if (null !== _instance6) { current$$1.effectTag |= 64; cutOffTailIfNeeded(newProps, !1); - newProps = _instance5.updateQueue; + newProps = _instance6.updateQueue; null !== newProps && ((current$$1.updateQueue = newProps), (current$$1.effectTag |= 4)); @@ -6135,9 +6124,9 @@ function completeUnitOfWork(unitOfWork) { (renderExpirationTime$jscomp$0.nextEffect = null), (renderExpirationTime$jscomp$0.firstEffect = null), (renderExpirationTime$jscomp$0.lastEffect = null), - (_instance5 = + (_instance6 = renderExpirationTime$jscomp$0.alternate), - null === _instance5 + null === _instance6 ? ((renderExpirationTime$jscomp$0.childExpirationTime = 0), (renderExpirationTime$jscomp$0.expirationTime = type), (renderExpirationTime$jscomp$0.child = null), @@ -6146,25 +6135,24 @@ function completeUnitOfWork(unitOfWork) { (renderExpirationTime$jscomp$0.updateQueue = null), (renderExpirationTime$jscomp$0.dependencies = null)) : ((renderExpirationTime$jscomp$0.childExpirationTime = - _instance5.childExpirationTime), + _instance6.childExpirationTime), (renderExpirationTime$jscomp$0.expirationTime = - _instance5.expirationTime), + _instance6.expirationTime), (renderExpirationTime$jscomp$0.child = - _instance5.child), + _instance6.child), (renderExpirationTime$jscomp$0.memoizedProps = - _instance5.memoizedProps), + _instance6.memoizedProps), (renderExpirationTime$jscomp$0.memoizedState = - _instance5.memoizedState), + _instance6.memoizedState), (renderExpirationTime$jscomp$0.updateQueue = - _instance5.updateQueue), - (type = _instance5.dependencies), + _instance6.updateQueue), + (type = _instance6.dependencies), (renderExpirationTime$jscomp$0.dependencies = null === type ? null : { expirationTime: type.expirationTime, firstContext: type.firstContext, - listeners: type.listeners, responders: type.responders })), (current = current.sibling); @@ -6184,7 +6172,7 @@ function completeUnitOfWork(unitOfWork) { else { if (!type) if ( - ((current = findFirstSuspended(_instance5)), null !== current) + ((current = findFirstSuspended(_instance6)), null !== current) ) { if ( ((current$$1.effectTag |= 64), @@ -6209,13 +6197,13 @@ function completeUnitOfWork(unitOfWork) { (current$$1.expirationTime = current$$1.childExpirationTime = renderExpirationTime$jscomp$0 - 1)); newProps.isBackwards - ? ((_instance5.sibling = current$$1.child), - (current$$1.child = _instance5)) + ? ((_instance6.sibling = current$$1.child), + (current$$1.child = _instance6)) : ((current = newProps.last), null !== current - ? (current.sibling = _instance5) - : (current$$1.child = _instance5), - (newProps.last = _instance5)); + ? (current.sibling = _instance6) + : (current$$1.child = _instance6), + (newProps.last = _instance6)); } if (null !== newProps.tail) { 0 === newProps.tailExpiration && @@ -6255,9 +6243,9 @@ function completeUnitOfWork(unitOfWork) { ) (type = renderExpirationTime$jscomp$0.expirationTime), - (_instance5 = renderExpirationTime$jscomp$0.childExpirationTime), + (_instance6 = renderExpirationTime$jscomp$0.childExpirationTime), type > current && (current = type), - _instance5 > current && (current = _instance5), + _instance6 > current && (current = _instance6), (renderExpirationTime$jscomp$0 = renderExpirationTime$jscomp$0.sibling); newProps.childExpirationTime = current; @@ -6293,16 +6281,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6404,7 +6392,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6430,14 +6418,14 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - unmountHostComponents(current$$1); - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps = nextEffect; + unmountHostComponents(prevProps, current$$1); + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6575,24 +6563,27 @@ function commitRootImpl(root) { executionContext = childExpirationTimeBeforeCommit; } else root.current = finishedWork; if (rootDoesHavePassiveEffects) - (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root); + (rootDoesHavePassiveEffects = !1), + (rootWithPendingPassiveEffects = root), + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (effectTag$jscomp$0 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = effectTag$jscomp$0); - effectTag$jscomp$0 = root.firstPendingTime; - 0 !== effectTag$jscomp$0 - ? ((current$$1$jscomp$1 = requestCurrentTime()), - (current$$1$jscomp$1 = inferPriorityFromExpirationTime( - current$$1$jscomp$1, - effectTag$jscomp$0 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + 0 !== renderPriorityLevel + ? ((effectTag$jscomp$0 = requestCurrentTime()), + (effectTag$jscomp$0 = inferPriorityFromExpirationTime( + effectTag$jscomp$0, + renderPriorityLevel )), - scheduleCallbackForRoot(root, current$$1$jscomp$1, effectTag$jscomp$0)) + scheduleCallbackForRoot(root, effectTag$jscomp$0, renderPriorityLevel)) : (legacyErrorBoundariesThatAlreadyFailed = null); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === effectTag$jscomp$0 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6608,8 +6599,18 @@ function commitRootImpl(root) { } function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; - var root = rootWithPendingPassiveEffects; + var root = rootWithPendingPassiveEffects, + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; + pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root) { if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError( Error("Cannot flush passive effects while already rendering.") @@ -6767,32 +6768,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6811,25 +6806,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6838,8 +6833,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6850,9 +6845,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -6872,28 +6867,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6902,7 +6897,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6911,7 +6906,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -6920,8 +6915,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -6930,7 +6925,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -6939,32 +6934,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -6977,8 +6972,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -6987,7 +6982,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -7051,16 +7046,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7097,9 +7092,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -7113,7 +7108,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7195,7 +7190,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7203,12 +7198,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7220,16 +7218,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7247,11 +7245,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7264,13 +7262,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7384,7 +7382,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js b/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js index 2d278cf341ea20..07581c709acadc 100644 --- a/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js +++ b/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js @@ -1662,22 +1662,8 @@ function finalizeInitialChildren(parentInstance) { return !1; } var scheduleTimeout = setTimeout, - cancelTimeout = clearTimeout; -function removeChild(parentInstance, child) { - recursivelyUncacheFiberNode(child); - var children = parentInstance._children; - child = children.indexOf(child); - children.splice(child, 1); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - [], - [], - [child] - ); -} -var BEFORE_SLASH_RE = /^(.*)[\\\/]/; + cancelTimeout = clearTimeout, + BEFORE_SLASH_RE = /^(.*)[\\\/]/; function getStackByFiberInDevAndProd(workInProgress) { var info = ""; do { @@ -2080,7 +2066,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3297,24 +3282,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3665,7 +3634,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3739,7 +3708,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3794,7 +3763,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, now$1 = Scheduler.unstable_now, commitTime = 0, @@ -4024,17 +3993,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -4684,7 +4653,6 @@ var appendAllChildren = void 0, appendAllChildren = function(parent, workInProgress) { for (var node = workInProgress.child; null !== node; ) { if (5 === node.tag || 6 === node.tag) parent._children.push(node.stateNode); - else if (20 === node.tag) parent._children.push(node.stateNode.instance); else if (4 !== node.tag && null !== node.child) { node.child.return = node; node = node.child; @@ -4963,7 +4931,6 @@ function completeWork(current, workInProgress, renderExpirationTime) { : { expirationTime: tag.expirationTime, firstContext: tag.firstContext, - listeners: tag.listeners, responders: tag.responders }), (rootContainerInstance.selfBaseDuration = @@ -5140,6 +5107,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -5168,7 +5144,7 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } -function commitUnmount(current$$1$jscomp$0) { +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(current$$1$jscomp$0); switch (current$$1$jscomp$0.tag) { @@ -5181,54 +5157,43 @@ function commitUnmount(current$$1$jscomp$0) { null !== updateQueue && ((updateQueue = updateQueue.lastEffect), null !== updateQueue) ) { - var effect = (updateQueue = updateQueue.next); - do { - var destroy = effect.destroy; - if (void 0 !== destroy) { - var current$$1 = current$$1$jscomp$0; - try { - destroy(); - } catch (error) { - captureCommitPhaseError(current$$1, error); - } + var firstEffect = updateQueue.next; + runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); } - effect = effect.next; - } while (effect !== updateQueue); + ); } break; case 1: safelyDetachRef(current$$1$jscomp$0); - updateQueue = current$$1$jscomp$0.stateNode; - if ("function" === typeof updateQueue.componentWillUnmount) - try { - (updateQueue.props = current$$1$jscomp$0.memoizedProps), - (updateQueue.state = current$$1$jscomp$0.memoizedState), - updateQueue.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(current$$1$jscomp$0, unmountError); - } + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); break; case 5: safelyDetachRef(current$$1$jscomp$0); break; case 4: - unmountHostComponents(current$$1$jscomp$0); + unmountHostComponents(current$$1$jscomp$0, renderPriorityLevel); } } -function commitNestedUnmounts(root) { - for (var node = root; ; ) - if ((commitUnmount(node), null !== node.child && 4 !== node.tag)) - (node.child.return = node), (node = node.child); - else { - if (node === root) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === root) return; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } -} function isHostParent(fiber) { return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; } @@ -5295,7 +5260,7 @@ function commitPlacement(finishedWork) { } for (var node = finishedWork; ; ) { var isHost = 5 === node.tag || 6 === node.tag; - if (isHost || 20 === node.tag) { + if (isHost) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (parentFiber) if (isContainer) { @@ -5379,7 +5344,7 @@ function commitPlacement(finishedWork) { node = node.sibling; } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel$jscomp$0) { for ( var node = current$$1, currentParentIsValid = !1, @@ -5415,37 +5380,56 @@ function unmountHostComponents(current$$1) { } currentParentIsValid = !0; } - if (5 === node.tag || 6 === node.tag) - if ((commitNestedUnmounts(node), currentParentIsContainer)) { - var parentInstance = currentParent; - recursivelyUncacheFiberNode(node.stateNode); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, node.stateNode); - else if (20 === node.tag) - if ( - ((parentInstance = node.stateNode.instance), - commitNestedUnmounts(node), - currentParentIsContainer) - ) { - var parentInstance$jscomp$0 = currentParent; - recursivelyUncacheFiberNode(parentInstance); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance$jscomp$0, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, parentInstance); - else if (4 === node.tag) { + if (5 === node.tag || 6 === node.tag) { + a: for ( + var root = node, + renderPriorityLevel = renderPriorityLevel$jscomp$0, + node$jscomp$0 = root; + ; + + ) + if ( + (commitUnmount(node$jscomp$0, renderPriorityLevel), + null !== node$jscomp$0.child && 4 !== node$jscomp$0.tag) + ) + (node$jscomp$0.child.return = node$jscomp$0), + (node$jscomp$0 = node$jscomp$0.child); + else { + if (node$jscomp$0 === root) break; + for (; null === node$jscomp$0.sibling; ) { + if (null === node$jscomp$0.return || node$jscomp$0.return === root) + break a; + node$jscomp$0 = node$jscomp$0.return; + } + node$jscomp$0.sibling.return = node$jscomp$0.return; + node$jscomp$0 = node$jscomp$0.sibling; + } + currentParentIsContainer + ? ((root = currentParent), + recursivelyUncacheFiberNode(node.stateNode), + ReactNativePrivateInterface.UIManager.manageChildren( + root, + [], + [], + [], + [], + [0] + )) + : ((root = currentParent), + (node$jscomp$0 = node.stateNode), + recursivelyUncacheFiberNode(node$jscomp$0), + (renderPriorityLevel = root._children), + (node$jscomp$0 = renderPriorityLevel.indexOf(node$jscomp$0)), + renderPriorityLevel.splice(node$jscomp$0, 1), + ReactNativePrivateInterface.UIManager.manageChildren( + root._nativeTag, + [], + [], + [], + [], + [node$jscomp$0] + )); + } else if (4 === node.tag) { if (null !== node.child) { currentParent = node.stateNode.containerInfo; currentParentIsContainer = !0; @@ -5453,7 +5437,9 @@ function unmountHostComponents(current$$1) { node = node.child; continue; } - } else if ((commitUnmount(node), null !== node.child)) { + } else if ( + (commitUnmount(node, renderPriorityLevel$jscomp$0), null !== node.child) + ) { node.child.return = node; node = node.child; continue; @@ -5684,6 +5670,7 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, @@ -6390,16 +6377,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6504,7 +6491,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6530,14 +6517,14 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - unmountHostComponents(current$$1); - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps = nextEffect; + unmountHostComponents(prevProps, current$$1); + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6689,38 +6676,39 @@ function commitRootImpl(root) { if ((effectTag$jscomp$0 = rootDoesHavePassiveEffects)) (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root), - (pendingPassiveEffectsExpirationTime = expirationTime); + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (current$$1$jscomp$1 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = current$$1$jscomp$1); - current$$1$jscomp$1 = root.firstPendingTime; - if (0 !== current$$1$jscomp$1) { - instance$jscomp$0 = requestCurrentTime(); - instance$jscomp$0 = inferPriorityFromExpirationTime( - instance$jscomp$0, - current$$1$jscomp$1 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + if (0 !== renderPriorityLevel) { + current$$1$jscomp$1 = requestCurrentTime(); + current$$1$jscomp$1 = inferPriorityFromExpirationTime( + current$$1$jscomp$1, + renderPriorityLevel ); if (null !== spawnedWorkDuringRender) for ( - prevProps$jscomp$0 = spawnedWorkDuringRender, + instance$jscomp$0 = spawnedWorkDuringRender, spawnedWorkDuringRender = null, - updateQueue = 0; - updateQueue < prevProps$jscomp$0.length; - updateQueue++ + prevProps$jscomp$0 = 0; + prevProps$jscomp$0 < instance$jscomp$0.length; + prevProps$jscomp$0++ ) scheduleInteractions( root, - prevProps$jscomp$0[updateQueue], + instance$jscomp$0[prevProps$jscomp$0], root.memoizedInteractions ); - scheduleCallbackForRoot(root, instance$jscomp$0, current$$1$jscomp$1); + scheduleCallbackForRoot(root, current$$1$jscomp$1, renderPriorityLevel); } else legacyErrorBoundariesThatAlreadyFailed = null; effectTag$jscomp$0 || finishPendingInteractions(root, expirationTime); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === current$$1$jscomp$1 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6737,9 +6725,17 @@ function commitRootImpl(root) { function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; var root = rootWithPendingPassiveEffects, - expirationTime = pendingPassiveEffectsExpirationTime; + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = tracing.__interactionsRef.current; tracing.__interactionsRef.current = root.memoizedInteractions; if ((executionContext & (RenderContext | CommitContext)) !== NoContext) @@ -6904,32 +6900,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6948,25 +6938,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6975,8 +6965,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6987,9 +6977,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -7009,28 +6999,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -7039,7 +7029,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -7048,7 +7038,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -7057,8 +7047,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -7067,7 +7057,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -7076,32 +7066,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7114,8 +7104,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -7124,7 +7114,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -7188,16 +7178,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7235,9 +7225,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -7251,7 +7241,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7333,7 +7323,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7341,12 +7331,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7358,16 +7351,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7385,11 +7378,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7402,13 +7395,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7614,7 +7607,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js b/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js index e32498979c427b..f0f9fac5063b6c 100644 --- a/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +++ b/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js @@ -1662,22 +1662,8 @@ function finalizeInitialChildren(parentInstance) { return !1; } var scheduleTimeout = setTimeout, - cancelTimeout = clearTimeout; -function removeChild(parentInstance, child) { - recursivelyUncacheFiberNode(child); - var children = parentInstance._children; - child = children.indexOf(child); - children.splice(child, 1); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - [], - [], - [child] - ); -} -var BEFORE_SLASH_RE = /^(.*)[\\\/]/; + cancelTimeout = clearTimeout, + BEFORE_SLASH_RE = /^(.*)[\\\/]/; function getStackByFiberInDevAndProd(workInProgress) { var info = ""; do { @@ -2080,7 +2066,6 @@ function readContext(context, observedBits) { currentlyRenderingFiber.dependencies = { expirationTime: 0, firstContext: observedBits, - listeners: null, responders: null }; } else lastContextDependency = lastContextDependency.next = observedBits; @@ -3297,24 +3282,8 @@ function findFirstSuspended(row) { } return null; } -var currentListenerHookIndex = 0; -function updateListenerHook(responder, props) { - var dependencies = null.dependencies; - null === dependencies && - (dependencies = null.dependencies = { - expirationTime: 0, - firstContext: null, - listeners: [], - responders: null - }); - var listeners = dependencies.listeners; - null === listeners && (dependencies.listeners = listeners = []); - listeners.length === currentListenerHookIndex - ? (listeners.push({ responder: responder, props: props }), - currentListenerHookIndex++) - : ((listeners = listeners[currentListenerHookIndex++]), - (listeners.responder = responder), - (listeners.props = props)); +function createResponderListener(responder, props) { + return { responder: responder, props: props }; } var NoEffect$1 = 0, UnmountSnapshot = 2, @@ -3665,7 +3634,7 @@ var ContextOnlyDispatcher = { useRef: throwInvalidHookError, useState: throwInvalidHookError, useDebugValue: throwInvalidHookError, - useListener: throwInvalidHookError + useResponder: throwInvalidHookError }, HooksDispatcherOnMount = { readContext: readContext, @@ -3739,7 +3708,7 @@ var ContextOnlyDispatcher = { return [hook.memoizedState, initialState]; }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, HooksDispatcherOnUpdate = { readContext: readContext, @@ -3794,7 +3763,7 @@ var ContextOnlyDispatcher = { return updateReducer(basicStateReducer, initialState); }, useDebugValue: mountDebugValue, - useListener: updateListenerHook + useResponder: createResponderListener }, now$1 = Scheduler.unstable_now, commitTime = 0, @@ -4024,17 +3993,17 @@ function updateFunctionComponent( nextProps, renderExpirationTime ) { - var unmaskedContext = isContextProvider(Component) + var context = isContextProvider(Component) ? previousContext : contextStackCursor.current; - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + context = getMaskedContext(workInProgress, context); prepareToReadContext(workInProgress, renderExpirationTime); Component = renderWithHooks( current$$1, workInProgress, Component, nextProps, - unmaskedContext, + context, renderExpirationTime ); if (null !== current$$1 && !didReceiveUpdate) @@ -4684,7 +4653,6 @@ var appendAllChildren = void 0, appendAllChildren = function(parent, workInProgress) { for (var node = workInProgress.child; null !== node; ) { if (5 === node.tag || 6 === node.tag) parent._children.push(node.stateNode); - else if (20 === node.tag) parent._children.push(node.stateNode.instance); else if (4 !== node.tag && null !== node.child) { node.child.return = node; node = node.child; @@ -4963,7 +4931,6 @@ function completeWork(current, workInProgress, renderExpirationTime) { : { expirationTime: tag.expirationTime, firstContext: tag.firstContext, - listeners: tag.listeners, responders: tag.responders }), (rootContainerInstance.selfBaseDuration = @@ -5140,6 +5107,15 @@ function logError(boundary, errorInfo) { }); } } +function safelyCallComponentWillUnmount(current$$1, instance) { + try { + (instance.props = current$$1.memoizedProps), + (instance.state = current$$1.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1, unmountError); + } +} function safelyDetachRef(current$$1) { var ref = current$$1.ref; if (null !== ref) @@ -5168,7 +5144,7 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { } while (effect !== finishedWork); } } -function commitUnmount(current$$1$jscomp$0) { +function commitUnmount(current$$1$jscomp$0, renderPriorityLevel) { "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(current$$1$jscomp$0); switch (current$$1$jscomp$0.tag) { @@ -5181,54 +5157,43 @@ function commitUnmount(current$$1$jscomp$0) { null !== updateQueue && ((updateQueue = updateQueue.lastEffect), null !== updateQueue) ) { - var effect = (updateQueue = updateQueue.next); - do { - var destroy = effect.destroy; - if (void 0 !== destroy) { - var current$$1 = current$$1$jscomp$0; - try { - destroy(); - } catch (error) { - captureCommitPhaseError(current$$1, error); - } + var firstEffect = updateQueue.next; + runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + function() { + var effect = firstEffect; + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1, error); + } + } + effect = effect.next; + } while (effect !== firstEffect); } - effect = effect.next; - } while (effect !== updateQueue); + ); } break; case 1: safelyDetachRef(current$$1$jscomp$0); - updateQueue = current$$1$jscomp$0.stateNode; - if ("function" === typeof updateQueue.componentWillUnmount) - try { - (updateQueue.props = current$$1$jscomp$0.memoizedProps), - (updateQueue.state = current$$1$jscomp$0.memoizedState), - updateQueue.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError(current$$1$jscomp$0, unmountError); - } + renderPriorityLevel = current$$1$jscomp$0.stateNode; + "function" === typeof renderPriorityLevel.componentWillUnmount && + safelyCallComponentWillUnmount( + current$$1$jscomp$0, + renderPriorityLevel + ); break; case 5: safelyDetachRef(current$$1$jscomp$0); break; case 4: - unmountHostComponents(current$$1$jscomp$0); + unmountHostComponents(current$$1$jscomp$0, renderPriorityLevel); } } -function commitNestedUnmounts(root) { - for (var node = root; ; ) - if ((commitUnmount(node), null !== node.child && 4 !== node.tag)) - (node.child.return = node), (node = node.child); - else { - if (node === root) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === root) return; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } -} function isHostParent(fiber) { return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; } @@ -5295,7 +5260,7 @@ function commitPlacement(finishedWork) { } for (var node = finishedWork; ; ) { var isHost = 5 === node.tag || 6 === node.tag; - if (isHost || 20 === node.tag) { + if (isHost) { var stateNode = isHost ? node.stateNode : node.stateNode.instance; if (parentFiber) if (isContainer) { @@ -5379,7 +5344,7 @@ function commitPlacement(finishedWork) { node = node.sibling; } } -function unmountHostComponents(current$$1) { +function unmountHostComponents(current$$1, renderPriorityLevel$jscomp$0) { for ( var node = current$$1, currentParentIsValid = !1, @@ -5415,37 +5380,56 @@ function unmountHostComponents(current$$1) { } currentParentIsValid = !0; } - if (5 === node.tag || 6 === node.tag) - if ((commitNestedUnmounts(node), currentParentIsContainer)) { - var parentInstance = currentParent; - recursivelyUncacheFiberNode(node.stateNode); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, node.stateNode); - else if (20 === node.tag) - if ( - ((parentInstance = node.stateNode.instance), - commitNestedUnmounts(node), - currentParentIsContainer) - ) { - var parentInstance$jscomp$0 = currentParent; - recursivelyUncacheFiberNode(parentInstance); - ReactNativePrivateInterface.UIManager.manageChildren( - parentInstance$jscomp$0, - [], - [], - [], - [], - [0] - ); - } else removeChild(currentParent, parentInstance); - else if (4 === node.tag) { + if (5 === node.tag || 6 === node.tag) { + a: for ( + var root = node, + renderPriorityLevel = renderPriorityLevel$jscomp$0, + node$jscomp$0 = root; + ; + + ) + if ( + (commitUnmount(node$jscomp$0, renderPriorityLevel), + null !== node$jscomp$0.child && 4 !== node$jscomp$0.tag) + ) + (node$jscomp$0.child.return = node$jscomp$0), + (node$jscomp$0 = node$jscomp$0.child); + else { + if (node$jscomp$0 === root) break; + for (; null === node$jscomp$0.sibling; ) { + if (null === node$jscomp$0.return || node$jscomp$0.return === root) + break a; + node$jscomp$0 = node$jscomp$0.return; + } + node$jscomp$0.sibling.return = node$jscomp$0.return; + node$jscomp$0 = node$jscomp$0.sibling; + } + currentParentIsContainer + ? ((root = currentParent), + recursivelyUncacheFiberNode(node.stateNode), + ReactNativePrivateInterface.UIManager.manageChildren( + root, + [], + [], + [], + [], + [0] + )) + : ((root = currentParent), + (node$jscomp$0 = node.stateNode), + recursivelyUncacheFiberNode(node$jscomp$0), + (renderPriorityLevel = root._children), + (node$jscomp$0 = renderPriorityLevel.indexOf(node$jscomp$0)), + renderPriorityLevel.splice(node$jscomp$0, 1), + ReactNativePrivateInterface.UIManager.manageChildren( + root._nativeTag, + [], + [], + [], + [], + [node$jscomp$0] + )); + } else if (4 === node.tag) { if (null !== node.child) { currentParent = node.stateNode.containerInfo; currentParentIsContainer = !0; @@ -5453,7 +5437,9 @@ function unmountHostComponents(current$$1) { node = node.child; continue; } - } else if ((commitUnmount(node), null !== node.child)) { + } else if ( + (commitUnmount(node, renderPriorityLevel$jscomp$0), null !== node.child) + ) { node.child.return = node; node = node.child; continue; @@ -5684,6 +5670,7 @@ var ceil = Math.ceil, legacyErrorBoundariesThatAlreadyFailed = null, rootDoesHavePassiveEffects = !1, rootWithPendingPassiveEffects = null, + pendingPassiveEffectsRenderPriority = 90, pendingPassiveEffectsExpirationTime = 0, rootsWithPendingDiscreteUpdates = null, nestedUpdateCount = 0, @@ -6390,16 +6377,16 @@ function completeUnitOfWork(unitOfWork) { return null; } function commitRoot(root) { - runWithPriority(99, commitRootImpl.bind(null, root)); + var renderPriorityLevel = getCurrentPriorityLevel(); + runWithPriority(99, commitRootImpl.bind(null, root, renderPriorityLevel)); null !== rootWithPendingPassiveEffects && - ((root = getCurrentPriorityLevel()), - scheduleCallback(root, function() { + scheduleCallback(97, function() { flushPassiveEffects(); return null; - })); + }); return null; } -function commitRootImpl(root) { +function commitRootImpl(root, renderPriorityLevel) { flushPassiveEffects(); if ((executionContext & (RenderContext | CommitContext)) !== NoContext) throw ReactError(Error("Should not already be working.")); @@ -6504,7 +6491,7 @@ function commitRootImpl(root) { nextEffect = updateExpirationTimeBeforeCommit; do try { - for (; null !== nextEffect; ) { + for (current$$1 = renderPriorityLevel; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; if (effectTag & 128) { var current$$1$jscomp$0 = nextEffect.alternate; @@ -6530,14 +6517,14 @@ function commitRootImpl(root) { commitWork(nextEffect.alternate, nextEffect); break; case 8: - current$$1 = nextEffect; - unmountHostComponents(current$$1); - current$$1.return = null; - current$$1.child = null; - current$$1.memoizedState = null; - current$$1.updateQueue = null; - current$$1.dependencies = null; - var alternate = current$$1.alternate; + prevProps = nextEffect; + unmountHostComponents(prevProps, current$$1); + prevProps.return = null; + prevProps.child = null; + prevProps.memoizedState = null; + prevProps.updateQueue = null; + prevProps.dependencies = null; + var alternate = prevProps.alternate; null !== alternate && ((alternate.return = null), (alternate.child = null), @@ -6689,38 +6676,39 @@ function commitRootImpl(root) { if ((effectTag$jscomp$0 = rootDoesHavePassiveEffects)) (rootDoesHavePassiveEffects = !1), (rootWithPendingPassiveEffects = root), - (pendingPassiveEffectsExpirationTime = expirationTime); + (pendingPassiveEffectsExpirationTime = expirationTime), + (pendingPassiveEffectsRenderPriority = renderPriorityLevel); else for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) - (current$$1$jscomp$1 = nextEffect.nextEffect), + (renderPriorityLevel = nextEffect.nextEffect), (nextEffect.nextEffect = null), - (nextEffect = current$$1$jscomp$1); - current$$1$jscomp$1 = root.firstPendingTime; - if (0 !== current$$1$jscomp$1) { - instance$jscomp$0 = requestCurrentTime(); - instance$jscomp$0 = inferPriorityFromExpirationTime( - instance$jscomp$0, - current$$1$jscomp$1 + (nextEffect = renderPriorityLevel); + renderPriorityLevel = root.firstPendingTime; + if (0 !== renderPriorityLevel) { + current$$1$jscomp$1 = requestCurrentTime(); + current$$1$jscomp$1 = inferPriorityFromExpirationTime( + current$$1$jscomp$1, + renderPriorityLevel ); if (null !== spawnedWorkDuringRender) for ( - prevProps$jscomp$0 = spawnedWorkDuringRender, + instance$jscomp$0 = spawnedWorkDuringRender, spawnedWorkDuringRender = null, - updateQueue = 0; - updateQueue < prevProps$jscomp$0.length; - updateQueue++ + prevProps$jscomp$0 = 0; + prevProps$jscomp$0 < instance$jscomp$0.length; + prevProps$jscomp$0++ ) scheduleInteractions( root, - prevProps$jscomp$0[updateQueue], + instance$jscomp$0[prevProps$jscomp$0], root.memoizedInteractions ); - scheduleCallbackForRoot(root, instance$jscomp$0, current$$1$jscomp$1); + scheduleCallbackForRoot(root, current$$1$jscomp$1, renderPriorityLevel); } else legacyErrorBoundariesThatAlreadyFailed = null; effectTag$jscomp$0 || finishPendingInteractions(root, expirationTime); "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode, expirationTime); - 1073741823 === current$$1$jscomp$1 + 1073741823 === renderPriorityLevel ? root === rootWithNestedUpdates ? nestedUpdateCount++ : ((nestedUpdateCount = 0), (rootWithNestedUpdates = root)) @@ -6737,9 +6725,17 @@ function commitRootImpl(root) { function flushPassiveEffects() { if (null === rootWithPendingPassiveEffects) return !1; var root = rootWithPendingPassiveEffects, - expirationTime = pendingPassiveEffectsExpirationTime; + expirationTime = pendingPassiveEffectsExpirationTime, + renderPriorityLevel = pendingPassiveEffectsRenderPriority; rootWithPendingPassiveEffects = null; pendingPassiveEffectsExpirationTime = 0; + pendingPassiveEffectsRenderPriority = 90; + return runWithPriority( + 97 < renderPriorityLevel ? 97 : renderPriorityLevel, + flushPassiveEffectsImpl.bind(null, root, expirationTime) + ); +} +function flushPassiveEffectsImpl(root, expirationTime) { var prevInteractions = tracing.__interactionsRef.current; tracing.__interactionsRef.current = root.memoizedInteractions; if ((executionContext & (RenderContext | CommitContext)) !== NoContext) @@ -6904,32 +6900,26 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); break; case 19: - updateExpirationTime = 0 !== (current$$1.effectTag & 64); - if (workInProgress.childExpirationTime < renderExpirationTime) - return ( - push( - suspenseStackCursor, - suspenseStackCursor.current, - workInProgress - ), - updateExpirationTime && (workInProgress.effectTag |= 64), - null - ); - if (updateExpirationTime) - return updateSuspenseListComponent( - current$$1, - workInProgress, - renderExpirationTime - ); - updateExpirationTime = workInProgress.memoizedState; - null !== updateExpirationTime && - ((updateExpirationTime.rendering = null), - (updateExpirationTime.tail = null)); + updateExpirationTime = + workInProgress.childExpirationTime >= renderExpirationTime; + if (0 !== (current$$1.effectTag & 64)) { + if (updateExpirationTime) + return updateSuspenseListComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress.effectTag |= 64; + } + var renderState = workInProgress.memoizedState; + null !== renderState && + ((renderState.rendering = null), (renderState.tail = null)); push( suspenseStackCursor, suspenseStackCursor.current, workInProgress ); + if (!updateExpirationTime) return null; } return bailoutOnAlreadyFinishedWork( current$$1, @@ -6948,25 +6938,25 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - var context = getMaskedContext( + renderState = getMaskedContext( workInProgress, contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = renderWithHooks( + renderState = renderWithHooks( null, workInProgress, updateExpirationTime, current$$1, - context, + renderState, renderExpirationTime ); workInProgress.effectTag |= 1; if ( - "object" === typeof context && - null !== context && - "function" === typeof context.render && - void 0 === context.$$typeof + "object" === typeof renderState && + null !== renderState && + "function" === typeof renderState.render && + void 0 === renderState.$$typeof ) { workInProgress.tag = 1; resetHooks(); @@ -6975,8 +6965,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { pushContextProvider(workInProgress); } else hasContext = !1; workInProgress.memoizedState = - null !== context.state && void 0 !== context.state - ? context.state + null !== renderState.state && void 0 !== renderState.state + ? renderState.state : null; var getDerivedStateFromProps = updateExpirationTime.getDerivedStateFromProps; @@ -6987,9 +6977,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { getDerivedStateFromProps, current$$1 ); - context.updater = classComponentUpdater; - workInProgress.stateNode = context; - context._reactInternalFiber = workInProgress; + renderState.updater = classComponentUpdater; + workInProgress.stateNode = renderState; + renderState._reactInternalFiber = workInProgress; mountClassInstance( workInProgress, updateExpirationTime, @@ -7009,28 +6999,28 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( null, workInProgress, - context, + renderState, renderExpirationTime ), (workInProgress = workInProgress.child); return workInProgress; case 16: - context = workInProgress.elementType; + renderState = workInProgress.elementType; null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), (workInProgress.effectTag |= 2)); current$$1 = workInProgress.pendingProps; - context = readLazyComponentType(context); - workInProgress.type = context; - hasContext = workInProgress.tag = resolveLazyComponentTag(context); - current$$1 = resolveDefaultProps(context, current$$1); + renderState = readLazyComponentType(renderState); + workInProgress.type = renderState; + hasContext = workInProgress.tag = resolveLazyComponentTag(renderState); + current$$1 = resolveDefaultProps(renderState, current$$1); switch (hasContext) { case 0: workInProgress = updateFunctionComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -7039,7 +7029,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateClassComponent( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -7048,7 +7038,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateForwardRef( null, workInProgress, - context, + renderState, current$$1, renderExpirationTime ); @@ -7057,8 +7047,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { workInProgress = updateMemoComponent( null, workInProgress, - context, - resolveDefaultProps(context.type, current$$1), + renderState, + resolveDefaultProps(renderState.type, current$$1), updateExpirationTime, renderExpirationTime ); @@ -7067,7 +7057,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { throw ReactError( Error( "Element type is invalid. Received a promise that resolves to: " + - context + + renderState + ". Lazy element type must resolve to a class or function." ) ); @@ -7076,32 +7066,32 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 0: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateFunctionComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); case 1: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateClassComponent( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7114,8 +7104,8 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { "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." ) ); - context = workInProgress.memoizedState; - context = null !== context ? context.element : null; + renderState = workInProgress.memoizedState; + renderState = null !== renderState ? renderState.element : null; processUpdateQueue( workInProgress, updateExpirationTime, @@ -7124,7 +7114,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); updateExpirationTime = workInProgress.memoizedState.element; - updateExpirationTime === context + updateExpirationTime === renderState ? (workInProgress = bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -7188,16 +7178,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 11: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), updateForwardRef( current$$1, workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ) ); @@ -7235,9 +7225,9 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 10: a: { updateExpirationTime = workInProgress.type._context; - context = workInProgress.pendingProps; + renderState = workInProgress.pendingProps; getDerivedStateFromProps = workInProgress.memoizedProps; - hasContext = context.value; + hasContext = renderState.value; pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; @@ -7251,7 +7241,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { : 1073741823) | 0; if (0 === hasContext) { if ( - getDerivedStateFromProps.children === context.children && + getDerivedStateFromProps.children === renderState.children && !didPerformWorkStackCursor.current ) { workInProgress = bailoutOnAlreadyFinishedWork( @@ -7333,7 +7323,7 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { reconcileChildren( current$$1, workInProgress, - context.children, + renderState.children, renderExpirationTime ); workInProgress = workInProgress.child; @@ -7341,12 +7331,15 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { return workInProgress; case 9: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = workInProgress.pendingProps), (updateExpirationTime = hasContext.children), prepareToReadContext(workInProgress, renderExpirationTime), - (context = readContext(context, hasContext.unstable_observedBits)), - (updateExpirationTime = updateExpirationTime(context)), + (renderState = readContext( + renderState, + hasContext.unstable_observedBits + )), + (updateExpirationTime = updateExpirationTime(renderState)), (workInProgress.effectTag |= 1), reconcileChildren( current$$1, @@ -7358,16 +7351,16 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), + (renderState = workInProgress.type), (hasContext = resolveDefaultProps( - context, + renderState, workInProgress.pendingProps )), - (hasContext = resolveDefaultProps(context.type, hasContext)), + (hasContext = resolveDefaultProps(renderState.type, hasContext)), updateMemoComponent( current$$1, workInProgress, - context, + renderState, hasContext, updateExpirationTime, renderExpirationTime @@ -7385,11 +7378,11 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { case 17: return ( (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = + (renderState = workInProgress.pendingProps), + (renderState = workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), + ? renderState + : resolveDefaultProps(updateExpirationTime, renderState)), null !== current$$1 && ((current$$1.alternate = null), (workInProgress.alternate = null), @@ -7402,13 +7395,13 @@ beginWork$$1 = function(current$$1, workInProgress, renderExpirationTime) { constructClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), mountClassInstance( workInProgress, updateExpirationTime, - context, + renderState, renderExpirationTime ), finishClassComponent( @@ -7614,7 +7607,6 @@ function createWorkInProgress(current, pendingProps) { : { expirationTime: pendingProps.expirationTime, firstContext: pendingProps.firstContext, - listeners: pendingProps.listeners, responders: pendingProps.responders }; workInProgress.sibling = current.sibling; diff --git a/Libraries/Renderer/shims/ReactNativeTypes.js b/Libraries/Renderer/shims/ReactNativeTypes.js index 200bf86592b57d..04200f2bb9fa87 100644 --- a/Libraries/Renderer/shims/ReactNativeTypes.js +++ b/Libraries/Renderer/shims/ReactNativeTypes.js @@ -198,8 +198,8 @@ export type ReactNativeResponderEvent = { export type ReactNativeResponderContext = { dispatchEvent: ( - eventProp: string, eventValue: any, + listener: (any) => void, eventPriority: EventPriority, ) => void, isTargetWithinNode: ( diff --git a/Libraries/Renderer/shims/ReactTypes.js b/Libraries/Renderer/shims/ReactTypes.js index 74565344365f1c..7f72ce6782c09a 100644 --- a/Libraries/Renderer/shims/ReactTypes.js +++ b/Libraries/Renderer/shims/ReactTypes.js @@ -88,6 +88,11 @@ export type ReactEventResponderInstance = {| target: mixed, |}; +export type ReactEventResponderListener = {| + props: Object, + responder: ReactEventResponder, +|}; + export type ReactEventResponder = { $$typeof: Symbol | number, displayName: string, diff --git a/package.json b/package.json index 1892225511a992..00270e1c2da948 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "test-ios": "./scripts/objc-test.sh test" }, "peerDependencies": { - "react": "16.8.6" + "react": "16.9.0" }, "dependencies": { "@babel/runtime": "^7.0.0", @@ -110,7 +110,7 @@ "react-devtools-core": "^3.6.3", "react-refresh": "^0.4.0", "regenerator-runtime": "^0.13.2", - "scheduler": "0.14.0", + "scheduler": "0.15.0", "stacktrace-parser": "^0.1.3", "whatwg-fetch": "^3.0.0" }, @@ -145,8 +145,8 @@ "jscodeshift": "^0.6.2", "mkdirp": "^0.5.1", "prettier": "1.17.0", - "react": "16.8.6", - "react-test-renderer": "16.8.6", + "react": "16.9.0", + "react-test-renderer": "16.9.0", "shelljs": "^0.7.8", "ws": "^6.1.4", "yargs": "^9.0.0" diff --git a/yarn.lock b/yarn.lock index a4f63cf7022c25..9cc05620e6aaf5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5872,10 +5872,10 @@ react-is@^16.8.1, react-is@^16.8.4: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.4.tgz#90f336a68c3a29a096a3d648ab80e87ec61482a2" integrity sha512-PVadd+WaUDOAciICm/J1waJaSvgq+4rHE/K70j0PFqKhkTBsPv/82UGQJNXAngz1fOQLLxI6z1sEDmJDQhCTAA== -react-is@^16.8.6: - version "16.8.6" - resolved "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" - integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA== +react-is@^16.9.0: + version "16.9.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb" + integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw== react-proxy@^1.1.7: version "1.1.8" @@ -5890,15 +5890,15 @@ react-refresh@^0.4.0: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.0.tgz#d421f9bd65e0e4b9822a399f14ac56bda9c92292" integrity sha512-bacjSio8GOtzNZKZZM6EWqbhlbb6pr28JWJWFTLwEBKvPIBRo6/Ob68D2EWZA2VyTdQxAh+TRnCYOPNKsQiXTA== -react-test-renderer@16.8.6: - version "16.8.6" - resolved "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.8.6.tgz#188d8029b8c39c786f998aa3efd3ffe7642d5ba1" - integrity sha512-H2srzU5IWYT6cZXof6AhUcx/wEyJddQ8l7cLM/F7gDXYyPr4oq+vCIxJYXVGhId1J706sqziAjuOEjyNkfgoEw== +react-test-renderer@16.9.0: + version "16.9.0" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.9.0.tgz#7ed657a374af47af88f66f33a3ef99c9610c8ae9" + integrity sha512-R62stB73qZyhrJo7wmCW9jgl/07ai+YzvouvCXIJLBkRlRqLx4j9RqcLEAfNfU3OxTGucqR2Whmn3/Aad6L3hQ== dependencies: object-assign "^4.1.1" prop-types "^15.6.2" - react-is "^16.8.6" - scheduler "^0.13.6" + react-is "^16.9.0" + scheduler "^0.15.0" react-transform-hmr@^1.0.4: version "1.0.4" @@ -5908,15 +5908,14 @@ react-transform-hmr@^1.0.4: global "^4.3.0" react-proxy "^1.1.7" -react@16.8.6: - version "16.8.6" - resolved "https://registry.npmjs.org/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe" - integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw== +react@16.9.0: + version "16.9.0" + resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa" + integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.13.6" read-pkg-up@^2.0.0: version "2.0.0" @@ -6312,18 +6311,10 @@ sax@~1.1.1: resolved "https://registry.yarnpkg.com/sax/-/sax-1.1.6.tgz#5d616be8a5e607d54e114afae55b7eaf2fcc3240" integrity sha1-XWFr6KXmB9VOEUr65Vt+ry/MMkA= -scheduler@0.14.0: - version "0.14.0" - resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.14.0.tgz#b392c23c9c14bfa2933d4740ad5603cc0d59ea5b" - integrity sha512-9CgbS06Kki2f4R9FjLSITjZo5BZxPsryiRNyL3LpvrM9WxcVmhlqAOc9E+KQbeI2nqej4JIIbOsfdL51cNb4Iw== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - -scheduler@^0.13.6: - version "0.13.6" - resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889" - integrity sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ== +scheduler@0.15.0, scheduler@^0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.15.0.tgz#6bfcf80ff850b280fed4aeecc6513bc0b4f17f8e" + integrity sha512-xAefmSfN6jqAa7Kuq7LIJY0bwAPG3xlCj0HMEBQk1lxYiDKZscY2xJ5U/61ZTrYbmNQbXa+gc7czPkVo11tnCg== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1"