@@ -3,7 +3,9 @@ use std::{collections::BTreeMap, io::Write, iter::once};
33use anyhow:: { bail, Context , Result } ;
44use indexmap:: map:: Entry ;
55use next_core:: {
6- next_manifests:: { ActionLayer , ActionManifestWorkerEntry , ServerReferenceManifest } ,
6+ next_manifests:: {
7+ ActionLayer , ActionManifestModuleId , ActionManifestWorkerEntry , ServerReferenceManifest ,
8+ } ,
79 util:: NextRuntime ,
810} ;
911use swc_core:: {
@@ -22,7 +24,7 @@ use turbo_tasks::{
2224use turbo_tasks_fs:: { self , rope:: RopeBuilder , File , FileSystemPath } ;
2325use turbopack_core:: {
2426 asset:: AssetContent ,
25- chunk:: { ChunkItemExt , ChunkableModule , ChunkingContext , EvaluatableAsset } ,
27+ chunk:: { ChunkItem , ChunkItemExt , ChunkableModule , ChunkingContext , EvaluatableAsset } ,
2628 context:: AssetContext ,
2729 file_source:: FileSource ,
2830 module:: { Module , Modules } ,
@@ -69,11 +71,8 @@ pub(crate) async fn create_server_actions_manifest(
6971 . await ?
7072 . context ( "loader module must be evaluatable" ) ?;
7173
72- let loader_id = loader
73- . as_chunk_item ( Vc :: upcast ( chunking_context) )
74- . id ( )
75- . to_string ( ) ;
76- let manifest = build_manifest ( node_root, page_name, runtime, actions, loader_id) . await ?;
74+ let chunk_item = loader. as_chunk_item ( Vc :: upcast ( chunking_context) ) ;
75+ let manifest = build_manifest ( node_root, page_name, runtime, actions, chunk_item) . await ?;
7776 Ok ( ServerActionsManifest {
7877 loader : evaluable,
7978 manifest,
@@ -96,11 +95,11 @@ async fn build_server_actions_loader(
9695) -> Result < Vc < Box < dyn EcmascriptChunkPlaceable > > > {
9796 let actions = actions. await ?;
9897
99- // Every module which exports an action (that is accessible starting from our
100- // app page entry point) will be present. We generate a single loader file
101- // which lazily imports the respective module's chunk_item id and invokes
102- // the exported action function .
103- let mut contents = RopeBuilder :: from ( "__turbopack_export_value__({ \n " ) ;
98+ // Every module which exports an action (that is accessible starting from
99+ // our app page entry point) will be present. We generate a single loader
100+ // file which re-exports the respective module's action function using the
101+ // hashed ID as export name .
102+ let mut contents = RopeBuilder :: from ( "" ) ;
104103 let mut import_map = FxIndexMap :: default ( ) ;
105104 for ( hash_id, ( _layer, name, module) ) in actions. iter ( ) {
106105 let index = import_map. len ( ) ;
@@ -109,11 +108,9 @@ async fn build_server_actions_loader(
109108 . or_insert_with ( || format ! ( "ACTIONS_MODULE{index}" ) . into ( ) ) ;
110109 writeln ! (
111110 contents,
112- " '{hash_id}': (...args) => Promise.resolve(require('{module_name}')).then(mod => \
113- (0, mod['{name}'])(...args)),",
111+ "export {{{name} as '{hash_id}'}} from '{module_name}'"
114112 ) ?;
115113 }
116- write ! ( contents, "}});" ) ?;
117114
118115 let output_path =
119116 project_path. join ( format ! ( ".next-internal/server/app{page_name}/actions.js" ) . into ( ) ) ;
@@ -143,7 +140,7 @@ async fn build_manifest(
143140 page_name : RcStr ,
144141 runtime : NextRuntime ,
145142 actions : Vc < AllActions > ,
146- loader_id : Vc < RcStr > ,
143+ chunk_item : Vc < Box < dyn ChunkItem > > ,
147144) -> Result < Vc < Box < dyn OutputAsset > > > {
148145 let manifest_path_prefix = & page_name;
149146 let manifest_path = node_root
@@ -155,7 +152,7 @@ async fn build_manifest(
155152 let key = format ! ( "app{page_name}" ) ;
156153
157154 let actions_value = actions. await ?;
158- let loader_id_value = loader_id . await ?;
155+ let loader_id = chunk_item . id ( ) . to_string ( ) . await ?;
159156 let mapping = match runtime {
160157 NextRuntime :: Edge => & mut manifest. edge ,
161158 NextRuntime :: NodeJs => & mut manifest. node ,
@@ -165,7 +162,10 @@ async fn build_manifest(
165162 let entry = mapping. entry ( hash_id. as_str ( ) ) . or_default ( ) ;
166163 entry. workers . insert (
167164 & key,
168- ActionManifestWorkerEntry :: String ( loader_id_value. as_str ( ) ) ,
165+ ActionManifestWorkerEntry {
166+ module_id : ActionManifestModuleId :: String ( loader_id. as_str ( ) ) ,
167+ is_async : * chunk_item. is_self_async ( ) . await ?,
168+ } ,
169169 ) ;
170170 entry. layer . insert ( & key, * layer) ;
171171 }
0 commit comments