@@ -78,7 +78,7 @@ use crate::{
7878 all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
7979 get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
8080 } ,
81- project:: Project ,
81+ project:: { Project , get_module_graph_for_modules_operation } ,
8282 route:: { Endpoint , EndpointOutput , EndpointOutputPaths , ModuleGraphs , Route , Routes } ,
8383 webpack_stats:: generate_webpack_stats,
8484} ;
@@ -699,71 +699,13 @@ impl PageEndpoint {
699699 }
700700
701701 #[ turbo_tasks:: function]
702- async fn client_module_graph ( self : Vc < Self > ) -> Result < Vc < ModuleGraph > > {
703- let this = self . await ?;
704- let project = this. pages_project . project ( ) ;
705- let evaluatable_assets = self . client_evaluatable_assets ( ) ;
706- Ok ( project. module_graph_for_modules ( evaluatable_assets) )
702+ async fn client_module_graph ( self : ResolvedVc < Self > ) -> Result < Vc < ModuleGraph > > {
703+ Ok ( get_pages_client_module_graph_operation ( self ) . connect ( ) )
707704 }
708705
709706 #[ turbo_tasks:: function]
710- async fn ssr_module_graph ( self : Vc < Self > ) -> Result < Vc < ModuleGraph > > {
711- let this = self . await ?;
712- let project = this. pages_project . project ( ) ;
713-
714- if * project. per_page_module_graph ( ) . await ? {
715- let next_mode = project. next_mode ( ) ;
716- let next_mode_ref = next_mode. await ?;
717- let should_trace = next_mode_ref. is_production ( ) ;
718- let should_read_binding_usage = next_mode_ref. is_production ( ) ;
719-
720- let ssr_chunk_module = self . internal_ssr_chunk_module ( ) . await ?;
721- // Implements layout segment optimization to compute a graph "chain" for document, app,
722- // page
723- let mut graphs = vec ! [ ] ;
724- let mut visited_modules = VisitedModules :: empty ( ) ;
725- for module in [
726- ssr_chunk_module. document_module ,
727- ssr_chunk_module. app_module ,
728- ]
729- . into_iter ( )
730- . flatten ( )
731- {
732- let graph = SingleModuleGraph :: new_with_entries_visited_intern (
733- vec ! [ ChunkGroupEntry :: Shared ( module) ] ,
734- visited_modules,
735- should_trace,
736- should_read_binding_usage,
737- ) ;
738- graphs. push ( graph) ;
739- visited_modules = VisitedModules :: concatenate ( visited_modules, graph) ;
740- }
741-
742- let graph = SingleModuleGraph :: new_with_entries_visited_intern (
743- vec ! [ ChunkGroupEntry :: Entry ( vec![ ssr_chunk_module. ssr_module] ) ] ,
744- visited_modules,
745- should_trace,
746- should_read_binding_usage,
747- ) ;
748- graphs. push ( graph) ;
749-
750- let remove_unused_imports = * project
751- . next_config ( )
752- . turbopack_remove_unused_imports ( next_mode)
753- . await ?;
754-
755- let graph = if remove_unused_imports {
756- let graph = ModuleGraph :: from_graphs ( graphs. clone ( ) ) ;
757- let binding_usage_info = compute_binding_usage_info ( graph, true ) ;
758- ModuleGraph :: from_graphs_without_unused_references ( graphs, binding_usage_info)
759- } else {
760- ModuleGraph :: from_graphs ( graphs)
761- } ;
762-
763- Ok ( graph. connect ( ) )
764- } else {
765- Ok ( * project. whole_app_module_graphs ( ) . await ?. full )
766- }
707+ async fn ssr_module_graph ( self : ResolvedVc < Self > ) -> Result < Vc < ModuleGraph > > {
708+ Ok ( get_pages_ssr_module_graph_operation ( self ) . connect ( ) )
767709 }
768710
769711 #[ turbo_tasks:: function]
@@ -1726,13 +1668,12 @@ impl Endpoint for PageEndpoint {
17261668
17271669 #[ turbo_tasks:: function]
17281670 async fn module_graphs ( self : Vc < Self > ) -> Result < Vc < ModuleGraphs > > {
1729- let client_module_graph = self . client_module_graph ( ) . to_resolved ( ) . await ?;
1730- let ssr_module_graph = self . ssr_module_graph ( ) . to_resolved ( ) . await ?;
1731- Ok ( Vc :: cell ( if client_module_graph != ssr_module_graph {
1732- vec ! [ client_module_graph, ssr_module_graph]
1733- } else {
1734- vec ! [ ssr_module_graph]
1735- } ) )
1671+ let this = self . to_resolved ( ) . await ?;
1672+ let client_module_graph = get_pages_client_module_graph_operation ( this) ;
1673+ let ssr_module_graph = get_pages_ssr_module_graph_operation ( this) ;
1674+ // Note: We can't easily deduplicate these anymore since OperationVc
1675+ // doesn't implement Eq, but that's fine - they're operation references
1676+ Ok ( Vc :: cell ( vec ! [ client_module_graph, ssr_module_graph] ) )
17361677 }
17371678}
17381679
@@ -1796,3 +1737,75 @@ pub enum SsrChunk {
17961737 regions : Option < Vec < RcStr > > ,
17971738 } ,
17981739}
1740+
1741+ #[ turbo_tasks:: function( operation) ]
1742+ async fn get_pages_client_module_graph_operation (
1743+ endpoint : ResolvedVc < PageEndpoint > ,
1744+ ) -> Result < Vc < ModuleGraph > > {
1745+ let this = endpoint. await ?;
1746+ let project = this. pages_project . project ( ) . to_resolved ( ) . await ?;
1747+ let evaluatable_assets = endpoint. client_evaluatable_assets ( ) . to_resolved ( ) . await ?;
1748+ Ok ( get_module_graph_for_modules_operation ( project, evaluatable_assets) . connect ( ) )
1749+ }
1750+
1751+ #[ turbo_tasks:: function( operation) ]
1752+ async fn get_pages_ssr_module_graph_operation (
1753+ endpoint : ResolvedVc < PageEndpoint > ,
1754+ ) -> Result < Vc < ModuleGraph > > {
1755+ let this = endpoint. await ?;
1756+ let project = this. pages_project . project ( ) ;
1757+
1758+ if * project. per_page_module_graph ( ) . await ? {
1759+ let next_mode = project. next_mode ( ) ;
1760+ let next_mode_ref = next_mode. await ?;
1761+ let should_trace = next_mode_ref. is_production ( ) ;
1762+ let should_read_binding_usage = next_mode_ref. is_production ( ) ;
1763+
1764+ let ssr_chunk_module = endpoint. internal_ssr_chunk_module ( ) . await ?;
1765+ // Implements layout segment optimization to compute a graph "chain" for document, app,
1766+ // page
1767+ let mut graphs = vec ! [ ] ;
1768+ let mut visited_modules = VisitedModules :: empty ( ) ;
1769+ for module in [
1770+ ssr_chunk_module. document_module ,
1771+ ssr_chunk_module. app_module ,
1772+ ]
1773+ . into_iter ( )
1774+ . flatten ( )
1775+ {
1776+ let graph = SingleModuleGraph :: new_with_entries_visited_intern (
1777+ vec ! [ ChunkGroupEntry :: Shared ( module) ] ,
1778+ visited_modules,
1779+ should_trace,
1780+ should_read_binding_usage,
1781+ ) ;
1782+ graphs. push ( graph) ;
1783+ visited_modules = VisitedModules :: concatenate ( visited_modules, graph) ;
1784+ }
1785+
1786+ let graph = SingleModuleGraph :: new_with_entries_visited_intern (
1787+ vec ! [ ChunkGroupEntry :: Entry ( vec![ ssr_chunk_module. ssr_module] ) ] ,
1788+ visited_modules,
1789+ should_trace,
1790+ should_read_binding_usage,
1791+ ) ;
1792+ graphs. push ( graph) ;
1793+
1794+ let remove_unused_imports = * project
1795+ . next_config ( )
1796+ . turbopack_remove_unused_imports ( next_mode)
1797+ . await ?;
1798+
1799+ let graph = if remove_unused_imports {
1800+ let graph = ModuleGraph :: from_graphs ( graphs. clone ( ) ) ;
1801+ let binding_usage_info = compute_binding_usage_info ( graph, true ) ;
1802+ ModuleGraph :: from_graphs_without_unused_references ( graphs, binding_usage_info)
1803+ } else {
1804+ ModuleGraph :: from_graphs ( graphs)
1805+ } ;
1806+
1807+ Ok ( graph. connect ( ) )
1808+ } else {
1809+ Ok ( project. whole_app_module_graphs ( ) . await ?. full . connect ( ) )
1810+ }
1811+ }
0 commit comments