Change warning() to automatically inject the stack, and add warningWithoutStack() as opt-out#13161
Merged
gaearon merged 13 commits intofacebook:masterfrom Jul 16, 2018
Merged
Conversation
Collaborator
Author
|
@sebmarkbage Not ready for review but feel free to flag if I'm going in some completely different direction than you imagined |
|
ReactDOM: size: -0.0%, gzip: -0.1% Details of bundled changes.Comparing: 854c953...e0eab4c react
react-dom
react-art
react-test-renderer
react-reconciler
react-native-renderer
simple-cache-provider
react-scheduler
Generated by 🚫 dangerJS |
67500ad to
71cafa8
Compare
a1903f4 to
c597279
Compare
I changed my mind and want to keep this PR without functional changes. So we won't "fix" any warnings that are already missing stacks. We'll do it in follow-ups instead.
c597279 to
349fb1e
Compare
bvaughn
approved these changes
Jul 16, 2018
| // Update | ||
| ReactNoop.render(<Context.Provider value={2} />); | ||
| ReactNoop.flush(); | ||
| }).toWarnDev( |
Contributor
There was a problem hiding this comment.
tiny nit: Might be nicer to move ReactNoop.render outside of the expect call.
| console.error('Hi %s'); | ||
| }).toWarnDev('Hi', {withoutStack: true}); | ||
| }).toThrow('Received 0 arguments for a message with 1 placeholders'); | ||
| }); |
| args, | ||
| expectedArgCount: argIndex, | ||
| }; | ||
| } |
Contributor
There was a problem hiding this comment.
Clever!
Could use an inline comment. Wasn't clear (to me at least) on first read what it was doing.
| 'warning() instead of warningWithoutStack() in a package that does not ' + | ||
| 'depend on React.' | ||
| ); | ||
| } |
| require.resolve(targetModule) | ||
| typeof targetModule === 'string' | ||
| ? require.resolve(targetModule) | ||
| : targetModule |
Collaborator
Author
There was a problem hiding this comment.
Since I added ability to return an error from a fork config, I need to ensure I don’t run require.resolve on that error 🙂
On the other hand I can’t throw it early either because I don’t know if that module will get used or not.
gaearon
added a commit
that referenced
this pull request
Jul 16, 2018
This is a leftover from #13161 that I forgot to include. It ensures we don't accidentally write code in the old way and end up passing the stack twice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This flips
warning()to always include a component stack by default if it exists. It also adds a counterpartwarningWithoutStack()for cases where you don't want to have a stack.I opted to have two separate methods because
warningarguments already have a meaning (they get interpolated). I decided against something likewarning.withoutStack()because this proved to be a bit annoying in the past (e.g.emptyFunction.*), and would be a tiny bit more difficult to adopt our transforms to. I don't feel strongly about this though.This PR shouldn't contain any functional changes. Only warnings without stacks were converted to use the new function. Warnings that already have stacks just lost their last argument because it's provided automatically now.
Why
ReactDebugCurrentFramedirect calls, imports, and wiring.warning(), e.g. determining whether we're in strict mode. Which is something we'll want to expose in every warning so that we can get rid of internal blacklist.How to Review
warning()that had stacks now omit the last formatting argument.warning()that didn't have stacks now usewarningWithoutStack().%sinterpolations in tests.One notable change is that instead of formatting before calling
console.error(), we now pass through the message and the arguments, e.g.console.error('%s is a bad component', 'Foo'). This works in all major browsers (including IE), and Node.js. Theoretically this might be a breaking change for somebody who was relying on filteringconsole.errorcalls by exact messages. But we already change warning messages between releases anyway, and this change should make it easier to filter messages because the original formatting string is now exposed before the interpolation.Work Log
warningWithStack()that automatically includes a stack from the currently injected implementation.warningWithStack()and remove threading ofgetStackthrough utilities shared between SSR and client.assertValidPropsand how they need the frame. Why don't test fails in prod there?warningWithStack()because it would create a circular dependency betweenReactandwarningWithStack.warning()have a stack, andwarningWithoutStack()its explicit counterpart.Follow-up work
warningWithStack()just do it by default? Other ideas?warningWithStack().getCurrentFiberStackAddendum. Always go through the central isomorphic module.%sinterpolation having already happened don't break