Skip to content
10 changes: 9 additions & 1 deletion packages/vinext/src/entries/app-rsc-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ const appPrerenderStaticParamsPath = resolveEntryPath(
import.meta.url,
);
const seedCachePath = resolveEntryPath("../server/seed-cache.js", import.meta.url);
const pagesExecutionTracingPath = resolveEntryPath(
"../server/pages-execution-tracing.js",
import.meta.url,
);
const pregeneratedConcretePathsPath = resolveEntryPath(
"../server/pregenerated-concrete-paths.js",
import.meta.url,
Expand Down Expand Up @@ -1141,6 +1145,7 @@ import { clearAppRequestContext as __clearRequestContext, setAppNavigationContex
__configureMemoryCacheHandler({ cacheMaxMemorySize: ${JSON.stringify(cacheMaxMemorySize)} });
import { createAppPrerenderStaticParamsResolver as __createAppPrerenderStaticParamsResolver } from ${JSON.stringify(appPrerenderStaticParamsPath)};
import { ensureAppRouteModulesLoaded as __ensureRouteLoaded } from ${JSON.stringify(appRouteModuleLoaderPath)};
import { traceRouteModuleLoad as __traceRouteModuleLoad } from ${JSON.stringify(pagesExecutionTracingPath)};
import {
getRenderedConcreteUrlPathsForRoute as __getRenderedConcreteUrlPathsForRoute,
initPregeneratedPathsFromGlobals as __initPregeneratedPathsFromGlobals,
Expand Down Expand Up @@ -1989,7 +1994,10 @@ ${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandle
readActionFormDataWithLimit: __readFormDataWithLimit,
} = await __loadAppServerActionExecution();
const __actionMatch = routeMatch;
if (__actionMatch) await __ensureRouteLoaded(__actionMatch.route);
// Like Next.js, the page's own modules load only once the action isn't forwarded.
if (__actionMatch) {
await __traceRouteModuleLoad(__actionMatch.route.pattern, () => __ensureRouteLoaded(__actionMatch.route));
}
const __actionIsEdgeRuntime = __actionMatch
? __isEdgeRuntime(__resolveRouteRuntime(__actionMatch.route))
: false;
Expand Down
8 changes: 6 additions & 2 deletions packages/vinext/src/server/api-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
type PagesReqResRequest,
type PagesReqResResponse,
} from "./pages-node-compat.js";
import { tracePagesApiHandler } from "./pages-execution-tracing.js";
import { tracePagesApiHandler, tracePrepareRouteModule } from "./pages-execution-tracing.js";
import { logRequestError } from "./request-error-log.js";

/**
Expand Down Expand Up @@ -505,7 +505,11 @@ export async function handleApiRoute(

// Parse query from URL + route params. Path params win over same-key search
// params so a query string cannot change the dynamic route value.
const query = mergeRouteParamsIntoQuery(parseQueryString(url), params);
// Like Next.js's Node API template, which prepares the route module (its
// query and params) before every handler call; edge API routes skip it.
const query = tracePrepareRouteModule(() =>
mergeRouteParamsIntoQuery(parseQueryString(url), params),
);

// Honour `export const config = { api: { bodyParser: ... } }` on the
// route module. When the handler opts out (`bodyParser: false`) we must
Expand Down
80 changes: 67 additions & 13 deletions packages/vinext/src/server/app-rsc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
normalizePathnameForRouteMatchStrict,
} from "../routing/utils.js";
import { patternToNextFormat } from "../routing/route-validation.js";
import { traceFindPageComponents } from "./pages-execution-tracing.js";
import { tracePrepareRouteModule, traceRouteModuleLoad } from "./pages-execution-tracing.js";
import { isExternalUrl } from "../utils/external-url.js";
import {
getActiveDraftModeState,
Expand Down Expand Up @@ -2609,6 +2609,41 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
const isFinalRouteMatch = isInterceptionMatch || requestsLiteralRoutePattern;
const preActionMatchIsFinal =
preActionMatch !== null && (isFinalRouteMatch || !preActionMatch.route.isDynamic);
// Next.js prepares the matched route module once, at the start of its
// handler (`RouteModule.prepare`), before handling a Server Action or a
// prefetch. Routing that resumes after a miss prepares the route it lands on.
let preparedRoute: TRoute | null = null;
const prepareRouteModule = <T>(route: TRoute, callback: () => T): T => {
if (preparedRoute === route) return callback();
preparedRoute = route;
return tracePrepareRouteModule(callback);
};
// The route whose modules this request already resolved, so the page render
// that follows a form-state action doesn't resolve them again.
let loadedRoute: TRoute | null = null;
const loadRouteModule = async (route: TRoute) => {
if (!options.ensureRouteLoaded) return;
if (loadedRoute === route) {
await options.ensureRouteLoaded(route);
return;
}
loadedRoute = route;
await traceRouteModuleLoad(route.pattern, () => options.ensureRouteLoaded!(route));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper is unreachable for metadata routes: renderMetadataRouteIfMatched() returns at lines 1960-1963 before matched-route loading/preparation runs, and the split app-metadata stage likewise returns before its tracing block. Next.js 16.4 compiles metadata files as App Route modules; its app-route template calls routeModule.prepare() for them, and the self-hosted path also wraps their module load in LoadComponents.loadRouteModule. Consequently requests such as /robots.txt still omit RouteModule.prepare (and, on the local/self-hosted path, the load span). Route metadata dispatch through equivalent tracing in both local and response-stage execution.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this one for this PR. vinext doesn't serve metadata files through route modules. A separate metadata dispatcher (metadata-route-response.ts) matches and answers them through several distinct paths: generated sitemaps, prerendered cache reads and dynamic renders. There is no route-module load or prepare step to wrap, so matching Next's spans there means restructuring that dispatcher. That is separate from this PR, which ports the spans for the route modules vinext does dispatch through: App pages, Node route handlers, and Pages pages and API routes.

};
// Like Next.js, prepare the action's page before handling the action. The
// action and the page it renders see the route's root params.
const prepareActionRoute = (routeMatch: AppRscRouteMatch<TRoute>) =>
prepareRouteModule(routeMatch.route, () =>
setRootParams(pickRootParams(routeMatch.params, routeMatch.route.rootParamNames)),
);
// Load the action's page, then prepare it. A Server Action that may be
// forwarded to the route that owns it loads the page only once it isn't, so
// the page's modules don't run for a forwarded action.
const loadAndPrepareActionRoute = async (routeMatch: AppRscRouteMatch<TRoute> | null) => {
if (!routeMatch) return;
await loadRouteModule(routeMatch.route);
prepareActionRoute(routeMatch);
};
let serverActionHandled = false;
const handleServerAction = async (
routeMatch: AppRscRouteMatch<TRoute> | null,
Expand All @@ -2617,10 +2652,13 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
if (!filesystemRouteEligible || !isPostRequest || !actionId) return null;
if (routeMatch && isAppRouteHandlerRoute(routeMatch.route)) return null;
if (!options.handleServerActionRequest) {
// A build without Server Actions has nothing to forward.
await loadAndPrepareActionRoute(routeMatch);
return markServerActionResponse(
respondServerActionNotFound(actionId, options.clearRequestContext),
);
}
if (routeMatch) prepareActionRoute(routeMatch);
const sourceConfigHeaders = new Headers();
await applyAppRscConfigHeaders(sourceConfigHeaders, request, {
basePath: options.basePath,
Expand Down Expand Up @@ -2658,11 +2696,16 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
if (!filesystemRouteEligible || !isProgressiveActionRequest) return null;
if (routeMatch && isAppRouteHandlerRoute(routeMatch.route)) return null;
if (!options.handleProgressiveActionRequest) {
// A build without Server Actions has nothing to forward.
await loadAndPrepareActionRoute(routeMatch);
return unrenderedRouteMatch?.route.__loadPage &&
!unrenderedRouteMatch.route.__loadRouteHandler
? markServerActionResponse(respondServerActionNotFound(null, options.clearRequestContext))
: null;
}
// The action may be forwarded, so its page loads only for the render that
// follows a form-state result.
if (routeMatch) prepareActionRoute(routeMatch);
const progressiveActionResult = await options.handleProgressiveActionRequest({
actionId,
cleanPathname,
Expand Down Expand Up @@ -3243,11 +3286,13 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
: rewriteCachePathname(canonicalPathname, cleanPathname);
// Hydrate lazy page/route-handler modules before the page-vs-handler dispatch
// branch and any downstream synchronous module reads.
if (options.ensureRouteLoaded) {
await traceFindPageComponents(route.pattern, () => options.ensureRouteLoaded!(route));
}
const resolvedSearchParams = getResolvedSearchParams();
await loadRouteModule(route);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unmatched App request returns through renderUnmatchedRoute() at lines 3225-3238 before reaching this load, while the split app-not-found stage returns at app-rsc-response-stage.ts:305-306 before both new wrappers. Next.js handles that request through its /_not-found/page App page route, so it emits LoadComponents.loadRouteModule and RouteModule.prepare. Add the not-found route load/preparation tracing to both local and split paths (without applying it to static-asset 404s or a route handler own notFound()).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this one for this PR, for the same reason as the metadata routes. vinext renders an unmatched App request through the fallback renderer (renderHttpAccessFallback with route: null), not through a /_not-found page route. It has no separate module resolution or preparation step: the not-found module is resolved inside the render. Emitting loadRouteModule / prepare there would mean wrapping operations that don't exist separately, or splitting the fallback renderer, which is outside this PR's route-module span port.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still emits findPageComponents / loadRouteModule for edge App routes. In Next.js v16.4.6, both edge-app-route.ts and edge-ssr.ts statically import userland; LoadComponents.loadRouteModule only wraps the Node requirePage() path in server/load-components.ts. The latest runtime gate correctly suppresses prepare for edge route handlers, but this unconditional call (and the equivalent response-stage call) leaves edge pages and handlers with a Node-only load span. Gate load tracing on the effective edge runtime in both local and split paths, and make the edge test assert the complete route-module span list.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this one. Next's edge templates skip loadRouteModule because an edge function statically imports its userland, so there is no load step. vinext has no such split: an edge App route is lazy-loaded through the same ensureAppRouteModulesLoaded as a Node route (in the same Worker or server), so the span times work that really happens for both runtimes. An App route's runtime also isn't known before that load. It comes from the segment config of the page, layouts and slots, which live in the modules being loaded (__resolveRouteRuntime). So the span can't be skipped up front without a backdated post-load span, which would make this PR depend on the timing support in #4913. prepare is different: it doesn't depend on loading, so the edge route handler gate stays.

const isRouteTreePrefetch = isRouteTreePrefetchRequest(request) && !route.routeHandler;
// A tree prefetch answers from the matched route alone, so reading its
// query is all it prepares, before its params are admitted.
const resolvedSearchParams = isRouteTreePrefetch
? prepareRouteModule(route, getResolvedSearchParams)
: getResolvedSearchParams();
// Next.js rejects a dynamicParams = false miss while routing, outside draft
// mode, so a fallback rewrite can claim the URL's route tree. Without one
// that could, vinext doesn't run the route's generators for each prefetched
Expand All @@ -3271,6 +3316,7 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
return new Response(null, { status: 404 });
}
setFrameworkRequestRoute(patternToNextFormat(route.pattern), isRscRequest);
const matchedResponseStage = transportedResponseStage ?? options.renderResponseStageLocally;
if (isRouteTreePrefetch) {
const response = await createRouteTreePrefetchResponse(route, {
buildId: options.buildId,
Expand Down Expand Up @@ -3301,7 +3347,6 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
: cleanPathnameIsRequestPathname
? requestPathname || "/"
: cleanPathname || "/";
const matchedResponseStage = transportedResponseStage ?? options.renderResponseStageLocally;
let runtimeFallbackShells: AppPagePprFallbackCacheShell[] = [];
if (
options.createPprFallbackShells &&
Expand All @@ -3319,13 +3364,22 @@ async function handleAppRscRequest<TRoute extends AppRscHandlerRoute>(
params,
);
}
options.setNavigationContext({
pathname: canonicalPathname,
searchParams: resolvedSearchParams,
params: renderParams,
});
const rootParams = pickRootParams(renderParams, route.rootParamNames);
setRootParams(rootParams);
const setMatchedRouteContext = () => {
options.setNavigationContext({
pathname: canonicalPathname,
searchParams: resolvedSearchParams,
params: renderParams,
});
const matchedRootParams = pickRootParams(renderParams, route.rootParamNames);
setRootParams(matchedRootParams);
return matchedRootParams;
};
// A response stage prepares the route module it renders. Next.js's edge
// route handler template doesn't prepare its route module.
const rootParams =
matchedResponseStage || (route.routeHandler && isEdgeRouteHandler(route.routeHandler))
? setMatchedRouteContext()
: prepareRouteModule(route, setMatchedRouteContext);

if (route.routeHandler) {
// Next.js edge route handlers run through web/adapter.ts, which strips
Expand Down
26 changes: 17 additions & 9 deletions packages/vinext/src/server/app-rsc-response-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { traceAppPageRender } from "./app-page-tracing.js";
import { getRenderedConcreteUrlPathsForRoute } from "./pregenerated-concrete-paths.js";
import { runWithPrerenderWorkUnit } from "./prerender-work-unit-setup.js";
import { stripInheritedResponseStageCookies } from "./response-stage-policy.js";
import { traceFindPageComponents } from "./pages-execution-tracing.js";
import { tracePrepareRouteModule, traceRouteModuleLoad } from "./pages-execution-tracing.js";
import { runOutsideWorkStoreScope } from "vinext/shims/internal/work-store-scope";
import {
cloneRequestWithHeaders,
Expand Down Expand Up @@ -217,7 +217,7 @@ export async function renderAppWorkerResponseStage<TRoute extends AppRscHandlerR
const route = match?.route ?? null;
if (route) {
if (options.ensureRouteLoaded) {
await traceFindPageComponents(route.pattern, () => options.ensureRouteLoaded!(route));
await traceRouteModuleLoad(route.pattern, () => options.ensureRouteLoaded!(route));
}
if (
(props.kind === "app-page" && route.routeHandler) ||
Expand Down Expand Up @@ -361,13 +361,21 @@ export async function renderAppWorkerResponseStage<TRoute extends AppRscHandlerR
}
const searchParams = new URL(props.resolvedUrl, request.url).searchParams;
const renderParams = props.params;
options.setNavigationContext({
pathname: props.canonicalPathname,
searchParams,
params: renderParams,
});
const rootParams = pickRootParams(renderParams, route.rootParamNames);
setRootParams(rootParams);
const setMatchedRouteContext = () => {
options.setNavigationContext({
pathname: props.canonicalPathname,
searchParams,
params: renderParams,
});
const matchedRootParams = pickRootParams(renderParams, route.rootParamNames);
setRootParams(matchedRootParams);
return matchedRootParams;
};
// Next.js's edge route handler template doesn't prepare its route module.
const rootParams =
props.kind === "app-route-handler" && isEdgeRouteHandler(route.routeHandler)
? setMatchedRouteContext()
: tracePrepareRouteModule(setMatchedRouteContext);

if (props.kind === "app-route-handler") {
setCurrentFetchSoftTags(
Expand Down
55 changes: 33 additions & 22 deletions packages/vinext/src/server/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ import {
tracePagesDocument,
tracePagesDocumentStream,
traceFindPageComponents,
traceLoadRouteModule,
tracePrepareRouteModule,
} from "./pages-execution-tracing.js";
import { logRequestError } from "./request-error-log.js";
import type { FontOwners } from "vinext/shims/font-utils";
Expand Down Expand Up @@ -924,7 +926,9 @@ export function createSSRHandler(
// beneath one findPageComponents span before data methods run.
const { pageModule, AppComponent, appFilePath, DocumentComponent } =
await traceFindPageComponents(route.pattern, async () => {
const pageModule = await importModule(runner, route.filePath);
const pageModule = await traceLoadRouteModule(() =>
importModule(runner, route.filePath),
);
const appFilePath = findFileWithExts(pagesDir, "_app", matcher);
const appModule = appFilePath ? await importModule(runner, appFilePath) : null;
const docFilePath = findFileWithExts(pagesDir, "_document", matcher);
Expand Down Expand Up @@ -990,20 +994,22 @@ export function createSSRHandler(
pagesNextData,
)
: true;
if (typeof routerShim.setSSRContext === "function") {
routerShim.setSSRContext({
pathname: patternToNextFormat(route.pattern),
query,
asPath: requestAsPath,
navigationIsReady,
nextData: pagesNextData,
locale: locale ?? currentDefaultLocale,
locales: i18nConfig?.locales,
defaultLocale: currentDefaultLocale,
domainLocales,
isPreview: requestPreviewData !== false,
});
}
tracePrepareRouteModule(() => {
if (typeof routerShim.setSSRContext === "function") {
routerShim.setSSRContext({
pathname: patternToNextFormat(route.pattern),
query,
asPath: requestAsPath,
navigationIsReady,
nextData: pagesNextData,
locale: locale ?? currentDefaultLocale,
locales: i18nConfig?.locales,
defaultLocale: currentDefaultLocale,
domainLocales,
isPreview: requestPreviewData !== false,
});
}
});
// Mark end of compile phase: everything from here is rendering.
_compileEnd = now();

Expand Down Expand Up @@ -1951,7 +1957,9 @@ async function renderErrorPage(
const errorPage = candidate === "_error" ? "/_error" : `/${candidate}`;
const { errorModule, AppComponent, appAssetPath, DocumentComponent } =
await traceFindPageComponents(errorPage, async () => {
const errorModule = await importModule(runner, errorAssetPath ?? "next/error");
const errorModule = await traceLoadRouteModule(() =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error route now emits load route module, but renderErrorPage never emits the matching prepare route module: its error-router context is installed at lines 1995-2002 without tracePrepareRouteModule. As a result, a route miss has no preparation span at all, and a render failure prepares only the failed page rather than the error module. Wrap the error route's context setup and cover missing/thrown routes so dev matches the production and Next.js one-prepare-per-route behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1ba735b. renderErrorPage now prepares the error page by wrapping its router SSR context setup. In Next, the error render also goes through the error page's own handler, which calls prepare. Covered by "prepares the 404 page it renders for a route miss in dev".

importModule(runner, errorAssetPath ?? "next/error"),
);
const appAssetPath = findFileWithExts(pagesDir, "_app", matcher);
const appModule = appAssetPath ? await importModule(runner, appAssetPath) : null;
const docFilePath = findFileWithExts(pagesDir, "_document", matcher);
Expand Down Expand Up @@ -1986,12 +1994,15 @@ async function renderErrorPage(
};
try {
errorRouterShim = await importModule(runner, "next/router");
if (typeof errorRouterShim.setSSRContext === "function") {
errorRouterShim.setSSRContext({
...errorRouter,
navigationIsReady: true,
});
}
// The error page's own handler prepares it, as in Next.js.
tracePrepareRouteModule(() => {
if (typeof errorRouterShim.setSSRContext === "function") {
errorRouterShim.setSSRContext({
...errorRouter,
navigationIsReady: true,
});
}
});
} catch {
// router shim not available — continue without it
}
Expand Down
6 changes: 4 additions & 2 deletions packages/vinext/src/server/pages-api-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { NextRequest } from "vinext/shims/server";
import { markRouteCacheabilityExplicitResponsePolicy } from "vinext/shims/cacheability-classification";
import { hasCdnResponsePolicy } from "./cache-control.js";
import { tracePagesApiHandler } from "./pages-execution-tracing.js";
import { tracePagesApiHandler, tracePrepareRouteModule } from "./pages-execution-tracing.js";
import { isWebSocketUpgradeResponse } from "./websocket-upgrade-response.js";

type PagesApiRouteConfig = {
Expand Down Expand Up @@ -225,7 +225,9 @@ async function _handlePagesApiRoute(options: HandlePagesApiRouteOptions): Promis
}
const handler = route.module.default;

const query = buildPagesApiQuery(options.url, params);
// Next.js's Node API template prepares the route module (its query and
// params) before every handler call; edge API routes skip it.
const query = tracePrepareRouteModule(() => buildPagesApiQuery(options.url, params));

// Honour `export const config = { api: { bodyParser: ... } }` on the
// route module. When the handler opts out (`bodyParser: false`) we must
Expand Down
37 changes: 37 additions & 0 deletions packages/vinext/src/server/pages-execution-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,40 @@ export function createFindPageComponentsSpanDescriptor(routePattern: string) {
export function traceFindPageComponents<T>(routePattern: string, callback: () => T): T {
return frameworkTracer.trace(createFindPageComponentsSpanDescriptor(routePattern), callback);
}

// Next.js 16.4 traces loading the page's own module inside
// `findPageComponents` (`loadRouteModule` in server/load-components.ts) and
// the route module's request preparation (`RouteModule.prepare` in
// server/route-modules/route-module.ts) on every request.
const LOAD_ROUTE_MODULE_SPAN = {
name: "load route module",
type: "LoadComponents.loadRouteModule",
} as const;

const PREPARE_ROUTE_MODULE_SPAN = {
name: "prepare route module",
type: "RouteModule.prepare",
} as const;

export function createLoadRouteModuleSpanDescriptor() {
return LOAD_ROUTE_MODULE_SPAN;
}

export function createPrepareRouteModuleSpanDescriptor() {
return PREPARE_ROUTE_MODULE_SPAN;
}

/** Resolve the page's own module, beneath its `findPageComponents` span. */
export function traceLoadRouteModule<T>(callback: () => T): T {
return frameworkTracer.trace(LOAD_ROUTE_MODULE_SPAN, callback);
}

/** Resolve a matched route's modules, as Next.js's `findPageComponents`. */
export function traceRouteModuleLoad<T>(routePattern: string, load: () => T): T {
return traceFindPageComponents(routePattern, () => traceLoadRouteModule(load));
}

/** Set up the matched route's request context (pathname, query, params). */
export function tracePrepareRouteModule<T>(callback: () => T): T {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new preparation span is not wired into Pages API requests. Production/Workers dispatch in pages-api-route.ts and dev dispatch in api-handler.ts both invoke the API handler without tracePrepareRouteModule. The Next.js 16.4 build/templates/pages-api.ts template calls routeModule.prepare() before every API handler invocation, including direct/deploy execution, so vinext still omits this span for an entire Pages Router route class. Apply the preparation wrapper in both API paths (a LoadComponents.loadRouteModule span is not expected for the direct Pages API template).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ea51fbc. Node Pages API routes now prepare by wrapping their query and params, which is what Next's pages-api.ts prepare resolves, before the handler runs. That covers both production/Workers (pages-api-route.ts) and dev (api-handler.ts). Edge API routes don't prepare, because Next's pages-edge-api.ts template never calls prepare. Checking the templates also showed the same gap for edge-app-route.ts, so edge App route handlers no longer emit RouteModule.prepare in either the local or the response-stage path. Covered by the new Node/edge cases in tests/pages-api-route.test.ts, tests/api-handler.test.ts and tests/app-rsc-handler.test.ts.

return frameworkTracer.trace(PREPARE_ROUTE_MODULE_SPAN, callback);
}
Loading
Loading