Skip to content

Commit b167889

Browse files
committed
fix: JsModuleInfo
1 parent 5bd92b5 commit b167889

File tree

6 files changed

+45
-65
lines changed

6 files changed

+45
-65
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node_binding/binding.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ export interface JsModuleDescriptor {
799799

800800
export interface JsModuleInfo {
801801
moduleId: string
802-
isAsync: boolean
802+
async: boolean
803803
}
804804

805805
export interface JsModulePair {

crates/node_binding/src/raw_options/raw_builtins/raw_flight_client_entry_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use rustc_hash::FxHashMap as HashMap;
77
#[napi(object, object_from_js = false)]
88
pub struct JsModuleInfo {
99
pub module_id: String,
10-
pub is_async: bool,
10+
pub r#async: bool,
1111
}
1212

1313
impl From<ModuleInfo> for JsModuleInfo {
1414
fn from(value: ModuleInfo) -> Self {
1515
JsModuleInfo {
1616
module_id: value.module_id,
17-
is_async: value.is_async,
17+
r#async: value.r#async,
1818
}
1919
}
2020
}

crates/rspack_plugin_next_flight_client_entry/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tokio = { workspace = true, features = ["rt"] }
2929
tracing = { workspace = true }
3030
futures = { workspace = true }
3131
querystring = { version = "1.1.0" }
32+
form_urlencoded = "1.2.1"
3233
sugar_path= { workspace = true }
3334
serde_urlencoded = "0.7.1"
3435
lazy-regex = "3.4.1"

crates/rspack_plugin_next_flight_client_entry/src/lib.rs

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Actions = HashMap<String, Action>;
5454
#[derive(Clone, Serialize)]
5555
pub struct ModuleInfo {
5656
pub module_id: String,
57-
pub is_async: bool,
57+
pub r#async: bool,
5858
}
5959

6060
#[derive(Default, Clone)]
@@ -449,12 +449,6 @@ pub struct Manifest {
449449
pub edge: Actions,
450450
}
451451

452-
#[derive(Serialize)]
453-
pub struct LoaderParams {
454-
pub modules: String,
455-
pub server: bool,
456-
}
457-
458452
#[plugin]
459453
#[derive(Debug)]
460454
pub struct FlightClientEntryPlugin {
@@ -638,6 +632,7 @@ impl FlightClientEntryPlugin {
638632

639633
let mut should_invalidate = false;
640634

635+
// client_imports key 缺少
641636
let mut modules: Vec<_> = client_imports
642637
.keys()
643638
.map(|client_import_path| {
@@ -658,61 +653,43 @@ impl FlightClientEntryPlugin {
658653
// server is using the ESM build (when using the Edge runtime), we need to
659654
// replace them.
660655
let client_browser_loader = {
661-
let modules = if self.is_edge_server {
662-
modules
663-
.iter()
664-
.map(|(request, ids)| {
665-
serde_json::to_string(&json!({
666-
"request": request.replace(
667-
r"/next/dist/esm/",
668-
&format!("/next/dist/{}", std::path::MAIN_SEPARATOR)
669-
),
670-
"ids": ids
671-
}))
672-
.unwrap()
673-
})
674-
.join(",")
675-
} else {
676-
modules
677-
.iter()
678-
.map(|(request, ids)| {
679-
serde_json::to_string(&json!({
680-
"request": request,
681-
"ids": ids
682-
}))
683-
.unwrap()
684-
})
685-
.join(",")
686-
};
687-
let params = LoaderParams {
688-
modules,
689-
server: false,
690-
};
691-
format!(
692-
"next-flight-client-entry-loader?{}!",
693-
serde_urlencoded::to_string(params).unwrap()
694-
)
695-
};
696-
697-
let client_server_loader = {
698-
let modules = modules
699-
.iter()
700-
.map(|(request, ids)| {
656+
let mut serializer = form_urlencoded::Serializer::new(String::new());
657+
for (request, ids) in &modules {
658+
let module_json = if self.is_edge_server {
659+
serde_json::to_string(&json!({
660+
"request": request.replace(
661+
r"/next/dist/esm/",
662+
&format!("/next/dist/{}", std::path::MAIN_SEPARATOR)
663+
),
664+
"ids": ids
665+
}))
666+
.unwrap()
667+
} else {
701668
serde_json::to_string(&json!({
702669
"request": request,
703670
"ids": ids
704671
}))
705672
.unwrap()
706-
})
707-
.join(",");
708-
let params = LoaderParams {
709-
modules,
710-
server: true,
711-
};
712-
format!(
713-
"next-flight-client-entry-loader?{}!",
714-
serde_urlencoded::to_string(params).unwrap()
715-
)
673+
};
674+
serializer.append_pair("modules", &module_json);
675+
}
676+
serializer.append_pair("server", "false");
677+
678+
format!("next-flight-client-entry-loader?{}!", serializer.finish())
679+
};
680+
681+
let client_server_loader = {
682+
let mut serializer = form_urlencoded::Serializer::new(String::new());
683+
for (request, ids) in &modules {
684+
let module_json = serde_json::to_string(&json!({
685+
"request": request,
686+
"ids": ids
687+
}))
688+
.unwrap();
689+
serializer.append_pair("modules", &module_json);
690+
}
691+
serializer.append_pair("server", "true");
692+
format!("next-flight-client-entry-loader?{}!", serializer.finish())
716693
};
717694

718695
// Add for the client compilation
@@ -825,7 +802,7 @@ impl FlightClientEntryPlugin {
825802
bundle_path.to_string(),
826803
ModuleInfo {
827804
module_id: "".to_string(), // TODO: What's the meaning of this?
828-
is_async: false,
805+
r#async: false,
829806
},
830807
);
831808

@@ -1060,6 +1037,7 @@ impl FlightClientEntryPlugin {
10601037
// compiler: compiler.clone(),
10611038
// compilation: compilation.clone(),
10621039
entry_name: name.to_string(),
1040+
// client_component_imports keys 缺少很多
10631041
client_imports: component_info.client_component_imports,
10641042
bundle_path: bundle_path.clone(),
10651043
absolute_page_path: entry_request.to_string_lossy().to_string(),
@@ -1293,7 +1271,7 @@ impl FlightClientEntryPlugin {
12931271
.or_insert_with(Default::default);
12941272
let module_info = ModuleInfo {
12951273
module_id: module_id.to_string(),
1296-
is_async: ModuleGraph::is_async(&compilation, module_identifier),
1274+
r#async: ModuleGraph::is_async(&compilation, module_identifier),
12971275
};
12981276
if from_client {
12991277
module_pair.client = Some(module_info);
@@ -1458,7 +1436,7 @@ async fn after_emit(&self, compilation: &mut Compilation) -> Result<()> {
14581436

14591437
let module_info = ModuleInfo {
14601438
module_id: module_id.to_string(),
1461-
is_async: ModuleGraph::is_async(&compilation, &module.identifier()),
1439+
r#async: ModuleGraph::is_async(&compilation, &module.identifier()),
14621440
};
14631441

14641442
if self.is_edge_server {
@@ -1492,7 +1470,7 @@ async fn after_emit(&self, compilation: &mut Compilation) -> Result<()> {
14921470

14931471
let module_info = ModuleInfo {
14941472
module_id: module_id.to_string(),
1495-
is_async: ModuleGraph::is_async(&compilation, &module.identifier()),
1473+
r#async: ModuleGraph::is_async(&compilation, &module.identifier()),
14961474
};
14971475

14981476
if self.is_edge_server {

crates/rspack_plugin_next_flight_client_entry/src/loader_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ pub fn is_client_component_entry_module(module: &dyn Module) -> bool {
5858
// Determine if the whole module is client action, 'use server' in nested closure in the client module
5959
fn is_action_client_layer_module(module: &dyn Module) -> bool {
6060
let build_info = get_module_build_info(module);
61-
build_info.rsc.r#type == RSC_MODULE_TYPES.client
61+
build_info.rsc.actions.is_some() && build_info.rsc.r#type == RSC_MODULE_TYPES.client
6262
}

0 commit comments

Comments
 (0)