Skip to content

Commit

Permalink
enable ServerDirective transform and add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 5, 2023
1 parent 967259e commit 4ea155d
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use turbo_binding::{
free_var_references,
},
dev::DevChunkingContextVc,
ecmascript::EcmascriptInputTransform,
env::ProcessEnvAssetVc,
node::execution_context::ExecutionContextVc,
turbopack::{
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand All @@ -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()
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export default async function Action() {
return 42
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }: { children: any }) {
return (
<html>
<body>{children}</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Test action={action} />
</div>
)
}
Original file line number Diff line number Diff line change
@@ -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])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
};
Original file line number Diff line number Diff line change
@@ -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 /",
},
],
),
}

0 comments on commit 4ea155d

Please sign in to comment.