Skip to content

Commit

Permalink
Merge branch 'canary' into sam/next-font/update-capsize-css-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
samcx committed Apr 15, 2024
2 parents 523879d + f794402 commit e6b4285
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
22 changes: 21 additions & 1 deletion packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl AppProject {
fn route_ty(self: Vc<Self>) -> ServerContextType {
ServerContextType::AppRoute {
app_dir: self.app_dir(),
ecmascript_client_reference_transition_name: Some(self.client_transition_name()),
}
}

Expand Down Expand Up @@ -328,8 +329,27 @@ impl AppProject {

#[turbo_tasks::function]
fn route_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
let transitions = [
(
ECMASCRIPT_CLIENT_TRANSITION_NAME.to_string(),
Vc::upcast(NextEcmascriptClientReferenceTransition::new(
Vc::upcast(self.client_transition()),
self.ssr_transition(),
)),
),
(
"next-dynamic".to_string(),
Vc::upcast(NextDynamicTransition::new(Vc::upcast(
self.client_transition(),
))),
),
("next-ssr".to_string(), Vc::upcast(self.ssr_transition())),
]
.into_iter()
.collect();

ModuleAssetContext::new(
Default::default(),
Vc::cell(transitions),
self.project().server_compile_time_info(),
self.route_module_options_context(),
self.route_resolve_options_context(),
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ async fn insert_next_server_special_aliases(
// the logic closely follows the one in createRSCAliases in webpack-config.ts
ServerContextType::AppSSR { app_dir }
| ServerContextType::AppRSC { app_dir, .. }
| ServerContextType::AppRoute { app_dir } => {
| ServerContextType::AppRoute { app_dir, .. } => {
import_map.insert_exact_alias(
"styled-jsx",
request_to_import_mapping(get_next_package(app_dir), "styled-jsx"),
Expand Down
22 changes: 21 additions & 1 deletion packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub enum ServerContextType {
},
AppRoute {
app_dir: Vc<FileSystemPath>,
ecmascript_client_reference_transition_name: Option<Vc<String>>,
},
Middleware,
Instrumentation,
Expand Down Expand Up @@ -616,8 +617,27 @@ pub async fn get_server_module_options_context(
..module_options_context
}
}
ServerContextType::AppRoute { .. } => {
ServerContextType::AppRoute {
app_dir,
ecmascript_client_reference_transition_name,
} => {
next_server_rules.extend(source_transform_rules);
if let Some(ecmascript_client_reference_transition_name) =
ecmascript_client_reference_transition_name
{
next_server_rules.push(get_ecma_transform_rule(
Box::new(ClientDirectiveTransformer::new(
ecmascript_client_reference_transition_name,
)),
enable_mdx_rs.is_some(),
true,
));
}

next_server_rules.push(
get_next_react_server_components_transform_rule(next_config, true, Some(app_dir))
.await?,
);

let module_options_context = ModuleOptionsContext {
esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Full),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use client'

export function ClientComponent() {
return <div>ClientComponent</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'

describe('referencing a client component in an app route', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname)),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
})

it('responds without error', async () => {
expect(JSON.parse(await next.render('/runtime'))).toEqual({
// Turbopack's proxy components are functions
clientComponent: process.env.TURBOPACK ? 'function' : 'object',
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NextResponse } from 'next/server'
import { ClientComponent } from '../../ClientComponent'

export function GET() {
return NextResponse.json({
clientComponent: typeof ClientComponent,
})
}

0 comments on commit e6b4285

Please sign in to comment.