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

Remove propTypes in production #1322

Merged
merged 2 commits into from
Sep 4, 2018
Merged

Remove propTypes in production #1322

merged 2 commits into from
Sep 4, 2018

Conversation

lencioni
Copy link
Contributor

This will help reduce the bundle size impact. Note that any consumers
who are depending on any react-dates components having a .propTypes
property will no longer work as expected after this change.

I enabled this using wrap mode, which adds process.env.NODE_ENV
checks, which is a pretty standard method for React apps. I believe this
will allow this library to have propTypes in development, but for them
to be minified out in production builds.

To make this safe to enable in this repo, I enabled the
react/forbid-foreign-prop-types ESLint rule, which was written
specifically for the benefit of this plugin.

Here's a diff showing what effect this has on the esm build:

https://gist.github.com/lencioni/1b436d365570394ccde659c829ba02c3

This will help reduce the bundle size impact. Note that any consumers
who are depending on any react-dates components having a `.propTypes`
property will no longer work as expected after this change.

I enabled this using wrap mode, which adds `process.env.NODE_ENV`
checks, which is a pretty standard method for React apps. I believe this
will allow this library to have propTypes in development, but for them
to be minified out in production builds.

To make this safe to enable in this repo, I enabled the
react/forbid-foreign-prop-types ESLint rule, which was written
specifically for the benefit of this plugin.

Here's a diff showing what effect this has on the esm build:

  https://gist.github.com/lencioni/1b436d365570394ccde659c829ba02c3
@lencioni lencioni requested review from ljharb and majapw August 22, 2018 22:29
.babelrc Outdated
"production": {
"presets": ["airbnb"],
"plugins": [
"inline-react-svg",
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
["transform-react-remove-prop-types", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something we could add in babel-preset-airbnb, possibly behind an option, instead of in individual repos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I think so!

I think we'd still need to make it configurable though, since in some places we want the mode to be remove instead of wrap for instance, and other options might be important to manage on a case by case basis, but we could just have a passthrough option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, a passthrough option sounds great

@coveralls
Copy link

coveralls commented Aug 22, 2018

Coverage Status

Coverage remained the same at 84.632% when pulling c8df10b on remove-prop-types into ebf83a1 on master.

lencioni added a commit to airbnb/babel-preset-airbnb that referenced this pull request Aug 29, 2018
I originally started by adding this plugin to react-dates, but it seems
like we are going to want this in a lot of places, so it makes sense to
put it into our preset instead.

react-dates/react-dates#1322

For the default options, I decided to go with "wrap" as the mode, since
we are likely to use this more frequently in packages that are published
and consumed by other packages and apps, which aren't very compatible
with the "remove" option.

In our apps where this is not a concern, we will want to override this
to use the "remove" option in production and likely disable this plugin
entirely in development for better build speeds.
lencioni added a commit to airbnb/babel-preset-airbnb that referenced this pull request Aug 29, 2018
I originally started by adding this plugin to react-dates, but it seems
like we are going to want this in a lot of places, so it makes sense to
put it into our preset instead.

react-dates/react-dates#1322

For the default options, I decided to go with "wrap" as the mode, since
we are likely to use this more frequently in packages that are published
and consumed by other packages and apps, which aren't very compatible
with the "remove" option.

In our apps where this is not a concern, we will want to override this
to use the "remove" option in production and likely disable this plugin
entirely in development for better build speeds.
This new version includes an option for removing propTypes, so I am
removing that plugin in favor of using the preset option.
@lencioni
Copy link
Contributor Author

@ljharb I just published the new preset with the removePropTypes option and updated this PR to use that instead.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM But we should treat this as a semver major, just in case

@ljharb ljharb added the semver-major: breaking change A non-backwards-compatible change; anything that breaks code - including adding a peerDep. label Aug 29, 2018
@lencioni
Copy link
Contributor Author

Agreed! @majapw feel free to merge this when you think it makes sense for the next major.

@majapw majapw merged commit 5442054 into master Sep 4, 2018
@majapw majapw deleted the remove-prop-types branch September 4, 2018 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major: breaking change A non-backwards-compatible change; anything that breaks code - including adding a peerDep.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants