Skip to content

Commit 61bd287

Browse files
fix(mf): preserve consume fallback source emission
Emit consume-shared source data for shared consumers and let the runtime module reuse it when serializing consume metadata. This keeps module-output consume entries callable so layered federation consumers can initialize sharing before resolving shared react. Made-with: Cursor
1 parent 0fe891e commit 61bd287

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use rspack_core::{
88
BuildInfo, BuildMeta, BuildResult, CodeGenerationResult, Compilation, Context, DependenciesBlock,
99
DependencyId, ExportsType, FactoryMeta, LibIdentOptions, Module, ModuleCodeGenerationContext,
1010
ModuleGraph, ModuleIdentifier, ModuleLayer, ModuleType, RuntimeGlobals, RuntimeSpec, SourceType,
11-
impl_module_meta_info, impl_source_map_config, module_update_hash, rspack_sources::BoxSource,
11+
impl_module_meta_info, impl_source_map_config, module_update_hash,
12+
rspack_sources::{BoxSource, RawStringSource, SourceExt},
1213
};
1314
use rspack_error::{Result, impl_empty_diagnosable_trait};
1415
use rspack_hash::{RspackHash, RspackHashDigest};
@@ -252,6 +253,16 @@ impl Module for ConsumeSharedModule {
252253
runtime_template.async_module_factory(&self.get_blocks()[0], fallback, compilation)
253254
}
254255
});
256+
code_generation_result.add(
257+
SourceType::ConsumeShared,
258+
RawStringSource::from(factory.clone().unwrap_or_else(|| {
259+
format!(
260+
"()=>()=>{{throw new Error(\"Can not get '{}' \")}}",
261+
self.options.share_key
262+
)
263+
}))
264+
.boxed(),
265+
);
255266
code_generation_result
256267
.data
257268
.insert(CodeGenerationDataConsumeShared {

crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl RuntimeModule for ConsumeSharedRuntimeModule {
102102
.code_generation_results
103103
.get(&module, Some(chunk.runtime()));
104104
if let Some(data) = code_gen.data.get::<CodeGenerationDataConsumeShared>() {
105+
let fallback_source = code_gen
106+
.get(&SourceType::ConsumeShared)
107+
.map(|source| source.source().into_string_lossy().into_owned());
105108
let share_scope_json = if enhanced {
106109
json_stringify(&data.share_scope)
107110
} else {
@@ -133,7 +136,11 @@ impl RuntimeModule for ConsumeSharedRuntimeModule {
133136
json_stringify(&data.singleton),
134137
json_stringify(&data.eager),
135138
layer_data,
136-
data.fallback.as_deref().unwrap_or("undefined"),
139+
data
140+
.fallback
141+
.as_deref()
142+
.or(fallback_source.as_deref())
143+
.unwrap_or("undefined"),
137144
json_stringify(&data.tree_shaking_mode),
138145
));
139146
}

0 commit comments

Comments
 (0)