babel-plugin-transform-react-remove-prop-types icon indicating copy to clipboard operation
babel-plugin-transform-react-remove-prop-types copied to clipboard

propTypes from stateless functional components not being removed

Open nijk opened this issue 6 years ago • 9 comments

I'm aware that issues have been raised for this previously and work done to fix it.

However I'm seeing issues with a library (ReactPopper) that uses this plugin. The library currently uses this plugin but with { mode: 'wrap' } which results in minified builds that reference process.env - which is not something we want, react-popper GH Issue here. I've forked the library and made the config change to babel-plugin-transform-react-remove-prop-types here but I'm seeing that propTypes still exist on the stateless functional components:

Steps to reproduce

  1. git clone https://github.com/nijk/react-popper.git
  2. git checkout v0.x
  3. cd react-popper
  4. npm install
  5. grep propType dist/react-popper.min.js
  6. Observe that propTypes exists in the grep output, namely on the Target & Arrow components - both of which are stateless functional components.

nijk avatar Apr 19 '18 09:04 nijk

@nijk Thanks for the reproduction. It sounds like a bug.

oliviertassinari avatar Jul 11 '18 11:07 oliviertassinari

Typescript output is also not processed. It contains propTypes inside of class iife but this plugins handles only top level propTypes assignments.

TrySound avatar Oct 19 '18 18:10 TrySound

I'm experiencing same thing. At first I thought the plugin was not removing any propTypes but after reading this issue and looking into the build I noticed it was only the functional component's propTypes not being removed i.e. plugin removed propTypes from class components only.

cocacrave avatar Jan 15 '19 06:01 cocacrave

I'm closing, the react popper issue is too high level. It doesn't mean it's an issue with this Babel plugin. Library authors should use the wrap mode. They should have the prop types in the modules they publish to npm. For a UMD release, this depends on the dev vs prod target.

oliviertassinari avatar Jan 15 '19 09:01 oliviertassinari

@oliviertassinari Thanks, I've spent a few minutes generating a minimal reproduction of the issue here.

I may well be doing something wrong but here's what I found:

  1. When using the remove mode (default) the propTypes were not removed from either SFC or the ClassComponent.
  2. When using the wrap mode, the propTypes are wrapped with process.env - this is a problem for 3rd party React libs that can't really expect process.env to be available in the consuming app.

nijk avatar Jan 15 '19 10:01 nijk

  1. When using the remove mode (default) the propTypes were not removed from either SFC or the ClassComponent.

We should fix that: https://github.com/nijk/babel-plugin-transform-react-remove-prop-types-issue-140.

  1. When using the wrap mode, the propTypes are wrapped with process.env - this is a problem for 3rd party React libs that can't really expect process.env to be available in the consuming app.

This is a no problem: https://unpkg.com/react.

oliviertassinari avatar Jan 15 '19 10:01 oliviertassinari

@oliviertassinari is that not the development version of React? The production version doesn't attempt to access process.env.

nijk avatar Jan 15 '19 10:01 nijk

Sorry, ignore that - I've just re-read the file you linked to

nijk avatar Jan 15 '19 10:01 nijk

Anything I can do to help push this along? I can't tell if this is a fix or not...

kylemh avatar Jul 16 '19 19:07 kylemh