Skip to content

Commit 13710c6

Browse files
committed
Support writing to this.refs from userspace (#28867)
Previously, the `refs` property of a class component instance was read-only by user code — only React could write to it, and until/unless a string ref was used, it pointed to a shared empty object that was frozen in dev to prevent userspace mutations. Because string refs are deprecated, we want users to be able to codemod all their string refs to callback refs. The safest way to do this is to output a callback ref that assigns to `this.refs`. So to support this, we need to make `this.refs` writable by userspace. DiffTrain build for commit ea24427.
1 parent 48cda4a commit 13710c6

File tree

13 files changed

+40
-57
lines changed

13 files changed

+40
-57
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<f80067582f8d263400103116af004cc1>>
10+
* @generated SignedSource<<1af14f0d0942bd1e022dac734e776b15>>
1111
*/
1212

1313
"use strict";
@@ -12589,7 +12589,6 @@ if (__DEV__) {
1258912589
var instance = workInProgress.stateNode;
1259012590
instance.props = newProps;
1259112591
instance.state = workInProgress.memoizedState;
12592-
instance.refs = {};
1259312592
initializeUpdateQueue(workInProgress);
1259412593
var contextType = ctor.contextType;
1259512594

@@ -26673,7 +26672,7 @@ if (__DEV__) {
2667326672
return root;
2667426673
}
2667526674

26676-
var ReactVersion = "19.0.0-canary-a47ffde4";
26675+
var ReactVersion = "19.0.0-canary-4a670971";
2667726676

2667826677
/*
2667926678
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<f3eb1768c908f25292e8f079ec672f53>>
10+
* @generated SignedSource<<c7247ab9f63052e5a0750fdb7aaf6996>>
1111
*/
1212

1313
"use strict";
@@ -3426,7 +3426,6 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) {
34263426
var instance = workInProgress.stateNode;
34273427
instance.props = newProps;
34283428
instance.state = workInProgress.memoizedState;
3429-
instance.refs = {};
34303429
initializeUpdateQueue(workInProgress);
34313430
var contextType = ctor.contextType;
34323431
"object" === typeof contextType && null !== contextType
@@ -9144,7 +9143,7 @@ var devToolsConfig$jscomp$inline_1019 = {
91449143
throw Error("TestRenderer does not support findFiberByHostInstance()");
91459144
},
91469145
bundleType: 0,
9147-
version: "19.0.0-canary-7a48fce4",
9146+
version: "19.0.0-canary-3c5c4140",
91489147
rendererPackageName: "react-test-renderer"
91499148
};
91509149
var internals$jscomp$inline_1238 = {
@@ -9175,7 +9174,7 @@ var internals$jscomp$inline_1238 = {
91759174
scheduleRoot: null,
91769175
setRefreshHandler: null,
91779176
getCurrentFiber: null,
9178-
reconcilerVersion: "19.0.0-canary-7a48fce4"
9177+
reconcilerVersion: "19.0.0-canary-3c5c4140"
91799178
};
91809179
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91819180
var hook$jscomp$inline_1239 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9206ca0f6781a4c840d6d393f26b3429>>
10+
* @generated SignedSource<<2efa00521669a237ba088981baf581b8>>
1111
*/
1212

1313
"use strict";
@@ -3584,7 +3584,6 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) {
35843584
var instance = workInProgress.stateNode;
35853585
instance.props = newProps;
35863586
instance.state = workInProgress.memoizedState;
3587-
instance.refs = {};
35883587
initializeUpdateQueue(workInProgress);
35893588
var contextType = ctor.contextType;
35903589
"object" === typeof contextType && null !== contextType
@@ -9760,7 +9759,7 @@ var devToolsConfig$jscomp$inline_1101 = {
97609759
throw Error("TestRenderer does not support findFiberByHostInstance()");
97619760
},
97629761
bundleType: 0,
9763-
version: "19.0.0-canary-39a6938a",
9762+
version: "19.0.0-canary-dec118c3",
97649763
rendererPackageName: "react-test-renderer"
97659764
};
97669765
(function (internals) {
@@ -9804,7 +9803,7 @@ var devToolsConfig$jscomp$inline_1101 = {
98049803
scheduleRoot: null,
98059804
setRefreshHandler: null,
98069805
getCurrentFiber: null,
9807-
reconcilerVersion: "19.0.0-canary-39a6938a"
9806+
reconcilerVersion: "19.0.0-canary-dec118c3"
98089807
});
98099808
exports._Scheduler = Scheduler;
98109809
exports.act = act;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<150980e4b77b12c241c9997159b4f67a>>
10+
* @generated SignedSource<<df40c362ab4858d0f1f3b69d7d7eb4ad>>
1111
*/
1212

1313
"use strict";
@@ -26,7 +26,7 @@ if (__DEV__) {
2626
}
2727
var dynamicFlagsUntyped = require("ReactNativeInternalFeatureFlags");
2828

29-
var ReactVersion = "19.0.0-canary-a13a0c2f";
29+
var ReactVersion = "19.0.0-canary-d59b7713";
3030

3131
// ATTENTION
3232
// When adding new symbols to this file,
@@ -299,20 +299,14 @@ if (__DEV__) {
299299

300300
var assign = Object.assign;
301301

302-
var emptyObject = {};
303-
304-
{
305-
Object.freeze(emptyObject);
306-
}
307302
/**
308303
* Base class helpers for the updating state of a component.
309304
*/
310305

311306
function Component(props, context, updater) {
312307
this.props = props;
313-
this.context = context; // If a component has string refs, we will assign a different object later.
314-
315-
this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the
308+
this.context = context;
309+
this.refs = {}; // We initialize the default updater but the real one gets injected by the
316310
// renderer.
317311

318312
this.updater = updater || ReactNoopUpdateQueue;
@@ -429,7 +423,7 @@ if (__DEV__) {
429423
this.props = props;
430424
this.context = context; // If a component has string refs, we will assign a different object later.
431425

432-
this.refs = emptyObject;
426+
this.refs = {};
433427
this.updater = updater || ReactNoopUpdateQueue;
434428
}
435429

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<00252b7815c38ef0d757b44717a43f7d>>
10+
* @generated SignedSource<<4623f2323ff9fe23a59f41063e37036d>>
1111
*/
1212

1313
"use strict";
@@ -46,12 +46,11 @@ var ReactNoopUpdateQueue = {
4646
enqueueReplaceState: function () {},
4747
enqueueSetState: function () {}
4848
},
49-
assign = Object.assign,
50-
emptyObject = {};
49+
assign = Object.assign;
5150
function Component(props, context, updater) {
5251
this.props = props;
5352
this.context = context;
54-
this.refs = emptyObject;
53+
this.refs = {};
5554
this.updater = updater || ReactNoopUpdateQueue;
5655
}
5756
Component.prototype.isReactComponent = {};
@@ -74,7 +73,7 @@ ComponentDummy.prototype = Component.prototype;
7473
function PureComponent(props, context, updater) {
7574
this.props = props;
7675
this.context = context;
77-
this.refs = emptyObject;
76+
this.refs = {};
7877
this.updater = updater || ReactNoopUpdateQueue;
7978
}
8079
var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
@@ -679,4 +678,4 @@ exports.useSyncExternalStore = function (
679678
exports.useTransition = function () {
680679
return ReactSharedInternals.H.useTransition();
681680
};
682-
exports.version = "19.0.0-canary-3277b133";
681+
exports.version = "19.0.0-canary-43e619b6";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9fd3393509037fbe670735ccea6d8cca>>
10+
* @generated SignedSource<<6bf80ec383f6cf4c2e8d203cf6a830b0>>
1111
*/
1212

1313
"use strict";
@@ -50,12 +50,11 @@ var ReactNoopUpdateQueue = {
5050
enqueueReplaceState: function () {},
5151
enqueueSetState: function () {}
5252
},
53-
assign = Object.assign,
54-
emptyObject = {};
53+
assign = Object.assign;
5554
function Component(props, context, updater) {
5655
this.props = props;
5756
this.context = context;
58-
this.refs = emptyObject;
57+
this.refs = {};
5958
this.updater = updater || ReactNoopUpdateQueue;
6059
}
6160
Component.prototype.isReactComponent = {};
@@ -78,7 +77,7 @@ ComponentDummy.prototype = Component.prototype;
7877
function PureComponent(props, context, updater) {
7978
this.props = props;
8079
this.context = context;
81-
this.refs = emptyObject;
80+
this.refs = {};
8281
this.updater = updater || ReactNoopUpdateQueue;
8382
}
8483
var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
@@ -683,7 +682,7 @@ exports.useSyncExternalStore = function (
683682
exports.useTransition = function () {
684683
return ReactSharedInternals.H.useTransition();
685684
};
686-
exports.version = "19.0.0-canary-52747c26";
685+
exports.version = "19.0.0-canary-c3e8564d";
687686
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
688687
"function" ===
689688
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0061ca6cf47c5124d2ebe708481fb03da9e8e267
1+
ea24427d16f3ac9b0f3bb45cdc7919ac208130c9

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<84d884f07a1d5851f53652012b257860>>
10+
* @generated SignedSource<<69452b089b0732ebffeaf4ae565a8ac2>>
1111
*/
1212

1313
"use strict";
@@ -16131,7 +16131,6 @@ to return true:wantsResponderID| |
1613116131
var instance = workInProgress.stateNode;
1613216132
instance.props = newProps;
1613316133
instance.state = workInProgress.memoizedState;
16134-
instance.refs = {};
1613516134
initializeUpdateQueue(workInProgress);
1613616135
var contextType = ctor.contextType;
1613716136

@@ -30296,7 +30295,7 @@ to return true:wantsResponderID| |
3029630295
return root;
3029730296
}
3029830297

30299-
var ReactVersion = "19.0.0-canary-adfb7d73";
30298+
var ReactVersion = "19.0.0-canary-385c1224";
3030030299

3030130300
/*
3030230301
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<d42756695dd6c4c7a24ede54b6a5902a>>
10+
* @generated SignedSource<<13b0be8da9b49fcd1f29069f699207ea>>
1111
*/
1212

1313
"use strict";
@@ -4995,7 +4995,6 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) {
49954995
var instance = workInProgress.stateNode;
49964996
instance.props = newProps;
49974997
instance.state = workInProgress.memoizedState;
4998-
instance.refs = {};
49994998
initializeUpdateQueue(workInProgress);
50004999
var contextType = ctor.contextType;
50015000
"object" === typeof contextType && null !== contextType
@@ -10602,7 +10601,7 @@ var roots = new Map(),
1060210601
devToolsConfig$jscomp$inline_1099 = {
1060310602
findFiberByHostInstance: getInstanceFromNode,
1060410603
bundleType: 0,
10605-
version: "19.0.0-canary-7f7baf16",
10604+
version: "19.0.0-canary-7feb98a8",
1060610605
rendererPackageName: "react-native-renderer",
1060710606
rendererConfig: {
1060810607
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10645,7 +10644,7 @@ var internals$jscomp$inline_1366 = {
1064510644
scheduleRoot: null,
1064610645
setRefreshHandler: null,
1064710646
getCurrentFiber: null,
10648-
reconcilerVersion: "19.0.0-canary-7f7baf16"
10647+
reconcilerVersion: "19.0.0-canary-7feb98a8"
1064910648
};
1065010649
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1065110650
var hook$jscomp$inline_1367 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<64acec7be24561ecbf6d2eaf55e55d0a>>
10+
* @generated SignedSource<<dd792dd5b38efe98d74676e597f14301>>
1111
*/
1212

1313
"use strict";
@@ -5187,7 +5187,6 @@ function mountClassInstance(workInProgress, ctor, newProps, renderLanes) {
51875187
var instance = workInProgress.stateNode;
51885188
instance.props = newProps;
51895189
instance.state = workInProgress.memoizedState;
5190-
instance.refs = {};
51915190
initializeUpdateQueue(workInProgress);
51925191
var contextType = ctor.contextType;
51935192
"object" === typeof contextType && null !== contextType
@@ -11307,7 +11306,7 @@ var roots = new Map(),
1130711306
devToolsConfig$jscomp$inline_1179 = {
1130811307
findFiberByHostInstance: getInstanceFromNode,
1130911308
bundleType: 0,
11310-
version: "19.0.0-canary-ef6bcf29",
11309+
version: "19.0.0-canary-e320aa3b",
1131111310
rendererPackageName: "react-native-renderer",
1131211311
rendererConfig: {
1131311312
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11363,7 +11362,7 @@ var roots = new Map(),
1136311362
scheduleRoot: null,
1136411363
setRefreshHandler: null,
1136511364
getCurrentFiber: null,
11366-
reconcilerVersion: "19.0.0-canary-ef6bcf29"
11365+
reconcilerVersion: "19.0.0-canary-e320aa3b"
1136711366
});
1136811367
exports.createPortal = function (children, containerTag) {
1136911368
return createPortal$1(

0 commit comments

Comments
 (0)