fix: guard all require('node:stream') with NEXT_RUNTIME if/else for edge DCE
Webpack only eliminates require() calls inside if/else branches where
DefinePlugin can evaluate the condition. A throw-then-require pattern
does NOT work: webpack doesn't do control flow analysis for throws.
The canary pattern that works:
if (process.env.NEXT_RUNTIME === 'edge') {
throw new Error(...)
} else {
const { Readable } = require('node:stream') // DCE'd for edge
}
The pattern that breaks:
if (process.env.NEXT_RUNTIME === 'edge') {
throw new Error(...)
}
const { Readable } = require('node:stream') // NOT DCE'd
Applied the if/else pattern to all require('node:stream') callsites in:
- app-render.tsx (createRuntimePrefetchNodeTransform, PassThrough usage)
- app-render-prerender-utils.ts (tee, createClosingNodeStream,
createUnclosingNodeStream, processNodePrelude)
- use-flight-response.tsx (createInlinedDataNodeStream)
- stream-ops.ts (createPendingStream)
Also converted stream-ops.ts exports from module-level ternaries to
lazy function wrappers (module-scope requires are resolved before DCE).