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

Introduce generic warnOnce function for warning messages #22109

Closed
wants to merge 2 commits into from

Conversation

empyrical
Copy link
Contributor

@empyrical empyrical commented Nov 4, 2018

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 use warnOnce

Test Plan

I have tested this in RNTester, and the warning appears as expected. Flow and ESLint have also been ran.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 4, 2018
@elicwhite
Copy link
Member

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?

* @param {string} [renamed] - Optional; name of the API in the dest module,
* if it was renamed
*/
function warnMoved(api: string, destModule: string, renamed?: string) {
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@empyrical
Copy link
Contributor Author

That sounds good!

I wonder, maybe for cases like this we could have an __FB__ or __OSS__ variable, so stuff could be stripped out of bundles like they can with if(__DEV__) blocks

@elicwhite
Copy link
Member

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

@empyrical
Copy link
Contributor Author

For the JS side of things, perhaps we should try and make a codemod to help rewrite imports of {WebView}. I imagine that's only a small part of the work that needs to be done, however!

@elicwhite
Copy link
Member

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!

@cpojer
Copy link
Contributor

cpojer commented Dec 7, 2018

What's the status of this PR?

@empyrical
Copy link
Contributor Author

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)


warning(
false,
`'${api}' has moved to another module and will be removed from 'react-native' ` +
Copy link
Contributor

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?

@hramos
Copy link
Contributor

hramos commented Jan 15, 2019

I missed this PR way back then. #22980 landed, which adds the deprecation warning. We should still consider #22109 as a way to handle exported components in a consistent manner.

@empyrical
Copy link
Contributor Author

I've been meaning to address this PR's issues, I will try to get to it this week!

@cpojer
Copy link
Contributor

cpojer commented Feb 4, 2019

@empyrical do you wanna pick this back up or close it?

@empyrical
Copy link
Contributor Author

It looks like I took so long to pick this back up that there is another warning in place on master now. Sorry about that! 😅

I can pick this back up though, it would still be useful for the generic "warnOnce()" function so all the warnings in react-native-implementation.js don't need to add x_warning_showed variables, hopefully cleaning things up a bit.

@cpojer
Copy link
Contributor

cpojer commented Feb 4, 2019

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?

@empyrical empyrical changed the title Warn that 'WebView' has moved to 'react-native-webview' Introduce generic warnOnce function for warning messages Feb 4, 2019
@empyrical
Copy link
Contributor Author

I've modified this PR instead of making a new one 👍

@facebook facebook deleted a comment from pull-bot Feb 5, 2019
@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Feb 5, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@cpojer cpojer left a 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 :)

@react-native-bot
Copy link
Collaborator

@empyrical merged commit 9a7fff9 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Feb 5, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 5, 2019
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
…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
@facebook-github-bot facebook-github-bot added the Contributor A React Native contributor. label Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: View Component: WebView Related to the WebView component. Contributor A React Native contributor. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants