1
1
import React , { useEffect , useMemo } from 'react' ;
2
2
import { useLocation , useNavigate , useSearchParams } from 'react-router-dom' ;
3
3
4
+ import { useQueryClient } from '@tanstack/react-query' ;
5
+
4
6
import { Flex } from 'src/app-components/Flex/Flex' ;
5
7
import classes from 'src/components/form/Form.module.css' ;
6
8
import { MessageBanner } from 'src/components/form/MessageBanner' ;
@@ -14,6 +16,7 @@ import { FileScanResults } from 'src/features/attachments/types';
14
16
import { useExpandedWidthLayouts , useLayoutLookups } from 'src/features/form/layout/LayoutsContext' ;
15
17
import { useUiConfigContext } from 'src/features/form/layout/UiConfigContext' ;
16
18
import { usePageSettings } from 'src/features/form/layoutSettings/LayoutSettingsContext' ;
19
+ import { invalidateFormDataQueries } from 'src/features/formData/useFormDataQuery' ;
17
20
import { useLaxInstanceId } from 'src/features/instance/InstanceContext' ;
18
21
import { useLanguage } from 'src/features/language/useLanguage' ;
19
22
import { useOnFormSubmitValidation } from 'src/features/validation/callbacks/onFormSubmitValidation' ;
@@ -241,6 +244,7 @@ function HandleNavigationFocusComponent() {
241
244
const validate = useQueryKey ( SearchParams . Validate ) ?. toLocaleLowerCase ( ) === 'true' ;
242
245
const navigate = useNavigate ( ) ;
243
246
const searchStringRef = useAsRef ( useLocation ( ) . search ) ;
247
+ const queryClient = useQueryClient ( ) ;
244
248
245
249
React . useEffect ( ( ) => {
246
250
( async ( ) => {
@@ -250,10 +254,13 @@ function HandleNavigationFocusComponent() {
250
254
location . delete ( SearchParams . ExitSubform ) ;
251
255
const baseHash = window . location . hash . slice ( 1 ) . split ( '?' ) [ 0 ] ;
252
256
const nextLocation = location . size > 0 ? `${ baseHash } ?${ location . toString ( ) } ` : baseHash ;
257
+ if ( exitSubform ) {
258
+ invalidateFormDataQueries ( queryClient ) ;
259
+ }
253
260
navigate ( nextLocation , { replace : true } ) ;
254
261
}
255
262
} ) ( ) ;
256
- } , [ navigate , searchStringRef , exitSubform , validate , onFormSubmitValidation ] ) ;
263
+ } , [ navigate , searchStringRef , exitSubform , validate , onFormSubmitValidation , queryClient ] ) ;
257
264
258
265
return null ;
259
266
}
0 commit comments