-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Introduce generic warnOnce
function for warning messages
#22109
Conversation
I really want to land this but Facebook hasn’t yet swapped over to the community one and we need to build a tad bit of infrastructure to support pulling in those 3rd party modules. Can we delay adding this warning for a few weeks until we can make that switch? |
Libraries/Utilities/warnMoved.js
Outdated
* @param {string} [renamed] - Optional; name of the API in the dest module, | ||
* if it was renamed | ||
*/ | ||
function warnMoved(api: string, destModule: string, renamed?: string) { |
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.
If you make another function called warnOnce then it can be used for the existing warnings in the api as well.
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.
sounds like a good idea! with the delay, maybe I should instead split this helper function into its own pull request?
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.
Split maybe a good idea. We may have more usage for this if we move more component out.
That sounds good! I wonder, maybe for cases like this we could have an |
That seems reasonable but I would worry that it would make it too easy for FB to have a diverging version of react-native which would be detrimental for everyone. For now, I'd rather keep the pressure on us to fix our stuff and get out of the way of progress. :) We currently have the work to migrate to the community WebView on our short term roadmap |
For the JS side of things, perhaps we should try and make a codemod to help rewrite imports of |
Writing a codemod would be great! The community will need that when they upgrade to the version without WebView. If you don't want to work on it I'm sure there is someone around who would appreciate that opportunity! |
What's the status of this PR? |
Looks like I have to resolve a merge conflict, but I think the issue @TheSavior brought up above might still be relevant (I also need to still split this up into a separate helper function too) |
Libraries/Utilities/warnMoved.js
Outdated
|
||
warning( | ||
false, | ||
`'${api}' has moved to another module and will be removed from 'react-native' ` + |
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.
Could we add something like:
yarn add ${destModule}
to the instructions?
I've been meaning to address this PR's issues, I will try to get to it this week! |
@empyrical do you wanna pick this back up or close it? |
It looks like I took so long to pick this back up that there is another warning in place on I can pick this back up though, it would still be useful for the generic "warnOnce()" function so all the warnings in |
Yes exactly! A generic warning function is still valuable. Do you wanna modify your existing PR to do that or close this one and open a new one? |
35495d3
to
39fe07c
Compare
warnOnce
function for warning messages
I've modified this PR instead of making a new one 👍 |
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.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
This is nice, thank you :)
@empyrical merged commit 9a7fff9 into |
…22109) Summary: This pull request adds a function called `warnOnce` that prints a warning message to the console once per session. It uses a unique key per callsite to help ensure that the message is not printed multiple times. [General] [Added] - Added new `warnOnce` function for printing a message to the developer console once per session [General] [Changed] - Changed the warnings in `react-native-implementation` to use `warnOnce` Pull Request resolved: facebook#22109 Differential Revision: D13955887 Pulled By: cpojer fbshipit-source-id: aa51ac427a80cc0554a6bcc915715821d0bd5439
Summary
This pull request adds a function called
warnOnce
that prints a warning message to the console once per session.It uses a unique key per callsite to help ensure that the message is not printed multiple times.
Changelog
[General] [Added] - Added new
warnOnce
function for printing a message to the developer console once per session[General] [Changed] - Changed the warnings in
react-native-implementation
to usewarnOnce
Test Plan
I have tested this in RNTester, and the warning appears as expected. Flow and ESLint have also been ran.