Skip to content

Commit 9e2d714

Browse files
committed
(Land #28798) Move Current Owner (and Cache) to an Async Dispatcher (#28912)
Rebasing and landing #28798 This PR was approved already but held back to give time for the sync. Rebased and landing here without pushing to seb's remote to avoid possibility of lost updates --------- Co-authored-by: Sebastian Markbage <[email protected]> DiffTrain build for [94eed63](94eed63)
1 parent aef84c3 commit 9e2d714

35 files changed

+1016
-864
lines changed

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,19 @@ function getComponentNameFromFiber(fiber) {
918918
}
919919

920920
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
921+
922+
function getOwner() {
923+
{
924+
var dispatcher = ReactSharedInternals.A;
925+
926+
if (dispatcher === null) {
927+
return null;
928+
}
929+
930+
return dispatcher.getOwner();
931+
}
932+
}
933+
921934
var specialPropKeyWarningShown;
922935
var specialPropRefWarningShown;
923936
var didWarnAboutStringRefs;
@@ -958,11 +971,13 @@ function hasValidKey(config) {
958971

959972
function warnIfStringRefCannotBeAutoConverted(config, self) {
960973
{
961-
if (typeof config.ref === 'string' && ReactSharedInternals.owner && self && ReactSharedInternals.owner.stateNode !== self) {
962-
var componentName = getComponentNameFromType(ReactSharedInternals.owner.type);
974+
var owner;
975+
976+
if (typeof config.ref === 'string' && (owner = getOwner()) && self && owner.stateNode !== self) {
977+
var componentName = getComponentNameFromType(owner.type);
963978

964979
if (!didWarnAboutStringRefs[componentName]) {
965-
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://react.dev/link/strict-mode-string-ref', getComponentNameFromType(ReactSharedInternals.owner.type), config.ref);
980+
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://react.dev/link/strict-mode-string-ref', getComponentNameFromType(owner.type), config.ref);
966981

967982
didWarnAboutStringRefs[componentName] = true;
968983
}
@@ -1263,7 +1278,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
12631278
ref = config.ref;
12641279

12651280
{
1266-
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
1281+
ref = coerceStringRef(ref, getOwner(), type);
12671282
}
12681283
}
12691284

@@ -1295,7 +1310,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
12951310
// Skip over reserved prop names
12961311
if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
12971312
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
1298-
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
1313+
props.ref = coerceStringRef(config[propName], getOwner(), type);
12991314
} else {
13001315
props[propName] = config[propName];
13011316
}
@@ -1328,7 +1343,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
13281343
}
13291344
}
13301345

1331-
var element = ReactElement(type, key, ref, self, source, ReactSharedInternals.owner, props);
1346+
var element = ReactElement(type, key, ref, self, source, getOwner(), props);
13321347

13331348
if (type === REACT_FRAGMENT_TYPE) {
13341349
validateFragmentProps(element);
@@ -1340,8 +1355,10 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
13401355

13411356
function getDeclarationErrorAddendum() {
13421357
{
1343-
if (ReactSharedInternals.owner) {
1344-
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
1358+
var owner = getOwner();
1359+
1360+
if (owner) {
1361+
var name = getComponentNameFromType(owner.type);
13451362

13461363
if (name) {
13471364
return '\n\nCheck the render method of `' + name + '`.';
@@ -1448,7 +1465,7 @@ function validateExplicitKey(element, parentType) {
14481465

14491466
var childOwner = '';
14501467

1451-
if (element && element._owner != null && element._owner !== ReactSharedInternals.owner) {
1468+
if (element && element._owner != null && element._owner !== getOwner()) {
14521469
var ownerName = null;
14531470

14541471
if (typeof element._owner.tag === 'number') {

compiled/facebook-www/JSXDEVRuntime-dev.modern.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,19 @@ function getComponentNameFromFiber(fiber) {
921921
}
922922

923923
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
924+
925+
function getOwner() {
926+
{
927+
var dispatcher = ReactSharedInternals.A;
928+
929+
if (dispatcher === null) {
930+
return null;
931+
}
932+
933+
return dispatcher.getOwner();
934+
}
935+
}
936+
924937
var specialPropKeyWarningShown;
925938
var specialPropRefWarningShown;
926939
var didWarnAboutStringRefs;
@@ -961,11 +974,13 @@ function hasValidKey(config) {
961974

962975
function warnIfStringRefCannotBeAutoConverted(config, self) {
963976
{
964-
if (typeof config.ref === 'string' && ReactSharedInternals.owner && self && ReactSharedInternals.owner.stateNode !== self) {
965-
var componentName = getComponentNameFromType(ReactSharedInternals.owner.type);
977+
var owner;
978+
979+
if (typeof config.ref === 'string' && (owner = getOwner()) && self && owner.stateNode !== self) {
980+
var componentName = getComponentNameFromType(owner.type);
966981

967982
if (!didWarnAboutStringRefs[componentName]) {
968-
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://react.dev/link/strict-mode-string-ref', getComponentNameFromType(ReactSharedInternals.owner.type), config.ref);
983+
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://react.dev/link/strict-mode-string-ref', getComponentNameFromType(owner.type), config.ref);
969984

970985
didWarnAboutStringRefs[componentName] = true;
971986
}
@@ -1266,7 +1281,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
12661281
ref = config.ref;
12671282

12681283
{
1269-
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
1284+
ref = coerceStringRef(ref, getOwner(), type);
12701285
}
12711286
}
12721287

@@ -1298,7 +1313,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
12981313
// Skip over reserved prop names
12991314
if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
13001315
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
1301-
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
1316+
props.ref = coerceStringRef(config[propName], getOwner(), type);
13021317
} else {
13031318
props[propName] = config[propName];
13041319
}
@@ -1331,7 +1346,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
13311346
}
13321347
}
13331348

1334-
var element = ReactElement(type, key, ref, self, source, ReactSharedInternals.owner, props);
1349+
var element = ReactElement(type, key, ref, self, source, getOwner(), props);
13351350

13361351
if (type === REACT_FRAGMENT_TYPE) {
13371352
validateFragmentProps(element);
@@ -1343,8 +1358,10 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
13431358

13441359
function getDeclarationErrorAddendum() {
13451360
{
1346-
if (ReactSharedInternals.owner) {
1347-
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
1361+
var owner = getOwner();
1362+
1363+
if (owner) {
1364+
var name = getComponentNameFromType(owner.type);
13481365

13491366
if (name) {
13501367
return '\n\nCheck the render method of `' + name + '`.';
@@ -1451,7 +1468,7 @@ function validateExplicitKey(element, parentType) {
14511468

14521469
var childOwner = '';
14531470

1454-
if (element && element._owner != null && element._owner !== ReactSharedInternals.owner) {
1471+
if (element && element._owner != null && element._owner !== getOwner()) {
14551472
var ownerName = null;
14561473

14571474
if (typeof element._owner.tag === 'number') {

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f8a8eac86bac406724f327325f804e65e594dd68
1+
94eed63c49d989861ae7cd62e111de6d717f0a10

compiled/facebook-www/React-dev.classic.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (
2525
) {
2626
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2727
}
28-
var ReactVersion = '19.0.0-www-classic-e47f6d99';
28+
var ReactVersion = '19.0.0-www-classic-c72bd03a';
2929

3030
// Re-export dynamic flags from the www version.
3131
var dynamicFeatureFlags = require('ReactFeatureFlags');
@@ -566,14 +566,10 @@ function getComponentNameFromType(type) {
566566

567567
var ReactSharedInternals = {
568568
H: null,
569-
C: null,
569+
A: null,
570570
T: null
571571
};
572572

573-
{
574-
ReactSharedInternals.owner = null;
575-
}
576-
577573
{
578574
ReactSharedInternals.actQueue = null;
579575
ReactSharedInternals.isBatchingLegacy = false;
@@ -1204,6 +1200,19 @@ function getComponentNameFromFiber(fiber) {
12041200
}
12051201

12061202
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
1203+
1204+
function getOwner() {
1205+
{
1206+
var dispatcher = ReactSharedInternals.A;
1207+
1208+
if (dispatcher === null) {
1209+
return null;
1210+
}
1211+
1212+
return dispatcher.getOwner();
1213+
}
1214+
}
1215+
12071216
var specialPropKeyWarningShown;
12081217
var specialPropRefWarningShown;
12091218
var didWarnAboutStringRefs;
@@ -1245,11 +1254,13 @@ function hasValidKey(config) {
12451254

12461255
function warnIfStringRefCannotBeAutoConverted(config, self) {
12471256
{
1248-
if (typeof config.ref === 'string' && ReactSharedInternals.owner && self && ReactSharedInternals.owner.stateNode !== self) {
1249-
var componentName = getComponentNameFromType(ReactSharedInternals.owner.type);
1257+
var owner;
1258+
1259+
if (typeof config.ref === 'string' && (owner = getOwner()) && self && owner.stateNode !== self) {
1260+
var componentName = getComponentNameFromType(owner.type);
12501261

12511262
if (!didWarnAboutStringRefs[componentName]) {
1252-
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://react.dev/link/strict-mode-string-ref', getComponentNameFromType(ReactSharedInternals.owner.type), config.ref);
1263+
error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://react.dev/link/strict-mode-string-ref', getComponentNameFromType(owner.type), config.ref);
12531264

12541265
didWarnAboutStringRefs[componentName] = true;
12551266
}
@@ -1574,7 +1585,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
15741585
ref = config.ref;
15751586

15761587
{
1577-
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
1588+
ref = coerceStringRef(ref, getOwner(), type);
15781589
}
15791590
}
15801591

@@ -1606,7 +1617,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
16061617
// Skip over reserved prop names
16071618
if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
16081619
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
1609-
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
1620+
props.ref = coerceStringRef(config[propName], getOwner(), type);
16101621
} else {
16111622
props[propName] = config[propName];
16121623
}
@@ -1639,7 +1650,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
16391650
}
16401651
}
16411652

1642-
var element = ReactElement(type, key, ref, self, source, ReactSharedInternals.owner, props);
1653+
var element = ReactElement(type, key, ref, self, source, getOwner(), props);
16431654

16441655
if (type === REACT_FRAGMENT_TYPE) {
16451656
validateFragmentProps(element);
@@ -1719,7 +1730,7 @@ function createElement(type, config, children) {
17191730
ref = config.ref;
17201731

17211732
{
1722-
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
1733+
ref = coerceStringRef(ref, getOwner(), type);
17231734
}
17241735
}
17251736

@@ -1745,7 +1756,7 @@ function createElement(type, config, children) {
17451756
// transform never passed these as props; it used separate arguments.
17461757
propName !== '__self' && propName !== '__source') {
17471758
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
1748-
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
1759+
props.ref = coerceStringRef(config[propName], getOwner(), type);
17491760
} else {
17501761
props[propName] = config[propName];
17511762
}
@@ -1800,7 +1811,7 @@ function createElement(type, config, children) {
18001811
}
18011812
}
18021813

1803-
var element = ReactElement(type, key, ref, undefined, undefined, ReactSharedInternals.owner, props);
1814+
var element = ReactElement(type, key, ref, undefined, undefined, getOwner(), props);
18041815

18051816
if (type === REACT_FRAGMENT_TYPE) {
18061817
validateFragmentProps(element);
@@ -1834,7 +1845,7 @@ function cloneElement(element, config, children) {
18341845

18351846
if (config != null) {
18361847
if (hasValidRef(config)) {
1837-
owner = ReactSharedInternals.owner;
1848+
owner = getOwner() ;
18381849

18391850
if (!enableRefAsProp) {
18401851
// Silently steal the ref from the parent.
@@ -1914,8 +1925,10 @@ function cloneElement(element, config, children) {
19141925

19151926
function getDeclarationErrorAddendum() {
19161927
{
1917-
if (ReactSharedInternals.owner) {
1918-
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
1928+
var owner = getOwner();
1929+
1930+
if (owner) {
1931+
var name = getComponentNameFromType(owner.type);
19191932

19201933
if (name) {
19211934
return '\n\nCheck the render method of `' + name + '`.';
@@ -2022,7 +2035,7 @@ function validateExplicitKey(element, parentType) {
20222035

20232036
var childOwner = '';
20242037

2025-
if (element && element._owner != null && element._owner !== ReactSharedInternals.owner) {
2038+
if (element && element._owner != null && element._owner !== getOwner()) {
20262039
var ownerName = null;
20272040

20282041
if (typeof element._owner.tag === 'number') {
@@ -2854,7 +2867,7 @@ function resolveDispatcher() {
28542867
}
28552868

28562869
function getCacheForType(resourceType) {
2857-
var dispatcher = ReactSharedInternals.C;
2870+
var dispatcher = ReactSharedInternals.A;
28582871

28592872
if (!dispatcher) {
28602873
// If there is no dispatcher, then we treat this as not being cached.

0 commit comments

Comments
 (0)