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 c60e88ee87ad2..dacbc5b36af90 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,6 +19,7 @@ use turbo_binding::{ free_var_references, }, dev::DevChunkingContextVc, + ecmascript::EcmascriptInputTransform, env::ProcessEnvAssetVc, node::execution_context::ExecutionContextVc, turbopack::{ @@ -175,6 +176,9 @@ pub async fn get_client_module_options_context( }; let module_options_context = ModuleOptionsContext { + custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective( + StringVc::cell("TODO".to_string()), + )], preset_env_versions: Some(env), execution_context: Some(execution_context), ..Default::default() 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 0eb7bba03dbf7..8f58f77f23875 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 @@ -259,6 +259,9 @@ pub async fn get_server_module_options_context( } ServerContextType::AppSSR { .. } => { let module_options_context = ModuleOptionsContext { + custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective( + StringVc::cell("TODO".to_string()), + )], execution_context: Some(execution_context), ..Default::default() }; @@ -279,9 +282,12 @@ pub async fn get_server_module_options_context( } ServerContextType::AppRSC { .. } => { let module_options_context = ModuleOptionsContext { - custom_ecmascript_transforms: vec![EcmascriptInputTransform::ClientDirective( - StringVc::cell("server-to-client".to_string()), - )], + custom_ecmascript_transforms: vec![ + EcmascriptInputTransform::ClientDirective(StringVc::cell( + "server-to-client".to_string(), + )), + EcmascriptInputTransform::ServerDirective(StringVc::cell("TODO".to_string())), + ], execution_context: Some(execution_context), ..Default::default() }; diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/action.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/action.tsx new file mode 100644 index 0000000000000..41a47cf25dfde --- /dev/null +++ b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/action.tsx @@ -0,0 +1,5 @@ +'use server' + +export default async function Action() { + return 42 +} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/layout.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/layout.tsx new file mode 100644 index 0000000000000..7f4de05aba9b3 --- /dev/null +++ b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/layout.tsx @@ -0,0 +1,7 @@ +export default function RootLayout({ children }: { children: any }) { + return ( + + {children} + + ); +} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/page.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/page.tsx new file mode 100644 index 0000000000000..1ebdc1d7496c3 --- /dev/null +++ b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/page.tsx @@ -0,0 +1,15 @@ +import Test from './test' + +export default async function Page() { + let action + try { + await import('./action') + } catch (e) { + action = e.toString() + } + return ( +
+ +
+ ) +} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/test.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/test.tsx new file mode 100644 index 0000000000000..fd5964c6add81 --- /dev/null +++ b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/test.tsx @@ -0,0 +1,23 @@ +'use client' + +import { useEffect } from 'react' + +export default function Test({ action }) { + useEffect(() => { + import('@turbo/pack-test-harness').then(() => { + it('should run', () => {}) + it('should throw an error when importing server action in client component', async () => { + await expect(import('./action')).rejects.toMatchObject({ + message: + /Server actions \("use server"\) are not yet supported in Turbopack/, + }) + }) + it('should throw an error when importing server action in server component', () => { + expect(action).toMatch( + /Server actions \("use server"\) are not yet supported in Turbopack/ + ) + }) + }) + return () => {} + }, [action]) +} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/next.config.js b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/next.config.js new file mode 100644 index 0000000000000..ed0e87891f9e8 --- /dev/null +++ b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/next.config.js @@ -0,0 +1,5 @@ +module.exports = { + experimental: { + appDir: true, + }, +}; diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/issues/Server actions (__quo__use server__quo__) are not yet supported in Turbopack-4c3b2b.txt b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/issues/Server actions (__quo__use server__quo__) are not yet supported in Turbopack-4c3b2b.txt new file mode 100644 index 0000000000000..4d6c5a7afce7f --- /dev/null +++ b/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/issues/Server actions (__quo__use server__quo__) are not yet supported in Turbopack-4c3b2b.txt @@ -0,0 +1,21 @@ +PlainIssue { + severity: Error, + context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/action.tsx", + category: "unsupported", + title: "Server actions (\"use server\") are not yet supported in Turbopack", + description: "", + detail: "", + documentation_link: "", + source: None, + sub_issues: [], + processing_path: Some( + [ + PlainIssueProcessingPathItem { + context: Some( + "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app", + ), + description: "Next.js App Page Route /", + }, + ], + ), +} \ No newline at end of file