Skip to content

Commit 03d5ac4

Browse files
Fix(logout): use setTimeout instead of requestAnimationFrame as this could lead to unexpected behavior while logging out
1 parent 81f32d7 commit 03d5ac4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,23 @@ const useLogout = (): Logout => {
111111
if (redirectToParts[1]) {
112112
newLocation.search = redirectToParts[1];
113113
}
114-
navigateRef.current(newLocation, {
115-
...newLocationOptions,
116-
flushSync: true,
117-
});
118114

119-
// We need to reset the store after a litte delay to avoid a race condition
115+
// We need to navigate and reset the store after a litte delay to avoid a race condition
120116
// between the store reset and the navigation.
121117
//
122118
// This would only happen when the `authProvider.getPermissions` method returns
123119
// a resolved promise with no delay: If the store was reset before the navigation,
124120
// the `usePermissions` query would reset, causing the `CoreAdminRoutes` component to
125121
// rerender the `LogoutOnMount` component leading to an infinite loop.
126-
window.requestAnimationFrame(() => {
122+
setTimeout(() => {
123+
navigateRef.current(
124+
newLocation,
125+
newLocationOptions
126+
);
127+
127128
resetStore();
128129
queryClient.clear();
129-
});
130+
}, 0);
130131

131132
return redirectToFromProvider;
132133
});

0 commit comments

Comments
 (0)