Skip to content

Commit af6c6c8

Browse files
MelvinBoteh2077
andcommitted
Fix: remove duplicate Onyx subscriptions causing perf test render regression
The guard had its own connectWithoutView for SESSION and IS_LOADING_APP, duplicating the ones in guards/index.ts. The extra Onyx connections caused an additional render in the SidebarLinks perf test (render count +1). Instead, guards/index.ts now calls onSessionOrLoadingAppChanged() in its existing callbacks to pass the values through to the guard. Co-authored-by: Eric Han <eh2077@users.noreply.github.com>
1 parent a1907a5 commit af6c6c8

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

src/libs/Navigation/guards/MigratedUserWelcomeModalGuard.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,16 @@ function navigateToMigratedUserWelcomeModalIfReady() {
4545
Navigation.navigate(ROUTES.MIGRATED_USER_WELCOME_MODAL.getRoute());
4646
}
4747

48-
Onyx.connectWithoutView({
49-
key: ONYXKEYS.SESSION,
50-
callback: (value) => {
51-
session = value;
52-
navigateToMigratedUserWelcomeModalIfReady();
53-
},
54-
});
55-
56-
Onyx.connectWithoutView({
57-
key: ONYXKEYS.IS_LOADING_APP,
58-
callback: (value) => {
59-
isLoadingApp = value ?? true;
60-
navigateToMigratedUserWelcomeModalIfReady();
61-
},
62-
});
48+
/**
49+
* Called by guards/index.ts when session or loading app state changes.
50+
* Reuses the shared Onyx subscriptions from guards/index.ts to avoid duplicate connections
51+
* that cause extra renders in performance tests.
52+
*/
53+
function onSessionOrLoadingAppChanged(sessionValue: OnyxEntry<Session>, isLoadingAppValue: boolean) {
54+
session = sessionValue;
55+
isLoadingApp = isLoadingAppValue;
56+
navigateToMigratedUserWelcomeModalIfReady();
57+
}
6358

6459
Onyx.connectWithoutView({
6560
key: ONYXKEYS.NVP_TRY_NEW_DOT,
@@ -138,4 +133,4 @@ const MigratedUserWelcomeModalGuard: NavigationGuard = {
138133
};
139134

140135
export default MigratedUserWelcomeModalGuard;
141-
export {resetSessionFlag};
136+
export {resetSessionFlag, onSessionOrLoadingAppChanged};

src/libs/Navigation/guards/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {OnyxEntry} from 'react-native-onyx';
44
import getCurrentUrl from '@libs/Navigation/currentUrl';
55
import ONYXKEYS from '@src/ONYXKEYS';
66
import type {Session} from '@src/types/onyx';
7-
import MigratedUserWelcomeModalGuard from './MigratedUserWelcomeModalGuard';
7+
import MigratedUserWelcomeModalGuard, {onSessionOrLoadingAppChanged} from './MigratedUserWelcomeModalGuard';
88
import OnboardingGuard from './OnboardingGuard';
99
import type {GuardContext, GuardResult, NavigationGuard} from './types';
1010

@@ -19,13 +19,15 @@ Onyx.connectWithoutView({
1919
key: ONYXKEYS.SESSION,
2020
callback: (value) => {
2121
session = value;
22+
onSessionOrLoadingAppChanged(session, isLoadingApp);
2223
},
2324
});
2425

2526
Onyx.connectWithoutView({
2627
key: ONYXKEYS.IS_LOADING_APP,
2728
callback: (value) => {
2829
isLoadingApp = value ?? true;
30+
onSessionOrLoadingAppChanged(session, isLoadingApp);
2931
},
3032
});
3133

0 commit comments

Comments
 (0)