Skip to content

Commit

Permalink
fix: client directives
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangWeixian committed Apr 18, 2024
1 parent 3cb5103 commit 379a35d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/rspack_plugin_rsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

mod plugin;
pub use crate::plugin::*;
mod utils;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use rspack_core::{
use rspack_error::Result;
use rspack_hook::{plugin, plugin_hook, AsyncSeries};
use serde_json::to_string;

use crate::utils::has_client_directive;

#[plugin]
#[derive(Debug, Default, Clone)]
pub struct RSCClientEntryRspackPlugin {}
Expand Down Expand Up @@ -43,9 +46,8 @@ impl RSCClientEntryRspackPlugin {
};
// TODO: check css file is in used
// TODO: unique css files from other entry
let use_client = String::from("use client");
let is_client_components = match module.build_info() {
Some(build_info) => build_info.directives.contains(&use_client),
Some(build_info) => has_client_directive(&build_info.directives),
None => false,
};
// let og = module.original_source().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use rspack_hook::{plugin, plugin_hook, AsyncSeries};
use serde::Serialize;
use serde_json::to_string;

use crate::utils::has_client_directive;

#[plugin]
#[derive(Debug, Default, Clone)]
pub struct RSCClientReferenceManifestRspackPlugin;
Expand Down Expand Up @@ -66,7 +68,6 @@ impl RSCClientReferenceManifest {
let mut client_manifest = ClientReferenceManifest {
client_modules: HashMap::default(),
};
let use_client = String::from("use client");
let mg = compilation.get_module_graph();

for chunk_group in compilation.chunk_group_by_ukey.values() {
Expand All @@ -93,7 +94,7 @@ impl RSCClientReferenceManifest {
}
// Skip non client modules
if let Some(build_info) = module.build_info()
&& !build_info.directives.contains(&use_client)
&& !has_client_directive(&build_info.directives)
{
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions crates/rspack_plugin_rsc/src/utils/has_client_directive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn has_client_directive(directives: &Vec<String>) -> bool {
// TODO: client directives should config by plugin options
let client_directives = vec!["use client", "use client:island"];
directives
.iter()
.any(|item| client_directives.contains(&item.as_str()))
}
2 changes: 2 additions & 0 deletions crates/rspack_plugin_rsc/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod has_client_directive;
pub use has_client_directive::*;

0 comments on commit 379a35d

Please sign in to comment.