-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Components: replace console.warn with @wordpress/warning #19687
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for the follow-up work 💯
There are more places with console.warn
, should we leave them unchanged or we should open another PR?
Do you have any thoughts on how to simplify the API? It looks like warning( true, ... )
is the most popular usage. Maybe it could be optional and detection would be type based? /cc @aduth
function warning( messageOrCondition, ...messages ) {
const condition = typeof messageOrCondition === 'boolean' ? messageOrCondition : true;
if ( typeof messageOrCondition === 'string' ) {
messages.unshift( messageOrCondition );
}
...
}
I think this is a really good point to highlight, if a common use of this would have us passing I'm not sure if that's necessarily indicative that we won't want the condition to be considered in It might motivate us to consider whether we should treat the condition as at least optional, like @gziolo suggests. However, it seems like something where it could make sense to reverse the order of the arguments, which in my view would be a more natural way of handling this than overloading the function. Something like: function warning( message, condition = true ) {} Worth noting: We probably want to make a decision on this point before Monday's plugin release RC, so as to avoid going through a deprecation lifecycle. |
Based on my own experience using similar functions in other projects, I can say that I've updated the code to remove the condition parameter for now (I can create a separate PR for that if it's better). We can add it later as an optional parameter if needed.
What's the best way to introduce "experimental" packages? Can we release things as |
I added an edit to my previous comment in highlighting that one of the other benefits of including this as an argument to the function itself is that the logic associated with the condition can be removed as part of the production minification (via the associated Babel plugin). That being said, removing the argument would at least allow us to move forward and consider this as a future change, because either of the proposed adjustments (overloading vs. default parameter) would be backwards-compatible revisions.
I think for the NPM package, it doesn't matter so much. We can choose to bump the major version to represent a breaking change. If we really wanted to consider it experimental, I would think that should be effectively represented on the
https://semver.org/#spec-item-4 What matters more is that this would be exposed as a window global to plugin developers ( |
It still looks good to go. Good points raised by @aduth that it's safer to remove for now and iterate later. I like the fact that you could add the condition as part of the function call because it gets eliminated in the production mode together with the warning. Let's land this patch and work on the alternative approach separately.
It made me think that in production, there should be no |
Description
This PR implements the
@wordpress/warning
package introduced in #19317 on the@wordpress/components
package.How has this been tested?
npm run test-unit
Types of changes
Refactor
Checklist: