@@ -994,36 +994,26 @@ export function useFormAction(
994
994
method : FormMethod = "get"
995
995
) : string {
996
996
let { id } = useRemixRouteContext ( ) ;
997
+ let resolvedPath = useResolvedPath ( action ?? "." ) ;
997
998
998
- // The documented behavior of a form without an explicit action prop is:
999
- // - Forms without an action prop (<Form method="post">) will automatically
1000
- // post to the same route within which they are rendered.
1001
- //
1002
- // The problem with setting the default action to `.` is that
1003
- // `useResolvedPath(".")` excludes search params. This is the intended
1004
- // behavior of useResolvedPath, but it's unexpected for forms without an
1005
- // action prop since the search params are an important part of the current
1006
- // location, and the action function should receive those in the request URL.
1007
- //
1008
- // If the action prop is omitted, we'll append the current route's search
1009
- // string to the current location if it exists. If the action is explicitly
1010
- // set to `.` it will resolve without the search params to match the intended
1011
- // behavior of useResolvedPath, resolving the same URL as `<Link to="." />`
999
+ // Previously we set the default action to ".". The problem with this is that
1000
+ // `useResolvedPath(".")` excludes search params and the hash of the resolved
1001
+ // URL. This is the intended behavior of when "." is specifically provided as
1002
+ // the form action, but inconsistent w/ browsers when the action is omitted.
1012
1003
// https://github.com/remix-run/remix/issues/927
1013
- let { search : currentSearch } = useLocation ( ) ;
1014
- let actionIsCurrentRoute = action === undefined || action === "." ;
1015
- let path = useResolvedPath (
1016
- action === undefined ? { pathname : "." , search : currentSearch } : action
1017
- ) ;
1004
+ let location = useLocation ( ) ;
1005
+ let { search, hash } = resolvedPath ;
1006
+ if ( action === undefined ) {
1007
+ search = location . search ;
1008
+ hash = location . hash ;
1009
+ }
1018
1010
1019
- let search = path . search ;
1020
1011
let isIndexRoute = id . endsWith ( "/index" ) ;
1021
-
1022
- if ( actionIsCurrentRoute && isIndexRoute ) {
1012
+ if ( ( action === undefined || action === "." ) && isIndexRoute ) {
1023
1013
search = search ? search . replace ( / ^ \? / , "?index&" ) : "?index" ;
1024
1014
}
1025
1015
1026
- return path . pathname + search ;
1016
+ return resolvedPath . pathname + search + hash ;
1027
1017
}
1028
1018
1029
1019
export interface SubmitOptions {
0 commit comments