From 046f600cc23ff2d4aeb57be8e5606347f19b76d2 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 9 Aug 2017 12:18:46 -0700 Subject: [PATCH] React 16 beta 5 sync (5495e49...c3718c4) Reviewed By: spicyj Differential Revision: D5564030 fbshipit-source-id: fd3e6133df7ee8e7488a3c515ce6c783c11d9401 --- .../Animated/src/AnimatedImplementation.js | 5 +- Libraries/Renderer/REVISION | 2 +- Libraries/Renderer/ReactNativeFiber-dev.js | 9090 ++++++++--------- Libraries/Renderer/ReactNativeFiber-prod.js | 2013 ++-- Libraries/Renderer/ReactNativeStack-dev.js | 6110 ++++++----- Libraries/Renderer/ReactNativeStack-prod.js | 1892 ++-- jest/setup.js | 38 + package.json | 8 +- 8 files changed, 9414 insertions(+), 9744 deletions(-) diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 100b1382bc0..1f646426fc6 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -1760,6 +1760,8 @@ function createAnimatedComponent(Component: any): any { _eventDetachers: Array = []; _setComponentRef: Function; + static __skipSetNativeProps_FOR_TESTS_ONLY = false; + constructor(props: Object) { super(props); this._setComponentRef = this._setComponentRef.bind(this); @@ -1814,7 +1816,8 @@ function createAnimatedComponent(Component: any): any { // need to re-render it. In this case, we have a fallback that uses // forceUpdate. var callback = () => { - if (this._component.setNativeProps) { + if (!AnimatedComponent.__skipSetNativeProps_FOR_TESTS_ONLY && + this._component.setNativeProps) { if (!this._propsAnimated.__isNative) { this._component.setNativeProps( this._propsAnimated.__getAnimatedValue() diff --git a/Libraries/Renderer/REVISION b/Libraries/Renderer/REVISION index 0abe17731ba..41cea19495f 100644 --- a/Libraries/Renderer/REVISION +++ b/Libraries/Renderer/REVISION @@ -1 +1 @@ -5495e495de0bd15cd96a76ee0d7ca823cc09cc71 \ No newline at end of file +c3718c48f01fa6c2e04bd47226061769484c951b \ No newline at end of file diff --git a/Libraries/Renderer/ReactNativeFiber-dev.js b/Libraries/Renderer/ReactNativeFiber-dev.js index 3f97c870cc8..480954d339b 100644 --- a/Libraries/Renderer/ReactNativeFiber-dev.js +++ b/Libraries/Renderer/ReactNativeFiber-dev.js @@ -11,4698 +11,4512 @@ */ "use strict"; -var invariant = require("fbjs/lib/invariant"), warning = require("fbjs/lib/warning"), ExceptionsManager = require("ExceptionsManager"); - -require("InitializeCore"); - -var RCTEventEmitter = require("RCTEventEmitter"), emptyFunction = require("fbjs/lib/emptyFunction"), UIManager = require("UIManager"), checkPropTypes = require("prop-types/checkPropTypes"), emptyObject = require("fbjs/lib/emptyObject"), react = require("react"), shallowEqual = require("fbjs/lib/shallowEqual"), deepDiffer = require("deepDiffer"), flattenStyle = require("flattenStyle"), TextInputState = require("TextInputState"), deepFreezeAndThrowOnMutationInDev = require("deepFreezeAndThrowOnMutationInDev"), ExecutionEnvironment = require("fbjs/lib/ExecutionEnvironment"), performanceNow = require("fbjs/lib/performanceNow"), defaultShowDialog = function(capturedError) { - return !0; -}, showDialog = defaultShowDialog; - -function logCapturedError(capturedError) { - if (!1 !== showDialog(capturedError)) { - var componentName = capturedError.componentName, componentStack = capturedError.componentStack, error = capturedError.error, errorBoundaryName = capturedError.errorBoundaryName, errorBoundaryFound = capturedError.errorBoundaryFound, willRetry = capturedError.willRetry, message = error.message, name = error.name, stack = error.stack, errorSummary = message ? name + ": " + message : name, componentNameMessage = componentName ? "React caught an error thrown by " + componentName + "." : "React caught an error thrown by one of your components.", formattedCallStack = stack.slice(0, errorSummary.length) === errorSummary ? stack.slice(errorSummary.length) : stack; - formattedCallStack = formattedCallStack.trim().split("\n").map(function(line) { - return "\n " + line.trim(); - }).join(); - var errorBoundaryMessage = void 0; - errorBoundaryMessage = errorBoundaryFound && errorBoundaryName ? willRetry ? "React will try to recreate this component tree from scratch " + "using the error boundary you provided, " + errorBoundaryName + "." : "This error was initially handled by the error boundary " + errorBoundaryName + ". " + "Recreating the tree from scratch failed so React will unmount the tree." : "Consider adding an error boundary to your tree to customize error handling behavior.", - console.error(componentNameMessage + " You should fix this error in your code. " + errorBoundaryMessage + "\n\n" + errorSummary + "\n\n" + "The error is located at: " + componentStack + "\n\n" + "The error was thrown at: " + formattedCallStack); - } -} - -var injection = { - injectDialog: function(fn) { - invariant(showDialog === defaultShowDialog, "The custom dialog was already injected."), - invariant("function" == typeof fn, "Injected showDialog() must be a function."), - showDialog = fn; - } -}, logCapturedError_1 = logCapturedError, ReactFiberErrorLogger = { - injection: injection, - logCapturedError: logCapturedError_1 -}, caughtError = null, invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { - var funcArgs = Array.prototype.slice.call(arguments, 3); - try { - func.apply(context, funcArgs); - } catch (error) { - return error; - } - return null; -}; - -if ("undefined" != typeof window && "function" == typeof window.dispatchEvent && "undefined" != typeof document && "function" == typeof document.createEvent) { - var fakeNode = document.createElement("react"), depth = 0; - invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { - depth++; - var thisDepth = depth, funcArgs = Array.prototype.slice.call(arguments, 3), boundFunc = function() { - func.apply(context, funcArgs); - }, fakeEventError = null, onFakeEventError = function(event) { - depth === thisDepth && (fakeEventError = event.error); - }, evtType = "react-" + (name || "invokeguardedcallback") + "-" + depth; - window.addEventListener("error", onFakeEventError), fakeNode.addEventListener(evtType, boundFunc, !1); - var evt = document.createEvent("Event"); - return evt.initEvent(evtType, !1, !1), fakeNode.dispatchEvent(evt), fakeNode.removeEventListener(evtType, boundFunc, !1), - window.removeEventListener("error", onFakeEventError), depth--, fakeEventError; - }; -} - -var rethrowCaughtError = function() { - if (caughtError) { - var error = caughtError; - throw caughtError = null, error; - } -}, ReactErrorUtils = { - injection: { - injectErrorUtils: function(injectedErrorUtils) { - invariant("function" == typeof injectedErrorUtils.invokeGuardedCallback, "Injected invokeGuardedCallback() must be a function."), - invokeGuardedCallback = injectedErrorUtils.invokeGuardedCallback; - } - }, - invokeGuardedCallback: function(name, func, context, a, b, c, d, e, f) { - return invokeGuardedCallback.apply(this, arguments); - }, - invokeGuardedCallbackAndCatchFirstError: function(name, func, context, a, b, c, d, e, f) { - var error = ReactErrorUtils.invokeGuardedCallback.apply(this, arguments); - null !== error && null === caughtError && (caughtError = error); - }, - rethrowCaughtError: function() { - return rethrowCaughtError.apply(this, arguments); - } -}, ReactErrorUtils_1 = ReactErrorUtils, ComponentTree, injection$1 = { - injectComponentTree: function(Injected) { - ComponentTree = Injected, warning(Injected && Injected.getNodeFromInstance && Injected.getInstanceFromNode, "EventPluginUtils.injection.injectComponentTree(...): Injected " + "module is missing getNodeFromInstance or getInstanceFromNode."); - } -}; - -function isEndish(topLevelType) { - return "topMouseUp" === topLevelType || "topTouchEnd" === topLevelType || "topTouchCancel" === topLevelType; -} - -function isMoveish(topLevelType) { - return "topMouseMove" === topLevelType || "topTouchMove" === topLevelType; -} - -function isStartish(topLevelType) { - return "topMouseDown" === topLevelType || "topTouchStart" === topLevelType; -} - -var validateEventDispatches; - -validateEventDispatches = function(event) { - var dispatchListeners = event._dispatchListeners, dispatchInstances = event._dispatchInstances, listenersIsArr = Array.isArray(dispatchListeners), listenersLen = listenersIsArr ? dispatchListeners.length : dispatchListeners ? 1 : 0, instancesIsArr = Array.isArray(dispatchInstances), instancesLen = instancesIsArr ? dispatchInstances.length : dispatchInstances ? 1 : 0; - warning(instancesIsArr === listenersIsArr && instancesLen === listenersLen, "EventPluginUtils: Invalid `event`."); -}; - -function executeDispatch(event, simulated, listener, inst) { - var type = event.type || "unknown-event"; - event.currentTarget = EventPluginUtils.getNodeFromInstance(inst), ReactErrorUtils_1.invokeGuardedCallbackAndCatchFirstError(type, listener, void 0, event), - event.currentTarget = null; -} - -function executeDispatchesInOrder(event, simulated) { - var dispatchListeners = event._dispatchListeners, dispatchInstances = event._dispatchInstances; - if (validateEventDispatches(event), Array.isArray(dispatchListeners)) for (var i = 0; i < dispatchListeners.length && !event.isPropagationStopped(); i++) executeDispatch(event, simulated, dispatchListeners[i], dispatchInstances[i]); else dispatchListeners && executeDispatch(event, simulated, dispatchListeners, dispatchInstances); - event._dispatchListeners = null, event._dispatchInstances = null; -} - -function executeDispatchesInOrderStopAtTrueImpl(event) { - var dispatchListeners = event._dispatchListeners, dispatchInstances = event._dispatchInstances; - if (validateEventDispatches(event), Array.isArray(dispatchListeners)) { - for (var i = 0; i < dispatchListeners.length && !event.isPropagationStopped(); i++) if (dispatchListeners[i](event, dispatchInstances[i])) return dispatchInstances[i]; - } else if (dispatchListeners && dispatchListeners(event, dispatchInstances)) return dispatchInstances; - return null; -} - -function executeDispatchesInOrderStopAtTrue(event) { - var ret = executeDispatchesInOrderStopAtTrueImpl(event); - return event._dispatchInstances = null, event._dispatchListeners = null, ret; -} - -function executeDirectDispatch(event) { - validateEventDispatches(event); - var dispatchListener = event._dispatchListeners, dispatchInstance = event._dispatchInstances; - invariant(!Array.isArray(dispatchListener), "executeDirectDispatch(...): Invalid `event`."), - event.currentTarget = dispatchListener ? EventPluginUtils.getNodeFromInstance(dispatchInstance) : null; - var res = dispatchListener ? dispatchListener(event) : null; - return event.currentTarget = null, event._dispatchListeners = null, event._dispatchInstances = null, - res; -} - -function hasDispatches(event) { - return !!event._dispatchListeners; -} - -var EventPluginUtils = { - isEndish: isEndish, - isMoveish: isMoveish, - isStartish: isStartish, - executeDirectDispatch: executeDirectDispatch, - executeDispatchesInOrder: executeDispatchesInOrder, - executeDispatchesInOrderStopAtTrue: executeDispatchesInOrderStopAtTrue, - hasDispatches: hasDispatches, - getFiberCurrentPropsFromNode: function(node) { - return ComponentTree.getFiberCurrentPropsFromNode(node); - }, - getInstanceFromNode: function(node) { - return ComponentTree.getInstanceFromNode(node); - }, - getNodeFromInstance: function(node) { - return ComponentTree.getNodeFromInstance(node); - }, - injection: injection$1 -}, EventPluginUtils_1 = EventPluginUtils, fiberHostComponent = null, ReactControlledComponentInjection = { - injectFiberControlledHostComponent: function(hostComponentImpl) { - fiberHostComponent = hostComponentImpl; - } -}, restoreTarget = null, restoreQueue = null; - -function restoreStateOfTarget(target) { - var internalInstance = EventPluginUtils_1.getInstanceFromNode(target); - if (internalInstance) { - if ("number" == typeof internalInstance.tag) { - invariant(fiberHostComponent && "function" == typeof fiberHostComponent.restoreControlledState, "Fiber needs to be injected to handle a fiber target for controlled " + "events."); - var props = EventPluginUtils_1.getFiberCurrentPropsFromNode(internalInstance.stateNode); - return void fiberHostComponent.restoreControlledState(internalInstance.stateNode, internalInstance.type, props); - } - invariant("function" == typeof internalInstance.restoreControlledState, "The internal instance must be a React host component."), - internalInstance.restoreControlledState(); - } -} - -var ReactControlledComponent = { - injection: ReactControlledComponentInjection, - enqueueStateRestore: function(target) { - restoreTarget ? restoreQueue ? restoreQueue.push(target) : restoreQueue = [ target ] : restoreTarget = target; - }, - restoreStateIfNeeded: function() { - if (restoreTarget) { - var target = restoreTarget, queuedTargets = restoreQueue; - if (restoreTarget = null, restoreQueue = null, restoreStateOfTarget(target), queuedTargets) for (var i = 0; i < queuedTargets.length; i++) restoreStateOfTarget(queuedTargets[i]); +__DEV__ && function() { + var invariant = require("fbjs/lib/invariant"), require$$0 = require("fbjs/lib/warning"), ExceptionsManager = require("ExceptionsManager"), emptyObject = require("fbjs/lib/emptyObject"), react = require("react"), checkPropTypes = require("prop-types/checkPropTypes"), shallowEqual = require("fbjs/lib/shallowEqual"), deepDiffer = require("deepDiffer"), flattenStyle = require("flattenStyle"), TextInputState = require("TextInputState"), UIManager = require("UIManager"), deepFreezeAndThrowOnMutationInDev = require("deepFreezeAndThrowOnMutationInDev"); + require("InitializeCore"); + var RCTEventEmitter = require("RCTEventEmitter"), emptyFunction = require("fbjs/lib/emptyFunction"), ExecutionEnvironment = require("fbjs/lib/ExecutionEnvironment"), performanceNow = require("fbjs/lib/performanceNow"), defaultShowDialog = function(capturedError) { + return !0; + }, showDialog = defaultShowDialog; + function logCapturedError(capturedError) { + if (!1 !== showDialog(capturedError)) { + var componentName = (capturedError.error, capturedError.componentName), componentStack = capturedError.componentStack, errorBoundaryName = capturedError.errorBoundaryName, errorBoundaryFound = capturedError.errorBoundaryFound, willRetry = capturedError.willRetry, componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : "The above error occurred in one of your React components:", errorBoundaryMessage = void 0; + errorBoundaryMessage = errorBoundaryFound && errorBoundaryName ? willRetry ? "React will try to recreate this component tree from scratch " + "using the error boundary you provided, " + errorBoundaryName + "." : "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree." : "Consider adding an error boundary to your tree to customize error handling behavior.\n" + "You can learn more about error boundaries at https://fb.me/react-error-boundaries."; + var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + errorBoundaryMessage; + console.error(combinedMessage); } } -}, ReactControlledComponent_1 = ReactControlledComponent, stackBatchedUpdates = function(fn, a, b, c, d, e) { - return fn(a, b, c, d, e); -}, fiberBatchedUpdates = function(fn, bookkeeping) { - return fn(bookkeeping); -}; - -function performFiberBatchedUpdates(fn, bookkeeping) { - return fiberBatchedUpdates(fn, bookkeeping); -} - -function batchedUpdates(fn, bookkeeping) { - return stackBatchedUpdates(performFiberBatchedUpdates, fn, bookkeeping); -} - -var isNestingBatched = !1; - -function batchedUpdatesWithControlledComponents(fn, bookkeeping) { - if (isNestingBatched) return batchedUpdates(fn, bookkeeping); - isNestingBatched = !0; - try { - return batchedUpdates(fn, bookkeeping); - } finally { - isNestingBatched = !1, ReactControlledComponent_1.restoreStateIfNeeded(); - } -} - -var ReactGenericBatchingInjection = { - injectStackBatchedUpdates: function(_batchedUpdates) { - stackBatchedUpdates = _batchedUpdates; - }, - injectFiberBatchedUpdates: function(_batchedUpdates) { - fiberBatchedUpdates = _batchedUpdates; - } -}, ReactGenericBatching = { - batchedUpdates: batchedUpdatesWithControlledComponents, - injection: ReactGenericBatchingInjection -}, ReactGenericBatching_1 = ReactGenericBatching; - -function ReactNativeFiberErrorDialog(capturedError) { - var componentStack = capturedError.componentStack, error = capturedError.error, errorToHandle = void 0; - if (error instanceof Error) { - var message = error.message, name = error.name, summary = message ? name + ": " + message : name; - errorToHandle = error; + var injection = { + injectDialog: function(fn) { + invariant(showDialog === defaultShowDialog, "The custom dialog was already injected."), + invariant("function" == typeof fn, "Injected showDialog() must be a function."), + showDialog = fn; + } + }, logCapturedError_1 = logCapturedError, ReactFiberErrorLogger = { + injection: injection, + logCapturedError: logCapturedError_1 + }, ReactErrorUtils = { + _caughtError: null, + _hasCaughtError: !1, + _rethrowError: null, + _hasRethrowError: !1, + injection: { + injectErrorUtils: function(injectedErrorUtils) { + invariant("function" == typeof injectedErrorUtils.invokeGuardedCallback, "Injected invokeGuardedCallback() must be a function."), + invokeGuardedCallback = injectedErrorUtils.invokeGuardedCallback; + } + }, + invokeGuardedCallback: function(name, func, context, a, b, c, d, e, f) { + invokeGuardedCallback.apply(ReactErrorUtils, arguments); + }, + invokeGuardedCallbackAndCatchFirstError: function(name, func, context, a, b, c, d, e, f) { + if (ReactErrorUtils.invokeGuardedCallback.apply(this, arguments), ReactErrorUtils.hasCaughtError()) { + var error = ReactErrorUtils.clearCaughtError(); + ReactErrorUtils._hasRethrowError || (ReactErrorUtils._hasRethrowError = !0, ReactErrorUtils._rethrowError = error); + } + }, + rethrowCaughtError: function() { + return rethrowCaughtError.apply(ReactErrorUtils, arguments); + }, + hasCaughtError: function() { + return ReactErrorUtils._hasCaughtError; + }, + clearCaughtError: function() { + if (ReactErrorUtils._hasCaughtError) { + var error = ReactErrorUtils._caughtError; + return ReactErrorUtils._caughtError = null, ReactErrorUtils._hasCaughtError = !1, + error; + } + invariant(!1, "clearCaughtError was called but no error was captured. This error " + "is likely caused by a bug in React. Please file an issue."); + } + }, invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { + ReactErrorUtils._hasCaughtError = !1, ReactErrorUtils._caughtError = null; + var funcArgs = Array.prototype.slice.call(arguments, 3); try { - errorToHandle.message = summary + "\n\nThis error is located at:" + componentStack; - } catch (e) {} - } else errorToHandle = "string" == typeof error ? new Error(error + "\n\nThis error is located at:" + componentStack) : new Error("Unspecified error at:" + componentStack); - return ExceptionsManager.handleException(errorToHandle, !1), !1; -} - -var showDialog$1 = ReactNativeFiberErrorDialog, ReactNativeFiberErrorDialog_1 = { - showDialog: showDialog$1 -}, eventPluginOrder = null, namesToPlugins = {}; - -function recomputePluginOrdering() { - if (eventPluginOrder) for (var pluginName in namesToPlugins) { - var pluginModule = namesToPlugins[pluginName], pluginIndex = eventPluginOrder.indexOf(pluginName); - if (invariant(pluginIndex > -1, "EventPluginRegistry: Cannot inject event plugins that do not exist in " + "the plugin ordering, `%s`.", pluginName), - !EventPluginRegistry.plugins[pluginIndex]) { - invariant(pluginModule.extractEvents, "EventPluginRegistry: Event plugins must implement an `extractEvents` " + "method, but `%s` does not.", pluginName), - EventPluginRegistry.plugins[pluginIndex] = pluginModule; - var publishedEvents = pluginModule.eventTypes; - for (var eventName in publishedEvents) invariant(publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName), "EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.", eventName, pluginName); + func.apply(context, funcArgs); + } catch (error) { + ReactErrorUtils._caughtError = error, ReactErrorUtils._hasCaughtError = !0; + } + }; + if ("undefined" != typeof window && "function" == typeof window.dispatchEvent && "undefined" != typeof document && "function" == typeof document.createEvent) { + var fakeNode = document.createElement("react"); + invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { + var didError = !0, funcArgs = Array.prototype.slice.call(arguments, 3); + function callCallback() { + fakeNode.removeEventListener(evtType, callCallback, !1), func.apply(context, funcArgs), + didError = !1; + } + var error = void 0, didSetError = !1, isCrossOriginError = !1; + function onError(event) { + error = event.error, didSetError = !0, null === error && 0 === event.colno && 0 === event.lineno && (isCrossOriginError = !0); + } + var evtType = "react-" + (name || "invokeguardedcallback"); + window.addEventListener("error", onError), fakeNode.addEventListener(evtType, callCallback, !1); + var evt = document.createEvent("Event"); + evt.initEvent(evtType, !1, !1), fakeNode.dispatchEvent(evt), didError ? (didSetError ? isCrossOriginError && (error = new Error("A cross-origin error was thrown. React doesn't have access to " + "the actual error because it catches errors using a global " + 'error handler, in order to preserve the "Pause on exceptions" ' + "behavior of the DevTools. This is only an issue in DEV-mode; " + "in production, React uses a normal try-catch statement.\n\n" + "If you are using React from a CDN, ensure that the