Skip to content

Commit 7fbcf76

Browse files
fix(mf): preserve aliased remote and shared manifest links
1 parent 8a26aca commit 7fbcf76

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

crates/rspack_plugin_mf/src/manifest/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
527527
}
528528
record_shared_usage(
529529
&mut shared_usage_links,
530-
&pkg,
530+
&manifest_name,
531531
&module_identifier,
532532
module_graph,
533533
compilation,
@@ -811,7 +811,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
811811
}
812812
let rsc = build_rsc_reference_meta_from_modules(
813813
compilation,
814-
compose_remote_lookup(&federation_container_name, &module_name),
814+
compose_remote_lookup(&alias, &module_name),
815815
remote_usage_module_ids.into_iter(),
816816
);
817817
remote_list.push(StatsRemote {

crates/rspack_plugin_mf/src/manifest/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ pub fn compose_expose_lookup(container: &str, expose_path: &str) -> String {
139139
format!("{container}/{expose_key}")
140140
}
141141

142-
pub fn compose_remote_lookup(federation_container_name: &str, module_name: &str) -> String {
142+
pub fn compose_remote_lookup(remote_alias: &str, module_name: &str) -> String {
143143
if module_name.is_empty() || module_name == "." {
144-
federation_container_name.to_string()
144+
remote_alias.to_string()
145145
} else {
146-
format!("{federation_container_name}/{module_name}")
146+
format!("{remote_alias}/{module_name}")
147147
}
148148
}
149149

tests/rspack-test/configCases/container-1-5/manifest-rsc-references/exposed-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import remoteButton from "remote/Button";
3+
import remoteButton from "@remote/alias/Button";
44
import { SharedClientComponent, sharedAction, sharedValue } from "shared-rsc";
55

66
export default function ExposedButton() {

tests/rspack-test/configCases/container-1-5/manifest-rsc-references/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ it("should capture RSC references for shared modules by package key", () => {
1212
expect(shared.shareKey).toBe("rsc-shared-key");
1313
expect(shared.rsc).toBeDefined();
1414
expect(shared.rsc.lookup).toBe(shared.shareKey);
15+
expect(shared.usedIn).toEqual(
16+
expect.arrayContaining(["exposed-client.js", "rsc-consumer.js"])
17+
);
1518
expect(shared.rsc.moduleType).toBe("client");
1619
expect(shared.rsc.clientReferences).toEqual(
1720
expect.arrayContaining(["SharedClientComponent", "sharedAction", "sharedValue"])
@@ -28,16 +31,17 @@ it("should capture RSC references for exposes by remoteName/exposeKey", () => {
2831
expect(expose.rsc.clientReferences).toEqual(
2932
expect.arrayContaining(["default", "exposedAction"])
3033
);
34+
expect(expose.requires).toContain("shared-rsc");
3135
expect(expose.rsc.serverActions.length).toBeGreaterThan(0);
3236
});
3337

3438
it("should capture RSC context for remote module consumption", () => {
3539
const remoteButton = stats.remotes.find(
36-
item => item.alias === "remote" && item.moduleName === "Button"
40+
item => item.alias === "@remote/alias" && item.moduleName === "Button"
3741
);
3842
expect(remoteButton).toBeDefined();
3943
expect(remoteButton.rsc).toBeDefined();
40-
expect(remoteButton.rsc.lookup).toBe("remote/Button");
44+
expect(remoteButton.rsc.lookup).toBe("@remote/alias/Button");
4145
expect(remoteButton.rsc.moduleType).toBe("server");
4246
});
4347

@@ -66,10 +70,10 @@ it("should persist RSC metadata in mf-manifest.json", () => {
6670
expect(manifest.remotes).toEqual(
6771
expect.arrayContaining([
6872
expect.objectContaining({
69-
alias: "remote",
73+
alias: "@remote/alias",
7074
moduleName: "Button",
7175
rsc: expect.objectContaining({
72-
lookup: "remote/Button"
76+
lookup: "@remote/alias/Button"
7377
})
7478
})
7579
])

tests/rspack-test/configCases/container-1-5/manifest-rsc-references/rsc-consumer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use server";
22

3-
import remoteButton from "remote/Button";
3+
import remoteButton from "@remote/alias/Button";
44
import { sharedAction, sharedValue } from "shared-rsc";
55

66
export async function consumeRemoteAndShared() {

tests/rspack-test/configCases/container-1-5/manifest-rsc-references/rspack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = {
6767
},
6868
remoteType: "script",
6969
remotes: {
70-
remote: "remote@http://localhost:8000/remoteEntry.js"
70+
"@remote/alias": "remote@http://localhost:8000/remoteEntry.js"
7171
},
7272
shared: {
7373
"shared-rsc": {

0 commit comments

Comments
 (0)