Skip to content

Commit

Permalink
report error when using "use server" on module level (#47967)
Browse files Browse the repository at this point in the history
### 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 -->
  • Loading branch information
sokra authored Apr 6, 2023
1 parent 86cb8ec commit 95e46f7
Show file tree
Hide file tree
Showing 28 changed files with 131 additions and 37 deletions.
60 changes: 30 additions & 30 deletions packages/next-swc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/next-swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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
19 changes: 16 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,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()
};
Expand All @@ -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()
};
Expand Down
3 changes: 2 additions & 1 deletion packages/next-swc/crates/next-dev-tests/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
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>
)
}
Loading

0 comments on commit 95e46f7

Please sign in to comment.