Unverified Commit 3676d721 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: add `experimental.turbopackClient/ServerSideNestedAsyncChunking` (#85827)

### What?

Allow to configure nested vs flat async chunking with a new config option.

```
experimental: {
  turbopackClientSideNestedAsyncChunking: false,
  turbopackServerSideNestedAsyncChunking: true,
}
```
parent 66b6a80c
...@@ -1119,6 +1119,9 @@ impl Project { ...@@ -1119,6 +1119,9 @@ impl Project {
source_maps: self.next_config().client_source_maps(self.next_mode()), source_maps: self.next_config().client_source_maps(self.next_mode()),
no_mangling: self.no_mangling(), no_mangling: self.no_mangling(),
scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()), scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()),
nested_async_chunking: self
.next_config()
.turbo_nested_async_chunking(self.next_mode(), true),
debug_ids: self.next_config().turbopack_debug_ids(), debug_ids: self.next_config().turbopack_debug_ids(),
should_use_absolute_url_references: self.next_config().inline_css(), should_use_absolute_url_references: self.next_config().inline_css(),
})) }))
...@@ -1141,6 +1144,9 @@ impl Project { ...@@ -1141,6 +1144,9 @@ impl Project {
turbo_source_maps: self.next_config().server_source_maps(), turbo_source_maps: self.next_config().server_source_maps(),
no_mangling: self.no_mangling(), no_mangling: self.no_mangling(),
scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()), scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()),
nested_async_chunking: self
.next_config()
.turbo_nested_async_chunking(self.next_mode(), false),
debug_ids: self.next_config().turbopack_debug_ids(), debug_ids: self.next_config().turbopack_debug_ids(),
client_root: self.client_relative_path().owned().await?, client_root: self.client_relative_path().owned().await?,
asset_prefix: self.next_config().computed_asset_prefix().owned().await?, asset_prefix: self.next_config().computed_asset_prefix().owned().await?,
...@@ -1169,6 +1175,9 @@ impl Project { ...@@ -1169,6 +1175,9 @@ impl Project {
turbo_source_maps: self.next_config().server_source_maps(), turbo_source_maps: self.next_config().server_source_maps(),
no_mangling: self.no_mangling(), no_mangling: self.no_mangling(),
scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()), scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()),
nested_async_chunking: self
.next_config()
.turbo_nested_async_chunking(self.next_mode(), false),
client_root: self.client_relative_path().owned().await?, client_root: self.client_relative_path().owned().await?,
asset_prefix: self.next_config().computed_asset_prefix().owned().await?, asset_prefix: self.next_config().computed_asset_prefix().owned().await?,
}; };
......
...@@ -426,6 +426,7 @@ pub struct ClientChunkingContextOptions { ...@@ -426,6 +426,7 @@ pub struct ClientChunkingContextOptions {
pub source_maps: Vc<bool>, pub source_maps: Vc<bool>,
pub no_mangling: Vc<bool>, pub no_mangling: Vc<bool>,
pub scope_hoisting: Vc<bool>, pub scope_hoisting: Vc<bool>,
pub nested_async_chunking: Vc<bool>,
pub debug_ids: Vc<bool>, pub debug_ids: Vc<bool>,
pub should_use_absolute_url_references: Vc<bool>, pub should_use_absolute_url_references: Vc<bool>,
} }
...@@ -448,6 +449,7 @@ pub async fn get_client_chunking_context( ...@@ -448,6 +449,7 @@ pub async fn get_client_chunking_context(
source_maps, source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking,
debug_ids, debug_ids,
should_use_absolute_url_references, should_use_absolute_url_references,
} = options; } = options;
...@@ -484,7 +486,8 @@ pub async fn get_client_chunking_context( ...@@ -484,7 +486,8 @@ pub async fn get_client_chunking_context(
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.debug_ids(*debug_ids.await?) .debug_ids(*debug_ids.await?)
.should_use_absolute_url_references(*should_use_absolute_url_references.await?); .should_use_absolute_url_references(*should_use_absolute_url_references.await?)
.nested_async_availability(*nested_async_chunking.await?);
if next_mode.is_development() { if next_mode.is_development() {
builder = builder builder = builder
...@@ -510,7 +513,6 @@ pub async fn get_client_chunking_context( ...@@ -510,7 +513,6 @@ pub async fn get_client_chunking_context(
}, },
) )
.use_content_hashing(ContentHashing::Direct { length: 16 }) .use_content_hashing(ContentHashing::Direct { length: 16 })
.nested_async_availability(true)
.module_merging(*scope_hoisting.await?); .module_merging(*scope_hoisting.await?);
} }
......
...@@ -886,6 +886,8 @@ pub struct ExperimentalConfig { ...@@ -886,6 +886,8 @@ pub struct ExperimentalConfig {
turbopack_source_maps: Option<bool>, turbopack_source_maps: Option<bool>,
turbopack_tree_shaking: Option<bool>, turbopack_tree_shaking: Option<bool>,
turbopack_scope_hoisting: Option<bool>, turbopack_scope_hoisting: Option<bool>,
turbopack_client_side_nested_async_chunking: Option<bool>,
turbopack_server_side_nested_async_chunking: Option<bool>,
turbopack_import_type_bytes: Option<bool>, turbopack_import_type_bytes: Option<bool>,
turbopack_use_system_tls_certs: Option<bool>, turbopack_use_system_tls_certs: Option<bool>,
/// Disable automatic configuration of the sass loader. /// Disable automatic configuration of the sass loader.
...@@ -1790,6 +1792,29 @@ impl NextConfig { ...@@ -1790,6 +1792,29 @@ impl NextConfig {
})) }))
} }
#[turbo_tasks::function]
pub async fn turbo_nested_async_chunking(
&self,
mode: Vc<NextMode>,
client_side: bool,
) -> Result<Vc<bool>> {
let option = if client_side {
self.experimental
.turbopack_client_side_nested_async_chunking
} else {
self.experimental
.turbopack_server_side_nested_async_chunking
};
Ok(Vc::cell(if let Some(value) = option {
value
} else {
match *mode.await? {
NextMode::Development => false,
NextMode::Build => client_side,
}
}))
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn turbopack_import_type_bytes(&self) -> Vc<bool> { pub async fn turbopack_import_type_bytes(&self) -> Vc<bool> {
Vc::cell( Vc::cell(
......
...@@ -208,6 +208,7 @@ pub struct EdgeChunkingContextOptions { ...@@ -208,6 +208,7 @@ pub struct EdgeChunkingContextOptions {
pub turbo_source_maps: Vc<bool>, pub turbo_source_maps: Vc<bool>,
pub no_mangling: Vc<bool>, pub no_mangling: Vc<bool>,
pub scope_hoisting: Vc<bool>, pub scope_hoisting: Vc<bool>,
pub nested_async_chunking: Vc<bool>,
pub client_root: FileSystemPath, pub client_root: FileSystemPath,
pub asset_prefix: RcStr, pub asset_prefix: RcStr,
} }
...@@ -229,6 +230,7 @@ pub async fn get_edge_chunking_context_with_client_assets( ...@@ -229,6 +230,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
turbo_source_maps, turbo_source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking,
client_root, client_root,
asset_prefix, asset_prefix,
} = options; } = options;
...@@ -259,7 +261,8 @@ pub async fn get_edge_chunking_context_with_client_assets( ...@@ -259,7 +261,8 @@ pub async fn get_edge_chunking_context_with_client_assets(
SourceMapsType::None SourceMapsType::None
}) })
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?); .export_usage(*export_usage.await?)
.nested_async_availability(*nested_async_chunking.await?);
if !next_mode.is_development() { if !next_mode.is_development() {
builder = builder builder = builder
...@@ -300,6 +303,7 @@ pub async fn get_edge_chunking_context( ...@@ -300,6 +303,7 @@ pub async fn get_edge_chunking_context(
turbo_source_maps, turbo_source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking,
client_root, client_root,
asset_prefix, asset_prefix,
} = options; } = options;
...@@ -336,7 +340,8 @@ pub async fn get_edge_chunking_context( ...@@ -336,7 +340,8 @@ pub async fn get_edge_chunking_context(
SourceMapsType::None SourceMapsType::None
}) })
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?); .export_usage(*export_usage.await?)
.nested_async_availability(*nested_async_chunking.await?);
if !next_mode.is_development() { if !next_mode.is_development() {
builder = builder builder = builder
......
...@@ -1000,6 +1000,7 @@ pub struct ServerChunkingContextOptions { ...@@ -1000,6 +1000,7 @@ pub struct ServerChunkingContextOptions {
pub turbo_source_maps: Vc<bool>, pub turbo_source_maps: Vc<bool>,
pub no_mangling: Vc<bool>, pub no_mangling: Vc<bool>,
pub scope_hoisting: Vc<bool>, pub scope_hoisting: Vc<bool>,
pub nested_async_chunking: Vc<bool>,
pub debug_ids: Vc<bool>, pub debug_ids: Vc<bool>,
pub client_root: FileSystemPath, pub client_root: FileSystemPath,
pub asset_prefix: RcStr, pub asset_prefix: RcStr,
...@@ -1022,6 +1023,7 @@ pub async fn get_server_chunking_context_with_client_assets( ...@@ -1022,6 +1023,7 @@ pub async fn get_server_chunking_context_with_client_assets(
turbo_source_maps, turbo_source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking,
debug_ids, debug_ids,
client_root, client_root,
asset_prefix, asset_prefix,
...@@ -1058,7 +1060,8 @@ pub async fn get_server_chunking_context_with_client_assets( ...@@ -1058,7 +1060,8 @@ pub async fn get_server_chunking_context_with_client_assets(
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.file_tracing(next_mode.is_production()) .file_tracing(next_mode.is_production())
.debug_ids(*debug_ids.await?); .debug_ids(*debug_ids.await?)
.nested_async_availability(*nested_async_chunking.await?);
builder = builder.source_map_source_type(if next_mode.is_development() { builder = builder.source_map_source_type(if next_mode.is_development() {
SourceMapSourceType::AbsoluteFileUri SourceMapSourceType::AbsoluteFileUri
...@@ -1106,6 +1109,7 @@ pub async fn get_server_chunking_context( ...@@ -1106,6 +1109,7 @@ pub async fn get_server_chunking_context(
turbo_source_maps, turbo_source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking,
debug_ids, debug_ids,
client_root, client_root,
asset_prefix, asset_prefix,
...@@ -1142,7 +1146,8 @@ pub async fn get_server_chunking_context( ...@@ -1142,7 +1146,8 @@ pub async fn get_server_chunking_context(
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.file_tracing(next_mode.is_production()) .file_tracing(next_mode.is_production())
.debug_ids(*debug_ids.await?); .debug_ids(*debug_ids.await?)
.nested_async_availability(*nested_async_chunking.await?);
if next_mode.is_development() { if next_mode.is_development() {
builder = builder.source_map_source_type(SourceMapSourceType::AbsoluteFileUri); builder = builder.source_map_source_type(SourceMapSourceType::AbsoluteFileUri);
......
...@@ -301,6 +301,8 @@ export const experimentalSchema = { ...@@ -301,6 +301,8 @@ export const experimentalSchema = {
turbopackTreeShaking: z.boolean().optional(), turbopackTreeShaking: z.boolean().optional(),
turbopackRemoveUnusedExports: z.boolean().optional(), turbopackRemoveUnusedExports: z.boolean().optional(),
turbopackScopeHoisting: z.boolean().optional(), turbopackScopeHoisting: z.boolean().optional(),
turbopackClientSideNestedAsyncChunking: z.boolean().optional(),
turbopackServerSideNestedAsyncChunking: z.boolean().optional(),
turbopackImportTypeBytes: z.boolean().optional(), turbopackImportTypeBytes: z.boolean().optional(),
turbopackUseSystemTlsCerts: z.boolean().optional(), turbopackUseSystemTlsCerts: z.boolean().optional(),
turbopackUseBuiltinBabel: z.boolean().optional(), turbopackUseBuiltinBabel: z.boolean().optional(),
......
...@@ -413,6 +413,18 @@ export interface ExperimentalConfig { ...@@ -413,6 +413,18 @@ export interface ExperimentalConfig {
*/ */
turbopackScopeHoisting?: boolean turbopackScopeHoisting?: boolean
/**
* Enable nested async chunking for client side assets. Defaults to true in build mode and false in dev mode.
* This optimization computes all possible paths through dynamic imports in the applications to figure out the modules needed at dynamic imports for every path.
*/
turbopackClientSideNestedAsyncChunking?: boolean
/**
* Enable nested async chunking for server side assets. Defaults to false in dev and build mode.
* This optimization computes all possible paths through dynamic imports in the applications to figure out the modules needed at dynamic imports for every path.
*/
turbopackServerSideNestedAsyncChunking?: boolean
/** /**
* Enable filesystem cache for the turbopack dev server. * Enable filesystem cache for the turbopack dev server.
*/ */
......
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