Unverified Commit ec28a4fd authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove `experimental.useNodeStreams` flag as it's enabled (#93938)

### What?

Remove `experimental.useNodeStreams` from the public config surface and
make Node streams always-on for Node.js App Router rendering.

The smaller default-on change and dedicated CI cleanup landed in #94311.
The standalone compatibility update landed separately in #94347.

### Why?

Node streams are now the default Node.js runtime rendering path, so the
opt-in config and runtime selection plumbing are stale. Edge bundles
continue to use the web-stream path because Node streams are unavailable
there.

### How?

- Define `__NEXT_USE_NODE_STREAMS` as true for Node.js app runtime
bundles and false for edge user bundles.
- Remove config, schema, runtime, export, and server plumbing for
`experimental.useNodeStreams`.
- Delete the obsolete env-precedence fixture.
- Clean benchmark docs and scripts that still set or compare
`experimental.useNodeStreams`.

### Verification

- `pnpm --filter=next types`
- `pnpm build-all`

<!-- NEXT_JS_LLM_PR -->
parent 5e144103
...@@ -30,17 +30,6 @@ pnpm bench:render-pipeline \ ...@@ -30,17 +30,6 @@ pnpm bench:render-pipeline \
--artifact-dir=bench/render-pipeline/artifacts/<run> --artifact-dir=bench/render-pipeline/artifacts/<run>
``` ```
Web vs Node comparison:
```bash
pnpm bench:render-pipeline \
--scenario=e2e \
--stream-mode=both \
--build=true \
--json-out=bench/render-pipeline/artifacts/<run>/results.json \
--artifact-dir=bench/render-pipeline/artifacts/<run>
```
## 3. Minimal-server benchmark (isolated render path) ## 3. Minimal-server benchmark (isolated render path)
Use `--scenario=minimal-server` to bypass the router-server layer and measure the render pipeline in isolation. This starts a bare `NextServer` with `minimalMode: true` via `bench/next-minimal-server` — no `router-server`, no middleware, no asset serving. Prefer this when profiling changes to `app-render.tsx`, streaming internals, or Flight serialization where router overhead would add noise. Use `--scenario=minimal-server` to bypass the router-server layer and measure the render pipeline in isolation. This starts a bare `NextServer` with `minimalMode: true` via `bench/next-minimal-server` — no `router-server`, no middleware, no asset serving. Prefer this when profiling changes to `app-render.tsx`, streaming internals, or Flight serialization where router overhead would add noise.
......
#!/bin/bash #!/bin/bash
# Benchmark script for comparing web streams vs node streams performance. # Benchmark script for Node streams render pipeline performance.
# Uses the minimal server (bench/next-minimal-server) for lowest overhead. # Uses the minimal server (bench/next-minimal-server) for lowest overhead.
# Warms up with 50 requests, then runs two phases: # Warms up with 50 requests, then runs two phases:
# Phase 1: 10s at concurrency=1 (single-client latency) # Phase 1: 10s at concurrency=1 (single-client latency)
...@@ -104,34 +104,19 @@ run_benchmark() { ...@@ -104,34 +104,19 @@ run_benchmark() {
stop_server stop_server
} }
echo "Benchmark: web streams vs node streams" echo "Benchmark: node streams"
echo "=======================================" echo "======================="
echo "Duration: ${DURATION}s per phase | Warmup: ${WARMUP_REQS} reqs" echo "Duration: ${DURATION}s per phase | Warmup: ${WARMUP_REQS} reqs"
echo "Server: minimal-server (minimalMode: true)" echo "Server: minimal-server (minimalMode: true)"
# --- Web Streams (default) ---
cat > next.config.js <<'CONF' cat > next.config.js <<'CONF'
module.exports = {} module.exports = {}
CONF CONF
echo "" echo ""
echo "Building (web streams)..." echo "Building..."
node "$NEXT_BIN" build &>/dev/null node "$NEXT_BIN" build &>/dev/null
run_benchmark "Web Streams (default)" run_benchmark "Node Streams (default)"
# --- Node Streams ---
cat > next.config.js <<'CONF'
module.exports = {
experimental: {
useNodeStreams: true,
},
}
CONF
echo ""
echo "Building (node streams)..."
node "$NEXT_BIN" build &>/dev/null
run_benchmark "Node Streams (useNodeStreams: true)"
# Restore config # Restore config
cat > next.config.js <<'CONF' cat > next.config.js <<'CONF'
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
This benchmark targets the full App Router render path (`renderToHTMLOrFlight`) via real HTTP requests through `bench/next-minimal-server`. This benchmark targets the full App Router render path (`renderToHTMLOrFlight`) via real HTTP requests through `bench/next-minimal-server`.
It supports: It supports:
- `web` vs `node` streams mode comparison - Node streams mode benchmarking
- route-based stress suites for streaming SSR - route-based stress suites for streaming SSR
- CPU/heap profiling for the server process - CPU/heap profiling for the server process
- Node trace events and Next internal trace artifact capture - Node trace events and Next internal trace artifact capture
...@@ -17,7 +17,7 @@ Runs `next build` + `next start`, exercising the full production stack: ...@@ -17,7 +17,7 @@ Runs `next build` + `next start`, exercising the full production stack:
Use this for production-realistic throughput numbers. Use this for production-realistic throughput numbers.
```bash ```bash
pnpm bench:render-pipeline --scenario=e2e --stream-mode=both pnpm bench:render-pipeline --scenario=e2e --stream-mode=node
``` ```
### `--scenario=minimal-server` ### `--scenario=minimal-server`
...@@ -28,7 +28,7 @@ render pipeline from routing/middleware overhead — useful when profiling chang ...@@ -28,7 +28,7 @@ render pipeline from routing/middleware overhead — useful when profiling chang
to `app-render.tsx`, streaming, or Flight serialization. to `app-render.tsx`, streaming, or Flight serialization.
```bash ```bash
pnpm bench:render-pipeline --scenario=minimal-server --stream-mode=both pnpm bench:render-pipeline --scenario=minimal-server --stream-mode=node
``` ```
When comparing both scenarios, the delta reveals how much overhead the When comparing both scenarios, the delta reveals how much overhead the
...@@ -39,7 +39,7 @@ router-server layer adds on top of the raw render path. ...@@ -39,7 +39,7 @@ router-server layer adds on top of the raw render path.
Run end-to-end benchmark (default stress routes): Run end-to-end benchmark (default stress routes):
```bash ```bash
pnpm bench:render-pipeline --scenario=e2e --stream-mode=both pnpm bench:render-pipeline --scenario=e2e --stream-mode=node
``` ```
CPU profiling is off by default. Enable with `--capture-cpu=true` for profiling runs. CPU profiling is off by default. Enable with `--capture-cpu=true` for profiling runs.
...@@ -50,13 +50,10 @@ Skip rebuild for faster iteration (after you already built once): ...@@ -50,13 +50,10 @@ Skip rebuild for faster iteration (after you already built once):
pnpm bench:render-pipeline --scenario=e2e --stream-mode=node --build=false pnpm bench:render-pipeline --scenario=e2e --stream-mode=node --build=false
``` ```
When `--stream-mode=both`, the runner forces `--build=true` so web/node
comparisons do not accidentally reuse stale build output.
Output JSON report: Output JSON report:
```bash ```bash
pnpm bench:render-pipeline --scenario=e2e --stream-mode=both --json-out=/tmp/render-pipeline.json pnpm bench:render-pipeline --scenario=e2e --stream-mode=node --json-out=/tmp/render-pipeline.json
``` ```
## Profiling and traces ## Profiling and traces
...@@ -66,7 +63,7 @@ Capture CPU profiles + Node trace events + Next trace logs: ...@@ -66,7 +63,7 @@ Capture CPU profiles + Node trace events + Next trace logs:
```bash ```bash
pnpm bench:render-pipeline \ pnpm bench:render-pipeline \
--scenario=e2e \ --scenario=e2e \
--stream-mode=both \ --stream-mode=node \
--capture-cpu=true \ --capture-cpu=true \
--capture-trace=true \ --capture-trace=true \
--capture-next-trace=true --capture-next-trace=true
...@@ -78,7 +75,7 @@ Artifacts are written to: ...@@ -78,7 +75,7 @@ Artifacts are written to:
bench/render-pipeline/artifacts/<timestamp>/ bench/render-pipeline/artifacts/<timestamp>/
``` ```
Per mode (`web` and `node`) this includes: Per run this includes:
- `<mode>.cpuprofile` (if `--capture-cpu=true`) - `<mode>.cpuprofile` (if `--capture-cpu=true`)
- `<mode>.heapprofile` (if `--capture-heap=true`) - `<mode>.heapprofile` (if `--capture-heap=true`)
- `<mode>-trace-*.json` (if `--capture-trace=true`) - `<mode>-trace-*.json` (if `--capture-trace=true`)
...@@ -118,8 +115,8 @@ pnpm bench:render-pipeline --scenario=e2e --routes=/,/streaming/heavy ...@@ -118,8 +115,8 @@ pnpm bench:render-pipeline --scenario=e2e --routes=/,/streaming/heavy
The benchmark uses a **closed-loop** load generator: each concurrent worker The benchmark uses a **closed-loop** load generator: each concurrent worker
issues the next request only after the current one completes. This means: issues the next request only after the current one completes. This means:
- **Throughput numbers are reliable for relative comparison** (A/B between stream - **Throughput numbers are reliable for relative comparison** (before/after a
modes, before/after a code change). Both sides experience the same measurement code change). Both sides experience the same measurement
model, so deltas are valid. model, so deltas are valid.
- **Latency percentiles (p95, max) under load are optimistic.** Slow requests - **Latency percentiles (p95, max) under load are optimistic.** Slow requests
reduce back-pressure instead of queuing, masking tail latency. Do not compare reduce back-pressure instead of queuing, masking tail latency. Do not compare
......
...@@ -13,7 +13,7 @@ const DEFAULT_ARTIFACTS_ROOT = resolve( ...@@ -13,7 +13,7 @@ const DEFAULT_ARTIFACTS_ROOT = resolve(
) )
type FullRoutePhaseResult = { type FullRoutePhaseResult = {
mode: 'web' | 'node' mode: 'node'
route: string route: string
phase: 'single-client' | 'under-load' phase: 'single-client' | 'under-load'
requests: number requests: number
...@@ -30,7 +30,7 @@ type FullRoutePhaseResult = { ...@@ -30,7 +30,7 @@ type FullRoutePhaseResult = {
type BenchmarkJson = { type BenchmarkJson = {
fullResults?: Array<{ fullResults?: Array<{
mode: 'web' | 'node' mode: 'node'
routeResults: FullRoutePhaseResult[] routeResults: FullRoutePhaseResult[]
}> }>
} }
...@@ -275,7 +275,7 @@ async function analyzeProfile( ...@@ -275,7 +275,7 @@ async function analyzeProfile(
} }
function printProfileAnalysis( function printProfileAnalysis(
mode: 'web' | 'node', mode: 'node',
analysis: ProfileAnalysis, analysis: ProfileAnalysis,
top: number top: number
) { ) {
...@@ -315,47 +315,6 @@ function printProfileAnalysis( ...@@ -315,47 +315,6 @@ function printProfileAnalysis(
} }
} }
function printComparison(results: BenchmarkJson) {
const fullResults = results.fullResults
if (!fullResults || fullResults.length < 2) return
const web = fullResults.find((entry) => entry.mode === 'web')
const node = fullResults.find((entry) => entry.mode === 'node')
if (!web || !node) return
const webByKey = new Map(
web.routeResults.map((item) => [`${item.route}|${item.phase}`, item])
)
console.log('\n[comparison node vs web]')
console.log(
' route'.padEnd(20) +
'phase'.padEnd(16) +
'RPS delta'.padEnd(14) +
'P95 delta'
)
for (const nodeEntry of node.routeResults) {
const key = `${nodeEntry.route}|${nodeEntry.phase}`
const webEntry = webByKey.get(key)
if (!webEntry) continue
const rpsDelta =
((nodeEntry.throughputRps - webEntry.throughputRps) /
webEntry.throughputRps) *
100
const p95Delta =
((webEntry.latency.p95 - nodeEntry.latency.p95) / webEntry.latency.p95) *
100
const line =
` ${nodeEntry.route}`.padEnd(20) +
`${nodeEntry.phase}`.padEnd(16) +
`${rpsDelta >= 0 ? '+' : ''}${rpsDelta.toFixed(2)}%`.padEnd(14) +
`${p95Delta >= 0 ? '+' : ''}${p95Delta.toFixed(2)}%`
console.log(line)
}
}
async function main() { async function main() {
const { artifactDirArg, top } = parseArgs() const { artifactDirArg, top } = parseArgs()
const runDir = await resolveArtifactRunDir(artifactDirArg) const runDir = await resolveArtifactRunDir(artifactDirArg)
...@@ -366,29 +325,26 @@ async function main() { ...@@ -366,29 +325,26 @@ async function main() {
const resultsPath = resolve(runDir, 'results.json') const resultsPath = resolve(runDir, 'results.json')
const resultsRaw = await readFile(resultsPath, 'utf8') const resultsRaw = await readFile(resultsPath, 'utf8')
const resultsJson = JSON.parse(resultsRaw) as BenchmarkJson const resultsJson = JSON.parse(resultsRaw) as BenchmarkJson
printComparison(resultsJson) if (!resultsJson.fullResults || resultsJson.fullResults.length === 0) {
console.log('\nNo benchmark results found in results.json.')
}
const webProfile = resolve(runDir, 'web/web.cpuprofile')
const nodeProfile = resolve(runDir, 'node/node.cpuprofile') const nodeProfile = resolve(runDir, 'node/node.cpuprofile')
const [webAnalysis, nodeAnalysis] = await Promise.all([ const nodeAnalysis = await analyzeProfile(nodeProfile, top)
analyzeProfile(webProfile, top),
analyzeProfile(nodeProfile, top),
])
if (!webAnalysis && !nodeAnalysis) { if (!nodeAnalysis) {
console.log('\nNo CPU profiles found in this artifact run.') console.log('\nNo CPU profiles found in this artifact run.')
console.log( console.log(
'This analyzer reads only <mode>/<mode>.cpuprofile artifacts (not trace-event JSON or next-runtime-trace.log).' 'This analyzer reads only <mode>/<mode>.cpuprofile artifacts (not trace-event JSON or next-runtime-trace.log).'
) )
console.log( console.log(
'Run benchmark with --capture-cpu=true, e.g. pnpm bench:render-pipeline --scenario=full --stream-mode=node --capture-cpu=true' 'Run benchmark with --capture-cpu=true, e.g. pnpm bench:render-pipeline --scenario=e2e --stream-mode=node --capture-cpu=true'
) )
return return
} }
if (webAnalysis) printProfileAnalysis('web', webAnalysis, top) printProfileAnalysis('node', nodeAnalysis, top)
if (nodeAnalysis) printProfileAnalysis('node', nodeAnalysis, top)
console.log('\nDone.') console.log('\nDone.')
} }
......
...@@ -16,7 +16,7 @@ const MINIMAL_SERVER = resolve( ...@@ -16,7 +16,7 @@ const MINIMAL_SERVER = resolve(
) )
type Scenario = 'minimal-server' | 'e2e' type Scenario = 'minimal-server' | 'e2e'
type StreamMode = 'web' | 'node' | 'both' type StreamMode = 'node'
type CliOptions = { type CliOptions = {
scenario: Scenario scenario: Scenario
...@@ -54,7 +54,7 @@ type BenchStats = { ...@@ -54,7 +54,7 @@ type BenchStats = {
} }
type FullRoutePhaseResult = { type FullRoutePhaseResult = {
mode: 'web' | 'node' mode: StreamMode
route: string route: string
phase: 'single-client' | 'under-load' phase: 'single-client' | 'under-load'
requests: number requests: number
...@@ -65,7 +65,7 @@ type FullRoutePhaseResult = { ...@@ -65,7 +65,7 @@ type FullRoutePhaseResult = {
} }
type FullRunResult = { type FullRunResult = {
mode: 'web' | 'node' mode: StreamMode
routeResults: FullRoutePhaseResult[] routeResults: FullRoutePhaseResult[]
} }
...@@ -130,9 +130,8 @@ Options: ...@@ -130,9 +130,8 @@ Options:
Benchmark options: Benchmark options:
--app-dir=<path> (default: bench/basic-app) --app-dir=<path> (default: bench/basic-app)
--routes=/,/streaming/light,... (default: built-in stress suite) --routes=/,/streaming/light,... (default: built-in stress suite)
--stream-mode=web|node|both (default: both) --stream-mode=node (default: node)
--build=true|false (default: true) --build=true|false (default: true)
When stream-mode=both, build is forced to true.
--warmup-requests=<number> (default: 50) --warmup-requests=<number> (default: 50)
Batch size per warmup iteration. Batch size per warmup iteration.
--warmup-until-stable=true|false (default: true) --warmup-until-stable=true|false (default: true)
...@@ -178,15 +177,9 @@ function parseCli(): CliOptions { ...@@ -178,15 +177,9 @@ function parseCli(): CliOptions {
) )
} }
const streamModeRaw = args.get('stream-mode') ?? 'both' const streamModeRaw = args.get('stream-mode') ?? 'node'
if ( if (streamModeRaw !== 'node') {
streamModeRaw !== 'web' && throw new Error(`Invalid --stream-mode value: ${streamModeRaw}. Use node`)
streamModeRaw !== 'node' &&
streamModeRaw !== 'both'
) {
throw new Error(
`Invalid --stream-mode value: ${streamModeRaw}. Use web|node|both`
)
} }
const timestamp = new Date().toISOString().replace(/[:.]/g, '-') const timestamp = new Date().toISOString().replace(/[:.]/g, '-')
...@@ -197,13 +190,6 @@ function parseCli(): CliOptions { ...@@ -197,13 +190,6 @@ function parseCli(): CliOptions {
const routes = parseRoutes(args.get('routes')) const routes = parseRoutes(args.get('routes'))
const build = parseBoolean(args.get('build') ?? 'true') const build = parseBoolean(args.get('build') ?? 'true')
const shouldForceBuild = streamModeRaw === 'both' && !build
if (shouldForceBuild) {
console.warn(
'[bench/render-pipeline] forcing --build=true for stream-mode=both to avoid comparing stale build output.'
)
}
return { return {
scenario: scenarioRaw, scenario: scenarioRaw,
...@@ -212,7 +198,7 @@ function parseCli(): CliOptions { ...@@ -212,7 +198,7 @@ function parseCli(): CliOptions {
appDir: resolve(REPO_ROOT, args.get('app-dir') ?? 'bench/basic-app'), appDir: resolve(REPO_ROOT, args.get('app-dir') ?? 'bench/basic-app'),
routes, routes,
streamMode: streamModeRaw, streamMode: streamModeRaw,
build: build || shouldForceBuild, build,
warmupRequests: parseNumberArg(args, 'warmup-requests', 50), warmupRequests: parseNumberArg(args, 'warmup-requests', 50),
warmupUntilStable: parseBoolean(args.get('warmup-until-stable') ?? 'true'), warmupUntilStable: parseBoolean(args.get('warmup-until-stable') ?? 'true'),
serialRequests: parseNumberArg(args, 'serial-requests', 120), serialRequests: parseNumberArg(args, 'serial-requests', 120),
...@@ -275,15 +261,8 @@ async function ensureNextBuilt() { ...@@ -275,15 +261,8 @@ async function ensureNextBuilt() {
} }
} }
function configForMode(mode: 'web' | 'node'): string { function defaultConfig(): string {
if (mode === 'web') { return 'module.exports = {}\n'
return 'module.exports = {}\n'
}
return `module.exports = {
experimental: {
useNodeStreams: true,
},
}\n`
} }
async function waitForServerReady( async function waitForServerReady(
...@@ -404,50 +383,6 @@ function printFullResults(label: string, results: FullRunResult[]) { ...@@ -404,50 +383,6 @@ function printFullResults(label: string, results: FullRunResult[]) {
} }
} }
} }
if (results.length === 2) {
const web = results.find((result) => result.mode === 'web')
const node = results.find((result) => result.mode === 'node')
if (web && node) {
console.log('\nComparison (node vs web)')
const joinKeys = new Set(
web.routeResults.map((entry) => `${entry.route}|${entry.phase}`)
)
for (const key of joinKeys) {
const [route, phase] = key.split('|') as [
string,
'single-client' | 'under-load',
]
const webEntry = web.routeResults.find(
(entry) => entry.route === route && entry.phase === phase
)
const nodeEntry = node.routeResults.find(
(entry) => entry.route === route && entry.phase === phase
)
if (!webEntry || !nodeEntry) continue
const throughputDelta =
((nodeEntry.throughputRps - webEntry.throughputRps) /
webEntry.throughputRps) *
100
const p95Delta =
((webEntry.latency.p95 - nodeEntry.latency.p95) /
webEntry.latency.p95) *
100
console.log(` ${route} (${phase})`)
console.log(
` throughput delta: ${throughputDelta >= 0 ? '+' : ''}${throughputDelta.toFixed(2)}%`
)
console.log(
` p95 latency delta: ${p95Delta >= 0 ? '+' : ''}${p95Delta.toFixed(2)}% (positive is better)`
)
}
}
}
} }
function buildNodeArgs( function buildNodeArgs(
...@@ -540,7 +475,7 @@ async function runWarmup( ...@@ -540,7 +475,7 @@ async function runWarmup(
async function runRoutePhases( async function runRoutePhases(
options: CliOptions, options: CliOptions,
mode: 'web' | 'node', mode: StreamMode,
label: string label: string
): Promise<FullRoutePhaseResult[]> { ): Promise<FullRoutePhaseResult[]> {
const routeResults: FullRoutePhaseResult[] = [] const routeResults: FullRoutePhaseResult[] = []
...@@ -614,7 +549,7 @@ async function runRoutePhases( ...@@ -614,7 +549,7 @@ async function runRoutePhases(
async function runMinimalServerSession( async function runMinimalServerSession(
options: CliOptions, options: CliOptions,
mode: 'web' | 'node', mode: StreamMode,
modeArtifactDir: string, modeArtifactDir: string,
routeSubset: CliOptions routeSubset: CliOptions
): Promise<FullRoutePhaseResult[]> { ): Promise<FullRoutePhaseResult[]> {
...@@ -658,7 +593,7 @@ async function runMinimalServerSession( ...@@ -658,7 +593,7 @@ async function runMinimalServerSession(
async function runMinimalServerModeBenchmark( async function runMinimalServerModeBenchmark(
options: CliOptions, options: CliOptions,
mode: 'web' | 'node' mode: StreamMode
): Promise<FullRunResult> { ): Promise<FullRunResult> {
const nextConfigPath = resolve(options.appDir, 'next.config.js') const nextConfigPath = resolve(options.appDir, 'next.config.js')
const originalConfig = await readFile(nextConfigPath, 'utf8') const originalConfig = await readFile(nextConfigPath, 'utf8')
...@@ -667,7 +602,7 @@ async function runMinimalServerModeBenchmark( ...@@ -667,7 +602,7 @@ async function runMinimalServerModeBenchmark(
await mkdir(modeArtifactDir, { recursive: true }) await mkdir(modeArtifactDir, { recursive: true })
try { try {
await writeFile(nextConfigPath, configForMode(mode)) await writeFile(nextConfigPath, defaultConfig())
if (options.build) { if (options.build) {
console.log(`\n[minimal-server/${mode}] building app fixture...`) console.log(`\n[minimal-server/${mode}] building app fixture...`)
...@@ -723,17 +658,8 @@ async function runMinimalServerBenchmarks( ...@@ -723,17 +658,8 @@ async function runMinimalServerBenchmarks(
await ensureNextBuilt() await ensureNextBuilt()
await mkdir(options.artifactDir, { recursive: true }) await mkdir(options.artifactDir, { recursive: true })
const modes: Array<'web' | 'node'> =
options.streamMode === 'both' ? ['web', 'node'] : [options.streamMode]
const results: FullRunResult[] = [] const results: FullRunResult[] = []
for (let i = 0; i < modes.length; i++) { results.push(await runMinimalServerModeBenchmark(options, options.streamMode))
if (i > 0) {
console.log('[minimal-server] waiting 2s for port cleanup...')
await sleep(2000)
}
results.push(await runMinimalServerModeBenchmark(options, modes[i]))
}
return results return results
} }
...@@ -743,7 +669,7 @@ async function runMinimalServerBenchmarks( ...@@ -743,7 +669,7 @@ async function runMinimalServerBenchmarks(
async function runE2EServerSession( async function runE2EServerSession(
options: CliOptions, options: CliOptions,
mode: 'web' | 'node', mode: StreamMode,
modeArtifactDir: string, modeArtifactDir: string,
routeSubset: CliOptions routeSubset: CliOptions
): Promise<FullRoutePhaseResult[]> { ): Promise<FullRoutePhaseResult[]> {
...@@ -786,7 +712,7 @@ async function runE2EServerSession( ...@@ -786,7 +712,7 @@ async function runE2EServerSession(
async function runE2EModeBenchmark( async function runE2EModeBenchmark(
options: CliOptions, options: CliOptions,
mode: 'web' | 'node' mode: StreamMode
): Promise<FullRunResult> { ): Promise<FullRunResult> {
const nextConfigPath = resolve(options.appDir, 'next.config.js') const nextConfigPath = resolve(options.appDir, 'next.config.js')
const originalConfig = await readFile(nextConfigPath, 'utf8') const originalConfig = await readFile(nextConfigPath, 'utf8')
...@@ -795,7 +721,7 @@ async function runE2EModeBenchmark( ...@@ -795,7 +721,7 @@ async function runE2EModeBenchmark(
await mkdir(modeArtifactDir, { recursive: true }) await mkdir(modeArtifactDir, { recursive: true })
try { try {
await writeFile(nextConfigPath, configForMode(mode)) await writeFile(nextConfigPath, defaultConfig())
if (options.build) { if (options.build) {
console.log(`\n[e2e/${mode}] building app fixture...`) console.log(`\n[e2e/${mode}] building app fixture...`)
...@@ -844,17 +770,8 @@ async function runE2EBenchmarks(options: CliOptions): Promise<FullRunResult[]> { ...@@ -844,17 +770,8 @@ async function runE2EBenchmarks(options: CliOptions): Promise<FullRunResult[]> {
await ensureNextBuilt() await ensureNextBuilt()
await mkdir(options.artifactDir, { recursive: true }) await mkdir(options.artifactDir, { recursive: true })
const modes: Array<'web' | 'node'> =
options.streamMode === 'both' ? ['web', 'node'] : [options.streamMode]
const results: FullRunResult[] = [] const results: FullRunResult[] = []
for (let i = 0; i < modes.length; i++) { results.push(await runE2EModeBenchmark(options, options.streamMode))
if (i > 0) {
console.log('[e2e] waiting 2s for port cleanup...')
await sleep(2000)
}
results.push(await runE2EModeBenchmark(options, modes[i]))
}
return results return results
} }
......
...@@ -226,6 +226,9 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => { ...@@ -226,6 +226,9 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => {
'process.env.__NEXT_EXPERIMENTAL_REACT': JSON.stringify( 'process.env.__NEXT_EXPERIMENTAL_REACT': JSON.stringify(
experimental ? true : false experimental ? true : false
), ),
...(bundleType === 'app' || bundleType === 'app-worker'
? { 'process.env.__NEXT_USE_NODE_STREAMS': JSON.stringify(true) }
: {}),
'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'), 'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'),
'process.turbopack': JSON.stringify(turbo), 'process.turbopack': JSON.stringify(turbo),
'process.env.TURBOPACK': JSON.stringify(turbo), 'process.env.TURBOPACK': JSON.stringify(turbo),
......
...@@ -124,7 +124,6 @@ export function getDefineEnv({ ...@@ -124,7 +124,6 @@ export function getDefineEnv({
const isPPREnabled = checkIsAppPPREnabled(config.experimental.ppr) const isPPREnabled = checkIsAppPPREnabled(config.experimental.ppr)
const isCacheComponentsEnabled = !!config.cacheComponents const isCacheComponentsEnabled = !!config.cacheComponents
const isUseCacheEnabled = !!config.experimental.useCache const isUseCacheEnabled = !!config.experimental.useCache
const isUseNodeStreamsEnabled = !!config.experimental.useNodeStreams
const defineEnv: DefineEnv = { const defineEnv: DefineEnv = {
// internal field to identify the plugin config // internal field to identify the plugin config
...@@ -181,9 +180,7 @@ export function getDefineEnv({ ...@@ -181,9 +180,7 @@ export function getDefineEnv({
), ),
'process.env.__NEXT_INSTANT_NAV_TOGGLE': isCacheComponentsEnabled, 'process.env.__NEXT_INSTANT_NAV_TOGGLE': isCacheComponentsEnabled,
'process.env.__NEXT_USE_CACHE': isUseCacheEnabled, 'process.env.__NEXT_USE_CACHE': isUseCacheEnabled,
'process.env.__NEXT_USE_NODE_STREAMS': isEdgeServer 'process.env.__NEXT_USE_NODE_STREAMS': isEdgeServer ? false : true,
? false
: isUseNodeStreamsEnabled,
'process.env.NEXT_SUPPORTS_IMMUTABLE_ASSETS': 'process.env.NEXT_SUPPORTS_IMMUTABLE_ASSETS':
config.experimental.supportsImmutableAssets || false, config.experimental.supportsImmutableAssets || false,
......
...@@ -61,7 +61,6 @@ export interface ExportPageInput { ...@@ -61,7 +61,6 @@ export interface ExportPageInput {
debugOutput?: boolean debugOutput?: boolean
nextConfigOutput?: NextConfigComplete['output'] nextConfigOutput?: NextConfigComplete['output']
enableExperimentalReact?: boolean enableExperimentalReact?: boolean
enableNodeStreams?: boolean
sriEnabled: boolean sriEnabled: boolean
renderResumeDataCache: RenderResumeDataCache | undefined renderResumeDataCache: RenderResumeDataCache | undefined
} }
......
...@@ -82,7 +82,6 @@ async function exportPageImpl( ...@@ -82,7 +82,6 @@ async function exportPageImpl(
disableOptimizedLoading, disableOptimizedLoading,
debugOutput = false, debugOutput = false,
enableExperimentalReact, enableExperimentalReact,
enableNodeStreams,
trailingSlash, trailingSlash,
sriEnabled, sriEnabled,
renderOpts: commonRenderOpts, renderOpts: commonRenderOpts,
...@@ -96,9 +95,6 @@ async function exportPageImpl( ...@@ -96,9 +95,6 @@ async function exportPageImpl(
if (enableExperimentalReact) { if (enableExperimentalReact) {
process.env.__NEXT_EXPERIMENTAL_REACT = 'true' process.env.__NEXT_EXPERIMENTAL_REACT = 'true'
} }
if (enableNodeStreams) {
process.env.__NEXT_USE_NODE_STREAMS = 'true'
}
const { const {
path, path,
...@@ -438,7 +434,6 @@ export async function exportPages( ...@@ -438,7 +434,6 @@ export async function exportPages(
httpAgentOptions: nextConfig.httpAgentOptions, httpAgentOptions: nextConfig.httpAgentOptions,
debugOutput: options.debugOutput, debugOutput: options.debugOutput,
enableExperimentalReact: needsExperimentalReact(nextConfig), enableExperimentalReact: needsExperimentalReact(nextConfig),
enableNodeStreams: !!nextConfig.experimental.useNodeStreams,
sriEnabled: Boolean(nextConfig.experimental.sri?.algorithm), sriEnabled: Boolean(nextConfig.experimental.sri?.algorithm),
buildId: input.buildId, buildId: input.buildId,
deploymentId: input.deploymentId, deploymentId: input.deploymentId,
......
/** /**
* Web stream operations for the rendering pipeline. * Web stream operations for the rendering pipeline.
* Loaded by stream-ops.ts when __NEXT_USE_NODE_STREAMS is false (default). * Loaded by stream-ops.ts when __NEXT_USE_NODE_STREAMS is false, such as edge
* bundles where Node.js streams are unavailable.
* *
* AnyStream = AnyStreamType so the exported type surface matches stream-ops.node.ts, * AnyStream = AnyStreamType so the exported type surface matches stream-ops.node.ts,
* allowing the switcher to assign either module without `as unknown as`. * allowing the switcher to assign either module without `as unknown as`.
......
...@@ -429,7 +429,6 @@ export const experimentalSchema = { ...@@ -429,7 +429,6 @@ export const experimentalSchema = {
authInterrupts: z.boolean().optional(), authInterrupts: z.boolean().optional(),
useCache: z.boolean().optional(), useCache: z.boolean().optional(),
useCacheTimeout: z.number().positive().optional(), useCacheTimeout: z.number().positive().optional(),
useNodeStreams: z.boolean().optional(),
slowModuleDetection: z slowModuleDetection: z
.object({ .object({
buildTimeThresholdMs: z.number().int(), buildTimeThresholdMs: z.number().int(),
......
...@@ -1144,13 +1144,6 @@ export interface ExperimentalConfig { ...@@ -1144,13 +1144,6 @@ export interface ExperimentalConfig {
*/ */
useCache?: boolean useCache?: boolean
/**
* Use Node.js native streams instead of web streams for the App Router
* rendering pipeline on the Node.js runtime. This can improve performance
* by avoiding the overhead of web stream wrappers.
*/
useNodeStreams?: boolean
/** /**
* Enables detection and reporting of slow modules during development builds. * Enables detection and reporting of slow modules during development builds.
* Enabling this may impact build performance to ensure accurate measurements. * Enabling this may impact build performance to ensure accurate measurements.
...@@ -2069,7 +2062,6 @@ export const defaultConfig = Object.freeze({ ...@@ -2069,7 +2062,6 @@ export const defaultConfig = Object.freeze({
gestureTransition: false, gestureTransition: false,
inlineCss: false, inlineCss: false,
useCache: undefined, useCache: undefined,
useNodeStreams: true,
slowModuleDetection: undefined, slowModuleDetection: undefined,
globalNotFound: false, globalNotFound: false,
browserDebugInfoInTerminal: 'warn', browserDebugInfoInTerminal: 'warn',
...@@ -2189,7 +2181,6 @@ export interface NextConfigRuntime { ...@@ -2189,7 +2181,6 @@ export interface NextConfigRuntime {
| 'cachedNavigations' | 'cachedNavigations'
| 'exposeTestingApiInProductionBuild' | 'exposeTestingApiInProductionBuild'
| 'supportsImmutableAssets' | 'supportsImmutableAssets'
| 'useNodeStreams'
| 'instantInsights' | 'instantInsights'
> & { > & {
// Pick on @internal fields generates invalid .d.ts files // Pick on @internal fields generates invalid .d.ts files
...@@ -2259,7 +2250,6 @@ export function getNextConfigRuntime( ...@@ -2259,7 +2250,6 @@ export function getNextConfigRuntime(
cachedNavigations: ex.cachedNavigations, cachedNavigations: ex.cachedNavigations,
exposeTestingApiInProductionBuild: ex.exposeTestingApiInProductionBuild, exposeTestingApiInProductionBuild: ex.exposeTestingApiInProductionBuild,
supportsImmutableAssets: ex.supportsImmutableAssets, supportsImmutableAssets: ex.supportsImmutableAssets,
useNodeStreams: ex.useNodeStreams,
instantInsights: ex.instantInsights, instantInsights: ex.instantInsights,
trustHostHeader: ex.trustHostHeader, trustHostHeader: ex.trustHostHeader,
......
...@@ -1651,28 +1651,9 @@ function finalizeConfig(config: NextConfigComplete): NextConfigComplete { ...@@ -1651,28 +1651,9 @@ function finalizeConfig(config: NextConfigComplete): NextConfigComplete {
validationLevel: validationLevel:
config.experimental.instantInsights?.validationLevel ?? 'warning', config.experimental.instantInsights?.validationLevel ?? 'warning',
} }
syncUseNodeStreamsEnv(config)
return config return config
} }
function syncUseNodeStreamsEnv(config: NextConfig): void {
// This must use resolved config: user configs are inspected before defaults
// are merged, while runtime bundles must select the default implementation.
const useNodeStreams = config.experimental?.useNodeStreams
? 'true'
: undefined
if (useNodeStreams) {
process.env.__NEXT_USE_NODE_STREAMS = useNodeStreams
} else {
delete process.env.__NEXT_USE_NODE_STREAMS
}
// Dev env reloads restore process.env from this snapshot. Preserve the
// resolved runtime selection so a reload cannot mix stream implementations.
updateInitialEnv({ __NEXT_USE_NODE_STREAMS: useNodeStreams })
}
async function applyModifyConfig( async function applyModifyConfig(
config: NextConfigComplete, config: NextConfigComplete,
phase: PHASE_TYPE, phase: PHASE_TYPE,
...@@ -1800,7 +1781,6 @@ export default async function loadConfig( ...@@ -1800,7 +1781,6 @@ export default async function loadConfig(
return cachedResult.rawConfig return cachedResult.rawConfig
} }
syncUseNodeStreamsEnv(cachedResult.config)
return cachedResult.config return cachedResult.config
} else { } else {
// Reset next.config errors before loading config // Reset next.config errors before loading config
...@@ -1828,8 +1808,6 @@ export default async function loadConfig( ...@@ -1828,8 +1808,6 @@ export default async function loadConfig(
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG process.env.__NEXT_PRIVATE_STANDALONE_CONFIG
) )
syncUseNodeStreamsEnv(standaloneConfig)
// Cache the standalone config // Cache the standalone config
configCache.set(cacheKey, { configCache.set(cacheKey, {
config: standaloneConfig, config: standaloneConfig,
...@@ -2273,15 +2251,6 @@ function enforceExperimentalFeatures( ...@@ -2273,15 +2251,6 @@ function enforceExperimentalFeatures(
} }
} }
// Enable node streams via env var (for CI testing).
if (
process.env.__NEXT_USE_NODE_STREAMS === 'true' &&
(config.experimental.useNodeStreams === undefined ||
(isDefaultConfig && !config.experimental.useNodeStreams))
) {
config.experimental.useNodeStreams = true
}
// TODO: Remove this once strictRouteTypes is the default. // TODO: Remove this once strictRouteTypes is the default.
if ( if (
process.env.__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES === 'true' && process.env.__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES === 'true' &&
......
...@@ -222,9 +222,6 @@ export default class NextNodeServer extends BaseServer< ...@@ -222,9 +222,6 @@ export default class NextNodeServer extends BaseServer<
if (this.renderOpts.nextScriptWorkers) { if (this.renderOpts.nextScriptWorkers) {
process.env.__NEXT_SCRIPT_WORKERS = JSON.stringify(true) process.env.__NEXT_SCRIPT_WORKERS = JSON.stringify(true)
} }
if (this.nextConfig.experimental.useNodeStreams) {
process.env.__NEXT_USE_NODE_STREAMS = 'true'
}
if (!this.minimalMode) { if (!this.minimalMode) {
this.imageResponseCache = new ResponseCache(this.minimalMode) this.imageResponseCache = new ResponseCache(this.minimalMode)
......
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
useNodeStreams: false,
},
}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
describe('use-node-streams env precedence', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
env: {
__NEXT_USE_NODE_STREAMS: 'true',
},
})
it('should respect explicit useNodeStreams=false even when env flag is true', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).toBe(0)
expect(cliOutput).toContain('useNodeStreams')
})
})
...@@ -22368,15 +22368,6 @@ ...@@ -22368,15 +22368,6 @@
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/production/app-dir/use-node-streams-env-precedence/use-node-streams-env-precedence.test.ts": {
"passed": [
"use-node-streams env precedence should respect explicit useNodeStreams=false even when env flag is true"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/production/app-dir/worker-restart/worker-restart.test.ts": { "test/production/app-dir/worker-restart/worker-restart.test.ts": {
"passed": [ "passed": [
"worker-restart should fail the build if a worker process is killed", "worker-restart should fail the build if a worker process is killed",
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