Skip to content

Commit 91abbcd

Browse files
fix(mf): initialize share scopes before consume loading
Wait for consume share scopes to finish initializing before delegating to the bundler runtime so layered shared modules resolve consistently. Remove the temporary federation debug instrumentation that was added while tracing the runtime flow. Made-with: Cursor
1 parent b241619 commit 91abbcd

File tree

12 files changed

+66
-334
lines changed

12 files changed

+66
-334
lines changed

crates/rspack_binding_api/src/raw_options/raw_builtins/raw_mf.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rspack_plugin_mf::{
99
ModuleFederationRuntimeExperimentsOptions, ModuleFederationRuntimePluginOptions,
1010
OptimizeSharedConfig, ProvideOptions, ProvideVersion, RemoteAliasTarget, RemoteOptions,
1111
ShareScope, SharedContainerPluginOptions, SharedUsedExportsOptimizerPluginOptions,
12-
StatsBuildInfo, debug_log,
12+
StatsBuildInfo,
1313
};
1414
use rspack_util::fx_hash::FxHashMap as HashMap;
1515

@@ -136,35 +136,6 @@ pub struct RawProvideOptions {
136136

137137
impl From<RawProvideOptions> for (String, ProvideOptions) {
138138
fn from(value: RawProvideOptions) -> Self {
139-
// #region agent log
140-
if value.share_key == "react" || value.layer.is_some() || value.request.is_some() {
141-
debug_log(
142-
"H1",
143-
"raw_mf.rs:137",
144-
"raw provide options converted",
145-
serde_json::json!({
146-
"key": value.key,
147-
"request": value.request,
148-
"layer": value.layer,
149-
"shareKey": value.share_key,
150-
"shareScope": match &value.share_scope {
151-
Either::A(scope) => serde_json::json!(scope),
152-
Either::B(scopes) => serde_json::json!(scopes),
153-
},
154-
"version": value.version.as_ref().map(|v| match v {
155-
Either::A(version) => version.clone(),
156-
Either::B(flag) => flag.to_string(),
157-
}),
158-
"requiredVersion": value.required_version.as_ref().map(|v| match v {
159-
Either::A(version) => version.clone(),
160-
Either::B(flag) => flag.to_string(),
161-
}),
162-
"singleton": value.singleton,
163-
"strictVersion": value.strict_version,
164-
}),
165-
);
166-
}
167-
// #endregion
168139
(
169140
value.key,
170141
ProvideOptions {
@@ -317,35 +288,6 @@ pub struct RawConsumeOptions {
317288

318289
impl From<RawConsumeOptions> for (String, ConsumeOptions) {
319290
fn from(value: RawConsumeOptions) -> Self {
320-
// #region agent log
321-
if value.share_key == "react" || value.layer.is_some() || value.issuer_layer.is_some() {
322-
debug_log(
323-
"H1",
324-
"raw_mf.rs:289",
325-
"raw consume options converted",
326-
serde_json::json!({
327-
"key": value.key,
328-
"request": value.request,
329-
"issuerLayer": value.issuer_layer,
330-
"layer": value.layer,
331-
"import": value.import,
332-
"importResolved": value.import_resolved,
333-
"shareKey": value.share_key,
334-
"shareScope": match &value.share_scope {
335-
Either::A(scope) => serde_json::json!(scope),
336-
Either::B(scopes) => serde_json::json!(scopes),
337-
},
338-
"requiredVersion": value.required_version.as_ref().map(|v| match v {
339-
Either::A(version) => version.clone(),
340-
Either::B(flag) => flag.to_string(),
341-
}),
342-
"strictVersion": value.strict_version,
343-
"singleton": value.singleton,
344-
"eager": value.eager,
345-
}),
346-
);
347-
}
348-
// #endregion
349291
(
350292
value.key,
351293
ConsumeOptions {

crates/rspack_plugin_mf/src/container/container_entry_module.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hash::FxHashSet;
2121
use super::{
2222
container_exposed_dependency::ContainerExposedDependency, container_plugin::ExposeOptions,
2323
};
24-
use crate::{ShareScope, debug_log, utils::json_stringify};
24+
use crate::{ShareScope, utils::json_stringify};
2525

2626
#[impl_source_map_config]
2727
#[cacheable]
@@ -344,18 +344,6 @@ impl Module for ContainerEntryModule {
344344
let module_map = ExposeModuleMap::new(compilation, self, runtime_template);
345345
let module_map_str = module_map.render(runtime_template);
346346
let source = if self.enhanced {
347-
// #region agent log
348-
debug_log(
349-
"S1",
350-
"container_entry_module.rs:346",
351-
"rspack enhanced container entry codegen",
352-
serde_json::json!({
353-
"name": self.name,
354-
"shareScope": self.share_scope,
355-
"moduleMapKeys": self.exposes.iter().map(|(name, _)| name.clone()).collect::<Vec<_>>(),
356-
}),
357-
);
358-
// #endregion
359347
let define_property_getters =
360348
runtime_template.render_runtime_globals(&RuntimeGlobals::DEFINE_PROPERTY_GETTERS);
361349
let get_container = format!(

crates/rspack_plugin_mf/src/container/embed_federation_runtime_module.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use rspack_core::{
1212
use rspack_error::Result;
1313

1414
use super::module_federation_runtime_plugin::ModuleFederationRuntimeExperimentsOptions;
15-
use crate::debug_log;
16-
1715
#[cacheable]
1816
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq)]
1917
pub struct EmbedFederationRuntimeModuleOptions {
@@ -93,7 +91,6 @@ impl RuntimeModule for EmbedFederationRuntimeModule {
9391

9492
// Generate module execution code for each federation runtime dependency
9593
let mut module_executions = String::with_capacity(federation_runtime_modules.len() * 64);
96-
let federation_runtime_modules_count = federation_runtime_modules.len();
9794
let mut runtime_template = compilation.runtime_template.create_module_code_template();
9895

9996
for dep_id in federation_runtime_modules {
@@ -102,24 +99,6 @@ impl RuntimeModule for EmbedFederationRuntimeModule {
10299
module_executions.push_str(&module_str);
103100
module_executions.push('\n');
104101
}
105-
// #region agent log
106-
debug_log(
107-
"S3",
108-
"embed_federation_runtime_module.rs:103",
109-
"rspack embed federation runtime generate",
110-
serde_json::json!({
111-
"asyncStartup": self.options.experiments.async_startup,
112-
"federationRuntimeModulesCount": federation_runtime_modules_count,
113-
"entryChunk": compilation
114-
.build_chunk_graph_artifact
115-
.chunk_by_ukey
116-
.expect_get(&chunk_ukey)
117-
.id()
118-
.map(ToString::to_string),
119-
}),
120-
);
121-
// #endregion
122-
123102
if self.options.experiments.async_startup {
124103
let entry_chunk_ids = compilation
125104
.build_chunk_graph_artifact

crates/rspack_plugin_mf/src/container/expose_runtime_module.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rspack_core::{
44
};
55

66
use super::container_entry_module::CodeGenerationDataExpose;
7-
use crate::{debug_log, utils::json_stringify};
7+
use crate::utils::json_stringify;
88

99
#[impl_runtime_module]
1010
#[derive(Debug)]
@@ -69,16 +69,6 @@ impl RuntimeModule for ExposeRuntimeModule {
6969
let Some(data) = self.find_expose_data(&chunk_ukey, compilation) else {
7070
return Ok(String::new());
7171
};
72-
// #region agent log
73-
debug_log(
74-
"S2",
75-
"expose_runtime_module.rs:69",
76-
"rspack expose runtime data",
77-
serde_json::json!({
78-
"shareScope": data.share_scope,
79-
}),
80-
);
81-
// #endregion
8272
let mut runtime_template = compilation.runtime_template.create_module_code_template();
8373
let module_map = data.module_map.render(&mut runtime_template);
8474
let require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE);

crates/rspack_plugin_mf/src/container/remote_runtime_module.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hash::FxHashMap;
1111
use serde::Serialize;
1212

1313
use super::remote_module::RemoteModule;
14-
use crate::{ShareScope, debug_log, utils::json_stringify};
14+
use crate::{ShareScope, utils::json_stringify};
1515

1616
static REMOTES_LOADING_TEMPLATE: &str = include_str!("./remotesLoading.ejs");
1717
static REMOTES_LOADING_RUNTIME_REQUIREMENTS: LazyLock<RuntimeGlobals> =
@@ -100,29 +100,6 @@ impl RuntimeModule for RemoteRuntimeModule {
100100
external_module.identifier(),
101101
)
102102
.expect("should have module_id at <RemoteRuntimeModule as RuntimeModule>::generate");
103-
// #region agent log
104-
if m.remote_key == "containerA" || matches!(share_scope, ShareScopeField::Multiple(_)) {
105-
debug_log(
106-
"H7",
107-
"remote_runtime_module.rs:98",
108-
"remote runtime mapping emitted",
109-
serde_json::json!({
110-
"moduleId": id.to_string(),
111-
"remoteName": m.remote_key,
112-
"request": name,
113-
"shareScope": match &m.share_scope {
114-
ShareScope::Single(scope) => serde_json::json!(scope),
115-
ShareScope::Multiple(scopes) => serde_json::json!(scopes),
116-
},
117-
"externalModuleId": external_module_id,
118-
"remoteInfo": remote_info.as_ref().map(|info| serde_json::json!({
119-
"externalType": info.external_type,
120-
"name": info.name,
121-
})),
122-
}),
123-
);
124-
}
125-
// #endregion
126103
remotes.push(id.to_string());
127104
id_to_remote_data_mapping.insert(
128105
id,

crates/rspack_plugin_mf/src/lib.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,3 @@ mod utils {
7575
serde_json::to_string(v).unwrap_or_else(|e| panic!("{e}: {v:?} should able to json stringify"))
7676
}
7777
}
78-
79-
pub fn debug_log(hypothesis_id: &str, location: &str, message: &str, data: serde_json::Value) {
80-
let timestamp = std::time::SystemTime::now()
81-
.duration_since(std::time::UNIX_EPOCH)
82-
.map(|duration| duration.as_millis())
83-
.unwrap_or_default();
84-
let payload = serde_json::json!({
85-
"sessionId": "c5c28d",
86-
"runId": "rust-stack-1",
87-
"hypothesisId": hypothesis_id,
88-
"location": location,
89-
"message": message,
90-
"data": data,
91-
"timestamp": timestamp,
92-
});
93-
if let Ok(mut file) = std::fs::OpenOptions::new()
94-
.create(true)
95-
.append(true)
96-
.open("/Users/zackjackson/rspack/.cursor/debug-c5c28d.log")
97-
{
98-
let _ = std::io::Write::write_all(&mut file, payload.to_string().as_bytes());
99-
let _ = std::io::Write::write_all(&mut file, b"\n");
100-
}
101-
}

crates/rspack_plugin_mf/src/sharing/consume_shared_plugin.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use super::{
2424
consume_shared_runtime_module::ConsumeSharedRuntimeModule, create_lookup_key_for_sharing,
2525
strip_lookup_layer_prefix,
2626
};
27-
use crate::{ShareScope, debug_log};
27+
use crate::ShareScope;
2828

2929
#[cacheable]
3030
#[derive(Debug, Clone, Hash)]
@@ -359,29 +359,6 @@ impl ConsumeSharedPlugin {
359359
let required_version = self
360360
.get_required_version(context, request, config.clone(), add_diagnostic)
361361
.await;
362-
// #region agent log
363-
if config.share_key == "react" || config.layer.is_some() || config.issuer_layer.is_some() {
364-
debug_log(
365-
"H2",
366-
"consume_shared_plugin.rs:359",
367-
"create consume shared module",
368-
serde_json::json!({
369-
"request": request,
370-
"context": context.as_str(),
371-
"configRequest": config.request,
372-
"issuerLayer": config.issuer_layer,
373-
"layer": config.layer,
374-
"import": config.import,
375-
"importResolved": import_resolved.clone(),
376-
"shareKey": config.share_key,
377-
"shareScope": config.share_scope,
378-
"requiredVersion": required_version.as_ref().map(ToString::to_string),
379-
"singleton": config.singleton,
380-
"eager": config.eager,
381-
}),
382-
);
383-
}
384-
// #endregion
385362
ConsumeSharedModule::new(
386363
if direct_fallback {
387364
self.get_context()

crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rspack_util::json_stringify_str;
1010
use rustc_hash::FxHashMap;
1111

1212
use super::consume_shared_plugin::ConsumeVersion;
13-
use crate::{ShareScope, debug_log, utils::json_stringify};
13+
use crate::{ShareScope, utils::json_stringify};
1414

1515
static CONSUMES_COMMON_TEMPLATE: &str = include_str!("./consumesCommon.ejs");
1616
static CONSUMES_INITIAL_TEMPLATE: &str = include_str!("./consumesInitial.ejs");
@@ -105,28 +105,6 @@ impl RuntimeModule for ConsumeSharedRuntimeModule {
105105
let fallback_source = code_gen
106106
.get(&SourceType::ConsumeShared)
107107
.map(|source| source.source().into_string_lossy().into_owned());
108-
// #region agent log
109-
if data.share_key == "react" || data.layer.is_some() {
110-
debug_log(
111-
"H6",
112-
"consume_shared_runtime_module.rs:104",
113-
"consume runtime mapping source",
114-
serde_json::json!({
115-
"moduleId": id,
116-
"shareKey": data.share_key,
117-
"shareScope": data.share_scope,
118-
"requiredVersion": data.required_version.as_ref().map(ToString::to_string),
119-
"strictVersion": data.strict_version,
120-
"singleton": data.singleton,
121-
"eager": data.eager,
122-
"layer": data.layer,
123-
"import": data.import,
124-
"hasFallbackFactory": data.fallback.is_some(),
125-
"hasFallbackSource": fallback_source.is_some(),
126-
}),
127-
);
128-
}
129-
// #endregion
130108
let share_scope_json = if enhanced {
131109
json_stringify(&data.share_scope)
132110
} else {

crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{
2121
CodeGenerationDataShareInit, DataInitInfo, ProvideSharedInfo, ShareInitData,
2222
},
2323
};
24-
use crate::{ConsumeVersion, ShareScope, debug_log};
24+
use crate::{ConsumeVersion, ShareScope};
2525

2626
#[impl_source_map_config]
2727
#[cacheable]
@@ -216,26 +216,6 @@ impl Module for ProvideSharedModule {
216216
} else {
217217
runtime_template.async_module_factory(&self.get_blocks()[0], &self.request, compilation)
218218
};
219-
// #region agent log
220-
if self.name == "react" || self.layer.is_some() {
221-
debug_log(
222-
"H4",
223-
"provide_shared_module.rs:214",
224-
"provide shared module codegen",
225-
serde_json::json!({
226-
"request": self.request,
227-
"shareKey": self.name,
228-
"shareScope": self.share_scope,
229-
"version": self.version.to_string(),
230-
"eager": self.eager,
231-
"singleton": self.singleton,
232-
"requiredVersion": self.required_version.as_ref().map(ToString::to_string),
233-
"strictVersion": self.strict_version,
234-
"layer": self.layer,
235-
}),
236-
);
237-
}
238-
// #endregion
239219
code_generation_result
240220
.data
241221
.insert(CodeGenerationDataShareInit {

0 commit comments

Comments
 (0)