Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()),
sokra marked this conversation as resolved.
Show resolved Hide resolved
)],
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()),
sokra marked this conversation as resolved.
Show resolved Hide resolved
)],
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