File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
packages/ra-core/src/controller Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,11 @@ import { useParams } from 'react-router-dom';
33
44import { useAuthenticated , useRequireAccess } from '../../auth' ;
55import { RaRecord , MutationMode , TransformData } from '../../types' ;
6- import { useRedirect , RedirectionSideEffect } from '../../routing' ;
6+ import {
7+ useRedirect ,
8+ RedirectionSideEffect ,
9+ useCreatePath ,
10+ } from '../../routing' ;
711import { useNotify } from '../../notification' ;
812import {
913 useGetOne ,
@@ -82,6 +86,7 @@ export const useEditController = <
8286 const getRecordRepresentation = useGetRecordRepresentation ( resource ) ;
8387 const translate = useTranslate ( ) ;
8488 const notify = useNotify ( ) ;
89+ const createPath = useCreatePath ( ) ;
8590 const redirect = useRedirect ( ) ;
8691 const refresh = useRefresh ( ) ;
8792 const { id : routeId } = useParams < 'id' > ( ) ;
@@ -121,7 +126,15 @@ export const useEditController = <
121126 notify ( 'ra.notification.item_doesnt_exist' , {
122127 type : 'error' ,
123128 } ) ;
124- redirect ( 'list' , resource ) ;
129+ // We need to flushSync to ensure the redirect happens before the refresh
130+ // Otherwise this can cause an infinite loop when the record is not found
131+ redirect ( ( ) => ( {
132+ pathname : createPath ( {
133+ resource,
134+ type : 'list' ,
135+ } ) ,
136+ flushSync : true ,
137+ } ) ) ;
125138 refresh ( ) ;
126139 } ,
127140 refetchOnReconnect : false ,
Original file line number Diff line number Diff line change 99 UseGetOneOptions ,
1010} from '../../dataProvider' ;
1111import { useTranslate } from '../../i18n' ;
12- import { useRedirect } from '../../routing' ;
12+ import { useCreatePath , useRedirect } from '../../routing' ;
1313import { useNotify } from '../../notification' ;
1414import {
1515 useResourceContext ,
@@ -80,6 +80,7 @@ export const useShowController = <
8080 const getRecordRepresentation = useGetRecordRepresentation ( resource ) ;
8181 const translate = useTranslate ( ) ;
8282 const notify = useNotify ( ) ;
83+ const createPath = useCreatePath ( ) ;
8384 const redirect = useRedirect ( ) ;
8485 const refresh = useRefresh ( ) ;
8586 const { id : routeId } = useParams < 'id' > ( ) ;
@@ -109,7 +110,16 @@ export const useShowController = <
109110 notify ( 'ra.notification.item_doesnt_exist' , {
110111 type : 'error' ,
111112 } ) ;
112- redirect ( 'list' , resource ) ;
113+
114+ // We need to flushSync to ensure the redirect happens before the refresh
115+ // Otherwise this can cause an infinite loop when the record is not found
116+ redirect ( ( ) => ( {
117+ pathname : createPath ( {
118+ resource,
119+ type : 'list' ,
120+ } ) ,
121+ flushSync : true ,
122+ } ) ) ;
113123 refresh ( ) ;
114124 } ,
115125 retry : false ,
You can’t perform that action at this time.
0 commit comments