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

Turbopack: Allow client components from foreign code in app routes #64751

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub async fn get_server_module_options_context(
let mut foreign_next_server_rules =
get_next_server_transforms_rules(next_config, ty.into_value(), mode, true, next_runtime)
.await?;
let internal_custom_rules =
let mut internal_custom_rules =
get_next_server_internal_transforms_rules(ty.into_value(), *next_config.mdx_rs().await?)
.await?;

Expand Down Expand Up @@ -622,10 +622,16 @@ pub async fn get_server_module_options_context(
ecmascript_client_reference_transition_name,
} => {
next_server_rules.extend(source_transform_rules);

let mut common_next_server_rules = vec![
get_next_react_server_components_transform_rule(next_config, true, Some(app_dir))
.await?,
];

if let Some(ecmascript_client_reference_transition_name) =
ecmascript_client_reference_transition_name
{
next_server_rules.push(get_ecma_transform_rule(
common_next_server_rules.push(get_ecma_transform_rule(
Box::new(ClientDirectiveTransformer::new(
ecmascript_client_reference_transition_name,
)),
Expand All @@ -634,10 +640,8 @@ pub async fn get_server_module_options_context(
));
}

next_server_rules.push(
get_next_react_server_components_transform_rule(next_config, true, Some(app_dir))
.await?,
);
next_server_rules.extend(common_next_server_rules.iter().cloned());
internal_custom_rules.extend(common_next_server_rules);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this rule combination & ordering game gets more and more interesting 😅


let module_options_context = ModuleOptionsContext {
esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Full),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('referencing a client component in an app route', () => {
expect(JSON.parse(await next.render('/runtime'))).toEqual({
// Turbopack's proxy components are functions
clientComponent: process.env.TURBOPACK ? 'function' : 'object',
myModuleClientComponent: process.env.TURBOPACK ? 'function' : 'object',
})
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { NextResponse } from 'next/server'
import { ClientComponent } from '../../ClientComponent'
import { MyModuleClientComponent } from 'my-module/MyModuleClientComponent'

export function GET() {
console.log('!! test GET')
return NextResponse.json({
clientComponent: typeof ClientComponent,
myModuleClientComponent: typeof MyModuleClientComponent,
})
}

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

Loading