From 0096c7d226b575f8c6997ca622fcbacfc415bebd Mon Sep 17 00:00:00 2001 From: Luke Sandberg Date: Sun, 12 Oct 2025 22:42:50 -0700 Subject: [PATCH] introduce an option to use the whole app module graph in development --- crates/next-api/src/project.rs | 10 ++++++++-- crates/next-core/src/next_config.rs | 12 ++++++++++++ packages/next/src/server/config-schema.ts | 1 + packages/next/src/server/config-shared.ts | 6 ++++++ .../turbopack-core/src/chunk/chunking_context.rs | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/next-api/src/project.rs b/crates/next-api/src/project.rs index 67250477318fc..cc0f2990be0cf 100644 --- a/crates/next-api/src/project.rs +++ b/crates/next-api/src/project.rs @@ -792,7 +792,12 @@ impl Project { #[turbo_tasks::function] pub(super) async fn per_page_module_graph(&self) -> Result> { - Ok(Vc::cell(*self.mode.await? == NextMode::Development)) + Ok(Vc::cell( + !*self + .next_config + .turbo_use_whole_app_module_graph(*self.mode) + .await?, + )) } #[turbo_tasks::function] @@ -996,7 +1001,8 @@ impl Project { }; // At this point all modules have been computed and we can get rid of the node.js - // process pools + // process pools, in watch mode we don't completely turn it down since we do expect + // invalidations if *self.is_watch_enabled().await? { turbopack_node::evaluate::scale_down(); } else { diff --git a/crates/next-core/src/next_config.rs b/crates/next-core/src/next_config.rs index 3c41b2b02388c..b7342242dc941 100644 --- a/crates/next-core/src/next_config.rs +++ b/crates/next-core/src/next_config.rs @@ -877,6 +877,7 @@ pub struct ExperimentalConfig { turbopack_scope_hoisting: Option, turbopack_import_type_bytes: Option, turbopack_use_system_tls_certs: Option, + turbopack_use_whole_app_module_graph_in_dev: Option, /// Disable automatic configuration of the sass loader. #[serde(default)] turbopack_use_builtin_sass: Option, @@ -1840,6 +1841,17 @@ impl NextConfig { ) } + #[turbo_tasks::function] + pub async fn turbo_use_whole_app_module_graph(&self, mode: Vc) -> Result> { + Ok(Vc::cell(match *mode.await? { + NextMode::Development => self + .experimental + .turbopack_use_whole_app_module_graph_in_dev + .unwrap_or(true), + NextMode::Build => true, + })) + } + #[turbo_tasks::function] pub async fn client_source_maps(&self, mode: Vc) -> Result> { let source_maps = self.experimental.turbopack_source_maps; diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index 712af8e4f4675..c40811927990e 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -309,6 +309,7 @@ export const experimentalSchema = { turbopackUseBuiltinBabel: z.boolean().optional(), turbopackUseBuiltinSass: z.boolean().optional(), turbopackModuleIds: z.enum(['named', 'deterministic']).optional(), + turbopackUseWholeAppModuleGraphInDev: z.boolean().optional(), optimizePackageImports: z.array(z.string()).optional(), optimizeServerReact: z.boolean().optional(), clientTraceMetadata: z.array(z.string()).optional(), diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 1a4a4737e55d9..a43c319a7efab 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -491,6 +491,12 @@ export interface ExperimentalConfig { */ turbopackModuleIds?: 'named' | 'deterministic' + /** + * Whether to compute the whole app module graph in development mode. This may reduce memory usage + * by enabling more sharing of chunking decisions across routes. + */ + turbopackUseWholeAppModuleGraphInDev?: boolean + /** * For use with `@next/mdx`. Compile MDX files using the new Rust compiler. * @see https://nextjs.org/docs/app/api-reference/next-config-js/mdxRs diff --git a/turbopack/crates/turbopack-core/src/chunk/chunking_context.rs b/turbopack/crates/turbopack-core/src/chunk/chunking_context.rs index 519b1cb1bb66f..96dab6b46d756 100644 --- a/turbopack/crates/turbopack-core/src/chunk/chunking_context.rs +++ b/turbopack/crates/turbopack-core/src/chunk/chunking_context.rs @@ -138,6 +138,7 @@ pub struct ChunkingConfigs(FxHashMap>, ChunkingCon pub trait ChunkingContext { #[turbo_tasks::function] fn name(self: Vc) -> Vc; + /// Whether to use file URIs in source maps. #[turbo_tasks::function] fn should_use_file_source_map_uris(self: Vc) -> Vc; /// The root path of the project