Skip to content

Commit

Permalink
fix(next-core): adjust server alias for the context (#61690)
Browse files Browse the repository at this point in the history
### What

This PR attempts to adjust import map to `server-only` / `client-only`
close to the existing webpack configs, makes to pass more tests.

Closes PACK-2396
  • Loading branch information
kwonoj authored Feb 5, 2024
1 parent bb7577a commit a4d33d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 6 additions & 7 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,22 +532,21 @@ async fn insert_next_server_special_aliases(

// see https://github.com/vercel/next.js/blob/8013ef7372fc545d49dbd060461224ceb563b454/packages/next/src/build/webpack-config.ts#L1449-L1531
match ty {
ServerContextType::Pages { .. }
| ServerContextType::PagesData { .. }
| ServerContextType::PagesApi { .. } => {
ServerContextType::Pages { .. } => {
insert_exact_alias_map(
import_map,
project_path,
indexmap! {
"server-only" => "next/dist/compiled/server-only/index".to_string(),
"server-only" => "next/dist/compiled/server-only/empty".to_string(),
"client-only" => "next/dist/compiled/client-only/index".to_string(),
"next/dist/compiled/server-only" => "next/dist/compiled/server-only/index".to_string(),
"next/dist/compiled/server-only" => "next/dist/compiled/server-only/empty".to_string(),
"next/dist/compiled/client-only" => "next/dist/compiled/client-only/index".to_string(),
},
);
}
// TODO: should include `ServerContextType::PagesApi` routes, but that type doesn't exist.
ServerContextType::AppRSC { .. }
ServerContextType::PagesData { .. }
| ServerContextType::PagesApi { .. }
| ServerContextType::AppRSC { .. }
| ServerContextType::AppRoute { .. }
| ServerContextType::Middleware
| ServerContextType::Instrumentation => {
Expand Down
5 changes: 2 additions & 3 deletions test/turbopack-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5764,14 +5764,13 @@
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/route",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/route-edge",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server-edge"
],
"failed": [
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server-edge",
"module layer no server-only in server targets should render routes marked with restriction marks without errors /api/hello",
"module layer no server-only in server targets should render routes marked with restriction marks without errors /api/hello-edge",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /api/hello",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /api/hello-edge"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
Expand Down

0 comments on commit a4d33d4

Please sign in to comment.