-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Hot reloading (HMR) not working with functional components #10991
Comments
@martinbigio is this a known behavior of HMR in React Native? |
Reading https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html
Looks like that transformer library historically had issues with hot reloading functional components according to gaearon/babel-plugin-react-transform#57 I can guess both iOS and Android will be broken, this seems purely like a limitation of the JavaScript transformation process. |
HMR with stateless functional components throws "Maximum call stack exceeded" for me: Enabling JS debugging yields:
Note it loops on Is it possible to switch to gaearon/react-hot-loader (v3) perhaps? |
@tlvince I was experiencing the same issue and fixed it after finding and removing a circular dependency in my project. I noticed that the "Maximum call stack exceeded" was only being thrown when I edited files under a certain level in my "dependency tree". Not sure it's correct behaviour for the Hot Loading but it could be what is happening in your case too. |
Just wanted to mention I have a similar issue here: gaearon/react-transform-hmr#82 @mattread90 Do you have your project in a public repo, so I can see the commit where you solved the issue? Because it seems odd to me that you could have a circular dependency, and yet only have it cause problems with the hot-reloading, as opposed to the initial load. |
+1 any news on the horizont? |
I'm not seeing the infinite loop, but hot reloading isn't working. I update my styles and they aren't updated on the simulator. |
+1 |
Especially painful when working with react-navigation b/c it's almost all composed of functional components that don't reload on save. I think this is a solid dev experience pain point - cc @grabbou is there anything to be done here? |
Not sure there's anything related to react-navigation to be done here. The issue exists in React Native. |
The reason why React Native HMR doesn't work with stateless functional components is because it uses React Native will either have to use something like |
I'm seeing the same issue with |
I can confirm the issue @tlvenn has when I use circular dependencies. |
+1 |
1 similar comment
+1 |
HMR appears to work for all components that are beneath at least one class component. So I made my root component a class, and now HMR is still working even with SFCs below. Hope this helps someone! |
What @kristojorg said is true - the HMR does indeed detect changes functional components and reloads the app correctly, however there is a caveat to this: it will reload the closest parent class based component, not the component itself. So if you make your root component a class based one, every time you change one of your functional components it will reload from the root down, instead just the component you changed. |
Yep that's a good point I forgot to mention. Not sure why it's working this way. Is it using the same implementation as create react app? |
I tested it on 0.43.4 and can confirm that it does not work for either functional component or PureComponent. |
If I do (inside a class component): renderSomeText = () => {
console.log('render Some Text');
return (<Text>Some Text</Text>);
}
render() {
console.log('render');
return (
<View>
{this.renderSomeText()}
</View>
};
} On hot reload, |
Any update? |
renderSomeText = () => {
console.log('render Some Text');
return (<Text>Some Text</Text>);
} doesn't hot reload because of the way the code is transpiled into the constructor before hot reload can proxy it. I can't find the source for it anymore, but can confirm from personal experience. constructor(props) {
super(props);
this.renderSomeText = this.renderSomeText.bind(this);
}
function renderSomeText(){
console.log('render Some Text');
return (<Text>Some Text</Text>);
} works differently, you can run your app in debug mode and step through it to see what it's doing when hot reload is enabled. https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html#react-components might help you understand how it works better. |
@mattread90 Thank you so much ! I remove all circular dependencies from my app and it works ! 😍 |
@pie6k Try my babel plugin https://github.com/bvic23/babel-plugin-functional-hmr until the issue is fixed. |
did this get fixed I still have it and with react-native 57 on babel7 the above plugin isn't working for me? |
did this get fixed in 59? |
@jrwpatterson It's still not working for me on 0.59 |
+1 |
I think it has gotten worse actually. Im seeing it crash even when HMR is off and live reloading is enabled. Every save, crash. |
Is a there a fix available, which still enables to use react hooks and HMR? |
What is working for me is to use class components for screens. Then, any child components can be functional w/ hooks, and HMR still works. Also, if you're using mobx, make sure you're using https://github.com/mobxjs/mobx-react-lite |
@zeevl I converted all of my views into class components, but still the same. Save, crash. I also cleared the builds, reinstalled everything, and upgraded everything to the latest version. I do have providers that use hooks that are wrapping the views within the app.js. Could these be what are killing everything? I am using the useContext hook. So the app.js looks sort of like this
|
This has been fixed on master with a new implementation we're calling Fast Refresh. It will be a part of the 0.61 release. I'm going to close this issue. |
seems 0.61-rc.0 not working |
@GreatAuk "not working" is not a helpful way to describe the issue. Unfortunately I can't help without reproducing instructions. |
I'm locking this issue to prevent further confusion and drive-by comments that don't have reproduction cases. I've verified that the issue reported originally is solved. If you can still reproduce problems in a stable React Native 0.61 release (to be out soon), please file a new issue with a reproducing example. Thank you! |
Description
Hot reloading doesn't work on functional components. The "hot loading" message appears, but the changes don't show up.
Reproduction
Open index.android.js and replace :
with
Enable hot reloading, reload the app and try to make changes.
Additional Information
The text was updated successfully, but these errors were encountered: