Skip to content

Commit

Permalink
[string-refs] log string ref from prod (#31161)
Browse files Browse the repository at this point in the history
If passed as a feature flag, this calls the configured function when a
string ref is used even from prod code to find the last usages.

DiffTrain build for [5636fad](5636fad)
  • Loading branch information
kassens committed Oct 10, 2024
1 parent 877636d commit 0ccec15
Show file tree
Hide file tree
Showing 36 changed files with 728 additions and 176 deletions.
5 changes: 4 additions & 1 deletion compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ __DEV__ &&
)
(type = getComponentNameFromFiber(owner) || "Component"),
didWarnAboutStringRefs[type] ||
(error(
(enableLogStringRefsProd &&
enableLogStringRefsProd(type, stringRef),
error(
'Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. We recommend using useRef() or createRef() instead. Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref',
type,
stringRef
Expand All @@ -811,6 +813,7 @@ __DEV__ &&
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
enableLogStringRefsProd = dynamicFeatureFlags.enableLogStringRefsProd,
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
Expand Down
5 changes: 4 additions & 1 deletion compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ __DEV__ &&
)
(type = getComponentNameFromFiber(owner) || "Component"),
didWarnAboutStringRefs[type] ||
(error(
(enableLogStringRefsProd &&
enableLogStringRefsProd(type, stringRef),
error(
'Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. We recommend using useRef() or createRef() instead. Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref',
type,
stringRef
Expand All @@ -808,6 +810,7 @@ __DEV__ &&
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
enableLogStringRefsProd = dynamicFeatureFlags.enableLogStringRefsProd,
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing;
dynamicFeatureFlags = dynamicFeatureFlags.renameElementSymbol;
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b78a7f2f35e554a8647c3262d7f392e68d06febc
5636fad840942cfea80301d91e931a50c6370d19
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b78a7f2f35e554a8647c3262d7f392e68d06febc
5636fad840942cfea80301d91e931a50c6370d19
7 changes: 5 additions & 2 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,9 @@ __DEV__ &&
)
(type = getComponentNameFromFiber(owner) || "Component"),
didWarnAboutStringRefs[type] ||
(error$jscomp$0(
(enableLogStringRefsProd &&
enableLogStringRefsProd(type, stringRef),
error$jscomp$0(
'Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. We recommend using useRef() or createRef() instead. Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref',
type,
stringRef
Expand Down Expand Up @@ -1200,6 +1202,7 @@ __DEV__ &&
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
enableLogStringRefsProd = dynamicFeatureFlags.enableLogStringRefsProd,
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
Expand Down Expand Up @@ -2002,7 +2005,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
exports.version = "19.0.0-www-classic-5636fad8-20241010";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
7 changes: 5 additions & 2 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,9 @@ __DEV__ &&
)
(type = getComponentNameFromFiber(owner) || "Component"),
didWarnAboutStringRefs[type] ||
(error$jscomp$0(
(enableLogStringRefsProd &&
enableLogStringRefsProd(type, stringRef),
error$jscomp$0(
'Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. We recommend using useRef() or createRef() instead. Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref',
type,
stringRef
Expand Down Expand Up @@ -1197,6 +1199,7 @@ __DEV__ &&
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
enableLogStringRefsProd = dynamicFeatureFlags.enableLogStringRefsProd,
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
Expand Down Expand Up @@ -1982,7 +1985,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
exports.version = "19.0.0-www-modern-5636fad8-20241010";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
155 changes: 146 additions & 9 deletions compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
var dynamicFeatureFlags = require("ReactFeatureFlags"),
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
enableLogStringRefsProd = dynamicFeatureFlags.enableLogStringRefsProd,
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
disableLegacyMode = dynamicFeatureFlags.disableLegacyMode,
REACT_LEGACY_ELEMENT_TYPE = Symbol.for("react.element"),
REACT_ELEMENT_TYPE = renameElementSymbol
? Symbol.for("react.transitional.element")
Expand Down Expand Up @@ -90,12 +92,140 @@ pureComponentPrototype.constructor = PureComponent;
assign(pureComponentPrototype, Component.prototype);
pureComponentPrototype.isPureReactComponent = !0;
var isArrayImpl = Array.isArray,
ReactSharedInternals = { H: null, A: null, T: null, S: null },
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
function getComponentNameFromType(type) {
if (null == type) return null;
if ("function" === typeof type)
return type.$$typeof === REACT_CLIENT_REFERENCE
? null
: type.displayName || type.name || null;
if ("string" === typeof type) return type;
switch (type) {
case REACT_FRAGMENT_TYPE:
return "Fragment";
case REACT_PORTAL_TYPE:
return "Portal";
case REACT_PROFILER_TYPE:
return "Profiler";
case REACT_STRICT_MODE_TYPE:
return "StrictMode";
case REACT_SUSPENSE_TYPE:
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_TRACING_MARKER_TYPE:
if (enableTransitionTracing) return "TracingMarker";
}
if ("object" === typeof type)
switch (type.$$typeof) {
case REACT_PROVIDER_TYPE:
if (enableRenderableContext) break;
else return (type._context.displayName || "Context") + ".Provider";
case REACT_CONTEXT_TYPE:
return enableRenderableContext
? (type.displayName || "Context") + ".Provider"
: (type.displayName || "Context") + ".Consumer";
case REACT_CONSUMER_TYPE:
if (enableRenderableContext)
return (type._context.displayName || "Context") + ".Consumer";
break;
case REACT_FORWARD_REF_TYPE:
var innerType = type.render;
type = type.displayName;
type ||
((type = innerType.displayName || innerType.name || ""),
(type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
return type;
case REACT_MEMO_TYPE:
return (
(innerType = type.displayName || null),
null !== innerType
? innerType
: getComponentNameFromType(type.type) || "Memo"
);
case REACT_LAZY_TYPE:
innerType = type._payload;
type = type._init;
try {
return getComponentNameFromType(type(innerType));
} catch (x) {}
}
return null;
}
var ReactSharedInternals = { H: null, A: null, T: null, S: null },
hasOwnProperty = Object.prototype.hasOwnProperty;
function getComponentNameFromFiber(fiber) {
var type = fiber.type;
switch (fiber.tag) {
case 24:
return "Cache";
case 9:
return enableRenderableContext
? (type._context.displayName || "Context") + ".Consumer"
: (type.displayName || "Context") + ".Consumer";
case 10:
return enableRenderableContext
? (type.displayName || "Context") + ".Provider"
: (type._context.displayName || "Context") + ".Provider";
case 18:
return "DehydratedFragment";
case 11:
return (
(fiber = type.render),
(fiber = fiber.displayName || fiber.name || ""),
type.displayName ||
("" !== fiber ? "ForwardRef(" + fiber + ")" : "ForwardRef")
);
case 7:
return "Fragment";
case 26:
case 27:
case 5:
return type;
case 4:
return "Portal";
case 3:
return "Root";
case 6:
return "Text";
case 16:
return getComponentNameFromType(type);
case 8:
return type === REACT_STRICT_MODE_TYPE ? "StrictMode" : "Mode";
case 22:
return "Offscreen";
case 12:
return "Profiler";
case 21:
return "Scope";
case 13:
return "Suspense";
case 19:
return "SuspenseList";
case 25:
return "TracingMarker";
case 17:
case 28:
if (disableLegacyMode) break;
case 1:
case 0:
case 14:
case 15:
if ("function" === typeof type)
return type.displayName || type.name || null;
if ("string" === typeof type) return type;
break;
case 23:
return "LegacyHidden";
}
return null;
}
function getOwner() {
var dispatcher = ReactSharedInternals.A;
return null === dispatcher ? null : dispatcher.getOwner();
}
var didWarnAboutStringRefs;
enableLogStringRefsProd && (didWarnAboutStringRefs = {});
function ReactElement(type, key, _ref, self, source, owner, props) {
_ref = props.ref;
return {
Expand All @@ -121,9 +251,9 @@ function jsxProd(type, config, maybeKey) {
} else maybeKey = config;
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
config = type.defaultProps;
for (var propName$0 in config)
void 0 === maybeKey[propName$0] &&
(maybeKey[propName$0] = config[propName$0]);
for (var propName$1 in config)
void 0 === maybeKey[propName$1] &&
(maybeKey[propName$1] = config[propName$1]);
}
return ReactElement(type, key, null, void 0, void 0, getOwner(), maybeKey);
}
Expand Down Expand Up @@ -167,15 +297,22 @@ function stringRefAsCallbackRef(stringRef, type, owner, value) {
throw Error(
"Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref"
);
type = owner.stateNode;
if (!type)
enableLogStringRefsProd &&
("function" !== typeof type ||
(type.prototype && type.prototype.isReactComponent)) &&
((type = getComponentNameFromFiber(owner) || "Component"),
didWarnAboutStringRefs[type] ||
(enableLogStringRefsProd && enableLogStringRefsProd(type, stringRef),
(didWarnAboutStringRefs[type] = !0)));
owner = owner.stateNode;
if (!owner)
throw Error(
"Missing owner for string ref " +
stringRef +
". This error is likely caused by a bug in React. Please file an issue."
);
type = type.refs;
null === value ? delete type[stringRef] : (type[stringRef] = value);
owner = owner.refs;
null === value ? delete owner[stringRef] : (owner[stringRef] = value);
}
function escape(key) {
var escaperLookup = { "=": "=0", ":": "=2" };
Expand Down Expand Up @@ -667,4 +804,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
exports.version = "19.0.0-www-classic-5636fad8-20241010";
Loading

0 comments on commit 0ccec15

Please sign in to comment.