Unverified Commit 014228f0 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

stabilize experimental.enablePrerenderSourcemaps (#84916)

As part of stabilizing cacheComponents, we are also stabilizing
supporting flags. This flag has been enabled with cacheComponents for
some time and so we are moving it out of experimental.

It will continue to be enabled by default if you are using
cacheComponents. Otherwise, it can be opted into independently via next
config.

Closes https://linear.app/vercel/issue/NDX-1048
Closes https://github.com/vercel/next.js/pull/80317

---------
Co-authored-by: 's avatarSebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
parent 206fa758
...@@ -125,6 +125,10 @@ Generating source maps consumes extra memory during the build process. ...@@ -125,6 +125,10 @@ Generating source maps consumes extra memory during the build process.
You can disable source map generation by adding `productionBrowserSourceMaps: false` and `experimental.serverSourceMaps: false` to your Next.js configuration. You can disable source map generation by adding `productionBrowserSourceMaps: false` and `experimental.serverSourceMaps: false` to your Next.js configuration.
When using the `experimental.cacheComponents` feature, Next.js will use source maps by default during the prerender phase of `next build`.
If you consistently encounter memory issues during that phase (after "Generating static pages"),
you can try disabling source maps in that phase by adding `enablePrerenderSourceMaps: false` to your Next.js configuration.
> **Good to know**: Some plugins may turn on source maps and may require custom configuration to disable. > **Good to know**: Some plugins may turn on source maps and may require custom configuration to disable.
## Edge memory issues ## Edge memory issues
......
...@@ -240,7 +240,7 @@ This enables several experimental options to make debugging easier: ...@@ -240,7 +240,7 @@ This enables several experimental options to make debugging easier:
- Generates source maps for server bundles: - Generates source maps for server bundles:
- `experimental.serverSourceMaps = true` - `experimental.serverSourceMaps = true`
- Enables source map consumption in child processes used for prerendering: - Enables source map consumption in child processes used for prerendering:
- `experimental.enablePrerenderSourceMaps = true` - `enablePrerenderSourceMaps = true`
- Continues building even after the first prerender error, so you can see all issues at once: - Continues building even after the first prerender error, so you can see all issues at once:
- `experimental.prerenderEarlyExit = false` - `experimental.prerenderEarlyExit = false`
......
...@@ -853,7 +853,7 @@ export function createStaticWorker( ...@@ -853,7 +853,7 @@ export function createStaticWorker(
progress?.clear() progress?.clear()
}, },
debuggerPortOffset, debuggerPortOffset,
enableSourceMaps: config.experimental.enablePrerenderSourceMaps, enableSourceMaps: config.enablePrerenderSourceMaps,
// remove --max-old-space-size flag as it can cause memory issues. // remove --max-old-space-size flag as it can cause memory issues.
isolatedMemory: true, isolatedMemory: true,
enableWorkerThreads: config.experimental.workerThreads, enableWorkerThreads: config.experimental.workerThreads,
......
...@@ -413,7 +413,7 @@ async function exportAppImpl( ...@@ -413,7 +413,7 @@ async function exportAppImpl(
(process.env.TURBOPACK (process.env.TURBOPACK
? nextConfig.experimental.turbopackMinify === false ? nextConfig.experimental.turbopackMinify === false
: nextConfig.experimental.serverMinification === false) && : nextConfig.experimental.serverMinification === false) &&
nextConfig.experimental.enablePrerenderSourceMaps === true, nextConfig.enablePrerenderSourceMaps === true,
} }
// We need this for server rendering the Link component. // We need this for server rendering the Link component.
......
...@@ -339,7 +339,7 @@ export async function exportPages( ...@@ -339,7 +339,7 @@ export async function exportPages(
installGlobalBehaviors(nextConfig) installGlobalBehaviors(nextConfig)
if (nextConfig.experimental.enablePrerenderSourceMaps) { if (nextConfig.enablePrerenderSourceMaps) {
try { try {
// Same as `next dev` // Same as `next dev`
// Limiting the stack trace to a useful amount of frames is handled by ignore-listing. // Limiting the stack trace to a useful amount of frames is handled by ignore-listing.
......
...@@ -313,7 +313,6 @@ export const experimentalSchema = { ...@@ -313,7 +313,6 @@ export const experimentalSchema = {
optimizeServerReact: z.boolean().optional(), optimizeServerReact: z.boolean().optional(),
clientTraceMetadata: z.array(z.string()).optional(), clientTraceMetadata: z.array(z.string()).optional(),
serverMinification: z.boolean().optional(), serverMinification: z.boolean().optional(),
enablePrerenderSourceMaps: z.boolean().optional(),
serverSourceMaps: z.boolean().optional(), serverSourceMaps: z.boolean().optional(),
useWasmBinary: z.boolean().optional(), useWasmBinary: z.boolean().optional(),
useLightningcss: z.boolean().optional(), useLightningcss: z.boolean().optional(),
...@@ -468,6 +467,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -468,6 +467,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
.optional(), .optional(),
distDir: z.string().min(1).optional(), distDir: z.string().min(1).optional(),
env: z.record(z.string(), z.union([z.string(), z.undefined()])).optional(), env: z.record(z.string(), z.union([z.string(), z.undefined()])).optional(),
enablePrerenderSourceMaps: z.boolean().optional(),
excludeDefaultMomentLocales: z.boolean().optional(), excludeDefaultMomentLocales: z.boolean().optional(),
experimental: z.strictObject(experimentalSchema).optional(), experimental: z.strictObject(experimentalSchema).optional(),
exportPathMap: z exportPathMap: z
......
...@@ -625,12 +625,6 @@ export interface ExperimentalConfig { ...@@ -625,12 +625,6 @@ export interface ExperimentalConfig {
*/ */
serverMinification?: boolean serverMinification?: boolean
/**
* Enables source maps while generating static pages.
* Helps with errors during the prerender phase in `next build`.
*/
enablePrerenderSourceMaps?: boolean
/** /**
* Enables source maps generation for the server production bundle. * Enables source maps generation for the server production bundle.
*/ */
...@@ -1260,6 +1254,12 @@ export interface NextConfig { ...@@ -1260,6 +1254,12 @@ export interface NextConfig {
*/ */
logging?: LoggingConfig | false logging?: LoggingConfig | false
/**
* Enables source maps while generating static pages.
* Helps with errors during the prerender phase in `next build`.
*/
enablePrerenderSourceMaps?: boolean
/** /**
* period (in seconds) where the server allow to serve stale cache * period (in seconds) where the server allow to serve stale cache
*/ */
...@@ -1385,6 +1385,8 @@ export const defaultConfig = Object.freeze({ ...@@ -1385,6 +1385,8 @@ export const defaultConfig = Object.freeze({
modularizeImports: undefined, modularizeImports: undefined,
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '', outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
allowedDevOrigins: undefined, allowedDevOrigins: undefined,
// Will default to cacheComponents value.
enablePrerenderSourceMaps: undefined,
experimental: { experimental: {
adapterPath: process.env.NEXT_ADAPTER_PATH || undefined, adapterPath: process.env.NEXT_ADAPTER_PATH || undefined,
useSkewCookie: false, useSkewCookie: false,
...@@ -1435,8 +1437,6 @@ export const defaultConfig = Object.freeze({ ...@@ -1435,8 +1437,6 @@ export const defaultConfig = Object.freeze({
appNavFailHandling: false, appNavFailHandling: false,
prerenderEarlyExit: true, prerenderEarlyExit: true,
serverMinification: true, serverMinification: true,
// Will default to cacheComponents value.
enablePrerenderSourceMaps: undefined,
serverSourceMaps: false, serverSourceMaps: false,
linkNoTouchStart: false, linkNoTouchStart: false,
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
......
...@@ -707,6 +707,13 @@ function assignDefaultsAndValidate( ...@@ -707,6 +707,13 @@ function assignDefaultsAndValidate(
configFileName, configFileName,
silent silent
) )
warnOptionHasBeenMovedOutOfExperimental(
result,
'enablePrerenderSourceMaps',
'enablePrerenderSourceMaps',
configFileName,
silent
)
if ((result.experimental as any).outputStandalone) { if ((result.experimental as any).outputStandalone) {
if (!silent) { if (!silent) {
...@@ -1269,9 +1276,14 @@ function assignDefaultsAndValidate( ...@@ -1269,9 +1276,14 @@ function assignDefaultsAndValidate(
result.experimental.mcpServer = true result.experimental.mcpServer = true
} }
// TODO: remove once we've finished migrating internally to cacheComponents.
if (result.experimental.cacheComponents) { if (result.experimental.cacheComponents) {
// TODO: remove once we've finished migrating internally to cacheComponents.
result.experimental.ppr = true result.experimental.ppr = true
// Prerender sourcemaps are enabled by default when using cacheComponents, unless explicitly disabled.
if (result.enablePrerenderSourceMaps === undefined) {
result.enablePrerenderSourceMaps = true
}
} }
// "use cache" was originally implicitly enabled with the cacheComponents flag, so // "use cache" was originally implicitly enabled with the cacheComponents flag, so
...@@ -1734,6 +1746,9 @@ function enforceExperimentalFeatures( ...@@ -1734,6 +1746,9 @@ function enforceExperimentalFeatures(
debugPrerender && debugPrerender &&
(phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT) (phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT)
) { ) {
// TODO: This is not an experimental feature, but should be enabled alongside other prerender debugging features.
config.enablePrerenderSourceMaps = true
setExperimentalFeatureForDebugPrerender( setExperimentalFeatureForDebugPrerender(
config.experimental, config.experimental,
'serverSourceMaps', 'serverSourceMaps',
...@@ -1748,13 +1763,6 @@ function enforceExperimentalFeatures( ...@@ -1748,13 +1763,6 @@ function enforceExperimentalFeatures(
configuredExperimentalFeatures configuredExperimentalFeatures
) )
setExperimentalFeatureForDebugPrerender(
config.experimental,
'enablePrerenderSourceMaps',
true,
configuredExperimentalFeatures
)
setExperimentalFeatureForDebugPrerender( setExperimentalFeatureForDebugPrerender(
config.experimental, config.experimental,
'prerenderEarlyExit', 'prerenderEarlyExit',
...@@ -1810,22 +1818,6 @@ function enforceExperimentalFeatures( ...@@ -1810,22 +1818,6 @@ function enforceExperimentalFeatures(
config.reactCompiler = true config.reactCompiler = true
// TODO: Report if we enable non-experimental features via env // TODO: Report if we enable non-experimental features via env
} }
if (
config.experimental.enablePrerenderSourceMaps === undefined &&
config.experimental.cacheComponents === true
) {
config.experimental.enablePrerenderSourceMaps = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'enablePrerenderSourceMaps',
true,
'enabled by `experimental.cacheComponents`'
)
}
}
} }
function addConfiguredExperimentalFeature< function addConfiguredExperimentalFeature<
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {
enablePrerenderSourceMaps: false,
experimental: { experimental: {
cacheComponents: true, cacheComponents: true,
enablePrerenderSourceMaps: false,
}, },
} }
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {
enablePrerenderSourceMaps: true,
experimental: { experimental: {
cpus: 1, cpus: 1,
enablePrerenderSourceMaps: true,
serverSourceMaps: true, serverSourceMaps: true,
}, },
} }
......
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