Skip to content

Commit 9cfd99d

Browse files
authored
Revert useResolvedPath fix in splat routes (#11078)
* Revert "Fix other code paths for resolveTo from a splat route (#11045)" This reverts commit 58d421f. * Revert "Add additional test case for #10983" This reverts commit f320378. * Revert "Fix issues with useFormAction/useResolvedPath for dot paths in param/splat routes (#10983)" This reverts commit fe066bd. * Fix test * Add changeset
1 parent 30917ae commit 9cfd99d

File tree

12 files changed

+36
-427
lines changed

12 files changed

+36
-427
lines changed

.changeset/revert-resolve-to-fix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"react-router-dom": patch
3+
"react-router": patch
4+
"@remix-run/router": patch
5+
---
6+
7+
Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329). We plan to re-introduce this fix behind a future flag in the next minor version.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
},
111111
"filesize": {
112112
"packages/router/dist/router.umd.min.js": {
113-
"none": "49.4 kB"
113+
"none": "49.3 kB"
114114
},
115115
"packages/react-router/dist/react-router.production.min.js": {
116116
"none": "13.9 kB"

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

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,44 +2942,6 @@ function testDomRouter(
29422942
"/foo/bar"
29432943
);
29442944
});
2945-
2946-
it("includes param portion of path when no action is specified (inline splat)", async () => {
2947-
let router = createTestRouter(
2948-
createRoutesFromElements(
2949-
<Route path="/">
2950-
<Route path="foo">
2951-
<Route path=":param" element={<NoActionComponent />} />
2952-
</Route>
2953-
</Route>
2954-
),
2955-
{
2956-
window: getWindow("/foo/bar"),
2957-
}
2958-
);
2959-
let { container } = render(<RouterProvider router={router} />);
2960-
2961-
expect(container.querySelector("form")?.getAttribute("action")).toBe(
2962-
"/foo/bar"
2963-
);
2964-
});
2965-
2966-
it("includes splat portion of path when no action is specified (nested splat)", async () => {
2967-
let router = createTestRouter(
2968-
createRoutesFromElements(
2969-
<Route path="/">
2970-
<Route path="foo/:param" element={<NoActionComponent />} />
2971-
</Route>
2972-
),
2973-
{
2974-
window: getWindow("/foo/bar"),
2975-
}
2976-
);
2977-
let { container } = render(<RouterProvider router={router} />);
2978-
2979-
expect(container.querySelector("form")?.getAttribute("action")).toBe(
2980-
"/foo/bar"
2981-
);
2982-
});
29832945
});
29842946

29852947
describe("splat routes", () => {
@@ -2999,7 +2961,7 @@ function testDomRouter(
29992961
let { container } = render(<RouterProvider router={router} />);
30002962

30012963
expect(container.querySelector("form")?.getAttribute("action")).toBe(
3002-
"/foo/bar?a=1"
2964+
"/foo?a=1"
30032965
);
30042966
});
30052967

@@ -3019,7 +2981,7 @@ function testDomRouter(
30192981
let { container } = render(<RouterProvider router={router} />);
30202982

30212983
expect(container.querySelector("form")?.getAttribute("action")).toBe(
3022-
"/foo/bar"
2984+
"/foo"
30232985
);
30242986
});
30252987

@@ -3039,25 +3001,7 @@ function testDomRouter(
30393001
let { container } = render(<RouterProvider router={router} />);
30403002

30413003
expect(container.querySelector("form")?.getAttribute("action")).toBe(
3042-
"/foo/bar"
3043-
);
3044-
});
3045-
3046-
it("includes splat portion of path when no action is specified (inline splat)", async () => {
3047-
let router = createTestRouter(
3048-
createRoutesFromElements(
3049-
<Route path="/">
3050-
<Route path="foo/*" element={<NoActionComponent />} />
3051-
</Route>
3052-
),
3053-
{
3054-
window: getWindow("/foo/bar/baz"),
3055-
}
3056-
);
3057-
let { container } = render(<RouterProvider router={router} />);
3058-
3059-
expect(container.querySelector("form")?.getAttribute("action")).toBe(
3060-
"/foo/bar/baz"
3004+
"/foo"
30613005
);
30623006
});
30633007
});
@@ -3179,13 +3123,10 @@ function testDomRouter(
31793123
it("navigates relative to the URL for splat routes", async () => {
31803124
let router = createTestRouter(
31813125
createRoutesFromElements(
3182-
<Route path="inbox">
3183-
<Route path="messages" />
3184-
<Route
3185-
path="messages/*"
3186-
element={<Form action=".." relative="path" />}
3187-
/>
3188-
</Route>
3126+
<Route
3127+
path="inbox/messages/*"
3128+
element={<Form action=".." relative="path" />}
3129+
/>
31893130
),
31903131
{
31913132
window: getWindow("/inbox/messages/1/2/3"),
@@ -3194,7 +3135,7 @@ function testDomRouter(
31943135
let { container } = render(<RouterProvider router={router} />);
31953136

31963137
expect(container.querySelector("form")?.getAttribute("action")).toBe(
3197-
"/inbox/messages/1/2"
3138+
"/inbox"
31983139
);
31993140
});
32003141
});

packages/react-router-dom/__tests__/link-href-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ describe("<Link> href", () => {
530530
});
531531

532532
expect(renderer.root.findByType("a").props.href).toEqual(
533-
"/inbox/messages/abc"
533+
"/inbox/messages"
534534
);
535535
});
536536

packages/react-router-dom/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,10 @@ export function useFormAction(
15431543
// object referenced by useMemo inside useResolvedPath
15441544
let path = { ...useResolvedPath(action ? action : ".", { relative }) };
15451545

1546-
// If no action was specified, browsers will persist current search params
1547-
// when determining the path, so match that behavior
1546+
// Previously we set the default action to ".". The problem with this is that
1547+
// `useResolvedPath(".")` excludes search params of the resolved URL. This is
1548+
// the intended behavior of when "." is specifically provided as
1549+
// the form action, but inconsistent w/ browsers when the action is omitted.
15481550
// https://github.com/remix-run/remix/issues/927
15491551
let location = useLocation();
15501552
if (action == null) {

0 commit comments

Comments
 (0)