Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rsc plugin #5824

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
73f315d
feat: client entry plugin
JiangWeixian Feb 26, 2024
23ce18c
feat: set directives in build_info
JiangWeixian Mar 1, 2024
5fd1e5a
feat: client ref manifest plugin
JiangWeixian Mar 6, 2024
a4272b0
fix: support css
JiangWeixian Mar 12, 2024
e924cbe
chore: re impl based on 0.5.7
JiangWeixian Mar 20, 2024
6b720c6
perf: skip imported entry visited
JiangWeixian Mar 21, 2024
610387e
perf: uniq client imports from main entry
JiangWeixian Mar 21, 2024
dd403b9
chore: revert template code
JiangWeixian Mar 21, 2024
d520483
ref: re impl in 0.5.9
JiangWeixian Mar 30, 2024
14ccb6b
fix: keep imports in order
JiangWeixian Apr 10, 2024
3cc57c4
fix: client directives
JiangWeixian Apr 10, 2024
27b9a5f
chore: re impl in 0.6.2
JiangWeixian Apr 18, 2024
485526a
chore: output ref manifest to server dir
JiangWeixian Apr 18, 2024
d3dbd85
feat: ssr module mapping
JiangWeixian Apr 20, 2024
6cc3c70
feat: routes
JiangWeixian Apr 22, 2024
a8690c2
fix: generate client boundary ref only
JiangWeixian Apr 23, 2024
14c7d65
fix: remove debug code
JiangWeixian Apr 25, 2024
7993f74
fix: shared data muteable
JiangWeixian May 9, 2024
7759e3a
chore: rebase 0.7.0
JiangWeixian Jun 3, 2024
9eb9e83
fix: lint
JiangWeixian Jun 3, 2024
ba4b499
ref: remove server ref plugin
JiangWeixian May 16, 2024
630c7e9
feat: rsc proxy loader
JiangWeixian May 17, 2024
4595c69
feat: rsc client entry loader
JiangWeixian May 17, 2024
5f06e86
feat: rsc proxy and manifest plugin
JiangWeixian May 22, 2024
c500ce2
chore: resolve entry options
JiangWeixian Jun 4, 2024
537fd2a
fix: hmr
JiangWeixian Jun 5, 2024
b28d520
chore: rename module_proxy
JiangWeixian Jun 5, 2024
87ae02d
feat: rsc flag
JiangWeixian Jun 5, 2024
5ab0cf7
docs: add ref
JiangWeixian Jun 5, 2024
58e22a7
chore: use visitor from rsc plugin
JiangWeixian Jun 5, 2024
f5442b6
fix: css parse error recovery
JiangWeixian Jun 6, 2024
2445b87
chore: rm debug code
JiangWeixian Jun 12, 2024
a31cff3
fix: css id with query
JiangWeixian Jun 13, 2024
b809782
ref: use add_include
JiangWeixian Jun 20, 2024
66d65f9
feat: use server (#1)
JiangWeixian Jun 24, 2024
d0b63e3
chore: rebase
JiangWeixian Jun 30, 2024
6c27f11
fix: compat with css.type undefined
JiangWeixian Jul 1, 2024
a9cf9c3
chore: docs code
JiangWeixian Jul 2, 2024
5ce4638
fix: hmr happy
JiangWeixian Jul 2, 2024
3b7d215
chore: check hash prevent file change
JiangWeixian Jul 11, 2024
1d19852
fix: indentify visited module by entry
JiangWeixian Jul 12, 2024
8da35c7
chore: use or_insert_with
JiangWeixian Jul 15, 2024
f759ddd
perf: use rwlock and check asset version
JiangWeixian Jul 24, 2024
2ce322b
perf: use asset version
JiangWeixian Jul 24, 2024
9bfd6ba
chore: remove debug code
JiangWeixian Jul 25, 2024
179ab30
chore: rebase 1.0.0-beta-4
JiangWeixian Aug 12, 2024
1d22571
chore: rebase at 0814
JiangWeixian Aug 14, 2024
976a682
fix: name for condition
JiangWeixian Aug 14, 2024
94ed332
chore: use make
JiangWeixian Aug 15, 2024
025a42e
fix: resourcequery
JiangWeixian Sep 11, 2024
0250c76
chore: rebase 1.0.3
JiangWeixian Sep 12, 2024
019ae7b
fix: compat with mf
JiangWeixian Sep 24, 2024
f602093
chore: rebase 1.1.x
JiangWeixian Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ rspack_plugin_progress = { version = "0.2.0", path = "crates/rsp
rspack_plugin_real_content_hash = { version = "0.2.0", path = "crates/rspack_plugin_real_content_hash" }
rspack_plugin_remove_duplicate_modules = { version = "0.2.0", path = "crates/rspack_plugin_remove_duplicate_modules" }
rspack_plugin_remove_empty_chunks = { version = "0.2.0", path = "crates/rspack_plugin_remove_empty_chunks" }
rspack_plugin_rsc = { version = "0.2.0", path = "crates/rspack_plugin_rsc" }
rspack_plugin_runtime = { version = "0.2.0", path = "crates/rspack_plugin_runtime" }
rspack_plugin_runtime_chunk = { version = "0.2.0", path = "crates/rspack_plugin_runtime_chunk" }
rspack_plugin_schemes = { version = "0.2.0", path = "crates/rspack_plugin_schemes" }
Expand Down
19 changes: 18 additions & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ export declare enum BuiltinPluginName {
BundlerInfoRspackPlugin = 'BundlerInfoRspackPlugin',
CssExtractRspackPlugin = 'CssExtractRspackPlugin',
JsLoaderRspackPlugin = 'JsLoaderRspackPlugin',
LazyCompilationPlugin = 'LazyCompilationPlugin'
LazyCompilationPlugin = 'LazyCompilationPlugin',
RSCClientEntryRspackPlugin = 'RSCClientEntryRspackPlugin',
RSCClientReferenceManifestRspackPlugin = 'RSCClientReferenceManifestRspackPlugin',
RSCProxyRspackPlugin = 'RSCProxyRspackPlugin'
}

export declare function cleanupGlobalTrace(): void
Expand Down Expand Up @@ -1392,6 +1395,7 @@ export interface RawExperiments {
incremental?: false | { [key: string]: boolean }
rspackFuture?: RawRspackFuture
cache: boolean | { type: "persistent" } & RawExperimentCacheOptionsPersistent | { type: "memory" }
rsc: boolean
}

export interface RawExperimentSnapshotOptions {
Expand Down Expand Up @@ -1853,6 +1857,11 @@ export interface RawProvideOptions {
strictVersion?: boolean
}

export interface RawReactRoute {
name: ChunkName
import: RoutePath
}

export interface RawRelated {
sourceMap?: string
}
Expand Down Expand Up @@ -1919,6 +1928,14 @@ export interface RawResolveTsconfigOptions {
references?: Array<string>
}

export interface RawRscClientEntryRspackPluginOptions {
routes?: Array<RawReactRoute>
}

export interface RawRscClientReferenceManifestRspackPluginOptions {
routes?: Array<RawReactRoute>
}

export interface RawRspackFuture {

}
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_values/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rspack_plugin_progress = { workspace = true }
rspack_plugin_real_content_hash = { workspace = true }
rspack_plugin_remove_duplicate_modules = { workspace = true }
rspack_plugin_remove_empty_chunks = { workspace = true }
rspack_plugin_rsc = { workspace = true }
rspack_plugin_runtime = { workspace = true }
rspack_plugin_runtime_chunk = { workspace = true }
rspack_plugin_schemes = { workspace = true }
Expand Down
53 changes: 53 additions & 0 deletions crates/rspack_binding_values/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ use rspack_loader_preact_refresh::PREACT_REFRESH_LOADER_IDENTIFIER;
use rspack_loader_react_refresh::REACT_REFRESH_LOADER_IDENTIFIER;
use rspack_loader_swc::{SwcLoader, SWC_LOADER_IDENTIFIER};
use rspack_paths::Utf8Path;
use rspack_plugin_rsc::{
RSCClientEntryLoader, RSCProxyLoader, RSCServerActionClientLoader, RSCServerActionServerLoader,
RSC_CLIENT_ENTRY_LOADER_IDENTIFIER, RSC_PROXY_LOADER_IDENTIFIER,
RSC_SERVER_ACTION_CLIENT_LOADER_IDENTIFIER, RSC_SERVER_ACTION_SERVER_LOADER_IDENTIFIER,
};
use rustc_hash::FxHashMap;
use tokio::sync::RwLock;

Expand Down Expand Up @@ -123,6 +128,54 @@ pub async fn get_builtin_loader(builtin: &str, options: Option<&str>) -> Result<
if builtin.starts_with(rspack_loader_testing::NO_PASS_THROUGH_LOADER_IDENTIFIER) {
return Ok(Arc::new(rspack_loader_testing::NoPassthroughLoader));
}
if builtin.starts_with(RSC_PROXY_LOADER_IDENTIFIER) {
return Ok(Arc::new(
RSCProxyLoader::new(serde_json::from_str(options.as_ref()).map_err(|e| {
serde_error_to_miette(
e,
options,
"failed to parse builtin:rsc-proxy-loader options",
)
})?)
.with_identifier(builtin.into()),
));
}
if builtin.starts_with(RSC_CLIENT_ENTRY_LOADER_IDENTIFIER) {
return Ok(Arc::new(
RSCClientEntryLoader::new(serde_json::from_str(options.as_ref()).map_err(|e| {
serde_error_to_miette(
e,
options,
"failed to parse builtin:rsc-client-entry-loader options",
)
})?)
.with_identifier(builtin.into()),
));
}
if builtin.starts_with(RSC_SERVER_ACTION_SERVER_LOADER_IDENTIFIER) {
return Ok(Arc::new(
RSCServerActionServerLoader::new(serde_json::from_str(options.as_ref()).map_err(|e| {
serde_error_to_miette(
e,
options,
"failed to parse builtin:rsc-server-action-server-loader options",
)
})?)
.with_identifier(builtin.into()),
));
}
if builtin.starts_with(RSC_SERVER_ACTION_CLIENT_LOADER_IDENTIFIER) {
return Ok(Arc::new(
RSCServerActionClientLoader::new(serde_json::from_str(options.as_ref()).map_err(|e| {
serde_error_to_miette(
e,
options,
"failed to parse builtin:rsc-server-client-server-loader options",
)
})?)
.with_identifier(builtin.into()),
));
}
unreachable!("Unexpected builtin loader: {builtin}")
}

Expand Down
26 changes: 23 additions & 3 deletions crates/rspack_binding_values/src/raw_options/raw_builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod raw_lightning_css_minimizer;
mod raw_limit_chunk_count;
mod raw_mf;
mod raw_progress;
mod raw_rsc;
mod raw_runtime_chunk;
mod raw_size_limits;
mod raw_swc_js_minimizer;
Expand Down Expand Up @@ -68,6 +69,9 @@ use rspack_plugin_progress::ProgressPlugin;
use rspack_plugin_real_content_hash::RealContentHashPlugin;
use rspack_plugin_remove_duplicate_modules::RemoveDuplicateModulesPlugin;
use rspack_plugin_remove_empty_chunks::RemoveEmptyChunksPlugin;
use rspack_plugin_rsc::{
RSCClientEntryRspackPlugin, RSCClientReferenceManifestRspackPlugin, RSCProxyRspackPlugin,
};
use rspack_plugin_runtime::{
enable_chunk_loading_plugin, ArrayPushCallbackChunkFormatPlugin, BundlerInfoPlugin,
ChunkPrefetchPreloadPlugin, CommonJsChunkFormatPlugin, ModuleChunkFormatPlugin, RuntimePlugin,
Expand All @@ -92,6 +96,9 @@ pub use self::{
raw_limit_chunk_count::RawLimitChunkCountPluginOptions,
raw_mf::RawContainerPluginOptions,
raw_progress::RawProgressPluginOptions,
raw_rsc::{
RawRSCClientEntryRspackPluginOptions, RawRSCClientReferenceManifestRspackPluginOptions,
},
raw_swc_js_minimizer::RawSwcJsMinimizerRspackPluginOptions,
};
use self::{
Expand Down Expand Up @@ -192,11 +199,11 @@ pub enum BuiltinPluginName {
LightningCssMinimizerRspackPlugin,
BundlerInfoRspackPlugin,
CssExtractRspackPlugin,

// rspack js adapter plugins
// naming format follow XxxRspackPlugin
JsLoaderRspackPlugin,
LazyCompilationPlugin,
RSCClientEntryRspackPlugin,
RSCClientReferenceManifestRspackPlugin,
RSCProxyRspackPlugin,
}

#[napi(object)]
Expand Down Expand Up @@ -558,6 +565,19 @@ impl BuiltinPlugin {
let options = raw_options.into();
plugins.push(DllReferenceAgencyPlugin::new(options).boxed());
}
BuiltinPluginName::RSCClientEntryRspackPlugin => {
let plugin_options: RawRSCClientEntryRspackPluginOptions =
downcast_into::<RawRSCClientEntryRspackPluginOptions>(self.options)?;
plugins.push(RSCClientEntryRspackPlugin::new(plugin_options.into()).boxed())
}
BuiltinPluginName::RSCClientReferenceManifestRspackPlugin => {
let plugin_options: RawRSCClientReferenceManifestRspackPluginOptions =
downcast_into::<RawRSCClientReferenceManifestRspackPluginOptions>(self.options)?;
plugins.push(RSCClientReferenceManifestRspackPlugin::new(plugin_options.into()).boxed())
}
BuiltinPluginName::RSCProxyRspackPlugin => {
plugins.push(RSCProxyRspackPlugin::new(Default::default()).boxed())
}
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use napi_derive::napi;
use rspack_plugin_rsc::rsc_client_entry_rspack_plugin::RSCClientEntryRspackPluginOptions;
use rspack_plugin_rsc::rsc_client_reference_manifest_rspack_plugin::RSCClientReferenceManifestRspackPluginOptions;
use rspack_plugin_rsc::ReactRoute;
use serde::Deserialize;
use serde::Serialize;

type ChunkName = String;
type RoutePath = String;

#[derive(Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[napi(object)]
pub struct RawReactRoute {
pub name: ChunkName,
pub import: RoutePath,
}

#[derive(Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[napi(object)]
pub struct RawRSCClientEntryRspackPluginOptions {
pub routes: Option<Vec<RawReactRoute>>,
}

#[derive(Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[napi(object)]
pub struct RawRSCClientReferenceManifestRspackPluginOptions {
pub routes: Option<Vec<RawReactRoute>>,
}

impl From<RawRSCClientReferenceManifestRspackPluginOptions>
for RSCClientReferenceManifestRspackPluginOptions
{
fn from(value: RawRSCClientReferenceManifestRspackPluginOptions) -> Self {
let raw_routes = value.routes.unwrap_or_default();
let routes: Vec<ReactRoute> = raw_routes
.into_iter()
.map(|route| ReactRoute {
name: route.name,
import: route.import,
})
.collect();
RSCClientReferenceManifestRspackPluginOptions { routes }
}
}

impl From<RawRSCClientEntryRspackPluginOptions> for RSCClientEntryRspackPluginOptions {
fn from(value: RawRSCClientEntryRspackPluginOptions) -> Self {
let raw_routes = value.routes.unwrap_or_default();
let routes: Vec<ReactRoute> = raw_routes
.into_iter()
.map(|route| ReactRoute {
name: route.name,
import: route.import,
})
.collect();
RSCClientEntryRspackPluginOptions { routes }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct RawExperiments {
ts_type = r#"boolean | { type: "persistent" } & RawExperimentCacheOptionsPersistent | { type: "memory" }"#
)]
pub cache: RawExperimentCacheOptions,
pub rsc: bool,
}

impl From<RawExperiments> for Experiments {
Expand All @@ -38,6 +39,7 @@ impl From<RawExperiments> for Experiments {
top_level_await: value.top_level_await,
rspack_future: value.rspack_future.unwrap_or_default().into(),
cache: normalize_raw_experiment_cache_options(value.cache),
rsc: value.rsc,
}
}
}
1 change: 1 addition & 0 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ impl Module for ConcatenatedModule {
json_data: Default::default(),
top_level_declarations: Some(Default::default()),
module_concatenation_bailout: Default::default(),
directives: Default::default(),
};
self.clear_diagnostics();

Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct BuildInfo {
#[cacheable(with=AsOption<AsVec<AsPreset>>)]
pub top_level_declarations: Option<HashSet<Atom>>,
pub module_concatenation_bailout: Option<String>,
pub directives: Vec<String>,
}

impl Default for BuildInfo {
Expand All @@ -85,6 +86,7 @@ impl Default for BuildInfo {
json_data: None,
top_level_declarations: None,
module_concatenation_bailout: None,
directives: Vec::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/options/experiments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Experiments {
pub top_level_await: bool,
pub rspack_future: RspackFuture,
pub cache: ExperimentCacheOptions,
pub rsc: bool,
}

#[allow(clippy::empty_structs_with_brackets)]
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_loader_swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rspack_core = { workspace = true }
rspack_error = { workspace = true }
rspack_loader_runner = { workspace = true }
rspack_plugin_javascript = { workspace = true }
rspack_plugin_rsc = { path = "../rspack_plugin_rsc" }
rspack_swc_plugin_import = { workspace = true }
rspack_util = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
Loading
Loading