Skip to content

Commit 7b5f27b

Browse files
fix: use <a> tag for external rewrites instead of relying on Next's Link component (#2707)
Co-authored-by: gabriel miranda <gabrielmfern@outlook.com>
1 parent 50115fa commit 7b5f27b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

apps/web/src/components/menu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use client';
22

33
import classnames from 'classnames';
4-
import Link from 'next/link';
54
import { usePathname } from 'next/navigation';
65
import * as React from 'react';
76
import { Drawer } from 'vaul';
7+
import { SmartLink } from './smart-link';
88

99
interface MenuItemProps {
1010
className?: string;
@@ -31,7 +31,7 @@ function MenuItem({ className, children, href, onClick }: MenuItemProps) {
3131

3232
return (
3333
<li className="inline-flex w-full items-center justify-center md:w-fit">
34-
<Link
34+
<SmartLink
3535
className={classnames(
3636
'inline-flex h-8 scroll-m-2 items-center rounded-md text-slate-11 text-sm transition-colors hover:bg-slate-6 hover:text-slate-12 focus:bg-slate-6 focus:outline-none focus:ring focus:ring-slate-3 md:justify-center',
3737
'data-[active=true]:bg-slate-6 data-[active=true]:text-slate-12',
@@ -43,7 +43,7 @@ function MenuItem({ className, children, href, onClick }: MenuItemProps) {
4343
data-active={activeItem === href.replace('/', '')}
4444
>
4545
{children}
46-
</Link>
46+
</SmartLink>
4747
</li>
4848
);
4949
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Link from 'next/link';
2+
import type { ComponentProps } from 'react';
3+
4+
const EXTERNAL_REWRITE_PATHS = ['/docs'];
5+
6+
type SmartLinkProps = ComponentProps<typeof Link>;
7+
8+
/**
9+
* We'll temporarily use <a> to redirect to external domains -- apparently Next.js 16 has a router regression
10+
* where <Link> components try to do client-side navigation for rewritten paths (e.g., /docs -> mintlify.com)
11+
* The router doesn't detect these are external rewrites and attempts to fetch RSC payloads by adding
12+
* ?_rsc= query params (since the external domain doesn't serve RSC payloads, navigation fails)
13+
*
14+
* Context:
15+
* https://resend.slack.com/archives/C05R55V6GBF/p1763739968845719?thread_ts=1763732012.356639&cid=C05R55V6GBF
16+
* https://github.com/vercel/next.js/issues/86385
17+
*/
18+
export function SmartLink({ href, ...props }: SmartLinkProps) {
19+
const isExternalRewrite =
20+
typeof href === 'string' &&
21+
EXTERNAL_REWRITE_PATHS.some((path) => href.startsWith(path));
22+
23+
if (isExternalRewrite) {
24+
return <a href={href} {...(props as ComponentProps<'a'>)} />;
25+
}
26+
27+
return <Link href={href} {...props} />;
28+
}

0 commit comments

Comments
 (0)