1
- import { useRef , type PropsWithChildren , useDeferredValue } from 'react' ;
1
+ import {
2
+ type PropsWithChildren ,
3
+ useCallback ,
4
+ useDeferredValue ,
5
+ useState ,
6
+ } from 'react' ;
2
7
import { useFetchers , useHref , useNavigation } from 'react-router' ;
3
8
import { Button } from './Button' ;
4
9
import { tv } from '@restate/util/styles' ;
@@ -32,8 +37,9 @@ function useIsSubmitting(action?: string) {
32
37
}
33
38
const formActionPathname =
34
39
basename === '/'
35
- ? actionUrl ?. pathname
36
- : actionUrl ?. pathname . split ( basename . replace ( / \/ $ / , '' ) ) . at ( - 1 ) ;
40
+ ? String ( actionUrl ?. pathname ) + actionUrl ?. search
41
+ : String ( actionUrl ?. pathname . split ( basename . replace ( / \/ $ / , '' ) ) . at ( - 1 ) ) +
42
+ actionUrl ?. search ;
37
43
const fetchers = useFetchers ( ) ;
38
44
const submitFetcher = fetchers . find (
39
45
( fetcher ) => fetcher . formAction === formActionPathname ,
@@ -59,16 +65,18 @@ export function SubmitButton({
59
65
isPending,
60
66
...props
61
67
} : PropsWithChildren < SubmitButtonProps > ) {
62
- const ref = useRef < HTMLButtonElement | null > ( null ) ;
63
- const formElement = ref . current ?. form ;
64
- const isSubmitting =
65
- useIsSubmitting ( formElement ?. action ) || Boolean ( isPending ) ;
68
+ const [ action , setAction ] = useState < string > ( ) ;
69
+ const isSubmitting = useIsSubmitting ( action ) || Boolean ( isPending ) ;
66
70
const deferredIsSubmitting = useDeferredValue ( isSubmitting ) ;
71
+ const setFormAction = useCallback ( ( el : HTMLButtonElement | null ) => {
72
+ setAction ( el ?. form ?. action ) ;
73
+ } , [ ] ) ;
74
+
67
75
return (
68
76
< Button
69
77
{ ...props }
70
78
type = "submit"
71
- ref = { ref }
79
+ ref = { setFormAction }
72
80
disabled = { deferredIsSubmitting || disabled }
73
81
>
74
82
{ deferredIsSubmitting && ! hideSpinner ? (
0 commit comments