Skip to content

Commit

Permalink
Revert "Fix other code paths for resolveTo from a splat route (#11045)"
Browse files Browse the repository at this point in the history
This reverts commit 58d421f.
  • Loading branch information
brophdawg11 committed Dec 1, 2023
1 parent 30917ae commit 29a886d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 45 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -110,7 +110,7 @@
},
"filesize": {
"packages/router/dist/router.umd.min.js": {
"none": "49.4 kB"
"none": "49.3 kB"
},
"packages/react-router/dist/react-router.production.min.js": {
"none": "13.9 kB"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/lib/components.tsx
Expand Up @@ -14,7 +14,7 @@ import {
AbortedDeferredError,
Action as NavigationType,
createMemoryHistory,
UNSAFE_getResolveToMatches as getResolveToMatches,
UNSAFE_getPathContributingMatches as getPathContributingMatches,
UNSAFE_invariant as invariant,
parsePath,
resolveTo,
Expand Down Expand Up @@ -281,7 +281,7 @@ export function Navigate({
// StrictMode they navigate to the same place
let path = resolveTo(
to,
getResolveToMatches(matches),
getPathContributingMatches(matches).map((match) => match.pathnameBase),
locationPathname,
relative === "path"
);
Expand Down
15 changes: 12 additions & 3 deletions packages/react-router/lib/hooks.tsx
Expand Up @@ -18,7 +18,7 @@ import {
IDLE_BLOCKER,
Action as NavigationType,
UNSAFE_convertRouteMatchToUiMatch as convertRouteMatchToUiMatch,
UNSAFE_getResolveToMatches as getResolveToMatches,
UNSAFE_getPathContributingMatches as getPathContributingMatches,
UNSAFE_invariant as invariant,
isRouteErrorResponse,
joinPaths,
Expand Down Expand Up @@ -197,7 +197,9 @@ function useNavigateUnstable(): NavigateFunction {
let { matches } = React.useContext(RouteContext);
let { pathname: locationPathname } = useLocation();

let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
let routePathnamesJson = JSON.stringify(
getPathContributingMatches(matches).map((match) => match.pathnameBase)
);

let activeRef = React.useRef(false);
useIsomorphicLayoutEffect(() => {
Expand Down Expand Up @@ -309,7 +311,14 @@ export function useResolvedPath(
): Path {
let { matches } = React.useContext(RouteContext);
let { pathname: locationPathname } = useLocation();
let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));

// Use the full pathname for the leaf match so we include splat values
// for "." links
let routePathnamesJson = JSON.stringify(
getPathContributingMatches(matches).map((match, idx) =>
idx === matches.length - 1 ? match.pathname : match.pathnameBase
)
);

return React.useMemo(
() =>
Expand Down
26 changes: 1 addition & 25 deletions packages/router/__tests__/path-resolution-test.ts
Expand Up @@ -138,7 +138,7 @@ describe("path resolution", () => {
path: "*",
},
],
"/foo/bar",
"/foo",
false
);
});
Expand Down Expand Up @@ -391,21 +391,6 @@ describe("path resolution", () => {
]);
});

it("from an index route", () => {
assertRoutingToChild([
{
path: "bar",
children: [
{
id: "activeRoute",
index: true,
},
{ path: "baz" },
],
},
]);
});

it("from a dynamic param route", () => {
assertRoutingToChild([
{
Expand All @@ -415,15 +400,6 @@ describe("path resolution", () => {
},
]);
});

it("from a splat route", () => {
assertRoutingToChild([
{
id: "activeRoute",
path: "*",
},
]);
});
/* eslint-enable jest/expect-expect */
});

Expand Down
2 changes: 1 addition & 1 deletion packages/router/index.ts
Expand Up @@ -87,7 +87,7 @@ export {
ErrorResponseImpl as UNSAFE_ErrorResponseImpl,
convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes,
convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch,
getResolveToMatches as UNSAFE_getResolveToMatches,
getPathContributingMatches as UNSAFE_getPathContributingMatches,
} from "./utils";

export {
Expand Down
3 changes: 1 addition & 2 deletions packages/router/router.ts
Expand Up @@ -40,7 +40,6 @@ import {
convertRouteMatchToUiMatch,
convertRoutesToDataRoutes,
getPathContributingMatches,
getResolveToMatches,
immutableRouteKeys,
isRouteErrorResponse,
joinPaths,
Expand Down Expand Up @@ -3341,7 +3340,7 @@ function normalizeTo(
// Resolve the relative path
let path = resolveTo(
to ? to : ".",
getResolveToMatches(contextualMatches),
getPathContributingMatches(contextualMatches).map((m) => m.pathnameBase),
stripBasename(location.pathname, basename) || location.pathname,
relative === "path"
);
Expand Down
11 changes: 0 additions & 11 deletions packages/router/utils.ts
Expand Up @@ -1145,17 +1145,6 @@ export function getPathContributingMatches<
);
}

// Return the array of pathnames for the current route matches - used to
// generate the routePathnames input for resolveTo()
export function getResolveToMatches<
T extends AgnosticRouteMatch = AgnosticRouteMatch
>(matches: T[]) {
// Use the full pathname for the leaf match so we include splat values for "." links
return getPathContributingMatches(matches).map((match, idx) =>
idx === matches.length - 1 ? match.pathname : match.pathnameBase
);
}

/**
* @private
*/
Expand Down

0 comments on commit 29a886d

Please sign in to comment.