@@ -19,11 +19,17 @@ use crate::{
1919
2020// { [request to inject into client compilation]: [exported names] }
2121pub type ClientComponentImports = FxIndexMap < String , FxIndexSet < Atom > > ;
22+ pub type ClientComponentImportsByServerEntry = FxIndexMap < String , ClientComponentImports > ;
2223
2324#[ derive( Debug , Default ) ]
2425pub struct ComponentInfo {
2526 pub should_inject_ssr_modules : bool ,
27+ /// All client component imports reached from this RSC entry.
2628 pub client_component_imports : ClientComponentImports ,
29+ /// Client component imports reached without a `use server-entry` owner.
30+ pub root_client_component_imports : ClientComponentImports ,
31+ /// Client component imports reached under each `use server-entry` owner.
32+ pub client_component_imports_by_server_entry : ClientComponentImportsByServerEntry ,
2733 pub css_imports_by_server_entry : CssImportsByServerEntry ,
2834 pub root_css_imports : RootCssImports ,
2935 pub action_imports : Vec < ( String , Vec < ActionIdNamePair > ) > ,
@@ -155,12 +161,12 @@ fn filter_client_components(
155161 . client_component_imports
156162 . contains_key ( resource. as_ref ( ) )
157163 {
158- add_client_import (
164+ add_client_import_for_owners (
159165 module,
160- & resource,
166+ resource. as_ref ( ) ,
161167 imported_identifiers,
162- false ,
163- & mut component_info. client_component_imports ,
168+ server_entries ,
169+ component_info,
164170 ) ;
165171 }
166172 return ;
@@ -188,20 +194,12 @@ fn filter_client_components(
188194
189195 let module_graph = compilation. get_module_graph ( ) ;
190196 if is_client_component_entry_module ( module) {
191- if !component_info
192- . client_component_imports
193- . contains_key ( resource. as_ref ( ) )
194- {
195- component_info
196- . client_component_imports
197- . insert ( resource. to_string ( ) , Default :: default ( ) ) ;
198- }
199- add_client_import (
197+ add_client_import_for_owners (
200198 module,
201199 resource. as_ref ( ) ,
202200 imported_identifiers,
203- true ,
204- & mut component_info. client_component_imports ,
201+ server_entries ,
202+ component_info,
205203 ) ;
206204 return ;
207205 }
@@ -251,6 +249,63 @@ fn filter_client_components(
251249 }
252250}
253251
252+ fn add_client_import_for_owners (
253+ module : & dyn Module ,
254+ resource : & str ,
255+ imported_identifiers : & [ Atom ] ,
256+ server_entries : & [ String ] ,
257+ component_info : & mut ComponentInfo ,
258+ ) {
259+ add_client_import_to_map (
260+ module,
261+ resource,
262+ imported_identifiers,
263+ & mut component_info. client_component_imports ,
264+ ) ;
265+
266+ if server_entries. is_empty ( ) {
267+ add_client_import_to_map (
268+ module,
269+ resource,
270+ imported_identifiers,
271+ & mut component_info. root_client_component_imports ,
272+ ) ;
273+ return ;
274+ }
275+
276+ for server_entry in server_entries {
277+ let client_component_imports = component_info
278+ . client_component_imports_by_server_entry
279+ . entry ( server_entry. clone ( ) )
280+ . or_default ( ) ;
281+ add_client_import_to_map (
282+ module,
283+ resource,
284+ imported_identifiers,
285+ client_component_imports,
286+ ) ;
287+ }
288+ }
289+
290+ fn add_client_import_to_map (
291+ module : & dyn Module ,
292+ mod_request : & str ,
293+ imported_identifiers : & [ Atom ] ,
294+ client_component_imports : & mut ClientComponentImports ,
295+ ) {
296+ let is_first_visit_module = !client_component_imports. contains_key ( mod_request) ;
297+ if is_first_visit_module {
298+ client_component_imports. insert ( mod_request. to_string ( ) , Default :: default ( ) ) ;
299+ }
300+ add_client_import (
301+ module,
302+ mod_request,
303+ imported_identifiers,
304+ is_first_visit_module,
305+ client_component_imports,
306+ ) ;
307+ }
308+
254309fn add_client_import (
255310 module : & dyn Module ,
256311 mod_request : & str ,
0 commit comments