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
Instead of removing propTypes, replace with empty object #95
Comments
Won't that potentially introduce sneaky issues? Some library actually use the object to perform logic not just runtime type checking. What about changing the default property of |
That's exactly what's happening here with With regards to the sneaky issues that could arise from people using propTypes for something other than validation, I agree that that would be a problem in certain cases, but I'm not seeing patterns like that showing up as frequently and would want to take the risk since it'll provide more out of the box support. Would it be okay to have this behavior be opt-in so that projects willing to take the risk can take it and those that don't, don't? I was looking at the code in an attempt to make a PR for this feature, but I was unsure as to how the ternary expression was being inserted. I saw that |
The purpose of the plugin is to remove prop types. That's what it should do. If a 3rd party library is using the plugin but expecting prop types .. then that's their issue. Using proper babel environments one can define the necessary requirements (dist should use this plugin, but development, normal imports should not). There are numerous examples of vendors using this properly allowing prop types in development, internal builds, but excluding for dist versions. Please see those. [close issue please] |
RN is starting to export propTypes as their own modules (e.g. |
@RangerMauve react-bootstrap is using that pattern in quite some occasions. Still, I agree that it's not frequent.
@necolas Oh, that's great! I have been hitting that wall in the past 💣 . I was trying to go in the opposite direction by throwing a syntax error with the following pattern: import { SomeComponent } from './SomeComponent';
const propTypes = {
value: SomeComponent.propTypes.value,
}; But I reverted as
I think that the whole community would agree on that point 👍 . I'm not sure about the best path going forward. That's not a call I can make on my own.
|
Option 2 please. The alternative is that libraries like RNW have to stop using the plugin and do it manually |
I'm using [react-native-web](https://github.com/necolas/react-native-web) in conjunction with this library in order to support more platforms with the same codebase. When building our app for development, everything works properly and this library does exactly what we need it to. However, react-native-web excludes propTypes when you do a production build in order to reduce bundle size and improve performance. This leads to [issues](necolas/react-native-web#423) when libraries depend on propTypes being defined. I propose feature-detecting whether Text.propTypes is actually defined so that people using react-native-web, or any bundlers for native that reduce size agressively, without affecting current users.
@oliviertassinari any thoughts? |
necolas ... Option 2 is not an option as it changes the sole intention of this transform. You must handle this in YOUR APPLICATION. |
Libraries using this expect the prop types to be removed completely, hashes are built against this, this would invalidate the whole purpose of the plugin. If you wanted to leave them in then , it needs to be an OPT-IN because option 2 breaks backwards compatibility. Otherwise, necolas can create a fork that does something different. |
@oliviertassinari thanks, doing it only for wrap sounds good |
@virgofx What do you mean by "hashes are built against this"? Can you show an example of code that relies on propTypes to be removed completely in wrap mode? |
I also found this issue because I need this for Then the the
So most Alternatively, we could just submit PRs to all the major |
@ndbroadbent this problem will go away entirely if propTypes is always an object, negating the need for widespread changes to packages |
Here's my attempt at replacing propTypes with an object. I've been testing it with my I'm still finding my way around the Babel AST, so the code is not very good. But it works well for me. |
@ndbroadbent Thanks for the proposed fix! I'm gonna port that into the lib. |
I have given a shot at this issue with #101. Let me know if that looks good to you. |
Thanks! |
Removing propTypes entirely is causing issues with third party dependencies that need them to be defined. This was causing issues when using react-native-web.
It was brought up that replacing propTypes with an empty object would have the effects of not needing those definitions, while allowing libraries to reference undefined properties on propTypes and prevent
cannot read [name] of undefined
errors.The text was updated successfully, but these errors were encountered: