Skip to content

Commit fe93126

Browse files
committed
enable ServerDirective transform and add test case
1 parent 4b25f96 commit fe93126

File tree

8 files changed

+89
-3
lines changed

8 files changed

+89
-3
lines changed

packages/next-swc/crates/next-core/src/next_client/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use turbo_binding::{
1919
free_var_references,
2020
},
2121
dev::DevChunkingContextVc,
22+
ecmascript::EcmascriptInputTransform,
2223
env::ProcessEnvAssetVc,
2324
node::execution_context::ExecutionContextVc,
2425
turbopack::{
@@ -175,6 +176,9 @@ pub async fn get_client_module_options_context(
175176
};
176177

177178
let module_options_context = ModuleOptionsContext {
179+
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
180+
StringVc::cell("TODO".to_string()),
181+
)],
178182
preset_env_versions: Some(env),
179183
execution_context: Some(execution_context),
180184
..Default::default()

packages/next-swc/crates/next-core/src/next_server/context.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ pub async fn get_server_module_options_context(
259259
}
260260
ServerContextType::AppSSR { .. } => {
261261
let module_options_context = ModuleOptionsContext {
262+
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
263+
StringVc::cell("TODO".to_string()),
264+
)],
262265
execution_context: Some(execution_context),
263266
..Default::default()
264267
};
@@ -279,9 +282,12 @@ pub async fn get_server_module_options_context(
279282
}
280283
ServerContextType::AppRSC { .. } => {
281284
let module_options_context = ModuleOptionsContext {
282-
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ClientDirective(
283-
StringVc::cell("server-to-client".to_string()),
284-
)],
285+
custom_ecmascript_transforms: vec![
286+
EcmascriptInputTransform::ClientDirective(StringVc::cell(
287+
"server-to-client".to_string(),
288+
)),
289+
EcmascriptInputTransform::ServerDirective(StringVc::cell("TODO".to_string())),
290+
],
285291
execution_context: Some(execution_context),
286292
..Default::default()
287293
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use server'
2+
3+
export default async function Action() {
4+
return 42
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function RootLayout({ children }: { children: any }) {
2+
return (
3+
<html>
4+
<body>{children}</body>
5+
</html>
6+
);
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Test from './test'
2+
3+
export default async function Page() {
4+
let action
5+
try {
6+
await import('./action')
7+
} catch (e) {
8+
action = e.toString()
9+
}
10+
return (
11+
<div>
12+
<Test action={action} />
13+
</div>
14+
)
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
5+
export default function Test({ action }) {
6+
useEffect(() => {
7+
import('@turbo/pack-test-harness').then(() => {
8+
it('should run', () => {})
9+
it('should throw an error when importing server action in client component', async () => {
10+
await expect(import('./action')).rejects.toMatchObject({
11+
message:
12+
/Server actions \("use server"\) are not yet supported in Turbopack/,
13+
})
14+
})
15+
it('should throw an error when importing server action in server component', () => {
16+
expect(action).toMatch(
17+
/Server actions \("use server"\) are not yet supported in Turbopack/
18+
)
19+
})
20+
})
21+
return () => {}
22+
}, [action])
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
experimental: {
3+
appDir: true,
4+
},
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PlainIssue {
2+
severity: Error,
3+
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app/action.tsx",
4+
category: "unsupported",
5+
title: "Server actions (\"use server\") are not yet supported in Turbopack",
6+
description: "",
7+
detail: "",
8+
documentation_link: "",
9+
source: None,
10+
sub_issues: [],
11+
processing_path: Some(
12+
[
13+
PlainIssueProcessingPathItem {
14+
context: Some(
15+
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/use-server/input/app",
16+
),
17+
description: "Next.js App Page Route /",
18+
},
19+
],
20+
),
21+
}

0 commit comments

Comments
 (0)