Skip to content

Remove future.v7_prependBasename from @remix-run/router #11726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/late-buckets-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"react-router-dom": major
"react-router": major
---

Remove `future.v7_prependBasename` from the ionternalized `@remix-run/router` package
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ describe("path resolution", () => {
it("handles pathless relative routing when a basename is present", () => {
let router = createRouter({
routes: [{ path: "/path" }],
future: { v7_prependBasename: true },
history: createMemoryHistory({ initialEntries: ["/base/path"] }),
basename: "/base",
}).initialize();
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/__tests__/router/redirects-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("redirects", () => {
initialEntries: ["/base/name"],
});

let nav1 = await t.navigate("/base/name/parent");
let nav1 = await t.navigate("/parent");

let nav2 = await nav1.loaders.parent.redirectReturn("/parent/child");
await nav2.loaders.parent.resolve("PARENT");
Expand Down Expand Up @@ -451,7 +451,7 @@ describe("redirects", () => {
it("properly handles same-origin absolute URLs when using a basename", async () => {
let t = setup({ routes: REDIRECT_ROUTES, basename: "/base" });

let A = await t.navigate("/base/parent/child", {
let A = await t.navigate("/parent/child", {
formMethod: "post",
formData: createFormData({}),
});
Expand All @@ -476,7 +476,7 @@ describe("redirects", () => {
it("treats same-origin absolute URLs as external if they don't match the basename", async () => {
let t = setup({ routes: REDIRECT_ROUTES, basename: "/base" });

let A = await t.navigate("/base/parent/child", {
let A = await t.navigate("/parent/child", {
formMethod: "post",
formData: createFormData({}),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/router/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe("a router", () => {
expect(t.history.action).toEqual("POP");
expect(t.history.location.pathname).toEqual("/base/name");

await t.navigate("/base/name/tasks");
await t.navigate("/tasks");
expect(t.router.state).toMatchObject({
location: {
pathname: "/base/name/tasks",
Expand All @@ -565,7 +565,7 @@ describe("a router", () => {
expect(t.history.action).toEqual("PUSH");
expect(t.history.location.pathname).toEqual("/base/name/tasks");

await t.navigate("/base/name/tasks/1");
await t.navigate("/tasks/1");
expect(t.router.state).toMatchObject({
location: {
pathname: "/base/name/tasks/1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("scroll restoration", () => {
}
);

let nav1 = await t.navigate("/base/tasks");
let nav1 = await t.navigate("/tasks");
await nav1.loaders.tasks.resolve("TASKS");
expect(pathname).toBe("/base/tasks");
expect(t.router.state.restoreScrollPosition).toBe(100);
Expand Down
3 changes: 0 additions & 3 deletions packages/react-router/__tests__/router/submission-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,6 @@ describe("submissions", () => {
],
},
],
future: {
v7_prependBasename: false,
},
});
let A = await t.navigate("/child", {
formMethod: "get",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,15 +608,7 @@ export function setup({
return helpers;
}

let navHref = href;
if (currentRouter.basename) {
navHref = stripBasename(navHref, currentRouter.basename) as string;
invariant(
navHref,
"href passed to t.navigate() should start with basename"
);
}
helpers = getNavigationHelpers(navHref, navigationId);
helpers = getNavigationHelpers(href, navigationId);
shims?.forEach((routeId) =>
shimHelper(helpers.loaders, "navigation", "loader", routeId)
);
Expand Down
7 changes: 2 additions & 5 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function createMemoryRouter(
routes: RouteObject[],
opts?: {
basename?: string;
future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
future?: Partial<RouterFutureConfig>;
hydrationData?: HydrationState;
initialEntries?: InitialEntry[];
initialIndex?: number;
Expand All @@ -137,10 +137,7 @@ export function createMemoryRouter(
): RemixRouter {
return createRouter({
basename: opts?.basename,
future: {
...opts?.future,
v7_prependBasename: true,
},
future: opts?.future,
history: createMemoryHistory({
initialEntries: opts?.initialEntries,
initialIndex: opts?.initialIndex,
Expand Down
12 changes: 3 additions & 9 deletions packages/react-router/lib/dom/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ try {

interface DOMRouterOpts {
basename?: string;
future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
future?: Partial<RouterFutureConfig>;
hydrationData?: HydrationState;
unstable_dataStrategy?: unstable_DataStrategyFunction;
unstable_patchRoutesOnMiss?: unstable_PatchRoutesOnMissFunction;
Expand All @@ -140,10 +140,7 @@ export function createBrowserRouter(
): RemixRouter {
return createRouter({
basename: opts?.basename,
future: {
...opts?.future,
v7_prependBasename: true,
},
future: opts?.future,
history: createBrowserHistory({ window: opts?.window }),
hydrationData: opts?.hydrationData || parseHydrationData(),
routes,
Expand All @@ -163,10 +160,7 @@ export function createHashRouter(
): RemixRouter {
return createRouter({
basename: opts?.basename,
future: {
...opts?.future,
v7_prependBasename: true,
},
future: opts?.future,
history: createHashHistory({ window: opts?.window }),
hydrationData: opts?.hydrationData || parseHydrationData(),
routes,
Expand Down
1 change: 0 additions & 1 deletion packages/react-router/lib/dom/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ export function createStaticRouter(
get future() {
return {
v7_fetcherPersist: false,
v7_prependBasename: false,
unstable_skipActionErrorRevalidation: false,
};
},
Expand Down
1 change: 0 additions & 1 deletion packages/react-router/lib/dom/ssr/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function createHydratedRouter(): RemixRouter {
basename: ssrInfo.context.basename,
future: {
v7_fetcherPersist: ssrInfo.context.future.v3_fetcherPersist,
v7_prependBasename: true,
// Single fetch enables this underlying behavior
unstable_skipActionErrorRevalidation: true,
},
Expand Down
8 changes: 1 addition & 7 deletions packages/react-router/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ export type HydrationState = Partial<
*/
export interface FutureConfig {
v7_fetcherPersist: boolean;
v7_prependBasename: boolean;
unstable_skipActionErrorRevalidation: boolean;
}

Expand Down Expand Up @@ -841,7 +840,6 @@ export function createRouter(init: RouterInit): Router {
// Config driven behavior flags
let future: FutureConfig = {
v7_fetcherPersist: false,
v7_prependBasename: false,
unstable_skipActionErrorRevalidation: false,
...init.future,
};
Expand Down Expand Up @@ -1357,7 +1355,6 @@ export function createRouter(init: RouterInit): Router {
state.location,
state.matches,
basename,
future.v7_prependBasename,
to,
opts?.fromRouteId,
opts?.relative
Expand Down Expand Up @@ -2145,7 +2142,6 @@ export function createRouter(init: RouterInit): Router {
state.location,
state.matches,
basename,
future.v7_prependBasename,
href,
routeId,
opts?.relative
Expand Down Expand Up @@ -4061,7 +4057,6 @@ function normalizeTo(
location: Path,
matches: AgnosticDataRouteMatch[],
basename: string,
prependBasename: boolean,
to: To | null,
fromRouteId?: string,
relative?: RelativeRoutingType
Expand Down Expand Up @@ -4116,7 +4111,7 @@ function normalizeTo(
// this is a root navigation, then just use the raw basename which allows
// the basename to have full control over the presence of a trailing slash
// on root actions
if (prependBasename && basename !== "/") {
if (basename !== "/") {
path.pathname =
path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
}
Expand Down Expand Up @@ -4967,7 +4962,6 @@ function normalizeRelativeRoutingRedirectResponse(
new URL(request.url),
trimmedMatches,
basename,
true,
location
);
response.headers.set("Location", location);
Expand Down