From d7066bf52f15c6843d1574bfd18e6aef9f5c8fdb Mon Sep 17 00:00:00 2001 From: acdlite Date: Thu, 25 Apr 2024 17:08:42 +0000 Subject: [PATCH] Go back to shared refs instance object (#28911) It turns out we already made refs writable in #25696, which has been in canary for over a year. The approach in that PR also has the benefit of being slightly more perf sensitive because it still uses a shared object until the fiber is mounted. So let's just go back to that. DiffTrain build for commit https://github.com/facebook/react/commit/d285b3acbade77f9b17e6171dbda69ff4a033878. --- .../cjs/ReactTestRenderer-dev.js | 13 +++---------- .../RKJSModules/vendor/react/cjs/React-dev.js | 17 ++++++++++++----- .../RKJSModules/vendor/react/cjs/React-prod.js | 11 ++++++----- .../vendor/react/cjs/React-profiling.js | 11 ++++++----- .../Libraries/Renderer/REVISION | 2 +- .../implementations/ReactFabric-dev.fb.js | 13 +++---------- .../ReactNativeRenderer-dev.fb.js | 13 +++---------- 7 files changed, 34 insertions(+), 46 deletions(-) diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js index 3fc037411652e..4b8db21b5f981 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<52b4dbf4e18cc25f133cd7e575c1b6cd>> + * @generated SignedSource<> */ 'use strict'; @@ -10931,14 +10931,7 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) { var instance = workInProgress.stateNode; instance.props = newProps; instance.state = workInProgress.memoizedState; - - { - // When string refs are used in create-react-class legacy components, - // we need to make refs writable unless we patch all such copies of the - // class code that sets to a frozen emptyObject. - instance.refs = {}; - } - + instance.refs = {}; initializeUpdateQueue(workInProgress); var contextType = ctor.contextType; @@ -22988,7 +22981,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition return root; } -var ReactVersion = '19.0.0-canary-8f31b884'; +var ReactVersion = '19.0.0-canary-03549b3a'; /* * The `'' + value` pattern (used in perf-sensitive code) throws for Symbol diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js index 2103d0afe14f1..ef208d01c32c0 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<89ae74e0102293ea28fa8a01ffa204a7>> + * @generated SignedSource<<5657642071f954739542e489d20fe745>> */ 'use strict'; @@ -27,7 +27,7 @@ if ( } var dynamicFlagsUntyped = require('ReactNativeInternalFeatureFlags'); -var ReactVersion = '19.0.0-canary-ffcb8911'; +var ReactVersion = '19.0.0-canary-bbf3fbcd'; // Re-export dynamic flags from the internal module. var dynamicFlags = dynamicFlagsUntyped; // We destructure each value before re-exporting to avoid a dynamic look-up on @@ -270,14 +270,21 @@ var ReactNoopUpdateQueue = { var assign = Object.assign; +var emptyObject = {}; + +{ + Object.freeze(emptyObject); +} /** * Base class helpers for the updating state of a component. */ + function Component(props, context, updater) { this.props = props; - this.context = context; - this.refs = {}; // We initialize the default updater but the real one gets injected by the + this.context = context; // If a component has string refs, we will assign a different object later. + + this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the // renderer. this.updater = updater || ReactNoopUpdateQueue; @@ -377,7 +384,7 @@ function PureComponent(props, context, updater) { this.props = props; this.context = context; // If a component has string refs, we will assign a different object later. - this.refs = {}; + this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js index b5097abc4b301..5f0d22bb58368 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<429307aea5989b6d3af53d1e3daeea57>> + * @generated SignedSource<> */ "use strict"; @@ -50,11 +50,12 @@ var ReactNoopUpdateQueue = { enqueueReplaceState: function () {}, enqueueSetState: function () {} }, - assign = Object.assign; + assign = Object.assign, + emptyObject = {}; function Component(props, context, updater) { this.props = props; this.context = context; - this.refs = {}; + this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } Component.prototype.isReactComponent = {}; @@ -77,7 +78,7 @@ ComponentDummy.prototype = Component.prototype; function PureComponent(props, context, updater) { this.props = props; this.context = context; - this.refs = {}; + this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy()); @@ -678,4 +679,4 @@ exports.useSyncExternalStore = function ( exports.useTransition = function () { return ReactSharedInternals.H.useTransition(); }; -exports.version = "19.0.0-canary-a22219fc"; +exports.version = "19.0.0-canary-55ecd63c"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js index 1fd9582301117..c3a9fc241c09e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<90a5fdd3d2d77ff49898cf96e4b802da>> + * @generated SignedSource<> */ "use strict"; @@ -54,11 +54,12 @@ var ReactNoopUpdateQueue = { enqueueReplaceState: function () {}, enqueueSetState: function () {} }, - assign = Object.assign; + assign = Object.assign, + emptyObject = {}; function Component(props, context, updater) { this.props = props; this.context = context; - this.refs = {}; + this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } Component.prototype.isReactComponent = {}; @@ -81,7 +82,7 @@ ComponentDummy.prototype = Component.prototype; function PureComponent(props, context, updater) { this.props = props; this.context = context; - this.refs = {}; + this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy()); @@ -682,7 +683,7 @@ exports.useSyncExternalStore = function ( exports.useTransition = function () { return ReactSharedInternals.H.useTransition(); }; -exports.version = "19.0.0-canary-64485d5e"; +exports.version = "19.0.0-canary-966142ac"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION index eb83bff4e4796..bc528698d37e6 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION @@ -1 +1 @@ -ed71a3ad2965617c27c6e7ca7577f15b8ca4152c +d285b3acbade77f9b17e6171dbda69ff4a033878 diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js index 2f97cc6169437..5839400dc30b8 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<<2b452522ba377c277e98a65fb11b3ba0>> */ 'use strict'; @@ -13968,14 +13968,7 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) { var instance = workInProgress.stateNode; instance.props = newProps; instance.state = workInProgress.memoizedState; - - { - // When string refs are used in create-react-class legacy components, - // we need to make refs writable unless we patch all such copies of the - // class code that sets to a frozen emptyObject. - instance.refs = {}; - } - + instance.refs = {}; initializeUpdateQueue(workInProgress); var contextType = ctor.contextType; @@ -26071,7 +26064,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition return root; } -var ReactVersion = '19.0.0-canary-f568fe98'; +var ReactVersion = '19.0.0-canary-86571a2a'; /* * The `'' + value` pattern (used in perf-sensitive code) throws for Symbol diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js index 9917b86ab009d..219607f4a194b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<429d382e81c12cadfefde85a5059684a>> + * @generated SignedSource<> */ 'use strict'; @@ -14207,14 +14207,7 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) { var instance = workInProgress.stateNode; instance.props = newProps; instance.state = workInProgress.memoizedState; - - { - // When string refs are used in create-react-class legacy components, - // we need to make refs writable unless we patch all such copies of the - // class code that sets to a frozen emptyObject. - instance.refs = {}; - } - + instance.refs = {}; initializeUpdateQueue(workInProgress); var contextType = ctor.contextType; @@ -26486,7 +26479,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition return root; } -var ReactVersion = '19.0.0-canary-6d8999b7'; +var ReactVersion = '19.0.0-canary-be3bb958'; /* * The `'' + value` pattern (used in perf-sensitive code) throws for Symbol