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

Optimize #268

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion factoryWithTypeCheckers.js
Expand Up @@ -206,7 +206,8 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
}
}
}
if (props[propName] == null) {
// undefined == null and null == null are true
if (props[propName] === null || props[propName] === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this a better change? == null is more reliable, since undefined can be redefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is this a better change? == null is more reliable, since undefined can be redefined.

Thanks @ljharb I found this question on stackoverflow, it looks like a problem related to legacy browsers only, but your review did make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also according to MDN, undefined should be un-writable but it's not a reserved word, so in some context it may be redefined as well.

(function() { var undefined = 'foo'; console.log(undefined, typeof undefined); })();

if (isRequired) {
if (props[propName] === null) {
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,6 @@
},
"homepage": "https://facebook.github.io/react/",
"dependencies": {
"loose-envify": "^1.4.0",
"object-assign": "^4.1.1",
"react-is": "^16.8.1"
},
Expand All @@ -47,6 +46,7 @@
"eslint": "^5.13.0",
"in-publish": "^2.0.0",
"jest": "^19.0.2",
"loose-envify": "^1.4.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this must be a runtime dependency, otherwise #203 (comment) breaks people.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this must be a runtime dependency, otherwise #203 (comment) breaks people.

Got it, I thought it was only used for build in the first place.

"react": "^15.5.1",
"uglifyify": "^3.0.4",
"uglifyjs": "^2.4.10"
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -2339,7 +2339,7 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:

loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
Expand Down