HMR transform breaks React.forwardRef
See original GitHub issueDo you want to request a feature or report a bug?
Bug.
What is the current behavior?
I originally filed this as https://github.com/gaearon/react-proxy/issues/82, but the project does not look active (no updates in three years).
In short, if you use the new forwardRef()
function on a component derived from (say) React.Component
, the result is not a component object but
{
$$typeof: Symbol(react.forward_ref),
render: forwardFn(props, ref) { ... }
}
This, then, causes an exception in react-proxy
, which expects a prototype; react-proxy
is a dependency of metro
via react-transform-hmr
.
Curiously, it does not happen when the component passed to forwardRef
derives an intermediate base class (itself derived from React.Component
), perhaps because it’s an ES6 class at transpile time?
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install
and yarn test
.
I do not currently have a minimal example. If needed, I can try to create one; I cannot share the code we have as it’s proprietary.
What is the expected behavior?
I would expect forwardRef
to work regardless of whether I’m using the metro Babel preset or not.
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
Node v10.4.0 npm v6.1.0 metro v0.45.6 OS: Ubuntu 18.04
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Another solution without patching — https://github.com/facebook/metro/issues/313#issuecomment-448899827
Thanks for your feedback @gaearon and @rafeca, I will have a go at updating
react-transform-hmr
andreact-proxy
.