Skip to content

Commit

Permalink
Remove method name prefix from warnings and errors (#28432)
Browse files Browse the repository at this point in the history
This pattern is a petpeeve of mine. I don't consider this best practice
and so most don't have these prefixes. Very inconsistent.

At best this is useless and noisey that you have to parse because the
information is also in the stack trace.

At worse these are misleading because they're highlighting something
internal (like validateDOMNesting) which even suggests an internal bug.
Even the ones public to React aren't necessarily what you called because
you might be calling a wrapper around it.

That would be properly reflected in a stack trace - which can also
properly ignore list so that the first stack you see is your callsite,

Which might be like `render()` in react-testing-library rather than
`createRoot()` for example.

DiffTrain build for commit d579e77.
  • Loading branch information
sebmarkbage committed Feb 23, 2024
1 parent 2b0bca0 commit 355d677
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<20ec57c573e0a0a7a0d1a3309fa44b1b>>
* @generated SignedSource<<cef9df27ccdfbbffd9d4f74c26147558>>
*/

"use strict";
Expand Down Expand Up @@ -10966,21 +10966,20 @@ if (__DEV__) {
Object.freeze(fakeInternalInstance);
}

function warnOnInvalidCallback(callback, callerName) {
function warnOnInvalidCallback(callback) {
{
if (callback === null || typeof callback === "function") {
return;
}
} // eslint-disable-next-line react-internal/safe-string-coercion

var key = callerName + "_" + callback;
var key = String(callback);

if (!didWarnOnInvalidCallback.has(key)) {
didWarnOnInvalidCallback.add(key);

error(
"%s(...): Expected the last optional `callback` argument to be a " +
"Expected the last optional `callback` argument to be a " +
"function. Instead received: %s.",
callerName,
callback
);
}
Expand Down Expand Up @@ -11043,7 +11042,7 @@ if (__DEV__) {

if (callback !== undefined && callback !== null) {
{
warnOnInvalidCallback(callback, "setState");
warnOnInvalidCallback(callback);
}

update.callback = callback;
Expand All @@ -11065,7 +11064,7 @@ if (__DEV__) {

if (callback !== undefined && callback !== null) {
{
warnOnInvalidCallback(callback, "replaceState");
warnOnInvalidCallback(callback);
}

update.callback = callback;
Expand All @@ -11087,7 +11086,7 @@ if (__DEV__) {

if (callback !== undefined && callback !== null) {
{
warnOnInvalidCallback(callback, "forceUpdate");
warnOnInvalidCallback(callback);
}

update.callback = callback;
Expand Down Expand Up @@ -11152,13 +11151,13 @@ if (__DEV__) {
if (!renderPresent) {
if (ctor.prototype && typeof ctor.prototype.render === "function") {
error(
"%s(...): No `render` method found on the returned component " +
"No `render` method found on the %s " +
"instance: did you accidentally return an object from the constructor?",
name
);
} else {
error(
"%s(...): No `render` method found on the returned component " +
"No `render` method found on the %s " +
"instance: you may have forgotten to define `render`.",
name
);
Expand Down Expand Up @@ -11293,9 +11292,8 @@ if (__DEV__) {

if (instance.props !== undefined && hasMutatedProps) {
error(
"%s(...): When calling super() in `%s`, make sure to pass " +
"When calling super() in `%s`, make sure to pass " +
"up the same props that your component's constructor was passed.",
name,
name
);
}
Expand Down Expand Up @@ -13963,7 +13961,8 @@ if (__DEV__) {
if (Component) {
if (Component.childContextTypes) {
error(
"%s(...): childContextTypes cannot be defined on a function component.",
"childContextTypes cannot be defined on a function component.\n" +
" %s.childContextTypes = ...",
Component.displayName || Component.name || "Component"
);
}
Expand Down Expand Up @@ -25728,7 +25727,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-canary-8fb0233a8-20240223";
var ReactVersion = "18.3.0-canary-d579e7748-20240223";

// Might add PROFILE later.

Expand Down Expand Up @@ -25825,7 +25824,7 @@ if (__DEV__) {
{
if (typeof callback !== "function") {
error(
"render(...): Expected the last optional `callback` argument to be a " +
"Expected the last optional `callback` argument to be a " +
"function. Instead received: %s.",
callback
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9171,7 +9171,7 @@ var devToolsConfig$jscomp$inline_1014 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-8fb0233a8-20240223",
version: "18.3.0-canary-d579e7748-20240223",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1195 = {
Expand Down Expand Up @@ -9202,7 +9202,7 @@ var internals$jscomp$inline_1195 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-8fb0233a8-20240223"
reconcilerVersion: "18.3.0-canary-d579e7748-20240223"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1196 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9599,7 +9599,7 @@ var devToolsConfig$jscomp$inline_1056 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-8fb0233a8-20240223",
version: "18.3.0-canary-d579e7748-20240223",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1236 = {
Expand Down Expand Up @@ -9630,7 +9630,7 @@ var internals$jscomp$inline_1236 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-8fb0233a8-20240223"
reconcilerVersion: "18.3.0-canary-d579e7748-20240223"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1237 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<0ecfa00d9e6316d213c0fcd6bd2fed34>>
* @generated SignedSource<<5829f9269f50c47e26af16e11355c71d>>
*/

"use strict";
Expand All @@ -26,7 +26,7 @@ if (__DEV__) {
}
var dynamicFlags = require("ReactNativeInternalFeatureFlags");

var ReactVersion = "18.3.0-canary-8fb0233a8-20240223";
var ReactVersion = "18.3.0-canary-d579e7748-20240223";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -383,7 +383,7 @@ if (__DEV__) {
partialState != null
) {
throw new Error(
"setState(...): takes an object of state variables to update or a " +
"takes an object of state variables to update or a " +
"function which returns an object of state variables."
);
}
Expand Down Expand Up @@ -1885,7 +1885,7 @@ if (__DEV__) {
function cloneElement(element, config, children) {
if (element === null || element === undefined) {
throw new Error(
"React.cloneElement(...): The argument must be a React element, but you passed " +
"The argument must be a React element, but you passed " +
element +
"."
);
Expand Down Expand Up @@ -2806,7 +2806,7 @@ if (__DEV__) {
// $FlowFixMe[missing-local-annot]
set: function (newDefaultProps) {
error(
"React.lazy(...): It is not supported to assign `defaultProps` to " +
"It is not supported to assign `defaultProps` to " +
"a lazy component import. Either specify them where the component " +
"is defined, or create a wrapping component around it."
);
Expand All @@ -2827,7 +2827,7 @@ if (__DEV__) {
// $FlowFixMe[missing-local-annot]
set: function (newPropTypes) {
error(
"React.lazy(...): It is not supported to assign `propTypes` to " +
"It is not supported to assign `propTypes` to " +
"a lazy component import. Either specify them where the component " +
"is defined, or create a wrapping component around it."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<37f4ed7242b99027f4654904bb633f36>>
* @generated SignedSource<<0993517f18dba2ba924e7d54b3b13100>>
*/

"use strict";
Expand Down Expand Up @@ -61,7 +61,7 @@ Component.prototype.setState = function (partialState, callback) {
null != partialState
)
throw Error(
"setState(...): takes an object of state variables to update or a function which returns an object of state variables."
"takes an object of state variables to update or a function which returns an object of state variables."
);
this.updater.enqueueSetState(this, partialState, callback, "setState");
};
Expand Down Expand Up @@ -422,9 +422,7 @@ exports.cache = function (fn) {
exports.cloneElement = function (element, config, children) {
if (null === element || void 0 === element)
throw Error(
"React.cloneElement(...): The argument must be a React element, but you passed " +
element +
"."
"The argument must be a React element, but you passed " + element + "."
);
var props = assign({}, element.props),
key = element.key,
Expand Down Expand Up @@ -600,4 +598,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-8fb0233a8-20240223";
exports.version = "18.3.0-canary-d579e7748-20240223";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<04ca2715fce5363a86317b200bb764c0>>
* @generated SignedSource<<0c357b236599560d718ddaa394fc28e0>>
*/

"use strict";
Expand Down Expand Up @@ -64,7 +64,7 @@ Component.prototype.setState = function (partialState, callback) {
null != partialState
)
throw Error(
"setState(...): takes an object of state variables to update or a function which returns an object of state variables."
"takes an object of state variables to update or a function which returns an object of state variables."
);
this.updater.enqueueSetState(this, partialState, callback, "setState");
};
Expand Down Expand Up @@ -389,9 +389,7 @@ exports.cache = function (fn) {
exports.cloneElement = function (element, config, children) {
if (null === element || void 0 === element)
throw Error(
"React.cloneElement(...): The argument must be a React element, but you passed " +
element +
"."
"The argument must be a React element, but you passed " + element + "."
);
var props = assign({}, element.props),
key = element.key,
Expand Down Expand Up @@ -596,7 +594,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-8fb0233a8-20240223";
exports.version = "18.3.0-canary-d579e7748-20240223";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8fb0233a845974b4b1049e54b6c25dc54d6dd173
d579e7748218920331252b0528850943d5e2dd31
Loading

0 comments on commit 355d677

Please sign in to comment.