Skip to content

Commit

Permalink
fix(rsc): support moduleIdStrategy hashed (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc authored May 23, 2024
1 parent 26603c3 commit 6190de2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions crates/mako/src/features/rsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::ast::file::File;
use crate::ast::js_ast::JsAst;
use crate::build::parse::ParseError;
use crate::compiler::Context;
use crate::config::{Config, LogServerComponent};
use crate::module::ModuleAst;
use crate::config::{Config, LogServerComponent, ModuleIdStrategy};
use crate::module::{ModuleAst, ModuleId};

#[derive(Serialize, Debug, Clone)]
pub struct RscClientInfo {
Expand Down Expand Up @@ -57,7 +57,13 @@ impl Rsc {
}

fn generate_client(file: &File, tpl: &str, context: Arc<Context>) -> ModuleAst {
let content = tpl.replace("{{path}}", file.relative_path.to_str().unwrap());
let path = if matches!(context.config.module_id_strategy, ModuleIdStrategy::Hashed) {
let id = ModuleId::new(file.path.to_string_lossy().to_string());
id.generate(&context)
} else {
file.relative_path.to_string_lossy().to_string()
};
let content = tpl.replace("{{path}}", path.as_str());
ModuleAst::Script(
JsAst::build(file.path.to_str().unwrap(), &content, context.clone()).unwrap(),
)
Expand Down
5 changes: 3 additions & 2 deletions examples/rsc/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const fs = require('fs');
index: path.join(root, 'src/index.tsx'),
runtime: path.join(root, 'src/server-runtime.tsx'),
},
moduleIdStrategy: 'hashed',
output: {
path: serverOutputPath,
},
Expand Down Expand Up @@ -71,10 +72,10 @@ export default () => {
umd: '__rsc_client__',
rscServer: false,
rscClient: {
// TODO: remove this
x: 1,
logServerComponent: 'error',
},
mode: 'production',
moduleIdStrategy: 'hashed',
},
hooks: {},
watch: false,
Expand Down

0 comments on commit 6190de2

Please sign in to comment.