Skip to content

fix(tracing): trace route module loading and preparation like Next.js 16.4 - #4912

Draft
james-elicx wants to merge 7 commits into
mainfrom
fix/otel-route-module-spans
Draft

james-elicx wants to merge 7 commits into
mainfrom
fix/otel-route-module-spans

Conversation

@james-elicx

Copy link
Copy Markdown
Member

What

Next.js 16.4 emits two spans that vinext didn't:

  • load route module (LoadComponents.loadRouteModule): the page's own module load, beneath resolve page components (NextNodeServer.findPageComponents). Source: server/load-components.ts loadRouteModule().
  • prepare route module (RouteModule.prepare): the route module's request preparation, beneath the request span (BaseServer.handleRequest). Source: server/route-modules/route-module.ts prepare().

Both are emitted on every request, in both routers. In vinext:

  • App Router. app-rsc-handler.ts (dev and prod) and the split response stage (app-rsc-response-stage.ts) wrap ensureRouteLoaded in load route module inside the existing findPageComponents span. The matched route's request context setup (navigation context: pathname, search params, params; plus root params) runs inside prepare route module.
  • Pages Router. The prod page handler (pages-page-handler.ts, also used by the Workers entry) and the dev server (dev-server.ts) wrap the page module load in load route module. Their initial router SSR context (pathname, query, asPath, preview) runs inside prepare route module. For _app/_document, Next only traces the page module, and so does this PR.

Without OpenTelemetry nothing changes: these are two more calls on frameworkTracer.trace, and its no-provider path just runs the callback, like the request's other ~10 framework spans.

Deploy suite

test/e2e/app-dir/otel-middleware-trace/otel-middleware-trace.test.ts on Next.js v16.4.6, from run 45649241516:

  • Baseline (CI): 24 failed.
  • This branch (local deploy-suite run): 8 fail → pass, 0 pass → fail. Passing now in both the proxy and edge-middleware variants:
    • traces a request the middleware does not match
    • traces /page with an incoming traceparent
    • traces /route-handler with an incoming traceparent
    • traces /rewrite with an incoming traceparent

The other 16 fail for unrelated reasons that this PR doesn't touch:

  • the 16.4 Next.request root span shared by middleware and the render;
  • the Instrumentation.* lifecycle spans.

The suite doesn't exist in 16.2.6, and 16.2.6 has no deploy test that asserts these span lists.

Tests

  • tests/app-rsc-handler.test.ts: parent/child shape for a page request and for the split response stage.
  • tests/pages-page-handler.test.ts: Pages prod handler shape.
  • tests/pages-router.test.ts: Pages dev server.
  • tests/pages-execution-tracing.test.ts: descriptors.

All fail with packages/vinext/src/server restored from main and pass with this change.

… 16.4

Next.js 16.4 traces loading the page's own module beneath
findPageComponents (LoadComponents.loadRouteModule) and the route module's
request preparation (RouteModule.prepare) on every request. vinext emitted
neither, so span trees lacked both. Emit them in the App Router handler and
split response stage, and in the Pages Router page handler and dev server.
@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

npm i https://pkg.pr.new/@vinext/cloudflare@4912

create-vinext-app

npm i https://pkg.pr.new/create-vinext-app@4912

@vinext/types

npm i https://pkg.pr.new/@vinext/types@4912

vinext

npm i https://pkg.pr.new/vinext@4912

@cloudflare/workers-response-store

npm i https://pkg.pr.new/@cloudflare/workers-response-store@4912

commit: 0c2cfeb

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head e0af8f9962978431a99a66bc13ef56ae9575f0ff without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@github-actions

Copy link
Copy Markdown
Contributor
Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
response-store-demo preview production
workers-cache preview production
kv preview production
static-assets-cache preview production
static-assets-pages preview production
static-assets-pages-i18n preview production
static-export preview production
web preview production

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 0c2cfeb against base 219c880 using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 7 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 157.3 KB 157.3 KB ⚫ 0.0%
Client entry size (gzip) vinext 145.5 KB 145.5 KB ⚫ 0.0%
Dev server cold start vinext 1.72 s 1.70 s ⚫ -0.9%
Dev server cold start (large Pages Router app) vinext 12.50 s 12.33 s ⚫ -1.3%
Production build time vinext 2.00 s 1.99 s ⚫ -0.5%
RSC entry closure size (gzip) vinext 150.6 KB 150.8 KB ⚫ +0.1%
Server bundle size (gzip) vinext 262.8 KB 263.1 KB ⚫ +0.1%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

pathname: canonicalPathname,
searchParams: resolvedSearchParams,
params: renderParams,
const rootParams = tracePrepareRouteModule(() => {

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 does not produce one preparation span per matched request across the supported execution paths. An ordinary split-stage GET executes this wrapper in the module-free request stage (where setAppRequestStageNavigationContext is a no-op), then executes the response-stage wrapper at app-rsc-response-stage.ts:370, so it emits two RouteModule.prepare spans. Conversely, route-tree prefetches return at line 3280 and successful Server Actions return at lines 2708/3142 before reaching this wrapper, so they emit none; the action's actual route load at generated app-rsc-entry.ts:1992 is outside traceLoadRouteModule too. Next.js 16.4 calls routeModule.prepare() once near generated-handler entry before prefetch/action classification. Please put ownership at a boundary that runs exactly once and wrap the action's actual route load.

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. handleAppRscRequest now prepares through a once-per-request guard:

  • A Server Action loads its page under findPageComponents / loadRouteModule, then prepares it, before handleServerActionRequest runs. That matches Next, which loads and prepares the page before handling (and possibly forwarding) the action. The entry's own __ensureRouteLoaded is then an idempotent no-op.
  • A route-tree prefetch prepares before it answers.
  • When a response stage renders the route, the request stage no longer prepares, so a split GET emits one prepare, from the response stage.

Covered by the three new tests in tests/app-rsc-handler.test.ts: route-tree prefetch, Server Action and dispatched response stage.


const { route, params } = match;
const pageModule = traceFindPageComponents(route.pattern, () => route.module);
const pageModule = traceFindPageComponents(route.pattern, () =>

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 tracing happens before the on-demand coalescing branch at line 751, which recursively calls renderPage. The leader therefore emits this find/load pair twice and one prepare span, while every concurrent follower emits one find/load pair and returns the shared response without ever emitting RouteModule.prepare. Next.js prepares each incoming request once. Avoid retracing the recursive render and ensure preparation occurs once for both leaders and followers.

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. Prepare now wraps buildPagesReadinessNextData, directly after the page lookup, so every request the page answers prepares once, before coalescing: the leader, each follower, and ISR hits. The leader's internal re-render (__skipOnDemandCoalesce) emits neither the find/load pair nor prepare again. Covered by "resolves and prepares the page once for each request sharing an on-demand revalidation".

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".

const { route, params } = match;
const pageModule = traceFindPageComponents(route.pattern, () => route.module);
const pageModule = traceFindPageComponents(route.pattern, () =>
traceLoadRouteModule(() => route.module),

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 callback only reads an already-populated object property; it does not load the route module. pages-server-entry.ts either statically imports every page before requests or imports all pages in __initializeApplication before _renderPage is created, so module-evaluation time and import failures remain outside LoadComponents.loadRouteModule. Next.js wraps the actual requirePage() call. Please expose/invoke a lazy route loader here, or move this span around the generated import, so the span measures the operation it claims to represent.

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. In Next, loadRouteModule also wraps a cached requirePage() on every request after the first. The 16.4.6 snapshots expect the span under findPageComponents on each request, and printSpanTree drops only the root one-time load. vinext's production Pages entry evaluates page modules at application initialization, so per request the span measures the same thing as Next's warm require cache. Making it measure the real import would mean lazy-loading Pages routes in production. That changes startup and cold-start behavior, which is out of scope for a tracing fix. Dev wraps the actual importModule call.

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review: 4 findings.

Posted 4 actionable inline comments against exact head e0af8f99. No branch modifications.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 1ba735b8efd88618f77671ad01010ce4cb765a6d without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

respondServerActionNotFound(actionId, options.clearRequestContext),
);
}
if (routeMatch) {

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 load/prepare block only runs for header-based Server Actions. A matched progressive multipart action is dispatched at line 2714 (or 3163 after late routing) without going through it. When that handler returns a Response, the request exits with neither LoadComponents.loadRouteModule nor RouteModule.prepare; when it returns form state, those spans occur only later, after the action has already executed. Next.js v16.4.6 calls routeModule.prepare() near the start of app-page-runtime.ts before action classification. Please share this matched-route load/preparation with the progressive action path and cover its early-response case.

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 fba2a13. Progressive actions now share the load/prepare step with header-based ones (prepareActionRoute), before handleProgressiveActionRequest runs. When the action returns form state, the page render that follows no longer resolves the same route's modules again: a per-request loadRouteModule guard handles that, alongside the once-per-request prepare guard. Covered for both outcomes by "loads and prepares a progressive Server Action's route module once when it answers / returns form state".

if (isRouteTreePrefetch) {
// The tree prefetch answers from the matched route alone, so naming it
// on the request span is all this request prepares.
prepareRouteModule(setRequestRoute);

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.

Preparation still happens too late for a rejected route-tree prefetch. The dynamicParams = false branch at lines 3279-3294 loads the matched module and then returns 404 before reaching this call, so that request emits loadRouteModule but no RouteModule.prepare. Next.js prepares the route before parameter admission/404 handling. Move the once-guarded preparation ahead of that early-return branch (while retaining the rejected-root-param cleanup), and add span coverage for this existing miss case.

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 fba2a13. A route-tree prefetch now prepares right after its route load: it wraps reading the request's query, before the dynamicParams = false check. The rejected-root-param cleanup is unchanged, and the request span still names the rejected tree as /404. Covered by "prepares a rejected route-tree prefetch's route module before admitting its params".

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review: 2 findings.

Posted 2 actionable inline comments against exact head 1ba735b8. Targeted tests passed. No branch modifications.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head fba2a139f3512e8cbd28f92f99a5919565a73285 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

? markServerActionResponse(respondServerActionNotFound(null, options.clearRequestContext))
: null;
}
await prepareActionRoute(routeMatch);

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 runs after the !options.handleProgressiveActionRequest return. That option is omitted by the generated entry when hasServerActions is false, so a multipart action POST to a matched page exits with action-not-found at lines 2692-2696 without either route-module span. Next.js still enters and prepares the page's route module before classifying the action. Move the matched-page load/preparation before the missing-handler return and cover the no-Server-Actions build path.

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 e9e893a. Both action paths now load and prepare the matched page before the missing-handler returns. A no-Server-Actions build therefore still emits the find/load and prepare spans before answering action-not-found. This is safe for the split request stage because non-GET requests always take the full App graph (appRequestUsesFullResponseGraph). Covered by "prepares the page of a header-based / progressive Server Action in a build without Server Actions".

// 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(getResolvedSearchParams)

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 marks the request-wide routeModulePrepared guard before isDynamicParamsMiss. If that miss calls resumeRoutingAfterMiss(), the loop at lines 3583-3599 matches and loads the fallback route, but its preparation at lines 3368-3370 is untraced because the first route already set the guard. The existing fallback-tree case at tests/app-rsc-handler.test.ts:5791 takes exactly this two-route path. Track preparation per route (or reset it when routing resumes) so the route that ultimately handles the request also emits RouteModule.prepare.

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 e9e893a. The guard now tracks the prepared route instead of a request-wide flag, so routing that resumes after a miss prepares the route it lands on. Covered by "prepares the fallback route that claims a rejected route-tree prefetch": the same two-route path, with find/load/prepare for the rejected route and again for the fallback route.

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Since last review: 2 resolved, 0 still open, 2 new.

Posted 2 inline findings. All 1,215 targeted tests passed. No branch modifications.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head e9e893a5c736b0763e98547b8b563dffeff6282b without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

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.

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.

hasRewrites,
});
const pagesReadiness = tracesRouteModule
? tracePrepareRouteModule(readPagesReadiness)

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 RouteModule.prepare span wraps only buildPagesReadinessNextData(), which is request-independent inspection of module exports. The actual Pages request context named by the new helper and PR description (pathname, query, asPath, preview state) is installed later by applySSRContext() at lines 920-948, outside the span. That makes the new span report neither the duration nor failures of the operation it claims to trace, unlike the dev implementation. Keep the once-per-request placement needed for ISR/coalescing, but move the request preparation work itself under this span.

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. The span has to sit where every request the page answers passes, which you asked for in the coalescing finding: ISR hits, coalesced followers and early data-method redirects all return before applySSRContext. So it can't wrap the router context install without losing those requests again. What it wraps is the request's resolution of the page module's route config (getStaticProps / getServerSideProps / getInitialProps / auto-export). That is part of what Next's prepareImpl resolves too. The router SSR context is set later, as part of rendering.

}

/** 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.

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review: 4 findings.

Posted 4 actionable inline comments against exact head e9e893a5. No branch modifications.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head ea51fbc2e7b7b44c70ee7f399e4fb57e2abfb1a7 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

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.

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.

// that leads it, which already resolved and prepared the page.
const tracesRouteModule = options?.__skipOnDemandCoalesce !== true;
const pageModule = tracesRouteModule
? traceRouteModuleLoad(route.pattern, () => route.module)

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.

Pages edge pages have the same load-span mismatch. Next.js v16.4.6's edge-ssr.ts statically imports userlandPage and calls prepare, but never goes through loadComponents / loadRouteModule; that span belongs to the Node requirePage() path. This unconditional wrapper therefore gives config.runtime = "edge" pages an extra Node-only find/load pair (and the dev wrapper is unconditional too). Detect the page module's effective runtime and skip only load tracing for edge Pages entries while retaining their preparation span.

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 the same reason as the App finding. runtime = "edge" doesn't change how vinext loads a Pages module. Production imports every page statically and dev imports each page through the module runner, for both runtimes. So the find/load pair describes the same lookup (production) or the same real import (dev) for edge and Node pages. In dev, the page's runtime isn't known until that import has run. Next's edge-only omission comes from its separate edge bundles, which vinext doesn't have.

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review: 2 findings.

Posted 2 actionable inline comments against exact head ea51fbc2. No branch modifications.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head ea51fbc2e7b7b44c70ee7f399e4fb57e2abfb1a7 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

// page it renders see the route's root params.
const prepareActionRoute = async (routeMatch: AppRscRouteMatch<TRoute> | null) => {
if (!routeMatch) return;
await loadRouteModule(routeMatch.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 now hydrates the source page, layouts, boundaries, and slots before handleServerActionRequest gets a chance to forward the action. In Next.js 16.4.6, loadComponents loads the generated app-page entry, but the loader-tree user modules remain lazy; handleAction selects and forwards to the owner before component-tree rendering invokes those getters. Consequently, a valid forwarded action can now trigger source-page module side effects or fail on a source-page import even though Next.js would forward it successfully. Preserve the load span here without eagerly invoking ensureRouteLoaded, and defer actual user-module hydration until forwarding has declined and local action execution/rendering is required.

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 20d8109. A header-based Server Action now only prepares its page before handleServerActionRequest, which sets the route's root params and touches no user modules. Its page load is back in the generated entry, after forwardServerActionIfNeeded declines, and is now traced (__traceRouteModuleLoad). A forwarded action therefore never runs the source page's modules, and a local one still gets the find/load pair. Builds without Server Actions have nothing to forward, so they keep loading and preparing before the not-found answer. Progressive actions are never forwarded, so their path is unchanged. Covered by "prepares a Server Action's route module, leaving its load to the action handler" in tests/app-rsc-handler.test.ts, plus an entry-templates assertion that the traced load comes after the forward check.

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.

Correction to my reply above: progressive actions are forwarded too (forwardAction in the generated handleProgressiveActionRequest), so the same fix applies to them in 0c2cfeb. With a progressive-action handler present, they now only prepare before handling. Their page loads, traced, in the render that follows a form-state result, through the same per-route load guard. An action answered with its own response (including a forwarded one) emits only RouteModule.prepare. That narrows the earlier progressive-action finding: an early response no longer gets the find/load pair, because loading the page there would run user modules Next never touches for a forwarded action. Covered by "prepares a progressive Server Action's route module once when it answers / returns form state".

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review: 1 finding.

Posted 1 actionable inline comment against exact head ea51fbc2. No branch modifications.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 20d8109f1ce724350024bb1a31d406a7a7ab43e8 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 0c2cfebdf501d36bcf44796c8848937d4f7913cf without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

): Promise<Response | ProgressiveActionFormStateResult | null> => {
if (!filesystemRouteEligible || !isProgressiveActionRequest) return null;
if (routeMatch && isAppRouteHandlerRoute(routeMatch.route)) return null;
await loadAndPrepareActionRoute(routeMatch);

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 eagerly hydrates the source page before a progressive action can be forwarded. The generated handleProgressiveActionRequest passes forwardAction into handleProgressiveServerActionRequest (app-rsc-entry.ts:1916), and that helper forwards direct/decoded action IDs before local execution (app-server-action-execution.ts:1315-1317, 1357-1364). Because this call runs first, a valid forwarded multipart action can trigger source-page/layout side effects or fail on an unrelated source import, the same regression the latest commit fixed for header-based actions. Prepare the route here, but move the traced load into the progressive action handler after both forwarding checks decline (and before local execution/rendering), with a forwarded-progressive-action test.

@ask-bonk

ask-bonk Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review: 1 finding.

Posted 1 actionable inline comment against exact head 20d8109f. No branch modifications.

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant