Files
CatoandClaude 76b5c6e8dc fix(links): a link does not preload its target (#418)
Next preloads every link that scrolls into view, and these pages are drawn on
request. Measured in a browser on 2026-11-29: one visit to the home page made
27 preload requests to the server. Solon, built the same way, made 91 to 778
a visit and stopped answering under a handful of readers (solon#643).

components/link.tsx wraps next/link with prefetch={false}; all 167 files that
imported next/link import it instead, and ESLint (no-restricted-imports)
keeps a bare next/link from coming back.

pnpm run verify passes (format, types, lint, 1,144 tests).


Claude-Session: https://claude.ai/code/session_019MDtmvTCDbJAYNKQpNyKzz

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-29 17:25:02 +01:00

89 lines
2.9 KiB
TypeScript

'use client';
/**
* The bar above every page. Left to right: where you are going (search,
* which opens the palette), then the one invitation (Join), then who you are
* (the account menu, last, where a hand looks for it). Loki's AppTopBar rule
* holds here too: account actions live in this bar, never in the sidebar.
*
* Below 768px there is no sidebar, so the bar carries the wordmark and the
* search collapses to a 44px icon; Join moves into the "More" sheet.
*/
import Link from '@/components/link';
import { useSyncExternalStore, type ReactNode } from 'react';
import { ACCOUNT_NAV, HOME_LINK, NAV_ACTION, isCurrent } from '@/config/site-nav';
import { Mark, SearchIcon } from '@/components/portal/Mark';
import { requestOpen } from '@/lib/ask-bridge';
function useShortcutLabel(): string {
return useSyncExternalStore(
() => () => {},
() => (/mac|iphone|ipad/i.test(navigator.platform) ? '⌘K' : 'Ctrl K'),
() => '⌘K',
);
}
export function TopBar({
pathname,
name,
account,
onSearch,
}: {
pathname: string;
name: string;
account: ReactNode;
onSearch: () => void;
}) {
const shortcut = useShortcutLabel();
return (
<header className="shell-topbar" data-shell>
<Link href={HOME_LINK.href} className="shell-topbar-brand">
<Mark className="h-7 w-7 shrink-0" />
<span>{name}</span>
</Link>
<button
type="button"
className="shell-search"
onClick={onSearch}
aria-haspopup="dialog"
aria-label="Search pages and research"
>
<SearchIcon className="h-5 w-5 shrink-0" />
<span className="shell-search-label">Search bottlenecks, companies, pages</span>
<kbd className="shell-kbd" aria-hidden>
{shortcut}
</kbd>
</button>
<div className="shell-topbar-end">
{/* Phones only: a floating Ask button covered the text above the tab
bar, so on a phone Ask lives here, as Loki's does. Not on the home
page, whose own first line is the Ask box: two Asks is one too many. */}
{pathname !== HOME_LINK.href && (
<button type="button" className="shell-ask" onClick={requestOpen}>
Ask
</button>
)}
{/* For every reader, not only a signed-in one: signed out, /account
says what the desk is and offers sign-in. Hidden behind the
session, nobody without an account could find it (2026-11-12). */}
<Link
href={ACCOUNT_NAV.desk.href}
className="shell-topbar-link"
aria-current={isCurrent(pathname, ACCOUNT_NAV.desk.href) ? 'page' : undefined}
>
{ACCOUNT_NAV.desk.label}
</Link>
<Link
href={NAV_ACTION.href}
className="shell-join"
aria-current={isCurrent(pathname, NAV_ACTION.href) ? 'page' : undefined}
>
{NAV_ACTION.label}
</Link>
{account}
</div>
</header>
);
}