Unverified Commit cc02d668 authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Avoid loading standalone React by separating render validation (#100467)

## Summary

App Router server traces currently include the installed React package
through shared framework modules. This separates render validation from
dynamic tracking so server bootstrap imports cannot reach the validation
code's React lookup. Validation keeps its direct `require('react')`
inside renderer bundles, where bundler aliases select the appropriate
React instance. The fetch patch marker also moves to a standalone module
so reading it does not load the fetch implementation.

The adapter minimal-server trace drops the installed React files and six
validation-only framework files.

This is an independent alternative to using the renderer React registry
in #100466. These solutions are for comparison; only one should land.

## Performance

Compared `bfe0ccd57f` against its immediate parent, `72895219`, in a
small production `next start` benchmark on October 20, 2026. Both
revisions used release builds, Turbopack-built applications, Node
24.21.0, and the same dependencies on an Apple M5 Pro. Cache Components
and Partial Prefetching remained enabled.

| Measurement | Base → branch | Change |
| --- | --- | --- |
| JavaScript files loaded through the first API/static response | 473 →
463 | 10 fewer files |
| JavaScript files loaded through the first dynamic response | 476 → 466
| 10 fewer files |
| Loaded file-backed JavaScript source | About 214 KiB less | About 4.8%
reduction |
| Median process start → complete API response | 171.36 → 168.79 ms |
1.50% faster |
| Median process start → complete static response | 168.60 → 167.33 ms |
0.75% faster |
| Median process start → complete dynamic response | 412.08 → 410.69 ms
| 0.34% faster |

Startup measurements used 30 paired fresh-process trials per route,
alternating revision order, with TCP-only readiness and exactly one HTTP
request. The branch completed sooner in 29/30 API pairs; the dynamic
startup result was inconclusive. Separate instrumented captures
reproduced the same loaded-file sets twice; source sizes describe files
loaded by the server, not browser downloads or allocated memory.

Warm throughput was essentially unchanged across five paired trials per
route: API −0.53%, static −0.11%, dynamic 0%. Each trial used 3 seconds
of warmup, 10 seconds of measurement, and 50 keep-alive connections. The
dynamic fixture includes a 200 ms wait, which limits its sensitivity to
rendering overhead. All load trials completed without errors, timeouts,
or non-2xx responses, and both revisions passed API, static response,
dynamic freshness, and streaming behavior checks.

These local measurements used warm filesystem caches and shared-machine
load generation. They show reduced eager dependency loading and a modest
API startup benefit; they do not establish serverless cold-start gains
or a material warm-throughput improvement.

## Verification

- `pnpm test-start-turbo
test/production/next-server-nft/next-server-nft.test.ts` — 6 tests and 5
snapshots passed.
- `pnpm test-start-webpack test/e2e/app-dir/app/standalone.test.ts` — 2
tests passed, including Edge runtime bundling.

- Existing Cache Components error coverage for RSC (Dynamic Root) and
SSR (`useSearchParams`) passed with both Turbopack and webpack: 2 tests
and 2 snapshots per bundler.
- `pnpm test-dev-turbo
test/e2e/app-dir/cache-components-errors/{client,sync-dynamic}.test.ts
-t 'useSearchParams in Client Components|Dynamic Root'`
- `pnpm test-dev-webpack
test/e2e/app-dir/cache-components-errors/{client,sync-dynamic}.test.ts
-t 'useSearchParams in Client Components|Dynamic Root'`

<!-- NEXT_JS_LLM -->
parent f196a3a5
......@@ -180,12 +180,14 @@ import {
formatDynamicAPIAccesses,
isPrerenderInterruptedError,
createDynamicTrackingState,
consumeDynamicAccess,
type DynamicAccess,
} from './dynamic-rendering'
import {
createDynamicValidationState,
trackAllowedDynamicAccess,
throwIfDisallowedDynamic,
PreludeState,
consumeDynamicAccess,
type DynamicAccess,
logDisallowedDynamicError,
trackDynamicHoleInStaticShell,
getStaticShellDisallowedDynamicReasons,
......@@ -200,7 +202,7 @@ import {
throwIfDisallowedDynamicInStaticRoute,
getDisallowedReasonsInStaticRoute,
type InstantValidationHoleKind,
} from './dynamic-rendering'
} from './dynamic-rendering-validation'
import { logBuildDebugHint } from './blocking-route-messages'
import { ClientComponentLoadTracker } from '../client-component-renderer-logger'
import { isNodeNextResponse } from '../base-http/helpers'
......
export const NEXT_PATCH_SYMBOL = Symbol.for('next-patch')
......@@ -20,6 +20,7 @@ import { markCurrentScopeAsDynamic } from '../app-render/dynamic-rendering'
import { makeDynamicHangingPromise } from '../dynamic-rendering-utils'
import type { FetchMetric } from '../base-http'
import { createDedupeFetch } from './dedupe-fetch'
import { NEXT_PATCH_SYMBOL } from './patch-fetch-symbol'
import {
getCacheSignal,
type RevalidateStore,
......@@ -87,8 +88,6 @@ type PatchedFetcher = Fetcher & {
readonly _nextOriginalFetch: Fetcher
}
export const NEXT_PATCH_SYMBOL = Symbol.for('next-patch')
function isFetchPatched() {
return (globalThis as Record<symbol, unknown>)[NEXT_PATCH_SYMBOL] === true
}
......
......@@ -53,7 +53,7 @@ import {
type AppIsrManifestMessage,
} from '../dev/hot-reloader-types'
import { normalizedAssetPrefix } from '../../shared/lib/normalized-asset-prefix'
import { NEXT_PATCH_SYMBOL } from './patch-fetch'
import { NEXT_PATCH_SYMBOL } from './patch-fetch-symbol'
import type { ServerInitResult } from './render-server'
import { filterInternalHeaders } from './server-ipc/utils'
import { blockCrossSiteDEV } from './router-utils/block-cross-site-dev'
......
......@@ -624,7 +624,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/compiled/ws/index.js",
"/node_modules/next/dist/lib/client-and-server-references.js",
"/node_modules/next/dist/lib/constants.js",
"/node_modules/next/dist/lib/framework/boundary-constants.js",
"/node_modules/next/dist/lib/interop-default.js",
"/node_modules/next/dist/lib/is-error.js",
"/node_modules/next/dist/lib/picocolors.js",
......@@ -635,15 +634,12 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/server/app-render/after-task-async-storage-instance.js",
"/node_modules/next/dist/server/app-render/after-task-async-storage.external.js",
"/node_modules/next/dist/server/app-render/async-local-storage.js",
"/node_modules/next/dist/server/app-render/blocking-route-messages.js",
"/node_modules/next/dist/server/app-render/cache-signal.js",
"/node_modules/next/dist/server/app-render/console-async-storage-instance.js",
"/node_modules/next/dist/server/app-render/console-async-storage.external.js",
"/node_modules/next/dist/server/app-render/dynamic-access-async-storage-instance.js",
"/node_modules/next/dist/server/app-render/dynamic-access-async-storage.external.js",
"/node_modules/next/dist/server/app-render/dynamic-rendering.js",
"/node_modules/next/dist/server/app-render/instant-validation/boundary-constants.js",
"/node_modules/next/dist/server/app-render/instant-validation/boundary-tracking.js",
"/node_modules/next/dist/server/app-render/module-loading/track-module-loading.external.js",
"/node_modules/next/dist/server/app-render/module-loading/track-module-loading.instance.js",
"/node_modules/next/dist/server/app-render/segment-config/ensure-static.js",
......@@ -701,11 +697,9 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/server/runtime-reacts.external.js",
"/node_modules/next/dist/shared/lib/deep-freeze.js",
"/node_modules/next/dist/shared/lib/i18n/normalize-locale-path.js",
"/node_modules/next/dist/shared/lib/instant-messages.js",
"/node_modules/next/dist/shared/lib/invariant-error.js",
"/node_modules/next/dist/shared/lib/is-plain-object.js",
"/node_modules/next/dist/shared/lib/is-thenable.js",
"/node_modules/next/dist/shared/lib/lazy-dynamic/react-browser-bailout.js",
"/node_modules/next/dist/shared/lib/no-fallback-error.external.js",
"/node_modules/next/dist/shared/lib/page-path/ensure-leading-slash.js",
"/node_modules/next/dist/shared/lib/page-path/normalize-page-path.js",
......@@ -719,9 +713,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/shared/lib/segment.js",
"/node_modules/next/dist/shared/lib/server-reference-info.js",
"/node_modules/next/dist/shared/lib/utils.js",
"/node_modules/react/cjs/react.development.js",
"/node_modules/react/cjs/react.production.js",
"/node_modules/react/index.js",
]
`)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment