Skip to content

Commit

Permalink
create forked impl for Link component (#73019)
Browse files Browse the repository at this point in the history
There's significant drift between how Link is implemented in pages vs app dir, and we're planning to make even more changes. (For example, we want to change the intersection observer prefetch behavior, but only in app router)

To simplify this drift in behavior, this will alias `next/link` to `client/app-dir/link.tsx` in app dir bundles. 

There is no change in behavior to the `link` component in this PR. The next PR in the stack will remove the current forked handling to remove things that are irrelevant to the router it's rendered in.
  • Loading branch information
ztanner authored and wyattjoh committed Nov 28, 2024
1 parent 34ad55b commit 5ae0101
Show file tree
Hide file tree
Showing 3 changed files with 780 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ pub async fn get_next_client_import_map(
"next/dynamic",
request_to_import_mapping(project_path, "next/dist/shared/lib/app-dynamic"),
);
import_map.insert_exact_alias(
"next/link",
request_to_import_mapping(project_path, "next/dist/client/app-dir/link"),
);
}
ClientContextType::Fallback => {}
ClientContextType::Other => {}
Expand Down Expand Up @@ -365,6 +369,10 @@ pub async fn get_next_server_import_map(
"next/dynamic",
request_to_import_mapping(project_path, "next/dist/shared/lib/app-dynamic"),
);
import_map.insert_exact_alias(
"next/link",
request_to_import_mapping(project_path, "next/dist/client/app-dir/link"),
)
}
ServerContextType::Middleware { .. } | ServerContextType::Instrumentation { .. } => {}
}
Expand Down Expand Up @@ -469,6 +477,10 @@ pub async fn get_next_edge_import_map(
"next/dynamic",
request_to_import_mapping(project_path, "next/dist/shared/lib/app-dynamic"),
);
import_map.insert_exact_alias(
"next/link",
request_to_import_mapping(project_path, "next/dist/client/app-dir/link"),
)
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/next/src/build/create-compiler-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export function createAppRouterApiAliases(isServerOnlyLayer: boolean) {
const mapping: Record<string, string> = {
head: 'next/dist/client/components/noop-head',
dynamic: 'next/dist/api/app-dynamic',
link: 'next/dist/client/app-dir/link',
}

if (isServerOnlyLayer) {
Expand Down
Loading

0 comments on commit 5ae0101

Please sign in to comment.