Skip to content

Commit 4effb24

Browse files
committed
fix: client_component_ssr_entry_dep should use client_server_loader
1 parent c7b6df2 commit 4effb24

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

crates/rspack_plugin_next_flight_client_entry/src/get_module_build_info.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use lazy_regex::Lazy;
2+
use regex::Regex;
13
use rspack_core::Module;
24
use serde::Deserialize;
35

4-
const RSPACK_RSC_MODULE_INFORMATION: &str =
5-
r"/\* __rspack_internal_rsc_module_information_do_not_use__ (\{[^}]+\}) \*/";
6+
static RSPACK_RSC_MODULE_INFORMATION: Lazy<Regex> = Lazy::new(|| {
7+
Regex::new(r"/\* __rspack_internal_rsc_module_information_do_not_use__ (\{[^}]+\}) \*/").unwrap()
8+
});
69

710
const CLIENT_DIRECTIVE: &str = "use client";
811
const SERVER_ACTION_DIRECTIVE: &str = "use server";
@@ -30,8 +33,7 @@ pub struct RSCMeta {
3033
}
3134

3235
fn get_rsc_module_information(source: &str) -> Option<RSCMeta> {
33-
regex::Regex::new(RSPACK_RSC_MODULE_INFORMATION)
34-
.unwrap()
36+
RSPACK_RSC_MODULE_INFORMATION
3537
.captures(source)
3638
.and_then(|caps| caps.get(1).map(|m| m.as_str()))
3739
.and_then(|info| serde_json::from_str(info).unwrap())

crates/rspack_plugin_next_flight_client_entry/src/lib.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use for_each_entry_module::for_each_entry_module;
2424
use futures::future::BoxFuture;
2525
use get_module_build_info::get_module_rsc_information;
2626
use is_metadata_route::is_metadata_route;
27-
use itertools::Itertools;
27+
use lazy_regex::Lazy;
2828
use loader_util::{get_actions_from_build_info, is_client_component_entry_module, is_css_mod};
2929
use regex::Regex;
3030
use rspack_collections::Identifiable;
@@ -47,6 +47,18 @@ use serde::Serialize;
4747
use serde_json::json;
4848
use sugar_path::SugarPath;
4949

50+
static NEXT_DIST_ESM_REGEX: Lazy<Regex> =
51+
Lazy::new(|| Regex::new("[\\/]next[\\/]dist[\\/]esm[\\/]").unwrap());
52+
53+
static NEXT_DIST: Lazy<String> = Lazy::new(|| {
54+
format!(
55+
"{}next{}dist{}",
56+
std::path::MAIN_SEPARATOR,
57+
std::path::MAIN_SEPARATOR,
58+
std::path::MAIN_SEPARATOR
59+
)
60+
});
61+
5062
#[derive(Clone, Serialize)]
5163
pub struct Action {
5264
pub workers: HashMap<String, ModuleInfo>,
@@ -641,7 +653,6 @@ impl FlightClientEntryPlugin {
641653

642654
let mut should_invalidate = false;
643655

644-
// client_imports key 缺少
645656
let mut modules: Vec<_> = client_imports
646657
.keys()
647658
.map(|client_import_path| {
@@ -668,10 +679,7 @@ impl FlightClientEntryPlugin {
668679
for (request, ids) in &modules {
669680
let module_json = if self.is_edge_server {
670681
serde_json::to_string(&json!({
671-
"request": request.replace(
672-
r"/next/dist/esm/",
673-
&format!("/next/dist/{}", std::path::MAIN_SEPARATOR)
674-
),
682+
"request": NEXT_DIST_ESM_REGEX.replace(request, &*NEXT_DIST),
675683
"ids": ids
676684
}))
677685
.unwrap()
@@ -722,7 +730,7 @@ impl FlightClientEntryPlugin {
722730
}
723731

724732
let client_component_ssr_entry_dep = EntryDependency::new(
725-
client_browser_loader,
733+
client_server_loader.to_string(),
726734
compilation.options.context.clone(),
727735
Some(WEBPACK_LAYERS.server_side_rendering.to_string()),
728736
false,
@@ -1045,10 +1053,7 @@ impl FlightClientEntryPlugin {
10451053
merged_css_imports.extend(component_info.css_imports);
10461054

10471055
client_entries_to_inject.push(ClientEntry {
1048-
// compiler: compiler.clone(),
1049-
// compilation: compilation.clone(),
10501056
entry_name: name.to_string(),
1051-
// client_component_imports keys 缺少很多
10521057
client_imports: component_info.client_component_imports,
10531058
bundle_path: bundle_path.clone(),
10541059
absolute_page_path: entry_request.to_string_lossy().to_string(),
@@ -1061,8 +1066,6 @@ impl FlightClientEntryPlugin {
10611066
&& bundle_path == "app/not-found"
10621067
{
10631068
client_entries_to_inject.push(ClientEntry {
1064-
// compiler: compiler.clone(),
1065-
// compilation: compilation.clone(),
10661069
entry_name: name.to_string(),
10671070
client_imports: HashMap::default(),
10681071
bundle_path: format!("app{}", UNDERSCORE_NOT_FOUND_ROUTE_ENTRY),
@@ -1126,8 +1129,6 @@ impl FlightClientEntryPlugin {
11261129
.inject_action_entry(
11271130
compilation,
11281131
ActionEntry {
1129-
// compiler: compiler.clone(),
1130-
// compilation: compilation.clone(),
11311132
actions: action_entry_imports,
11321133
entry_name: name.clone(),
11331134
bundle_path: name,
@@ -1217,8 +1218,6 @@ impl FlightClientEntryPlugin {
12171218
.inject_action_entry(
12181219
compilation,
12191220
ActionEntry {
1220-
// compiler: compiler.clone(),
1221-
// compilation: compilation.clone(),
12221221
actions: remaining_action_entry_imports,
12231222
entry_name: entry_name.clone(),
12241223
bundle_path: entry_name.clone(),

0 commit comments

Comments
 (0)