Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions src/components/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import Link from 'next/link';
import {NavigationLink} from '@/components/NavigationLink';
import {usePathname, useSearchParams} from 'next/navigation';

import {navigation, NavigationItem} from '@/data/navigation';
Expand Down Expand Up @@ -147,7 +147,7 @@ export function Navigation({
{separator.topics.map(topic => (
<li key={topic.title} className="relative">
<div className="flex w-full items-center justify-between">
<Link
<NavigationLink
href={prependVersion(topic.href)}
onClick={() => {
onLinkClick;
Expand All @@ -161,7 +161,7 @@ export function Navigation({
)}
>
{topic.title}
</Link>
</NavigationLink>
{topic.sections && (
<button
className="pointer-cursor rounded-md p-1 hover:bg-slate-200 dark:hover:bg-slate-800"
Expand Down Expand Up @@ -198,7 +198,7 @@ export function Navigation({
className="relative"
>
<div className="flex w-full items-center justify-between">
<Link
<NavigationLink
href={prependVersion(
section.href
)}
Expand All @@ -220,7 +220,7 @@ export function Navigation({
{
section.title
}
</Link>
</NavigationLink>
{section.subsections && (
<button
className="pointer-cursor rounded-md p-1 hover:bg-slate-200 dark:hover:bg-slate-800"
Expand Down Expand Up @@ -258,7 +258,7 @@ export function Navigation({
}
className="relative"
>
<Link
<NavigationLink
href={prependVersion(
subsection.href
)}
Expand All @@ -276,7 +276,7 @@ export function Navigation({
{
subsection.title
}
</Link>
</NavigationLink>
</li>
)
)}
Expand Down
24 changes: 24 additions & 0 deletions src/components/NavigationLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client';

import Link from 'next/link';
import {useState} from 'react';

type NavigationLinkProps = Omit<React.ComponentProps<typeof Link>, 'prefetch'>;

// The sidebar shows dozens of links at once, and Next's default prefetches
// the full static page for every link in the viewport: one page view fetched
// ~80 RSC payloads (2.4 MB decoded). Prefetch only once the user shows intent.
// https://nextjs.org/docs/app/guides/prefetching#hover-triggered-prefetch
export function NavigationLink(props: NavigationLinkProps) {
const [hasIntent, setHasIntent] = useState(false);
const markIntent = () => setHasIntent(true);

return (
<Link
{...props}
prefetch={hasIntent ? null : false}
onMouseEnter={markIntent}
onFocus={markIntent}
/>
);
}
Loading