@@ -154,6 +154,11 @@ impl BrowserChunkingContextBuilder {
154154 self
155155 }
156156
157+ pub fn inline_chunk_group_bootstrap ( mut self , inline_chunk_group_bootstrap : bool ) -> Self {
158+ self . chunking_context . inline_chunk_group_bootstrap = inline_chunk_group_bootstrap;
159+ self
160+ }
161+
157162 pub fn should_use_absolute_url_references (
158163 mut self ,
159164 should_use_absolute_url_references : bool ,
@@ -301,6 +306,9 @@ pub struct BrowserChunkingContext {
301306 enable_dynamic_chunk_content_loading : bool ,
302307 /// Enable debug IDs for chunks and source maps.
303308 debug_ids : bool ,
309+ /// Inline each entrypoint's chunk group bootstrap into the HTML (as the
310+ /// `ChunkGroupResult.chunk_group_bootstrap_params`).
311+ inline_chunk_group_bootstrap : bool ,
304312 /// The environment chunks will be evaluated in.
305313 environment : ResolvedVc < Environment > ,
306314 /// The kind of runtime to include in the output.
@@ -373,6 +381,7 @@ impl BrowserChunkingContext {
373381 enable_module_merging : false ,
374382 enable_dynamic_chunk_content_loading : false ,
375383 debug_ids : false ,
384+ inline_chunk_group_bootstrap : false ,
376385 environment,
377386 runtime_type,
378387 minify_type : MinifyType :: NoMinify ,
@@ -786,6 +795,7 @@ impl ChunkingContext for BrowserChunkingContext {
786795 referenced_assets : OutputAssets :: empty_resolved ( ) ,
787796 references : ResolvedVc :: cell ( references) ,
788797 availability_info,
798+ chunk_group_bootstrap_params : None ,
789799 }
790800 . cell ( ) )
791801 }
@@ -894,11 +904,29 @@ impl ChunkingContext for BrowserChunkingContext {
894904 ) ;
895905 }
896906
897- assets. push ( ResolvedVc :: upcast (
898- self . generate_evaluate_chunk ( ident, other_assets, entries)
899- . to_resolved ( )
900- . await ?,
901- ) ) ;
907+ // The evaluate chunk registers this entry's chunks/modules onto the
908+ // `globalThis[TURBOPACK]` queue. When `inline_chunk_group_bootstrap` is enabled we
909+ // return that chunk group's bootstrap params for Next to inline into the HTML and
910+ // skip emitting the per-route evaluate chunk file.
911+ //
912+ // Only `ChunkGroup::Entry` groups (the page/app client entries Next renders into
913+ // HTML) can be inlined. Other groups — notably `Isolated` web workers, which
914+ // bootstrap via `importScripts` with no HTML to inline into — must keep their
915+ // evaluate chunk so the entry still registers.
916+ let evaluate_chunk = self . generate_evaluate_chunk ( ident, other_assets, entries) ;
917+ let chunk_group_bootstrap_params = if this. inline_chunk_group_bootstrap
918+ && matches ! ( chunk_group, ChunkGroup :: Entry ( _) )
919+ {
920+ Some (
921+ evaluate_chunk
922+ . chunk_group_bootstrap_params ( )
923+ . owned ( )
924+ . await ?,
925+ )
926+ } else {
927+ assets. push ( ResolvedVc :: upcast ( evaluate_chunk. to_resolved ( ) . await ?) ) ;
928+ None
929+ } ;
902930
903931 // The shared runtime chunk must be the LAST asset of the group. It drains
904932 // the registration queue set up by the chunks above, so it has to load
@@ -918,6 +946,7 @@ impl ChunkingContext for BrowserChunkingContext {
918946 referenced_assets : OutputAssets :: empty_resolved ( ) ,
919947 references : ResolvedVc :: cell ( references) ,
920948 availability_info,
949+ chunk_group_bootstrap_params,
921950 }
922951 . cell ( ) )
923952 }
0 commit comments