Skip to content

Commit 81f32d7

Browse files
Fix(logout): avoid an infinite loop when loading the demo apps for the first time
1 parent c529941 commit 81f32d7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/ra-core/src/auth/useLogout.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,22 @@ const useLogout = (): Logout => {
111111
if (redirectToParts[1]) {
112112
newLocation.search = redirectToParts[1];
113113
}
114-
navigateRef.current(newLocation, newLocationOptions);
115-
resetStore();
116-
queryClient.clear();
114+
navigateRef.current(newLocation, {
115+
...newLocationOptions,
116+
flushSync: true,
117+
});
118+
119+
// We need to reset the store after a litte delay to avoid a race condition
120+
// between the store reset and the navigation.
121+
//
122+
// This would only happen when the `authProvider.getPermissions` method returns
123+
// a resolved promise with no delay: If the store was reset before the navigation,
124+
// the `usePermissions` query would reset, causing the `CoreAdminRoutes` component to
125+
// rerender the `LogoutOnMount` component leading to an infinite loop.
126+
window.requestAnimationFrame(() => {
127+
resetStore();
128+
queryClient.clear();
129+
});
117130

118131
return redirectToFromProvider;
119132
});

0 commit comments

Comments
 (0)