Skip to content

Commit 9f04aa3

Browse files
authored
Merge pull request marmelab#10769 from marmelab/fix/ecommerce-demo
Fix(logout): avoid an infinite loop when loading the demo apps for the first time
2 parents c529941 + 03d5ac4 commit 9f04aa3

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

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

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

118132
return redirectToFromProvider;
119133
});

0 commit comments

Comments
 (0)