You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Workaround metro not compiling static properties correctly. (#412)
Fixes the issue we encountered #406 (comment)
To review, the problem is as follows:
The correct syntax is:
```
static propTypes = {
...GenericTouchable.internalPropTypes
}
```
Metro/Babel compiles this to:
```
// Define GenericTouchable
GenericTouchable.propTypes = (0, _objectSpread2.default)({}, GenericTouchable.internalPropTypes, GenericTouchable.publicPropTypes);
```
But when metro then runs the HMR transform, this becomes:
```
// Create _class
_class.propTypes = (0, _objectSpread2.default)({}, GenericTouchable.internalPropTypes, GenericTouchable.publicPropTypes),
```
It rewrites the class name to `_class` during initialization, but misses the references in the spread, which then causes a undefined-access exception.
See this Gist for full outputs: https://gist.github.com/miracle2k/3bc7f1c50080397dbf0d92cfb3101677#file-generictouchable-babel-with-metro-preset-js
Part of the problem seems to be that metro uses a very old version of [react-hot-loader](facebook/metro#336).
The code as it is currently in the library, using `...this.publicPropTypes` has two problems: First, it does not compile at all with babel, when this library becomes imported as part of using `react-native-web`.
Second, while it does compile using metro, the generated code instead will be:
```
// Create _class
_class.propTypes = (0, _objectSpread2.default)({}, this.internalPropTypes, this.publicPropTypes),
```
With `this` probably referring to the window or global scope, thus not causing a crash, but not actually setting the proptypes correctly.
0 commit comments