From 9b6bca69dd8773212c885982901ba1ea14f2cfc5 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Fri, 12 Jun 2020 15:40:11 +0200 Subject: [PATCH] Fix update or delete resets the pagination Closes #4902 --- packages/ra-core/src/controller/useListController.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/ra-core/src/controller/useListController.ts b/packages/ra-core/src/controller/useListController.ts index 1d8f79930a6..0d8a337cd8c 100644 --- a/packages/ra-core/src/controller/useListController.ts +++ b/packages/ra-core/src/controller/useListController.ts @@ -174,15 +174,17 @@ const useListController = ( get(state.admin.resources, [resource, 'list', 'total'], 0) ); + const finalIds = typeof total === 'undefined' ? defaultIds : ids; + useEffect(() => { if ( query.page <= 0 || - (!loading && query.page > 1 && (ids || []).length === 0) + (!loading && query.page > 1 && (finalIds || []).length === 0) ) { // query for a page that doesn't exist, set page to 1 queryModifiers.setPage(1); } - }, [loading, query.page, ids, queryModifiers]); + }, [loading, query.page, finalIds, queryModifiers, total, defaultIds]); const currentSort = useMemo( () => ({ @@ -209,7 +211,7 @@ const useListController = ( filterValues: query.filterValues, hasCreate, hideFilter: queryModifiers.hideFilter, - ids: typeof total === 'undefined' ? defaultIds : ids, + ids: finalIds, loaded: loaded || defaultIds.length > 0, loading, onSelect: selectionModifiers.select,