Skip to content
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

Add future.v7_relativeSplatPath flag #11087

Merged
merged 9 commits into from Dec 5, 2023
12 changes: 8 additions & 4 deletions packages/react-router-dom/index.tsx
Expand Up @@ -657,6 +657,9 @@ export function RouterProvider({
navigator,
static: false,
basename,
future: {
v7_relativeSplatPath: router.future.v7_relativeSplatPath,
},
}),
[router, navigator, basename]
);
Expand Down Expand Up @@ -749,6 +752,7 @@ export function BrowserRouter({
location={state.location}
navigationType={state.action}
navigator={history}
future={future}
/>
);
}
Expand Down Expand Up @@ -799,6 +803,7 @@ export function HashRouter({
location={state.location}
navigationType={state.action}
navigator={history}
future={future}
/>
);
}
Expand Down Expand Up @@ -845,6 +850,7 @@ function HistoryRouter({
location={state.location}
navigationType={state.action}
navigator={history}
future={future}
/>
);
}
Expand Down Expand Up @@ -1543,10 +1549,8 @@ export function useFormAction(
// object referenced by useMemo inside useResolvedPath
let path = { ...useResolvedPath(action ? action : ".", { relative }) };

// Previously we set the default action to ".". The problem with this is that
// `useResolvedPath(".")` excludes search params of the resolved URL. This is
// the intended behavior of when "." is specifically provided as
// the form action, but inconsistent w/ browsers when the action is omitted.
// If no action was specified, browsers will persist current search params
// when determining the path, so match that behavior
// https://github.com/remix-run/remix/issues/927
let location = useLocation();
if (action == null) {
Expand Down
18 changes: 17 additions & 1 deletion packages/react-router-dom/server.tsx
Expand Up @@ -7,6 +7,7 @@ import type {
CreateStaticHandlerOptions as RouterCreateStaticHandlerOptions,
UNSAFE_RouteManifest as RouteManifest,
RouterState,
FutureConfig as RouterFutureConfig,
} from "@remix-run/router";
import {
IDLE_BLOCKER,
Expand Down Expand Up @@ -109,6 +110,9 @@ export function StaticRouterProvider({
static: true,
staticContext: context,
basename: context.basename || "/",
future: {
v7_relativeSplatPath: router.future.v7_relativeSplatPath,
},
};

let fetchersContext = new Map();
Expand Down Expand Up @@ -260,7 +264,11 @@ export function createStaticHandler(

export function createStaticRouter(
routes: RouteObject[],
context: StaticHandlerContext
context: StaticHandlerContext,
opts: {
// Only accept future flags that impact the server render
future?: Partial<Pick<RouterFutureConfig, "v7_relativeSplatPath">>;
} = {}
): RemixRouter {
let manifest: RouteManifest = {};
let dataRoutes = convertRoutesToDataRoutes(
Expand Down Expand Up @@ -288,6 +296,14 @@ export function createStaticRouter(
get basename() {
return context.basename;
},
get future() {
return {
v7_fetcherPersist: false,
v7_normalizeFormMethod: false,
v7_prependBasename: false,
v7_relativeSplatPath: opts.future?.v7_relativeSplatPath === true,
};
},
get state() {
return {
historyAction: Action.Pop,
Expand Down