question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HMR transform breaks React.forwardRef

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DimitryDushkincommented, Dec 20, 2018
1reaction
alex-mcleodcommented, Oct 15, 2018

Thanks for your feedback @gaearon and @rafeca, I will have a go at updating react-transform-hmr and react-proxy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forwarding Refs - React
When you start using forwardRef in a component library, you should treat it as a breaking change and release a new major version...
Read more >
13 Answers - 13 - Stack Overflow
react -transform-hmr/lib/index.js. This solution work for me. Only update node_modules\metro\src\reactNativeTransformer.js near line no.130.
Read more >
react-to-print | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Releases - styled-components
Only major versions have the potential to introduce breaking changes ... Attach displayName to forwardRef function as described in React docs (see #2508)....
Read more >
Setup Jest with Vite (featuring SWC) - Blog by hung.dev
Setup Jest to React Typescript Vite project, also SWC. ... you don't want a typescript error in your test file breaks your build...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found