Unverified Commit 95e46f73 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

report error when using "use server" on module level (#47967)

### What?

Add a error message when using "use server".

* https://github.com/vercel/turbo/pull/4477 <!-- Tobias Koppers - add
ServerDirective transform which reports unsupported -->


### Why?

Turbopack doesn't support "use server" yet.

### Other turbopack updates

* https://github.com/vercel/turbo/pull/4464 <!-- Justin Ridgewell -
Better dotenv error messages -->
* https://github.com/vercel/turbo/pull/4485 <!-- Justin Ridgewell - Add
ServerAddr::hostname method -->
parent 86cb8ec8
This diff is collapsed.
......@@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" }
# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
# General Deps
......
......@@ -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()
......
......@@ -259,6 +259,11 @@ pub async fn get_server_module_options_context(
}
ServerContextType::AppSSR { .. } => {
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
// 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.
StringVc::cell("TODO".to_string()),
)],
execution_context: Some(execution_context),
..Default::default()
};
......@@ -279,9 +284,17 @@ 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(
// 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.
StringVc::cell("TODO".to_string()),
),
],
execution_context: Some(execution_context),
..Default::default()
};
......
......@@ -108,8 +108,9 @@ fn run_async_test<'a, T>(future: impl Future<Output = T> + Send + 'a) -> T {
}
}
#[testing::fixture("tests/integration/*/*/*")]
#[testing::fixture("tests/integration/*/*/*/input")]
fn test(resource: PathBuf) {
let resource = resource.parent().unwrap().to_path_buf();
if resource.ends_with("__skipped__") || resource.ends_with("__flakey__") {
// "Skip" directories named `__skipped__`, which include test directories to
// skip. These tests are not considered truly skipped by `cargo test`, but they
......
export default function RootLayout({ children }: { children: any }) {
return (
<html>
<body>{children}</body>
</html>
);
}
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>
)
}
'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])
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment