You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Different refresh behavior across Android and iOS on Metro 0.81.1 #1440
Hey folks, on React Native 0.76.7, Metro version 0.81.1, I'm seeing different refresh behavior across Android and iOS on a clean React Native community CLI app. I'm not sure if this falls within the boundaries of a React native issue or a Metro issue. Starting here because the Metro server itself is the entrypoint into demonstrating the bug. I would be happy to file this elsewhere if it's not actually a Metro concern. Thanks for your consideration and time either way!
If I tap "R" in Metro, I should see the useEffect cleanup function in my logs. Then metro restarts. Then I see the useEffect start message. I would not expect to ever see the AppState change. I would expect the same behavior from Fast Refresh if I update the App.tsx file, since that useEffect hook is in there, and is going to always update, based on my interpretation from the fast refresh docs.
I would expect this behavior to be the same on both Android and iOS.
What happens
On iOS, the behavior works exactly as I expect.
On Android, I see some intermittently different behavior.
When I tap "R" in Metro server: In some cases, I get the useEffect cleanup. In others, I never see it. Very often, I also see AppState report that the state has changed to background.
When I update App.tsx and get a fast refresh: I see the behavior I expect more consistently.
If I add //@refresh reset to the top of the file: no change, but I see the useEffect cleanup more frequently, along with a huge wall of state changes to background after setting it.
Are there any workarounds for this issue? It is becoming a real pain when developing, since I cannot set required properties, clear listeners or subscriptions when the app closes. Furthermore, it makes testing a lot more difficult.
Backgrounding the metro connected app for more than 5 seconds seems to cause Error occurred, shutting down websocket connection: Websocket exception and lose its connection to the app
Backgrounding the metro connected app for more than 5 seconds seems to cause Error occurred, shutting down websocket connection: Websocket exception and lose its connection to the app
It might be related, but in my case the clean-up of the useEffect does not fire or rarely fires on android. The app state listener seems to, at least, properly log the app state. In my case, I use this clean-up to close a UDP socket, should it exist. Since it does not fire, the app creates a new socket with new listeners.
Like mentioned in the thread you posted, it does not seem to be an issue in production/release, but it is a hassle to develop with.
Note: The useEffect I am talking about was created in the main app function inside app.tsx
Activity
RobertKohde commentedon Jun 20, 2025
Hi,
Are there any workarounds for this issue? It is becoming a real pain when developing, since I cannot set required properties, clear listeners or subscriptions when the app closes. Furthermore, it makes testing a lot more difficult.
coolsoftwaretyler commentedon Jun 20, 2025
@RobertKohde - I never found a good workaround for it, but I wrapped up the project where it was a big issue for me so I stopped poking around at it.
NorseGaud commentedon Jul 5, 2025
Is this related? react/react-native#52447
Backgrounding the metro connected app for more than 5 seconds seems to cause
Error occurred, shutting down websocket connection: Websocket exceptionand lose its connection to the appRobertKohde commentedon Jul 7, 2025
It might be related, but in my case the clean-up of the
useEffectdoes not fire or rarely fires on android. The app state listener seems to, at least, properly log the app state. In my case, I use this clean-up to close a UDP socket, should it exist. Since it does not fire, the app creates a new socket with new listeners.Like mentioned in the thread you posted, it does not seem to be an issue in production/release, but it is a hassle to develop with.
Note: The
useEffectI am talking about was created in the main app function insideapp.tsx