Skip to content

Commit

Permalink
Remove ServerDirectiveTransformer (#56496)
Browse files Browse the repository at this point in the history
As discussed with @jridgewell this removes the hard error when using
`"use server"` in Turbopack.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
timneutkens and kodiakhq[bot] authored Oct 6, 2023
1 parent f954212 commit bfdb349
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
6 changes: 0 additions & 6 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,7 +19,6 @@ use turbopack_binding::{
},
dev::{react_refresh::assert_can_resolve_react_refresh, DevChunkingContext},
ecmascript::chunk::EcmascriptChunkingContext,
ecmascript_plugin::transform::directives::server::ServerDirectiveTransformer,
node::execution_context::ExecutionContext,
turbopack::{
condition::ContextCondition,
Expand Down Expand Up @@ -232,11 +231,6 @@ pub async fn get_client_module_options_context(
*get_emotion_transform_plugin(next_config).await?,
*get_styled_components_transform_plugin(next_config).await?,
*get_styled_jsx_transform_plugin().await?,
Some(Vc::cell(Box::new(ServerDirectiveTransformer::new(
// 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.
&Vc::cell("TODO".to_string()),
)) as _)),
]
.into_iter()
.flatten()
Expand Down
14 changes: 14 additions & 0 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ pub async fn get_next_server_import_map(
"next/dist/build/webpack/loaders/next-flight-loader/action-proxy",
),
);
import_map.insert_exact_alias(
"private-next-rsc-action-client-wrapper",
request_to_import_mapping(
project_path,
"next/dist/build/webpack/loaders/next-flight-loader/action-client-wrapper",
),
);
import_map.insert_exact_alias(
"private-next-rsc-action-validate",
request_to_import_mapping(
project_path,
"next/dist/build/webpack/loaders/next-flight-loader/action-validate",
),
);
import_map.insert_exact_alias(
"next/head",
request_to_import_mapping(project_path, "next/dist/client/components/noop-head"),
Expand Down
23 changes: 6 additions & 17 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use turbopack_binding::{
resolve::{parse::Request, pattern::Pattern},
},
ecmascript::TransformPlugin,
ecmascript_plugin::transform::directives::{
client::ClientDirectiveTransformer, server::ServerDirectiveTransformer,
},
ecmascript_plugin::transform::directives::client::ClientDirectiveTransformer,
node::execution_context::ExecutionContext,
turbopack::{
condition::ContextCondition,
Expand Down Expand Up @@ -276,12 +274,6 @@ pub async fn get_server_module_options_context(
let styled_components_transform_plugin =
*get_styled_components_transform_plugin(next_config).await?;
let styled_jsx_transform_plugin = *get_styled_jsx_transform_plugin().await?;
let server_directive_transform_plugin =
Some(Vc::cell(Box::new(ServerDirectiveTransformer::new(
// 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.
&Vc::cell("TODO".to_string()),
)) as _));

// ModuleOptionsContext related options
let tsconfig = get_typescript_transform_options(project_path);
Expand Down Expand Up @@ -374,7 +366,6 @@ pub async fn get_server_module_options_context(
let mut base_source_transforms: Vec<Vc<TransformPlugin>> = vec![
styled_components_transform_plugin,
styled_jsx_transform_plugin,
server_directive_transform_plugin,
]
.into_iter()
.flatten()
Expand Down Expand Up @@ -433,13 +424,11 @@ pub async fn get_server_module_options_context(
ecmascript_client_reference_transition_name,
..
} => {
let mut base_source_transforms: Vec<Vc<TransformPlugin>> = vec![
styled_components_transform_plugin,
server_directive_transform_plugin,
]
.into_iter()
.flatten()
.collect();
let mut base_source_transforms: Vec<Vc<TransformPlugin>> =
vec![styled_components_transform_plugin]
.into_iter()
.flatten()
.collect();

if let Some(ecmascript_client_reference_transition_name) =
ecmascript_client_reference_transition_name
Expand Down

0 comments on commit bfdb349

Please sign in to comment.