Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Consume PropTypes from the prop-types module #61

Merged
merged 4 commits into from
Jul 31, 2017

Conversation

eliperkins
Copy link
Contributor

@eliperkins eliperkins commented Jul 28, 2017

What:

Adds prop-types module and runs the React-PropTypes-to-prop-types codemod

Why:

This ensures compatibility with React 16+. Fixes Cannot read property 'object' of undefined on React 16.0.0-beta.1

screen shot 2017-07-28 at 4 59 14 pm

How:

$ cd glamorous-native
$ yarn add prop-types
$ cd .. && git clone https://github.com/reactjs/react-codemod.git
$ jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js ../glamorous-native/src`

This ensures compatibility with React 16+.
@atticoos
Copy link
Contributor

atticoos commented Jul 28, 2017

Thanks @eliperkins! We'll want to make sure this is backward compatible with React <15.5 too. We can set up a file in the project performs the conditional logic to load PropTypes from either react or prop-types depending on the react version.

glamorous does a good job with this (paypal/glamorous#32) and would be a helpful reference

@atticoos atticoos self-requested a review July 28, 2017 21:07
@atticoos atticoos added the bug label Jul 28, 2017
This suppresses warnings for projects which do not include PropTypes or versions of React less than 15.5.
@codecov-io
Copy link

codecov-io commented Jul 28, 2017

Codecov Report

Merging #61 into master will increase coverage by 0.22%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   92.02%   92.25%   +0.22%     
==========================================
  Files          10       11       +1     
  Lines         138      142       +4     
  Branches       37       39       +2     
==========================================
+ Hits          127      131       +4     
  Misses          7        7              
  Partials        4        4
Impacted Files Coverage Δ
src/create-glamorous.js 93.61% <ø> (ø) ⬆️
src/with-theme.js 84.61% <ø> (ø) ⬆️
src/theme-provider.js 69.23% <ø> (ø) ⬆️
src/react-compat.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 638ed1f...46aaed2. Read the comment docs.

@eliperkins
Copy link
Contributor Author

@ajwhite Not sure I totally agree with adding in a compat layer. Reading the README's section on compatibility it seems like it just encourages the user to upgrade to 15.3.0+ with a warning message.

I've updated it regardless, following how glamorous implemented the compat layer though!

@atticoos
Copy link
Contributor

Yeah, I agree that it's unfavorable, but there are some some folks that are locked into earlier react-native versions that have react dependencies locked to a certain version (us!). We unfortunately can't upgrade react-native (long story, happy to share over a different platform).

The section on Differences seems to indicate there is a version of React where this can actually result in an error being thrown, if I'm reading this correctly. If that's the case, I do lean towards the compat approach.

package.json Outdated
@@ -55,7 +55,8 @@
"semantic-release": "^6.3.6"
},
"dependencies": {
"brcast": "^2.0.0"
"brcast": "^2.0.0",
"prop-types": "^15.5.10"
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally we might opt to put this in peerDependencies, but since it's an optional dependency, let's follow glamorous and place this in devDependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@atticoos
Copy link
Contributor

Awesome - going to just pull down and double check on a project that doesn't use prop-types. All looks good here!

@atticoos atticoos self-assigned this Jul 31, 2017
@atticoos atticoos merged commit 4493a8c into robinpowered:master Jul 31, 2017
@atticoos
Copy link
Contributor

Thanks man 💯

@eliperkins eliperkins deleted the ep/prop-types branch July 31, 2017 20:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants