Skip to content
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

[bottom-tabs] Navigation delay with useFocusEffect, especially on low-end devices #11613

Open
4 of 12 tasks
rnqs opened this issue Sep 22, 2023 · 14 comments · May be fixed by #11770
Open
4 of 12 tasks

[bottom-tabs] Navigation delay with useFocusEffect, especially on low-end devices #11613

rnqs opened this issue Sep 22, 2023 · 14 comments · May be fixed by #11770

Comments

@rnqs
Copy link

rnqs commented Sep 22, 2023

Current behavior

I have an app in production that has a bottom tab navigation and screens with useFocusEffect that refresh the data in a list. Recently some users, particularly with low-end devices, reported attempt to navigate between bottom tabs, upon selecting a screen, they expect to transition smoothly to the new tab. However, the current behavior is:

  • The user initiates navigation from Screen 1 to Screen 2 by tapping the tab.
  • Instead of a swift transition, the user remains on Screen 1 until the expensive operation within the useFocusEffect on Screen 2 completes.
  • Only after the operation finishes, the user is finally able to access Screen 2.

Example of the problem:

Screen.Recording.2023-09-22.at.16.11.01.mov

I have already tried some approaches to mitigate this issue, including:

  • Adjusting the lazy, unmountOnBlur, and freezeOnBlur properties of the navigation components.
  • Implementing the useEffect hook with different configurations.
  • Using InteractionManager.runAfterInteractions to try not to interfere with the transition between screens.

Please let me know if you need any further information or if there are specific actions or configurations I should try.

Expected behavior

I think the expected behavior in this scenario would be to respond immediately to the user's interaction, taking them to the target tab and then triggering useFocusEffect to update the data.

I assumed that the problem is in React Navigation because it happens during tab navigation and with the use of useFocusEffect, but I could be wrong.

Reproduction

https://snack.expo.dev/@rnqs/bottom-tabs-navigator-%7C-react-navigation

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-tab-view

Environment

  • I've removed the packages that I don't use
package version
@react-navigation/native 6.1.1
@react-navigation/bottom-tabs 6.5.2
@react-navigation/drawer 6.5.7
@react-navigation/native-stack 6.9.7
react-native-safe-area-context 4.6.3
react-native-screens 3.22.0
react-native-gesture-handler 2.12.0
react-native-reanimated 3.3.0
react-native 0.72.4
expo 49.0.0
node 18
yarn 1.22.19
@github-actions
Copy link

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.1.1, latest: 6.1.7)
  • @react-navigation/bottom-tabs (found: 6.5.2, latest: 6.5.8)
  • @react-navigation/drawer (found: 6.5.7, latest: 6.6.3)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@rnqs
Copy link
Author

rnqs commented Sep 22, 2023

The behavior persists even after upgrading to the latest versions

@trattles
Copy link

trattles commented Oct 2, 2023

For what it's worth - I am experiencing similar navigation event lag w/ bottom tabs.

App is built with Expo, on SDK 49.

I just tested switching from hermes back to jsc -- and my navigation speed issues improved considerably.

@rnqs
Copy link
Author

rnqs commented Oct 3, 2023

I just tested switching from hermes back to jsc -- and my navigation speed issues improved considerably.

@trattles thanks for sharing! However, I tried the same thing in my app, and actually, it became slower.

App is built with Expo, on SDK 49.

Same here.

@rnqs
Copy link
Author

rnqs commented Oct 3, 2023

I've started to believe it might be related to React 18 Automatic Batching feature, but i'm not sure how this relates with React Navigation. I couldn't find anything on the docs. However, it noticeably affects navigation performance.

I'm still looking into it and would appreciate if anyone has any inputs to share on this.

@veeramarni
Copy link

@rnqs i'm in the same boat.

@ha-family
Copy link

I've started to believe it might be related to React 18 Automatic Batching feature, but i'm not sure how this relates with React Navigation. I couldn't find anything on the docs. However, it noticeably affects navigation performance.

I'm still looking into it and would appreciate if anyone has any inputs to share on this.

@rnqs How can I confirm if the issue is caused by the React 18 Automatic Batching feature? Is there a way to adjust this issue with React Navigation? I've also encountered a similar performance problem.

@jordann93
Copy link

Same problem for me, do you find any solution or temp fix ?

@rnqs
Copy link
Author

rnqs commented Nov 13, 2023

@rnqs How can I confirm if the issue is caused by the React 18 Automatic Batching feature? Is there a way to adjust this issue with React Navigation? I've also encountered a similar performance problem.

I just suspect the issue might be related to React 18 Automatic Batching.

Same problem for me, do you find any solution or temp fix ?

Unfortunately, I haven't found any solution or temp fix for this problem thus far.

I'd really appreciate it if someone with a more in-depth knowledge of this library could take a look at this.

@mobinni
Copy link

mobinni commented Jan 5, 2024

Is there any update on this issue, I've been noticing very similar behaviour due to the fact the default implementation awaits everything to render within the screen before transitioning. Haven't found a viable solution as of yet.

@oblador oblador linked a pull request Jan 5, 2024 that will close this issue
@oblador
Copy link

oblador commented Jan 5, 2024

I've posted a proposed fix, please verify that it solves your problems as well 👍

@santosdmg
Copy link

I was changing a state in a custom hook, however I had that deley when changing the state, I solved it by adding a setTimeout to change the state, Example:

const [isActive, setIsActive] = useState(true);

const subscribe = () => {
  setTimeout(() => {
    setIsActive(true);
  }, 300);
};

const unsubscribe = () => {
  setTimeout(() => {
    setIsActive(false);
  }, 300);
};

useFocusEffect(
  useCallback(() => {
    subscribe();

    return () => unsubscribe();
  }, [])
);

@sirusbaladi
Copy link

this is still happening. removing useIsFocused() solved the issue

@ahsanbhatti98
Copy link

I was changing a state in a custom hook, however I had that deley when changing the state, I solved it by adding a setTimeout to change the state, Example:

const [isActive, setIsActive] = useState(true);

const subscribe = () => {
  setTimeout(() => {
    setIsActive(true);
  }, 300);
};

const unsubscribe = () => {
  setTimeout(() => {
    setIsActive(false);
  }, 300);
};

useFocusEffect(
  useCallback(() => {
    subscribe();

    return () => unsubscribe();
  }, [])
);

Not works for me facing same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants