App goes back to the initial screen when using fast refresh #455
Replies: 14 comments 38 replies
-
I usually see this happen when saving changes to a |
Beta Was this translation helpful? Give feedback.
-
i discovered that if you have const outside the react component (for me it was zod schema) it will make that specific screen/component re-render the whole application. Fast Refresh is only on react component si if you have variable or function exported outside and initialized outside the react component context, it will trigger a full re-render. Only way i found to avoid that was to make anything outside react a function that i can call and init in the component itself. |
Beta Was this translation helpful? Give feedback.
-
I had this problem too but I figured it out by my self as I didn't find anything related to it, It is a hard Routing Issue. Routing problems can arise from various sources, such as incorrect configuration or mismanagement of routes. Even a small oversight, like a misplaced '/' in your routes, can lead to unexpected behavior. To resolve these issues, it's crucial to follow best practices outlined in the documentation. This includes properly configuring your app's routing within layouts and ensuring that all routes are defined correctly. Identifying and fixing routing problems often requires some trial and error. Through practice and experimentation, you can pinpoint the root cause of the issue and implement the necessary fixes. If you're still facing difficulties or if you need further clarification on any aspect, feel free to reply to this message, and I'll be happy to assist you further. Happy coding! 😊 |
Beta Was this translation helpful? Give feedback.
-
Hi! I experienced the same issue with the app going back to initial screen (fast refresh) every time I saved a change. import React from 'react';
import { View, Text } from 'react-native';
const settings = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings page</Text>
</View>
);
};
export default settings; When I change the screen name (see code below) with capital first letter everything was working again 🥳 import React from 'react';
import { View, Text } from 'react-native';
const Settings = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings page</Text>
</View>
);
};
export default Settings; |
Beta Was this translation helpful? Give feedback.
-
Hi For my part the problem is that i was doing this : ❌ BAD PRACTICE ❌ import { View, Text } from 'react-native';
export default Settings = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings page</Text>
</View>
);
}; ✅ GOOD PRACTICE ✅ import { View, Text } from 'react-native';
const Settings = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings page</Text>
</View>
);
};
export default Settings; Now the modified screen remains in place without returning to the initial screen ✅ |
Beta Was this translation helpful? Give feedback.
-
I'm also having the same issue where making change to a file such as I've tried everything from playing around with the way styles are being export, using different function syntax, capitalisation, folder placement etc, it will just force a full reload and it is sending me insane haha I tested the same functionality with |
Beta Was this translation helpful? Give feedback.
-
Here is my finding after spending hours. so instead of using const home = () => {
return (
<View>
<Text>Home</Text>
</View>
)
}
export default home use this const Home = () => {
return (
<View>
<Text>Home</Text>
</View>
)
}
export default Home let me know if this works for you too. |
Beta Was this translation helpful? Give feedback.
-
I did this and it works :
|
Beta Was this translation helpful? Give feedback.
-
I had this problem too, the problem I found was that my arrow function's name didn't start with a capital letter. |
Beta Was this translation helpful? Give feedback.
-
Hey all, I had the same problem and in my case I managed to fix it by making sure sibling files are not importing from one another, hope this is helpful! Before (WITH BUG)
After (FIXED)
|
Beta Was this translation helpful? Give feedback.
-
Also ran into this when re-exporting an ErrorBoundary like: export { ErrorBoundary } from '../../ErrorBoundary'; // (WRONG! THIS CAUSES THE BUG) To fix it, I had to first: import { ErrorBoundary as ErrorBoundaryBase } from '../../ErrorBoundary'; and then export const ErrorBoundary = ErrorBoundaryBase; |
Beta Was this translation helpful? Give feedback.
-
I had this issue and the root issue for me was exporting an object inside a route file (in the I was exporting a graphql query and because it has a different identity each time, it triggers a full refresh. Removing all exported objects fixed it for me. |
Beta Was this translation helpful? Give feedback.
-
Hi! I also have noticed that not using an arrow function I initially thought this was because of a library i was using (NativeWind v4) but suprisingly, i saw a pattern here in the solutions. I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
I ran into this issue as well and for me the behavior is very inconsistent. However, I noticed that if the I am using NativeWind v4 so it could potentially be a combination of using |
Beta Was this translation helpful? Give feedback.
-
Every time I make a change and fast refresh is fired I go back to the initial screen. Is there a way to keep the current screen when developing? It's super annoying to navigate to the screen I am developing on every code change. I remember that was possible using React Navigation.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions