Skip to content

Commit 0fcb7e1

Browse files
authored
refactor(app-router): remove dead intercept match helper (#2971)
1 parent 3a021ce commit 0fcb7e1

2 files changed

Lines changed: 25 additions & 113 deletions

File tree

packages/vinext/src/server/app-page-request.ts

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ type AppPageInterceptMatch<TPage = unknown> = {
108108
targetRouteGraphId?: string | null;
109109
};
110110

111-
type ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts> = {
111+
type AppPageInterceptState<TRoute, TPage> =
112+
| { kind: "none" }
113+
| { kind: "current-route"; intercept: AppPageInterceptMatch<TPage> }
114+
| { kind: "source-route"; intercept: AppPageInterceptMatch<TPage>; sourceRoute: TRoute };
115+
116+
type ResolveAppPageInterceptStateOptions<TRoute, TPage, TInterceptOpts> = {
112117
cleanPathname: string;
113118
currentRoute: TRoute;
114119
findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;
@@ -118,18 +123,6 @@ type ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts> = {
118123
toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;
119124
};
120125

121-
type ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> = {
122-
interceptOpts: TInterceptOpts;
123-
matchedParams: AppPageParams;
124-
sourceParams: AppPageParams;
125-
sourceRoute: TRoute;
126-
};
127-
128-
type AppPageInterceptState<TRoute, TPage> =
129-
| { kind: "none" }
130-
| { kind: "current-route"; intercept: AppPageInterceptMatch<TPage> }
131-
| { kind: "source-route"; intercept: AppPageInterceptMatch<TPage>; sourceRoute: TRoute };
132-
133126
type ResolveAppPageInterceptionRerenderTargetOptions<TRoute, TPage, TInterceptOpts> = {
134127
cleanPathname: string;
135128
currentParams: AppPageParams;
@@ -625,43 +618,8 @@ export async function validateAppPageDynamicParams(
625618
return null;
626619
}
627620

628-
/**
629-
* Pure: decides whether the incoming request should re-render an intercepted
630-
* source-route tree, and if so returns the source route, the source-route's
631-
* param slice, the full matched param set (the URL params the client sees),
632-
* and an opaque `interceptOpts` bag for the caller's render pipeline.
633-
*
634-
* Returns `null` in three decision-fallthrough cases:
635-
* - non-RSC requests (server rendering the direct page for a full HTML load)
636-
* - no intercepting route matches the path
637-
* - the match's source route IS the current route (the same branch today
638-
* returns `interceptOpts` for the direct render)
639-
*
640-
* Shared by both the GET path (resolveAppPageIntercept, which layers on
641-
* `setNavigationContext` + element build + Response wrap) and the server-action
642-
* POST path (entries/app-rsc-entry.ts), which runs its own response pipeline.
643-
*/
644-
export async function resolveAppPageInterceptMatch<TRoute, TPage, TInterceptOpts>(
645-
options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,
646-
): Promise<ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> | null> {
647-
const interceptState = await resolveAppPageInterceptState(options);
648-
if (interceptState.kind !== "source-route") {
649-
return null;
650-
}
651-
652-
return {
653-
interceptOpts: options.toInterceptOpts(interceptState.intercept),
654-
matchedParams: interceptState.intercept.matchedParams,
655-
sourceParams: pickRouteParams(
656-
interceptState.intercept.sourceMatchedParams ?? interceptState.intercept.matchedParams,
657-
options.getRouteParamNames(interceptState.sourceRoute),
658-
),
659-
sourceRoute: interceptState.sourceRoute,
660-
};
661-
}
662-
663621
async function resolveAppPageInterceptState<TRoute, TPage, TInterceptOpts>(
664-
options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,
622+
options: ResolveAppPageInterceptStateOptions<TRoute, TPage, TInterceptOpts>,
665623
): Promise<AppPageInterceptState<TRoute, TPage>> {
666624
if (!options.isRscRequest) {
667625
return { kind: "none" };

tests/app-page-request.test.ts

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
buildAppPageElement,
55
resolveAppPageActionRerenderTarget,
66
resolveAppPageIntercept,
7-
resolveAppPageInterceptMatch,
7+
resolveAppPageInterceptionRerenderTarget,
88
resolveAppPageGenerateStaticParamsSources,
99
validateAppPageDynamicParams,
1010
} from "../packages/vinext/src/server/app-page-request.js";
@@ -681,7 +681,7 @@ describe("app page request helpers", () => {
681681
});
682682
});
683683

684-
describe("resolveAppPageInterceptMatch", () => {
684+
describe("resolveAppPageInterceptionRerenderTarget intercept loading", () => {
685685
const sourceRoute = { params: [], pattern: "/feed" };
686686
const currentRoute = { params: ["id"], pattern: "/photos/[id]" };
687687

@@ -695,56 +695,7 @@ describe("resolveAppPageInterceptMatch", () => {
695695
interceptSlotKey: intercept.slotKey,
696696
});
697697

698-
it("returns null on non-RSC requests", async () => {
699-
const result = await resolveAppPageInterceptMatch({
700-
cleanPathname: "/photos/123",
701-
currentRoute,
702-
findIntercept() {
703-
throw new Error("should not look up intercepts on non-RSC requests");
704-
},
705-
getRouteParamNames: (route) => route.params,
706-
getSourceRoute: () => sourceRoute,
707-
isRscRequest: false,
708-
toInterceptOpts,
709-
});
710-
711-
expect(result).toBeNull();
712-
});
713-
714-
it("returns null when findIntercept returns nothing", async () => {
715-
const result = await resolveAppPageInterceptMatch({
716-
cleanPathname: "/photos/123",
717-
currentRoute,
718-
findIntercept: () => null,
719-
getRouteParamNames: (route) => route.params,
720-
getSourceRoute: () => sourceRoute,
721-
isRscRequest: true,
722-
toInterceptOpts,
723-
});
724-
725-
expect(result).toBeNull();
726-
});
727-
728-
it("returns null when the source route is the current route", async () => {
729-
const result = await resolveAppPageInterceptMatch({
730-
cleanPathname: "/photos/123",
731-
currentRoute,
732-
findIntercept: () => ({
733-
matchedParams: { id: "123" },
734-
page: { default: "modal-page" },
735-
slotKey: "modal@app/photos/@modal",
736-
sourceRouteIndex: 0,
737-
}),
738-
getRouteParamNames: (route) => route.params,
739-
getSourceRoute: () => currentRoute,
740-
isRscRequest: true,
741-
toInterceptOpts,
742-
});
743-
744-
expect(result).toBeNull();
745-
});
746-
747-
it("returns sourceRoute, sourceParams, matchedParams, and interceptOpts when an intercept applies", async () => {
698+
it("returns the source route, params, navigation params, and intercept options", async () => {
748699
const matchedParams = { id: "123" };
749700
const intercept = {
750701
matchedParams,
@@ -753,8 +704,9 @@ describe("resolveAppPageInterceptMatch", () => {
753704
sourceRouteIndex: 0,
754705
};
755706

756-
const result = await resolveAppPageInterceptMatch({
707+
const result = await resolveAppPageInterceptionRerenderTarget({
757708
cleanPathname: "/photos/123",
709+
currentParams: matchedParams,
758710
currentRoute,
759711
findIntercept: () => intercept,
760712
getRouteParamNames: (route) => route.params,
@@ -763,13 +715,12 @@ describe("resolveAppPageInterceptMatch", () => {
763715
toInterceptOpts,
764716
});
765717

766-
expect(result).not.toBeNull();
767-
expect(result?.sourceRoute).toBe(sourceRoute);
768-
expect(result?.matchedParams).toBe(matchedParams);
718+
expect(result.route).toBe(sourceRoute);
719+
expect(result.navigationParams).toEqual(matchedParams);
769720
// sourceParams keeps only the params declared by the source route.
770721
// /feed has no dynamic params, so the slice is empty.
771-
expect(result?.sourceParams).toEqual({});
772-
expect(result?.interceptOpts).toEqual(toInterceptOpts(intercept));
722+
expect(result.params).toEqual({});
723+
expect(result.interceptOpts).toEqual(toInterceptOpts(intercept));
773724
});
774725

775726
it("deduplicates concurrent intercept page and layout loads", async () => {
@@ -794,6 +745,7 @@ describe("resolveAppPageInterceptMatch", () => {
794745
};
795746
const options = {
796747
cleanPathname: "/photos/123",
748+
currentParams: { id: "123" },
797749
currentRoute,
798750
findIntercept: () => ({ ...intercept, page: sharedLoadState.page }),
799751
getRouteParamNames: (route: { params: string[] }) => route.params,
@@ -803,8 +755,8 @@ describe("resolveAppPageInterceptMatch", () => {
803755
};
804756

805757
await Promise.all([
806-
resolveAppPageInterceptMatch(options),
807-
resolveAppPageInterceptMatch(options),
758+
resolveAppPageInterceptionRerenderTarget(options),
759+
resolveAppPageInterceptionRerenderTarget(options),
808760
]);
809761

810762
expect(__pageLoader).toHaveBeenCalledTimes(1);
@@ -845,8 +797,9 @@ describe("resolveAppPageInterceptMatch", () => {
845797

846798
const liveCookie = await runWithRequestContext(requestContext, async () => {
847799
const live = (await cookies()).get("session")?.value;
848-
await resolveAppPageInterceptMatch({
800+
await resolveAppPageInterceptionRerenderTarget({
849801
cleanPathname: "/photos/123",
802+
currentParams: { id: "123" },
850803
currentRoute,
851804
findIntercept: () => intercept,
852805
getRouteParamNames: (route: { params: string[] }) => route.params,
@@ -869,8 +822,9 @@ describe("resolveAppPageInterceptMatch", () => {
869822
const categorySourceRoute = { params: ["category"], pattern: "/feed/[category]" };
870823
const matchedParams = { category: "nature", id: "123" };
871824

872-
const result = await resolveAppPageInterceptMatch({
825+
const result = await resolveAppPageInterceptionRerenderTarget({
873826
cleanPathname: "/photos/123",
827+
currentParams: matchedParams,
874828
currentRoute,
875829
findIntercept: () => ({
876830
matchedParams,
@@ -885,8 +839,8 @@ describe("resolveAppPageInterceptMatch", () => {
885839
toInterceptOpts,
886840
});
887841

888-
expect(result?.sourceParams).toEqual({ category: "nature" });
889-
expect(result?.matchedParams).toEqual({ category: "nature", id: "123" });
842+
expect(result.params).toEqual({ category: "nature" });
843+
expect(result.navigationParams).toEqual({ category: "nature", tab: "recent", id: "123" });
890844
});
891845
});
892846

0 commit comments

Comments
 (0)