Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove method name prefix from warnings and errors #28432

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

sebmarkbage
Copy link
Collaborator

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.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 23, 2024
@sebmarkbage
Copy link
Collaborator Author

I also don't think we should add Warning: to console.error.

@react-sizebot
Copy link

react-sizebot commented Feb 23, 2024

Comparing: 66c8346...8515602

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 176.86 kB 176.86 kB = 55.14 kB 55.13 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 179.01 kB 179.01 kB = 55.78 kB 55.77 kB
facebook-www/ReactDOM-prod.classic.js = 592.40 kB 592.40 kB = 104.67 kB 104.66 kB
facebook-www/ReactDOM-prod.modern.js = 575.68 kB 575.68 kB = 101.66 kB 101.65 kB
test_utils/ReactAllWarnings.js Deleted 66.59 kB 0.00 kB Deleted 16.30 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-www/React-profiling.classic.js = 21.07 kB 21.01 kB = 5.25 kB 5.23 kB
facebook-www/React-profiling.modern.js = 20.78 kB 20.73 kB = 5.18 kB 5.17 kB
facebook-www/React-prod.classic.js = 20.64 kB 20.58 kB = 5.17 kB 5.15 kB
facebook-www/React-prod.modern.js = 20.35 kB 20.29 kB = 5.10 kB 5.08 kB
facebook-react-native/react/cjs/React-profiling.js = 19.27 kB 19.22 kB = 4.88 kB 4.86 kB
facebook-react-native/react/cjs/React-prod.js = 19.13 kB 19.07 kB = 4.86 kB 4.85 kB
oss-experimental/react/umd/react.production.min.js = 13.32 kB 13.28 kB = 5.08 kB 5.07 kB
oss-experimental/react/umd/react.profiling.min.js = 13.32 kB 13.28 kB = 5.08 kB 5.07 kB
oss-stable/react/umd/react.production.min.js = 12.44 kB 12.40 kB = 4.81 kB 4.79 kB
oss-stable/react/umd/react.profiling.min.js = 12.44 kB 12.40 kB = 4.81 kB 4.79 kB
oss-stable-semver/react/umd/react.production.min.js = 12.42 kB 12.38 kB = 4.78 kB 4.77 kB
oss-stable-semver/react/umd/react.profiling.min.js = 12.42 kB 12.38 kB = 4.78 kB 4.77 kB
oss-experimental/react/cjs/react.production.min.js = 9.59 kB 9.55 kB = 3.57 kB 3.55 kB
oss-experimental/react-dom/umd/react-dom-test-utils.development.js = 58.43 kB 58.17 kB = 16.24 kB 16.21 kB
oss-stable-semver/react-dom/umd/react-dom-test-utils.development.js = 58.43 kB 58.17 kB = 16.24 kB 16.21 kB
oss-stable/react-dom/umd/react-dom-test-utils.development.js = 58.43 kB 58.17 kB = 16.24 kB 16.21 kB
oss-stable/react/cjs/react.production.min.js = 8.65 kB 8.61 kB = 3.28 kB 3.26 kB
oss-stable-semver/react/cjs/react.production.min.js = 8.62 kB 8.58 kB = 3.25 kB 3.24 kB
oss-experimental/react-dom/cjs/react-dom-test-utils.development.js = 55.27 kB 55.01 kB = 15.97 kB 15.92 kB
oss-stable-semver/react-dom/cjs/react-dom-test-utils.development.js = 55.27 kB 55.01 kB = 15.97 kB 15.92 kB
oss-stable/react-dom/cjs/react-dom-test-utils.development.js = 55.27 kB 55.01 kB = 15.97 kB 15.92 kB
facebook-www/ReactTestUtils-dev.classic.js = 54.41 kB 54.14 kB = 13.84 kB 13.80 kB
facebook-www/ReactTestUtils-dev.modern.js = 54.41 kB 54.14 kB = 13.84 kB 13.80 kB
oss-experimental/react-dom/cjs/react-dom-test-utils.production.js = 45.44 kB 45.18 kB = 12.85 kB 12.81 kB
oss-stable-semver/react-dom/cjs/react-dom-test-utils.production.js = 45.44 kB 45.18 kB = 12.85 kB 12.81 kB
oss-stable/react-dom/cjs/react-dom-test-utils.production.js = 45.44 kB 45.18 kB = 12.85 kB 12.81 kB
oss-experimental/react-dom/cjs/react-dom-test-utils.production.min.js = 12.67 kB 12.43 kB = 4.85 kB 4.82 kB
oss-stable-semver/react-dom/cjs/react-dom-test-utils.production.min.js = 12.67 kB 12.43 kB = 4.85 kB 4.82 kB
oss-stable/react-dom/cjs/react-dom-test-utils.production.min.js = 12.67 kB 12.43 kB = 4.85 kB 4.82 kB
oss-experimental/react-dom/umd/react-dom-test-utils.production.min.js = 12.77 kB 12.52 kB = 4.91 kB 4.87 kB
oss-stable-semver/react-dom/umd/react-dom-test-utils.production.min.js = 12.77 kB 12.52 kB = 4.91 kB 4.87 kB
oss-stable/react-dom/umd/react-dom-test-utils.production.min.js = 12.77 kB 12.52 kB = 4.91 kB 4.87 kB
test_utils/ReactAllWarnings.js Deleted 66.59 kB 0.00 kB Deleted 16.30 kB 0.00 kB

Generated by 🚫 dangerJS against 8515602

@yungsters
Copy link
Contributor

I'm not opposed to this change, but I wanted to provide some historical context.

This was a practice adopted from some early Facebook codebases when stack traces, symbolication, and production reporting were still a total mess. Providing these helped give us some semblance of diagnostic similar to the top stack frame in modern tooling.

I also don't think we should add Warning: to console.error.

Also not opposed, just want to make you aware of this dependent:

https://github.com/facebook/react-native/blob/2647dc8c3976e2e8763faa3f4a23b59e9a0ad218/packages/react-native/Libraries/LogBox/LogBox.js#L179-L188

@sebmarkbage
Copy link
Collaborator Author

Also not opposed, just want to make you aware of this dependent:

https://github.com/facebook/react-native/blob/2647dc8c3976e2e8763faa3f4a23b59e9a0ad218/packages/react-native/Libraries/LogBox/LogBox.js#L179-L188

DevTools itself has to do the same thing but the "correct" (meaning consistent) way is this check:

const alreadyHasComponentStack =
typeof lastArg === 'string' && isStringComponentStack(lastArg);

Maybe we can update LogBox to do the same check?

@sebmarkbage sebmarkbage force-pushed the rmerrorprefixes branch 2 times, most recently from 320cc9c to af31c9b Compare February 23, 2024 18:07
"121": "performUpdateIfNecessary: Unexpected batch number (current %s, pending %s)",
"122": "%s(...): Expected the last optional `callback` argument to be a function. Instead received: %s.",
Copy link
Collaborator Author

@sebmarkbage sebmarkbage Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this shifts where the second argument is, I'm going to give this a new error code. Otherwise args from old links would end up showing the argument in the wrong place on the docs page.

"279": "Trying to release an event instance into a pool of a different type.",
"280": "setRestoreImplementation() needs to be called to handle a target for controlled events. This error is likely caused by a bug in React. Please file an issue.",
"281": "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue.",
"282": "If the root does not have an updateQueue, we should have already bailed out. This error is likely caused by a bug in React. Please file an issue.",
"283": "Element type is invalid. Received a promise that resolves to: %s. Promise elements must resolve to a class or function.",
"284": "Expected ref to be a function, a string, an object returned by React.createRef(), or null.",
"285": "The root failed to unmount after an error. This is likely a bug in React. Please file an issue.",
"286": "%s(...): the first argument must be a React class instance. Instead received: %s.",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@sebmarkbage sebmarkbage force-pushed the rmerrorprefixes branch 2 times, most recently from 73e340c to 97b4970 Compare February 23, 2024 18:21
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'rehighlighting 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.
@sebmarkbage sebmarkbage merged commit d579e77 into facebook:main Feb 23, 2024
37 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 23, 2024
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 [d579e77](d579e77)
@rickhanlonii
Copy link
Member

@sebmarkbage the WarningFilter depends on that Warning: prefix too in order to know which errors are Reacts, we'll need to update that too with some other kind of heuristic

EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
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.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants