File size: 4,008 Bytes
b2cad4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
diff --git a/crates/next-api/src/app.rs b/crates/next-api/src/app.rs
index b61ef3375e..fbfcf9b367 100644
--- a/crates/next-api/src/app.rs
+++ b/crates/next-api/src/app.rs
@@ -1995,11 +1995,21 @@ impl AppEndpoint {
             )
             .await?;
 
+        // The server actions loader is a separate graph entry that is not reachable from
+        // rsc_entry, but it is chunked into the endpoint output, so its modules (e.g. externals
+        // imported by actions) must be traced as well.
+        let mut entry_modules = vec![rsc_entry];
+        entry_modules.extend(
+            self.additional_entries(*module_graphs.base)
+                .await?
+                .all_modules(),
+        );
+
         Ok(trace_endpoint(
             this.app_project.project(),
             Some(app_function_name(&app_entry.original_name).into()),
             *module_graphs.full,
-            *rsc_entry,
+            Vc::cell(entry_modules),
         ))
     }
 }
diff --git a/crates/next-api/src/instrumentation.rs b/crates/next-api/src/instrumentation.rs
index c08773bf03..2515c48e5c 100644
--- a/crates/next-api/src/instrumentation.rs
+++ b/crates/next-api/src/instrumentation.rs
@@ -200,12 +200,12 @@ impl InstrumentationEndpoint {
     #[turbo_tasks::function]
     async fn trace_result(self: Vc<Self>) -> Result<Vc<EndpointTraceResult>> {
         let this = self.await?;
-        let userland_module = self.entry_module();
+        let userland_module = self.entry_module().to_resolved().await?;
         Ok(trace_endpoint(
             *this.project,
             None,
-            this.project.module_graph(userland_module),
-            userland_module,
+            this.project.module_graph(*userland_module),
+            Vc::cell(vec![userland_module]),
         ))
     }
 }
diff --git a/crates/next-api/src/middleware.rs b/crates/next-api/src/middleware.rs
index 2bbba57500..a2e0f9814a 100644
--- a/crates/next-api/src/middleware.rs
+++ b/crates/next-api/src/middleware.rs
@@ -342,12 +342,12 @@ impl MiddlewareEndpoint {
     #[turbo_tasks::function]
     async fn trace_result(self: Vc<Self>) -> Result<Vc<EndpointTraceResult>> {
         let this = self.await?;
-        let userland_module = self.entry_module();
+        let userland_module = self.entry_module().to_resolved().await?;
         Ok(trace_endpoint(
             *this.project,
             None,
-            this.project.module_graph(userland_module),
-            userland_module,
+            this.project.module_graph(*userland_module),
+            Vc::cell(vec![userland_module]),
         ))
     }
 }
diff --git a/crates/next-api/src/nft.rs b/crates/next-api/src/nft.rs
index f09e23c000..6d08c15467 100644
--- a/crates/next-api/src/nft.rs
+++ b/crates/next-api/src/nft.rs
@@ -61,7 +61,7 @@ pub async fn trace_endpoint(
     project: ResolvedVc<Project>,
     page_name: Option<RcStr>,
     module_graph: ResolvedVc<ModuleGraph>,
-    entry_module: ResolvedVc<Box<dyn Module>>,
+    entry_modules: Vc<Modules>,
 ) -> Result<Vc<EndpointTraceResult>> {
     let span = tracing::info_span!("trace endpoint", path = debug(&page_name));
     async {
@@ -78,7 +78,7 @@ pub async fn trace_endpoint(
         // Collect referenced assets and externals from module graph
         let all_modules = traced_modules_for_entries(
             *module_graph,
-            Vc::cell(vec![entry_module]),
+            entry_modules,
             traced_entries,
             tracing_exclude_glob(page_name.clone(), project_path.clone(), next_config)
                 .await?
diff --git a/crates/next-api/src/pages.rs b/crates/next-api/src/pages.rs
index b89d365860..594eb93142 100644
--- a/crates/next-api/src/pages.rs
+++ b/crates/next-api/src/pages.rs
@@ -1591,7 +1591,7 @@ impl PageEndpoint {
             this.pages_project.project(),
             Some(pages_function_name(&this.original_name).into()),
             ssr_module_graph,
-            *ssr_module,
+            Vc::cell(vec![ssr_module]),
         ))
     }
 }