Skip to content

Commit

Permalink
(Land #28798) Move Current Owner (and Cache) to an Async Dispatcher (#…
Browse files Browse the repository at this point in the history
…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 <sebastian@calyptus.eu>

DiffTrain build for [94eed63](94eed63)
  • Loading branch information
gnoff committed Apr 25, 2024
1 parent aef84c3 commit 9e2d714
Show file tree
Hide file tree
Showing 35 changed files with 1,016 additions and 864 deletions.
35 changes: 26 additions & 9 deletions compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,19 @@ function getComponentNameFromFiber(fiber) {
}

var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');

function getOwner() {
{
var dispatcher = ReactSharedInternals.A;

if (dispatcher === null) {
return null;
}

return dispatcher.getOwner();
}
}

var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -958,11 +971,13 @@ function hasValidKey(config) {

function warnIfStringRefCannotBeAutoConverted(config, self) {
{
if (typeof config.ref === 'string' && ReactSharedInternals.owner && self && ReactSharedInternals.owner.stateNode !== self) {
var componentName = getComponentNameFromType(ReactSharedInternals.owner.type);
var owner;

if (typeof config.ref === 'string' && (owner = getOwner()) && self && owner.stateNode !== self) {
var componentName = getComponentNameFromType(owner.type);

if (!didWarnAboutStringRefs[componentName]) {
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);
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);

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

{
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
ref = coerceStringRef(ref, getOwner(), type);
}
}

Expand Down Expand Up @@ -1295,7 +1310,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
// Skip over reserved prop names
if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
props.ref = coerceStringRef(config[propName], getOwner(), type);
} else {
props[propName] = config[propName];
}
Expand Down Expand Up @@ -1328,7 +1343,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
}
}

var element = ReactElement(type, key, ref, self, source, ReactSharedInternals.owner, props);
var element = ReactElement(type, key, ref, self, source, getOwner(), props);

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

function getDeclarationErrorAddendum() {
{
if (ReactSharedInternals.owner) {
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
var owner = getOwner();

if (owner) {
var name = getComponentNameFromType(owner.type);

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

var childOwner = '';

if (element && element._owner != null && element._owner !== ReactSharedInternals.owner) {
if (element && element._owner != null && element._owner !== getOwner()) {
var ownerName = null;

if (typeof element._owner.tag === 'number') {
Expand Down
35 changes: 26 additions & 9 deletions compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,19 @@ function getComponentNameFromFiber(fiber) {
}

var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');

function getOwner() {
{
var dispatcher = ReactSharedInternals.A;

if (dispatcher === null) {
return null;
}

return dispatcher.getOwner();
}
}

var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -961,11 +974,13 @@ function hasValidKey(config) {

function warnIfStringRefCannotBeAutoConverted(config, self) {
{
if (typeof config.ref === 'string' && ReactSharedInternals.owner && self && ReactSharedInternals.owner.stateNode !== self) {
var componentName = getComponentNameFromType(ReactSharedInternals.owner.type);
var owner;

if (typeof config.ref === 'string' && (owner = getOwner()) && self && owner.stateNode !== self) {
var componentName = getComponentNameFromType(owner.type);

if (!didWarnAboutStringRefs[componentName]) {
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);
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);

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

{
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
ref = coerceStringRef(ref, getOwner(), type);
}
}

Expand Down Expand Up @@ -1298,7 +1313,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
// Skip over reserved prop names
if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
props.ref = coerceStringRef(config[propName], getOwner(), type);
} else {
props[propName] = config[propName];
}
Expand Down Expand Up @@ -1331,7 +1346,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
}
}

var element = ReactElement(type, key, ref, self, source, ReactSharedInternals.owner, props);
var element = ReactElement(type, key, ref, self, source, getOwner(), props);

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

function getDeclarationErrorAddendum() {
{
if (ReactSharedInternals.owner) {
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
var owner = getOwner();

if (owner) {
var name = getComponentNameFromType(owner.type);

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

var childOwner = '';

if (element && element._owner != null && element._owner !== ReactSharedInternals.owner) {
if (element && element._owner != null && element._owner !== getOwner()) {
var ownerName = null;

if (typeof element._owner.tag === 'number') {
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f8a8eac86bac406724f327325f804e65e594dd68
94eed63c49d989861ae7cd62e111de6d717f0a10
53 changes: 33 additions & 20 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = '19.0.0-www-classic-e47f6d99';
var ReactVersion = '19.0.0-www-classic-c72bd03a';

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

var ReactSharedInternals = {
H: null,
C: null,
A: null,
T: null
};

{
ReactSharedInternals.owner = null;
}

{
ReactSharedInternals.actQueue = null;
ReactSharedInternals.isBatchingLegacy = false;
Expand Down Expand Up @@ -1204,6 +1200,19 @@ function getComponentNameFromFiber(fiber) {
}

var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');

function getOwner() {
{
var dispatcher = ReactSharedInternals.A;

if (dispatcher === null) {
return null;
}

return dispatcher.getOwner();
}
}

var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -1245,11 +1254,13 @@ function hasValidKey(config) {

function warnIfStringRefCannotBeAutoConverted(config, self) {
{
if (typeof config.ref === 'string' && ReactSharedInternals.owner && self && ReactSharedInternals.owner.stateNode !== self) {
var componentName = getComponentNameFromType(ReactSharedInternals.owner.type);
var owner;

if (typeof config.ref === 'string' && (owner = getOwner()) && self && owner.stateNode !== self) {
var componentName = getComponentNameFromType(owner.type);

if (!didWarnAboutStringRefs[componentName]) {
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);
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);

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

{
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
ref = coerceStringRef(ref, getOwner(), type);
}
}

Expand Down Expand Up @@ -1606,7 +1617,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
// Skip over reserved prop names
if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
props.ref = coerceStringRef(config[propName], getOwner(), type);
} else {
props[propName] = config[propName];
}
Expand Down Expand Up @@ -1639,7 +1650,7 @@ function jsxDEV$1(type, config, maybeKey, isStaticChildren, source, self) {
}
}

var element = ReactElement(type, key, ref, self, source, ReactSharedInternals.owner, props);
var element = ReactElement(type, key, ref, self, source, getOwner(), props);

if (type === REACT_FRAGMENT_TYPE) {
validateFragmentProps(element);
Expand Down Expand Up @@ -1719,7 +1730,7 @@ function createElement(type, config, children) {
ref = config.ref;

{
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
ref = coerceStringRef(ref, getOwner(), type);
}
}

Expand All @@ -1745,7 +1756,7 @@ function createElement(type, config, children) {
// transform never passed these as props; it used separate arguments.
propName !== '__self' && propName !== '__source') {
if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
props.ref = coerceStringRef(config[propName], ReactSharedInternals.owner, type);
props.ref = coerceStringRef(config[propName], getOwner(), type);
} else {
props[propName] = config[propName];
}
Expand Down Expand Up @@ -1800,7 +1811,7 @@ function createElement(type, config, children) {
}
}

var element = ReactElement(type, key, ref, undefined, undefined, ReactSharedInternals.owner, props);
var element = ReactElement(type, key, ref, undefined, undefined, getOwner(), props);

if (type === REACT_FRAGMENT_TYPE) {
validateFragmentProps(element);
Expand Down Expand Up @@ -1834,7 +1845,7 @@ function cloneElement(element, config, children) {

if (config != null) {
if (hasValidRef(config)) {
owner = ReactSharedInternals.owner;
owner = getOwner() ;

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

function getDeclarationErrorAddendum() {
{
if (ReactSharedInternals.owner) {
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
var owner = getOwner();

if (owner) {
var name = getComponentNameFromType(owner.type);

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

var childOwner = '';

if (element && element._owner != null && element._owner !== ReactSharedInternals.owner) {
if (element && element._owner != null && element._owner !== getOwner()) {
var ownerName = null;

if (typeof element._owner.tag === 'number') {
Expand Down Expand Up @@ -2854,7 +2867,7 @@ function resolveDispatcher() {
}

function getCacheForType(resourceType) {
var dispatcher = ReactSharedInternals.C;
var dispatcher = ReactSharedInternals.A;

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

0 comments on commit 9e2d714

Please sign in to comment.