Workaround metro not compiling static properties correctly. #412
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes the issue we encountered #406 (comment)
To review, the problem is as follows:
The correct syntax is:
Metro/Babel compiles this to:
But when metro then runs the HMR transform, this becomes:
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.
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 usingreact-native-web
.Second, while it does compile using metro, the generated code instead will be:
With
this
probably referring to the window or global scope, thus not causing a crash, but not actually setting the proptypes correctly.