From bfdb349ebadced0346aa5b9c017851a166c493f6 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 6 Oct 2023 11:16:57 +0200 Subject: [PATCH] Remove ServerDirectiveTransformer (#56496) As discussed with @jridgewell this removes the hard error when using `"use server"` in Turbopack. --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../next-core/src/next_client/context.rs | 6 ----- .../crates/next-core/src/next_import_map.rs | 14 +++++++++++ .../next-core/src/next_server/context.rs | 23 +++++-------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/next-swc/crates/next-core/src/next_client/context.rs b/packages/next-swc/crates/next-core/src/next_client/context.rs index fe3b43aaf1564..08069da234d60 100644 --- a/packages/next-swc/crates/next-core/src/next_client/context.rs +++ b/packages/next-swc/crates/next-core/src/next_client/context.rs @@ -19,7 +19,6 @@ use turbopack_binding::{ }, dev::{react_refresh::assert_can_resolve_react_refresh, DevChunkingContext}, ecmascript::chunk::EcmascriptChunkingContext, - ecmascript_plugin::transform::directives::server::ServerDirectiveTransformer, node::execution_context::ExecutionContext, turbopack::{ condition::ContextCondition, @@ -232,11 +231,6 @@ pub async fn get_client_module_options_context( *get_emotion_transform_plugin(next_config).await?, *get_styled_components_transform_plugin(next_config).await?, *get_styled_jsx_transform_plugin().await?, - Some(Vc::cell(Box::new(ServerDirectiveTransformer::new( - // ServerDirective is not implemented yet and always reports an issue. - // We don't have to pass a valid transition name yet, but the API is prepared. - &Vc::cell("TODO".to_string()), - )) as _)), ] .into_iter() .flatten() diff --git a/packages/next-swc/crates/next-core/src/next_import_map.rs b/packages/next-swc/crates/next-core/src/next_import_map.rs index cec5657980867..3d0f2b788b67b 100644 --- a/packages/next-swc/crates/next-core/src/next_import_map.rs +++ b/packages/next-swc/crates/next-core/src/next_import_map.rs @@ -280,6 +280,20 @@ pub async fn get_next_server_import_map( "next/dist/build/webpack/loaders/next-flight-loader/action-proxy", ), ); + import_map.insert_exact_alias( + "private-next-rsc-action-client-wrapper", + request_to_import_mapping( + project_path, + "next/dist/build/webpack/loaders/next-flight-loader/action-client-wrapper", + ), + ); + import_map.insert_exact_alias( + "private-next-rsc-action-validate", + request_to_import_mapping( + project_path, + "next/dist/build/webpack/loaders/next-flight-loader/action-validate", + ), + ); import_map.insert_exact_alias( "next/head", request_to_import_mapping(project_path, "next/dist/client/components/noop-head"), diff --git a/packages/next-swc/crates/next-core/src/next_server/context.rs b/packages/next-swc/crates/next-core/src/next_server/context.rs index d789721362c58..02f64a86c574f 100644 --- a/packages/next-swc/crates/next-core/src/next_server/context.rs +++ b/packages/next-swc/crates/next-core/src/next_server/context.rs @@ -19,9 +19,7 @@ use turbopack_binding::{ resolve::{parse::Request, pattern::Pattern}, }, ecmascript::TransformPlugin, - ecmascript_plugin::transform::directives::{ - client::ClientDirectiveTransformer, server::ServerDirectiveTransformer, - }, + ecmascript_plugin::transform::directives::client::ClientDirectiveTransformer, node::execution_context::ExecutionContext, turbopack::{ condition::ContextCondition, @@ -276,12 +274,6 @@ pub async fn get_server_module_options_context( let styled_components_transform_plugin = *get_styled_components_transform_plugin(next_config).await?; let styled_jsx_transform_plugin = *get_styled_jsx_transform_plugin().await?; - let server_directive_transform_plugin = - Some(Vc::cell(Box::new(ServerDirectiveTransformer::new( - // ServerDirective is not implemented yet and always reports an issue. - // We don't have to pass a valid transition name yet, but the API is prepared. - &Vc::cell("TODO".to_string()), - )) as _)); // ModuleOptionsContext related options let tsconfig = get_typescript_transform_options(project_path); @@ -374,7 +366,6 @@ pub async fn get_server_module_options_context( let mut base_source_transforms: Vec> = vec![ styled_components_transform_plugin, styled_jsx_transform_plugin, - server_directive_transform_plugin, ] .into_iter() .flatten() @@ -433,13 +424,11 @@ pub async fn get_server_module_options_context( ecmascript_client_reference_transition_name, .. } => { - let mut base_source_transforms: Vec> = vec![ - styled_components_transform_plugin, - server_directive_transform_plugin, - ] - .into_iter() - .flatten() - .collect(); + let mut base_source_transforms: Vec> = + vec![styled_components_transform_plugin] + .into_iter() + .flatten() + .collect(); if let Some(ecmascript_client_reference_transition_name) = ecmascript_client_reference_transition_name