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

Revert useResolvedPath fix in splat routes #11078

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Revert "Fix other code paths for resolveTo from a splat route (#11045)"
This reverts commit 58d421f.
  • Loading branch information
brophdawg11 committed Dec 1, 2023
commit 29a886dd51ef41296b75147beff396aade27956a
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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