Workaround metro not compiling static properties correctly.#412
Merged
osdnk merged 1 commit intosoftware-mansion:masterfrom Jan 13, 2019
Merged
Workaround metro not compiling static properties correctly.#412osdnk merged 1 commit intosoftware-mansion:masterfrom
osdnk merged 1 commit intosoftware-mansion:masterfrom
Conversation
Contributor
|
Thanks, I had an intuition that's incorrect, but I have encountered the problem you've mentioned, so I found solution I committed workable and then leave it as temporary fix, which I forgot about. Sorry guys. |
janicduplessis
pushed a commit
to janicduplessis/react-native-gesture-handler
that referenced
this pull request
Feb 16, 2020
…-mansion#412) Fixes the issue we encountered software-mansion#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
_classduring 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.publicPropTypeshas 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
thisprobably referring to the window or global scope, thus not causing a crash, but not actually setting the proptypes correctly.