Skip to content

Commit

Permalink
Fix HMR when a function is extracted from Object.prototype (#292)
Browse files Browse the repository at this point in the history
* Check if passed type is not on Object.prototype, explain case

* Update hotPatch.js
  • Loading branch information
krizzu authored and satya164 committed Nov 21, 2017
1 parent 502d45c commit da0f752
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/hot/client/hotPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ if (typeof global.__REACT_HOT_LOADER__ !== 'undefined') {
if (
typeof type !== 'function' ||
typeof uniqueLocalName !== 'string' ||
typeof fileName !== 'string'
typeof fileName !== 'string' ||
/**
* In case where someone extract function from a prototype
* example: `const hasOwnProperty = Object.prototype.hasOwnProperty` in `react-native-safe-module`,
* then `hasOwnProperty` will be patched by HMR
* Here: https://github.com/gaearon/react-hot-loader/blob/master/src/patch.dev.js#L14-L20
* When we get to point where we retrives keys from patched functions
* here: https://github.com/gaearon/react-hot-loader/blob/master/src/patch.dev.js#L43
* We'll be actually looping over `hasOwnProperty`'s arities, which are `undefined`
* Accessing properties on `undefined` will throw an error
*/
Object.prototype[uniqueLocalName]
) {
return;
}
Expand Down

0 comments on commit da0f752

Please sign in to comment.