-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with react-proxy, forwardRefs & decorators #24553
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
it seems like edit: here's a full example with the App.js from the original issue included as well: https://snack.expo.io/@notbrent/vigorous-popsicle-lol edit 2: perhaps this only confirms that the issue didn't exist as far back as 0.57 ;P |
confirmed it's a import React from "react";
import { Text, View } from "react-native";
// this works
function withLol(Component) {
class MyThemedThing extends React.Component {
render() {
return <Component theme={{buttonColor: 'green'}} {...this.props} />
}
}
return MyThemedThing;
}
// this doesn't work
function withForwardRef(Component) {
const WithForwardRef = React.forwardRef((props, ref) => {
return <Component theme={{buttonColor: 'green'}} {...props} ref={ref} />;
});
return WithForwardRef;
}
@withForwardRef
export class Button extends React.Component {
render() {
const { theme } = this.props;
return (
<View>
<Text style={{color: theme.buttonColor}}>some text</Text>
</View>
);
}
} |
@brentvatne, does forwardRef work as expected when used without decorators? Does it work with decorators in a new project? |
@TheSavior - it works without decorators, yeah ( |
I think it ultimately comes down to this line in |
Same problem here after start using yarn workspace. When using single project (not monorepo), |
I'm having this problem with 0.59, not using forwardRef but I am using MobX decorators... |
Hey everyone, I was looking a bit closer at this issue today and I am concerned that this will affect more and more people, given that new versions of popular libraries like redux-react (v6 > v7 update) and mobx-react (v5 > v6 update) started using decorators. I found that apparently the reason why this started happening after the react-native upgrade lies in Metro's HMR facebook/metro#272 And (back in December!) @gaearon wrote that
So my best guess would be that:
Sorry, I don't have a perfect solution for this atm 😓But I hope that the new information can help coming up with a plan 🤞 |
We're going to get rid of |
this works for me |
We've replaced the transform with a different one that doesn't suffer from this issues. See #18899 (comment) for details. |
If you are having this issue when upgrading to RN 59, some of the workarounds written above might not work. You can change this line in
|
In general I would recommend avoiding the use of decorators, as they're not a stable language feature yet. (Although, as I said, this specific problem will be fixed in 0.61) |
I don't suppose you know how long we'll be waiting for the 0.61 release by any chance do you? |
the cut of 0.61 will likely happen over the next couple weeks - sorry it's taking so long again :( |
0.61 is out with a fix. |
🐛 Bug Report
I'm having problems upgrading a project from RN 55 to RN 58.6
(UPDATE: this also occurs on 59, repro: https://github.com/dslounge/rnDecorators59).
My project has been using styled-components for a long time and it worked well. As I'm upgrading this project to RN 58.6, the app breaks due to issues with the
withTheme
decorator and react-proxy. Here are a few screenshots:The error I'm getting:
The error location.
createClassProxy.js
fromreact-proxy
doesn't handle forwardRefs:This is a sample of the code that breaks. (repro: https://github.com/dslounge/rnDecorators59)
My babel configuration seems to be fine:
I don't quite understand why this would break with an upgrade. As far as I know, styled-components has been using forwardRefs for a long time, and react-proxy hasn't changed in a long time either. I can only think that the breaking change is the babel upgrade.
This was my babelrc before upgrading:
I'm not sure if
react-native-stage-0/decorator-support
behaves differently from@babel/plugin-proposal-decorators
.The only other thing I can think of is that there's some underlying change with Metro? I would love to understand what I'm missing here.
Related Issues:
I've looked for answers, I haven't found much, but some people are having this issue:
To Reproduce
Expected a constructor
error.I've created a repo reproducing this issue: https://github.com/dslounge/rnDecorators59
Expected Behavior
I'm expecting my existing use of styled-components
withTheme
decorator to work just like it worked in RN 55.Code Example
Repo reproducing the issue: https://github.com/dslounge/rnDecorators59
Environment
The text was updated successfully, but these errors were encountered: