Skip to content

Commit c37b21c

Browse files
committed
Turbopack: add experimental.turbopackClient/ServerSideNestedAsyncChunking
1 parent 1f6dbf2 commit c37b21c

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

crates/next-core/src/next_client/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ pub struct ClientChunkingContextOptions {
426426
pub source_maps: Vc<bool>,
427427
pub no_mangling: Vc<bool>,
428428
pub scope_hoisting: Vc<bool>,
429+
pub nested_async_chunking: Vc<bool>,
429430
pub debug_ids: Vc<bool>,
430431
pub should_use_absolute_url_references: Vc<bool>,
431432
}
@@ -448,6 +449,7 @@ pub async fn get_client_chunking_context(
448449
source_maps,
449450
no_mangling,
450451
scope_hoisting,
452+
nested_async_chunking,
451453
debug_ids,
452454
should_use_absolute_url_references,
453455
} = options;
@@ -484,7 +486,8 @@ pub async fn get_client_chunking_context(
484486
.export_usage(*export_usage.await?)
485487
.module_id_strategy(module_id_strategy.to_resolved().await?)
486488
.debug_ids(*debug_ids.await?)
487-
.should_use_absolute_url_references(*should_use_absolute_url_references.await?);
489+
.should_use_absolute_url_references(*should_use_absolute_url_references.await?)
490+
.nested_async_availability(*nested_async_chunking.await?);
488491

489492
if next_mode.is_development() {
490493
builder = builder
@@ -510,7 +513,6 @@ pub async fn get_client_chunking_context(
510513
},
511514
)
512515
.use_content_hashing(ContentHashing::Direct { length: 16 })
513-
.nested_async_availability(true)
514516
.module_merging(*scope_hoisting.await?);
515517
}
516518

crates/next-core/src/next_config.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ pub struct ExperimentalConfig {
885885
turbopack_source_maps: Option<bool>,
886886
turbopack_tree_shaking: Option<bool>,
887887
turbopack_scope_hoisting: Option<bool>,
888+
turbopack_client_side_nested_async_chunking: Option<bool>,
889+
turbopack_server_side_nested_async_chunking: Option<bool>,
888890
turbopack_import_type_bytes: Option<bool>,
889891
turbopack_use_system_tls_certs: Option<bool>,
890892
/// Disable automatic configuration of the sass loader.
@@ -1784,6 +1786,29 @@ impl NextConfig {
17841786
}))
17851787
}
17861788

1789+
#[turbo_tasks::function]
1790+
pub async fn turbo_nested_async_chunking(
1791+
&self,
1792+
mode: Vc<NextMode>,
1793+
client_side: bool,
1794+
) -> Result<Vc<bool>> {
1795+
let option = if client_side {
1796+
self.experimental
1797+
.turbopack_client_side_nested_async_chunking
1798+
} else {
1799+
self.experimental
1800+
.turbopack_server_side_nested_async_chunking
1801+
};
1802+
Ok(Vc::cell(if let Some(value) = option {
1803+
value
1804+
} else {
1805+
match *mode.await? {
1806+
NextMode::Development => false,
1807+
NextMode::Build => client_side,
1808+
}
1809+
}))
1810+
}
1811+
17871812
#[turbo_tasks::function]
17881813
pub async fn turbopack_import_type_bytes(&self) -> Vc<bool> {
17891814
Vc::cell(

crates/next-core/src/next_edge/context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pub struct EdgeChunkingContextOptions {
208208
pub turbo_source_maps: Vc<bool>,
209209
pub no_mangling: Vc<bool>,
210210
pub scope_hoisting: Vc<bool>,
211+
pub nested_async_chunking: Vc<bool>,
211212
pub client_root: FileSystemPath,
212213
pub asset_prefix: RcStr,
213214
}
@@ -229,6 +230,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
229230
turbo_source_maps,
230231
no_mangling,
231232
scope_hoisting,
233+
nested_async_chunking,
232234
client_root,
233235
asset_prefix,
234236
} = options;
@@ -259,7 +261,8 @@ pub async fn get_edge_chunking_context_with_client_assets(
259261
SourceMapsType::None
260262
})
261263
.module_id_strategy(module_id_strategy.to_resolved().await?)
262-
.export_usage(*export_usage.await?);
264+
.export_usage(*export_usage.await?)
265+
.nested_async_availability(*nested_async_chunking.await?);
263266

264267
if !next_mode.is_development() {
265268
builder = builder
@@ -300,6 +303,7 @@ pub async fn get_edge_chunking_context(
300303
turbo_source_maps,
301304
no_mangling,
302305
scope_hoisting,
306+
nested_async_chunking,
303307
client_root,
304308
asset_prefix,
305309
} = options;
@@ -336,7 +340,8 @@ pub async fn get_edge_chunking_context(
336340
SourceMapsType::None
337341
})
338342
.module_id_strategy(module_id_strategy.to_resolved().await?)
339-
.export_usage(*export_usage.await?);
343+
.export_usage(*export_usage.await?)
344+
.nested_async_availability(*nested_async_chunking.await?);
340345

341346
if !next_mode.is_development() {
342347
builder = builder

crates/next-core/src/next_server/context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ pub struct ServerChunkingContextOptions {
10001000
pub turbo_source_maps: Vc<bool>,
10011001
pub no_mangling: Vc<bool>,
10021002
pub scope_hoisting: Vc<bool>,
1003+
pub nested_async_chunking: Vc<bool>,
10031004
pub debug_ids: Vc<bool>,
10041005
pub client_root: FileSystemPath,
10051006
pub asset_prefix: RcStr,
@@ -1022,6 +1023,7 @@ pub async fn get_server_chunking_context_with_client_assets(
10221023
turbo_source_maps,
10231024
no_mangling,
10241025
scope_hoisting,
1026+
nested_async_chunking,
10251027
debug_ids,
10261028
client_root,
10271029
asset_prefix,
@@ -1058,7 +1060,8 @@ pub async fn get_server_chunking_context_with_client_assets(
10581060
.module_id_strategy(module_id_strategy.to_resolved().await?)
10591061
.export_usage(*export_usage.await?)
10601062
.file_tracing(next_mode.is_production())
1061-
.debug_ids(*debug_ids.await?);
1063+
.debug_ids(*debug_ids.await?)
1064+
.nested_async_availability(*nested_async_chunking.await?);
10621065

10631066
builder = builder.source_map_source_type(if next_mode.is_development() {
10641067
SourceMapSourceType::AbsoluteFileUri
@@ -1106,6 +1109,7 @@ pub async fn get_server_chunking_context(
11061109
turbo_source_maps,
11071110
no_mangling,
11081111
scope_hoisting,
1112+
nested_async_chunking,
11091113
debug_ids,
11101114
client_root,
11111115
asset_prefix,
@@ -1142,7 +1146,8 @@ pub async fn get_server_chunking_context(
11421146
.module_id_strategy(module_id_strategy.to_resolved().await?)
11431147
.export_usage(*export_usage.await?)
11441148
.file_tracing(next_mode.is_production())
1145-
.debug_ids(*debug_ids.await?);
1149+
.debug_ids(*debug_ids.await?)
1150+
.nested_async_availability(*nested_async_chunking.await?);
11461151

11471152
if next_mode.is_development() {
11481153
builder = builder.source_map_source_type(SourceMapSourceType::AbsoluteFileUri);

packages/next/src/server/config-schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ export const experimentalSchema = {
300300
turbopackTreeShaking: z.boolean().optional(),
301301
turbopackRemoveUnusedExports: z.boolean().optional(),
302302
turbopackScopeHoisting: z.boolean().optional(),
303+
turbopackClientSideNestedAsyncChunking: z.boolean().optional(),
304+
turbopackServerSideNestedAsyncChunking: z.boolean().optional(),
303305
turbopackImportTypeBytes: z.boolean().optional(),
304306
turbopackUseSystemTlsCerts: z.boolean().optional(),
305307
turbopackUseBuiltinBabel: z.boolean().optional(),

packages/next/src/server/config-shared.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ export interface ExperimentalConfig {
407407
*/
408408
turbopackScopeHoisting?: boolean
409409

410+
/**
411+
* Enable nested async chunking for client side assets. Defaults to true in build mode and false in dev mode.
412+
* This optimization computes all possible paths through dynamic imports in the applications to figure out the modules needed at dynamic imports for every path.
413+
*/
414+
turbopackClientSideNestedAsyncChunking?: boolean
415+
416+
/**
417+
* Enable nested async chunking for server side assets. Defaults to false in dev and build mode.
418+
* This optimization computes all possible paths through dynamic imports in the applications to figure out the modules needed at dynamic imports for every path.
419+
*/
420+
turbopackServerSideNestedAsyncChunking?: boolean
421+
410422
/**
411423
* Enable filesystem cache for the turbopack dev server.
412424
*/

0 commit comments

Comments
 (0)