Skip to content

Commit 60ec693

Browse files
MelvinBoteh2077
andcommitted
Defer proactive navigation check to avoid extra renders in perf tests
The navigateToMigratedUserWelcomeModalIfReady() calls were running synchronously inside Onyx connectWithoutView callbacks, which interfered with Onyx batch processing and caused an extra render cycle in SidebarLinks perf tests. Deferring the check to the next event loop tick via setTimeout(0) with debouncing ensures it doesn't affect the current batch while still navigating promptly when conditions are met. Co-authored-by: Eric Han <eh2077@users.noreply.github.com>
1 parent af6c6c8 commit 60ec693

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/libs/Navigation/guards/MigratedUserWelcomeModalGuard.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ function resetSessionFlag() {
2525
hasRedirectedToMigratedUserModal = false;
2626
}
2727

28+
let pendingNavigationCheck: ReturnType<typeof setTimeout> | undefined;
29+
30+
/**
31+
* Schedules a deferred navigation check. The check is deferred to the next event loop tick
32+
* so it doesn't run synchronously inside Onyx callbacks, which would interfere with
33+
* Onyx batch processing and cause extra component renders.
34+
*/
35+
function scheduleNavigationCheck() {
36+
if (pendingNavigationCheck !== undefined) {
37+
return;
38+
}
39+
pendingNavigationCheck = setTimeout(() => {
40+
pendingNavigationCheck = undefined;
41+
navigateToMigratedUserWelcomeModalIfReady();
42+
}, 0);
43+
}
44+
2845
/**
2946
* Proactively navigate to the migrated user welcome modal when all conditions are met,
3047
* without waiting for a user-initiated navigation action.
@@ -53,15 +70,15 @@ function navigateToMigratedUserWelcomeModalIfReady() {
5370
function onSessionOrLoadingAppChanged(sessionValue: OnyxEntry<Session>, isLoadingAppValue: boolean) {
5471
session = sessionValue;
5572
isLoadingApp = isLoadingAppValue;
56-
navigateToMigratedUserWelcomeModalIfReady();
73+
scheduleNavigationCheck();
5774
}
5875

5976
Onyx.connectWithoutView({
6077
key: ONYXKEYS.NVP_TRY_NEW_DOT,
6178
callback: (value) => {
6279
const result = value ? tryNewDotOnyxSelector(value) : undefined;
6380
hasBeenAddedToNudgeMigration = result?.hasBeenAddedToNudgeMigration ?? false;
64-
navigateToMigratedUserWelcomeModalIfReady();
81+
scheduleNavigationCheck();
6582
},
6683
});
6784

0 commit comments

Comments
 (0)