Skip to content

Commit 805924d

Browse files
authored
Revert "Ensure Form contains splat portion of pathname when no action is specified (#10933)" (#10965)
This reverts commit 908a40a.
1 parent 677d6c8 commit 805924d

File tree

3 files changed

+7
-52
lines changed

3 files changed

+7
-52
lines changed

.changeset/splat-form-action.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/react-router-dom/__tests__/data-browser-router-test.tsx

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,7 @@ function testDomRouter(
28942894
let { container } = render(<RouterProvider router={router} />);
28952895

28962896
expect(container.querySelector("form")?.getAttribute("action")).toBe(
2897-
"/foo/bar?a=1"
2897+
"/foo?a=1"
28982898
);
28992899
});
29002900

@@ -2937,44 +2937,6 @@ function testDomRouter(
29372937
"/foo"
29382938
);
29392939
});
2940-
2941-
it("includes splat portion of path when no action is specified (inline splat)", async () => {
2942-
let router = createTestRouter(
2943-
createRoutesFromElements(
2944-
<Route path="/">
2945-
<Route path="foo">
2946-
<Route path="*" element={<NoActionComponent />} />
2947-
</Route>
2948-
</Route>
2949-
),
2950-
{
2951-
window: getWindow("/foo/bar/baz"),
2952-
}
2953-
);
2954-
let { container } = render(<RouterProvider router={router} />);
2955-
2956-
expect(container.querySelector("form")?.getAttribute("action")).toBe(
2957-
"/foo/bar/baz"
2958-
);
2959-
});
2960-
2961-
it("includes splat portion of path when no action is specified (nested splat)", async () => {
2962-
let router = createTestRouter(
2963-
createRoutesFromElements(
2964-
<Route path="/">
2965-
<Route path="foo/*" element={<NoActionComponent />} />
2966-
</Route>
2967-
),
2968-
{
2969-
window: getWindow("/foo/bar/baz"),
2970-
}
2971-
);
2972-
let { container } = render(<RouterProvider router={router} />);
2973-
2974-
expect(container.querySelector("form")?.getAttribute("action")).toBe(
2975-
"/foo/bar/baz"
2976-
);
2977-
});
29782940
});
29792941

29802942
it("allows user to specify search params and hash", async () => {

packages/react-router-dom/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,20 +1457,18 @@ export function useFormAction(
14571457
let { basename } = React.useContext(NavigationContext);
14581458
let routeContext = React.useContext(RouteContext);
14591459
invariant(routeContext, "useFormAction must be used inside a RouteContext");
1460-
let location = useLocation();
14611460

14621461
let [match] = routeContext.matches.slice(-1);
14631462
// Shallow clone path so we can modify it below, otherwise we modify the
14641463
// object referenced by useMemo inside useResolvedPath
1465-
let path = {
1466-
...useResolvedPath(action != null ? action : location.pathname, {
1467-
relative,
1468-
}),
1469-
};
1464+
let path = { ...useResolvedPath(action ? action : ".", { relative }) };
14701465

1471-
// If no action was specified, browsers will persist current search params
1472-
// when determining the path, so match that behavior
1466+
// Previously we set the default action to ".". The problem with this is that
1467+
// `useResolvedPath(".")` excludes search params of the resolved URL. This is
1468+
// the intended behavior of when "." is specifically provided as
1469+
// the form action, but inconsistent w/ browsers when the action is omitted.
14731470
// https://github.com/remix-run/remix/issues/927
1471+
let location = useLocation();
14741472
if (action == null) {
14751473
// Safe to write to this directly here since if action was undefined, we
14761474
// would have called useResolvedPath(".") which will never include a search

0 commit comments

Comments
 (0)