Skip to content

Commit 95e46f7

Browse files
authored
report error when using "use server" on module level (#47967)
### What? Add a error message when using "use server". * vercel/turborepo#4477 <!-- Tobias Koppers - add ServerDirective transform which reports unsupported --> ### Why? Turbopack doesn't support "use server" yet. ### Other turbopack updates * vercel/turborepo#4464 <!-- Justin Ridgewell - Better dotenv error messages --> * vercel/turborepo#4485 <!-- Justin Ridgewell - Add ServerAddr::hostname method -->
1 parent 86cb8ec commit 95e46f7

File tree

28 files changed

+131
-37
lines changed

28 files changed

+131
-37
lines changed

packages/next-swc/Cargo.lock

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next-swc/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" }
4747
testing = { version = "0.31.31" }
4848

4949
# Turbo crates
50-
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
50+
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
5151
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
52-
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
52+
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
5353
# [TODO]: need to refactor embed_directory! macro usage in next-core
54-
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
54+
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
5555

5656
# General Deps
5757

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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ 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+
// ServerDirective is not implemented yet and always reports an issue.
264+
// We don't have to pass a valid transition name yet, but the API is prepared.
265+
StringVc::cell("TODO".to_string()),
266+
)],
262267
execution_context: Some(execution_context),
263268
..Default::default()
264269
};
@@ -279,9 +284,17 @@ pub async fn get_server_module_options_context(
279284
}
280285
ServerContextType::AppRSC { .. } => {
281286
let module_options_context = ModuleOptionsContext {
282-
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ClientDirective(
283-
StringVc::cell("server-to-client".to_string()),
284-
)],
287+
custom_ecmascript_transforms: vec![
288+
EcmascriptInputTransform::ClientDirective(StringVc::cell(
289+
"server-to-client".to_string(),
290+
)),
291+
EcmascriptInputTransform::ServerDirective(
292+
// ServerDirective is not implemented yet and always reports an issue.
293+
// We don't have to pass a valid transition name yet, but the API is
294+
// prepared.
295+
StringVc::cell("TODO".to_string()),
296+
),
297+
],
285298
execution_context: Some(execution_context),
286299
..Default::default()
287300
};

packages/next-swc/crates/next-dev-tests/tests/integration.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ fn run_async_test<'a, T>(future: impl Future<Output = T> + Send + 'a) -> T {
108108
}
109109
}
110110

111-
#[testing::fixture("tests/integration/*/*/*")]
111+
#[testing::fixture("tests/integration/*/*/*/input")]
112112
fn test(resource: PathBuf) {
113+
let resource = resource.parent().unwrap().to_path_buf();
113114
if resource.ends_with("__skipped__") || resource.ends_with("__flakey__") {
114115
// "Skip" directories named `__skipped__`, which include test directories to
115116
// skip. These tests are not considered truly skipped by `cargo test`, but they
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+
}

0 commit comments

Comments
 (0)