diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs index 0781680..c139cd8 100644 --- a/web/eslint.config.mjs +++ b/web/eslint.config.mjs @@ -42,7 +42,9 @@ const eslintConfig = defineConfig([ "no-restricted-imports": [ "error", { + // Only the component; its hooks are fine anywhere. name: "next/link", + importNames: ["default"], message: "Use Link from @/ui/Link, which turns off prefetching.", }, ], diff --git a/web/next.config.ts b/web/next.config.ts index fd9bc54..bbe0a26 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -23,6 +23,8 @@ const nextConfig: NextConfig = { // That proxying buffers request bodies, cut off at 10 MB by default; a packed map can be up to the API's // 256 MB (`staff/map_viewer_file.rs`). proxyClientMaxBodySize: "256mb", + // Pages block on their data by design (`instant = false` in the root layout), so don't warn about it. + instantInsights: { validationLevel: "manual-warning" }, }, turbopack: { rules: { diff --git a/web/src/app/activity/page.tsx b/web/src/app/activity/page.tsx index b93150e..7de643e 100644 --- a/web/src/app/activity/page.tsx +++ b/web/src/app/activity/page.tsx @@ -1,7 +1,6 @@ // Activity page: runs and world records per day, then the latest runs, narrowed by style, track, lowest tier or // world records only. import type { Metadata } from "next"; -import { Suspense } from "react"; import { RecentRuns } from "@/features/activity/RecentRuns"; import { DailyTotals } from "@/features/dailyTotals/DailyTotals"; import { Page } from "@/ui/Page"; @@ -15,21 +14,17 @@ export default function ActivityPage({ searchParams }: PageProps<"/activity">) { return (

Activity

- - - - - {searchParams.then(({ style, track, tier, show }) => ( - - ))} - + + {searchParams.then(({ style, track, tier, show }) => ( + + ))}
); } diff --git a/web/src/app/community/[post]/edit/page.tsx b/web/src/app/community/[post]/edit/page.tsx index 54c1e2c..f345e28 100644 --- a/web/src/app/community/[post]/edit/page.tsx +++ b/web/src/app/community/[post]/edit/page.tsx @@ -1,6 +1,5 @@ // Editing a community post, for its author and staff. import type { Metadata } from "next"; -import { Suspense } from "react"; import { WritePost } from "@/features/community/WritePost"; import { Page } from "@/ui/Page"; @@ -15,11 +14,9 @@ export default function EditPostPage({ return (

Edit post

- - {params.then(({ post }) => ( - - ))} - + {params.then(({ post }) => ( + + ))}
); } diff --git a/web/src/app/community/[post]/page.tsx b/web/src/app/community/[post]/page.tsx index 728d910..5fbf85c 100644 --- a/web/src/app/community/[post]/page.tsx +++ b/web/src/app/community/[post]/page.tsx @@ -1,6 +1,5 @@ // One community post. The address is `/community/{id}-{slug}`; other forms of it redirect there. import type { Metadata } from "next"; -import { Suspense } from "react"; import { PostView } from "@/features/community/PostView"; import { Page } from "@/ui/Page"; @@ -9,11 +8,9 @@ export const metadata: Metadata = { title: "Community" }; export default function PostPage({ params }: PageProps<"/community/[post]">) { return ( - - {params.then(({ post }) => ( - - ))} - + {params.then(({ post }) => ( + + ))} ); } diff --git a/web/src/app/community/new/page.tsx b/web/src/app/community/new/page.tsx index bc702be..c5c4e5c 100644 --- a/web/src/app/community/new/page.tsx +++ b/web/src/app/community/new/page.tsx @@ -1,6 +1,5 @@ // Writing a new community post, for players allowed to post. import type { Metadata } from "next"; -import { Suspense } from "react"; import { WritePost } from "@/features/community/WritePost"; import { Page } from "@/ui/Page"; @@ -13,9 +12,7 @@ export default function NewPostPage() { return (

New post

- - - +
); } diff --git a/web/src/app/community/page.tsx b/web/src/app/community/page.tsx index 461a105..49f5b8d 100644 --- a/web/src/app/community/page.tsx +++ b/web/src/app/community/page.tsx @@ -1,6 +1,5 @@ // Community page: posts and videos by players allowed to post, newest first. import type { Metadata } from "next"; -import { Suspense } from "react"; import { PostList } from "@/features/community/PostList"; import { Page } from "@/ui/Page"; @@ -15,16 +14,14 @@ export default function CommunityPage({ return (

Community

- - {searchParams.then((params) => ( - - ))} - + {searchParams.then((params) => ( + + ))}
); } diff --git a/web/src/app/layout.tsx b/web/src/app/layout.tsx index 6c71602..07418f3 100644 --- a/web/src/app/layout.tsx +++ b/web/src/app/layout.tsx @@ -5,6 +5,7 @@ import { Suspense } from "react"; import { RunDialogHost } from "@/features/runs/RunDialogHost"; import { SiteFooter } from "@/features/site/SiteFooter"; import { SiteHeader } from "@/features/site/SiteHeader"; +import { NavigationProgress } from "@/ui/NavigationProgress"; import "./globals.css"; const play = Play({ @@ -19,10 +20,14 @@ export const metadata: Metadata = { "Global records for the Counter-Strike: Source bunnyhop community.", }; +// Pages wait for their data and arrive whole; the progress bar covers the wait. +export const instant = false; + export default function RootLayout({ children }: LayoutProps<"/">) { return ( + {/* The header and page fill at least the window, so the footer starts right at the fold: the page always scrolls, and the scrollbar doesn't come and go between short and long pages. The space above the footer is padding in here, not a margin on the footer, so it doesn't push it lower. */} diff --git a/web/src/app/leaderboards/[ranking]/page.tsx b/web/src/app/leaderboards/[ranking]/page.tsx index 25a0210..a8f5854 100644 --- a/web/src/app/leaderboards/[ranking]/page.tsx +++ b/web/src/app/leaderboards/[ranking]/page.tsx @@ -1,7 +1,6 @@ // One leaderboard in full: /leaderboards/points or /leaderboards/completed, with the overview's choices. import type { Metadata } from "next"; import { notFound } from "next/navigation"; -import { Suspense } from "react"; import { LeaderboardList, listTitle, @@ -31,23 +30,21 @@ export default function LeaderboardListPage({ }: PageProps<"/leaderboards/[ranking]">) { return ( - - {Promise.all([params, searchParams]).then( - ([{ ranking }, { style, track, view }]) => { - if (!rankings.includes(ranking)) notFound(); - return ( - - ); - }, - )} - + {Promise.all([params, searchParams]).then( + ([{ ranking }, { style, track, view }]) => { + if (!rankings.includes(ranking)) notFound(); + return ( + + ); + }, + )} ); } diff --git a/web/src/app/leaderboards/page.tsx b/web/src/app/leaderboards/page.tsx index 10ec5e9..4c706ff 100644 --- a/web/src/app/leaderboards/page.tsx +++ b/web/src/app/leaderboards/page.tsx @@ -1,6 +1,5 @@ // Leaderboards page: the top players by points and by completions, per style and track, and pre-2.0. import type { Metadata } from "next"; -import { Suspense } from "react"; import { Leaderboards } from "@/features/leaderboards/Leaderboards"; import { Page } from "@/ui/Page"; @@ -15,17 +14,15 @@ export default function LeaderboardsPage({ return (

Leaderboards

- - {searchParams.then(({ style, track, view }) => ( - - ))} - + {searchParams.then(({ style, track, view }) => ( + + ))}
); } diff --git a/web/src/app/maps/[map]/layout.tsx b/web/src/app/maps/[map]/layout.tsx index 4da2544..e5ba9bf 100644 --- a/web/src/app/maps/[map]/layout.tsx +++ b/web/src/app/maps/[map]/layout.tsx @@ -1,5 +1,4 @@ // A map's pages: the banner and header stay while the map's view, its Zones and its Manage view swap beneath them. -import { Suspense } from "react"; import { MapHeader } from "@/features/maps/MapHeader"; import { Page } from "@/ui/Page"; @@ -9,11 +8,9 @@ export default function MapLayout({ }: LayoutProps<"/maps/[map]">) { return ( - - {params.then(({ map }) => ( - - ))} - + {params.then(({ map }) => ( + + ))} {children} ); diff --git a/web/src/app/maps/[map]/manage/page.tsx b/web/src/app/maps/[map]/manage/page.tsx index f94b759..4a02f21 100644 --- a/web/src/app/maps/[map]/manage/page.tsx +++ b/web/src/app/maps/[map]/manage/page.tsx @@ -1,6 +1,5 @@ // A map's Manage view, for staff, under the map's header. Kept out of search engines, as the staff area is. import type { Metadata } from "next"; -import { Suspense } from "react"; import { ManageMap } from "@/features/staff/maps/ManageMap"; import { PageView } from "@/ui/Page"; @@ -18,11 +17,9 @@ export default function ManageMapPage({ }: PageProps<"/maps/[map]/manage">) { return ( - - {params.then(({ map }) => ( - - ))} - + {params.then(({ map }) => ( + + ))} ); } diff --git a/web/src/app/maps/[map]/manage/zones/page.tsx b/web/src/app/maps/[map]/manage/zones/page.tsx index d6d4c63..fcca33b 100644 --- a/web/src/app/maps/[map]/manage/zones/page.tsx +++ b/web/src/app/maps/[map]/manage/zones/page.tsx @@ -1,7 +1,6 @@ // The zone editor for a map, under its header, for staff with manage_zones. Kept out of search engines, as the // staff area is. import type { Metadata } from "next"; -import { Suspense } from "react"; import { ZoneEditorView } from "@/features/staff/maps/ZoneEditorView"; import { PageView } from "@/ui/Page"; @@ -19,11 +18,9 @@ export default function ZoneEditorPage({ }: PageProps<"/maps/[map]/manage/zones">) { return ( - - {params.then(({ map }) => ( - - ))} - + {params.then(({ map }) => ( + + ))} ); } diff --git a/web/src/app/maps/[map]/page.tsx b/web/src/app/maps/[map]/page.tsx index 467cc32..91c6490 100644 --- a/web/src/app/maps/[map]/page.tsx +++ b/web/src/app/maps/[map]/page.tsx @@ -1,6 +1,5 @@ // A map's page: its description, leaderboards per style and track, and their WR history, under the map's header. import type { Metadata } from "next"; -import { Suspense } from "react"; import { MapView } from "@/features/maps/MapView"; import { PageView } from "@/ui/Page"; @@ -13,11 +12,9 @@ export async function generateMetadata({ export default function MapPage({ params }: PageProps<"/maps/[map]">) { return ( - - {params.then(({ map }) => ( - - ))} - + {params.then(({ map }) => ( + + ))} ); } diff --git a/web/src/app/maps/[map]/zones/page.tsx b/web/src/app/maps/[map]/zones/page.tsx index ff5bf75..654786e 100644 --- a/web/src/app/maps/[map]/zones/page.tsx +++ b/web/src/app/maps/[map]/zones/page.tsx @@ -1,6 +1,5 @@ // A map's Zones view, for everyone, under the map's header. import type { Metadata } from "next"; -import { Suspense } from "react"; import { MapZones } from "@/features/maps/MapZones"; import { PageView } from "@/ui/Page"; @@ -15,11 +14,9 @@ export default function MapZonesPage({ }: PageProps<"/maps/[map]/zones">) { return ( - - {params.then(({ map }) => ( - - ))} - + {params.then(({ map }) => ( + + ))} ); } diff --git a/web/src/app/maps/page.tsx b/web/src/app/maps/page.tsx index ba99f81..cde80b7 100644 --- a/web/src/app/maps/page.tsx +++ b/web/src/app/maps/page.tsx @@ -1,6 +1,5 @@ // Maps page: every map with a finished run, searchable, with its world record in a chosen style. import type { Metadata } from "next"; -import { Suspense } from "react"; import { MapList } from "@/features/maps/MapList"; import { Page } from "@/ui/Page"; @@ -13,11 +12,9 @@ export default function MapsPage({ searchParams }: PageProps<"/maps">) { return (

Maps

- - {searchParams.then((params) => ( - - ))} - + {searchParams.then((params) => ( + + ))}
); } diff --git a/web/src/app/page.tsx b/web/src/app/page.tsx index 1931505..6c77803 100644 --- a/web/src/app/page.tsx +++ b/web/src/app/page.tsx @@ -1,5 +1,4 @@ // Home page: the site's header, what bunnyhopping is, how to start, and the latest records and servers. -import { Suspense } from "react"; import { BhopIntro } from "@/features/home/BhopIntro"; import { GetStarted } from "@/features/home/GetStarted"; import { HomeHeader } from "@/features/home/HomeHeader"; @@ -12,9 +11,7 @@ export default function HomePage() { - - - + ); } diff --git a/web/src/app/players/[steamid]/layout.tsx b/web/src/app/players/[steamid]/layout.tsx index 53c11e0..df86c5f 100644 --- a/web/src/app/players/[steamid]/layout.tsx +++ b/web/src/app/players/[steamid]/layout.tsx @@ -1,5 +1,4 @@ // A player's pages: the header stays while the profile and the Manage view swap beneath it. -import { Suspense } from "react"; import { PlayerHeader } from "@/features/players/PlayerHeader"; import { Page } from "@/ui/Page"; @@ -9,12 +8,9 @@ export default function PlayerLayout({ }: LayoutProps<"/players/[steamid]">) { return ( - {/* Holds the header's height (its avatar's), so the profile below doesn't jump when the header arrives. */} - }> - {params.then(({ steamid }) => ( - - ))} - + {params.then(({ steamid }) => ( + + ))} {children} ); diff --git a/web/src/app/players/[steamid]/manage/page.tsx b/web/src/app/players/[steamid]/manage/page.tsx index 10c7a4d..eb9976b 100644 --- a/web/src/app/players/[steamid]/manage/page.tsx +++ b/web/src/app/players/[steamid]/manage/page.tsx @@ -1,6 +1,5 @@ // A player's Manage view, for staff, under their header. Kept out of search engines, as the staff area is. import type { Metadata } from "next"; -import { Suspense } from "react"; import { ManagePlayer } from "@/features/staff/players/ManagePlayer"; import { PageView } from "@/ui/Page"; @@ -14,11 +13,9 @@ export default function ManagePlayerPage({ }: PageProps<"/players/[steamid]/manage">) { return ( - - {params.then(({ steamid }) => ( - - ))} - + {params.then(({ steamid }) => ( + + ))} ); } diff --git a/web/src/app/players/[steamid]/page.tsx b/web/src/app/players/[steamid]/page.tsx index 5c9ba18..f29f57d 100644 --- a/web/src/app/players/[steamid]/page.tsx +++ b/web/src/app/players/[steamid]/page.tsx @@ -1,7 +1,6 @@ // A player's profile page, under their header. Any SteamID form works in the URL and lands on the SteamID64 // address. import type { Metadata } from "next"; -import { Suspense } from "react"; import { PlayerProfile } from "@/features/players/PlayerProfile"; import { PageView } from "@/ui/Page"; @@ -12,11 +11,9 @@ export default function PlayerPage({ }: PageProps<"/players/[steamid]">) { return ( - - {params.then(({ steamid }) => ( - - ))} - + {params.then(({ steamid }) => ( + + ))} ); } diff --git a/web/src/app/players/page.tsx b/web/src/app/players/page.tsx index 95bcbe2..37fc7ce 100644 --- a/web/src/app/players/page.tsx +++ b/web/src/app/players/page.tsx @@ -1,7 +1,6 @@ // Players page: how many players have a recorded time over time, search by name or SteamID, and recently // active players; for staff, a Banned tab. import type { Metadata } from "next"; -import { Suspense } from "react"; import { DailyTotals } from "@/features/dailyTotals/DailyTotals"; import { PlayerSearch } from "@/features/players/PlayerSearch"; import { Page } from "@/ui/Page"; @@ -15,17 +14,13 @@ export default function PlayersPage({ searchParams }: PageProps<"/players">) { return (

Players

- - - - - {searchParams.then(({ q, view }) => ( - - ))} - + + {searchParams.then(({ q, view }) => ( + + ))}
); } diff --git a/web/src/app/ruleset/page.tsx b/web/src/app/ruleset/page.tsx index c88958f..e96084e 100644 --- a/web/src/app/ruleset/page.tsx +++ b/web/src/app/ruleset/page.tsx @@ -1,6 +1,5 @@ // Ruleset page: the rules every connected server applies. import type { Metadata } from "next"; -import { Suspense } from "react"; import { RulesetView } from "@/features/ruleset/RulesetView"; import { Page } from "@/ui/Page"; @@ -17,9 +16,7 @@ export default function RulesetPage() { The rules every connected server applies. Each run records the ruleset version it was played under.

- Loading the ruleset…

}> - -
+ ); } diff --git a/web/src/app/runs/[id]/page.tsx b/web/src/app/runs/[id]/page.tsx index 489e489..8dd2821 100644 --- a/web/src/app/runs/[id]/page.tsx +++ b/web/src/app/runs/[id]/page.tsx @@ -2,7 +2,6 @@ // staff act on the run here. // Following a run link within the site opens the run dialog instead. import type { Metadata } from "next"; -import { Suspense } from "react"; import { getRun, RunDetails } from "@/features/runs/RunDetails"; import { Page } from "@/ui/Page"; @@ -16,11 +15,9 @@ export async function generateMetadata({ export default function RunPage({ params }: PageProps<"/runs/[id]">) { return ( - - {params.then(({ id }) => ( - - ))} - + {params.then(({ id }) => ( + + ))} ); } diff --git a/web/src/app/servers/page.tsx b/web/src/app/servers/page.tsx index afadf0f..c703778 100644 --- a/web/src/app/servers/page.tsx +++ b/web/src/app/servers/page.tsx @@ -1,6 +1,5 @@ // Servers page: the servers staff have listed, from their heartbeats. import type { Metadata } from "next"; -import { Suspense } from "react"; import { ServerList } from "@/features/servers/ServerList"; import { Page } from "@/ui/Page"; @@ -13,9 +12,7 @@ export default function ServersPage() { return (

Servers

- - - +
); } diff --git a/web/src/app/staff/keys/page.tsx b/web/src/app/staff/keys/page.tsx index c933e86..0f819f2 100644 --- a/web/src/app/staff/keys/page.tsx +++ b/web/src/app/staff/keys/page.tsx @@ -1,6 +1,5 @@ // Staff: server API keys. import type { Metadata } from "next"; -import { Suspense } from "react"; import { IssueKey } from "@/features/staff/keys/IssueKey"; import { KeyList } from "@/features/staff/keys/KeyList"; import { Page } from "@/ui/Page"; @@ -14,9 +13,7 @@ export default function StaffKeysPage() {

API keys

- - - + ); } diff --git a/web/src/app/staff/layout.tsx b/web/src/app/staff/layout.tsx index a5ad0ac..3533bcd 100644 --- a/web/src/app/staff/layout.tsx +++ b/web/src/app/staff/layout.tsx @@ -1,6 +1,5 @@ // The staff area: its sections beside each page. Kept out of search engines. import type { Metadata } from "next"; -import { Suspense } from "react"; import { StaffSidebar } from "@/features/staff/StaffSidebar"; export const metadata: Metadata = { @@ -11,9 +10,7 @@ export const metadata: Metadata = { export default function StaffLayout({ children }: LayoutProps<"/staff">) { return (
- - - + {children}
); diff --git a/web/src/app/staff/page.tsx b/web/src/app/staff/page.tsx index d56ebbc..831afca 100644 --- a/web/src/app/staff/page.tsx +++ b/web/src/app/staff/page.tsx @@ -1,6 +1,5 @@ // The staff area's first page: the staff log, newest first. import type { Metadata } from "next"; -import { Suspense } from "react"; import { logKind, StaffLogList } from "@/features/staff/StaffLogList"; import { Page } from "@/ui/Page"; @@ -10,18 +9,16 @@ export default function StaffPage({ searchParams }: PageProps<"/staff">) { return (

Logs

- - {searchParams.then(({ before, after, kind, about }) => ( - - ))} - + {searchParams.then(({ before, after, kind, about }) => ( + + ))}
); } diff --git a/web/src/ui/Link.tsx b/web/src/ui/Link.tsx index ba0da59..78022ee 100644 --- a/web/src/ui/Link.tsx +++ b/web/src/ui/Link.tsx @@ -1,12 +1,18 @@ // Every internal link on the site. Navigates without a full page load, and never preloads the target. import NextLink from "next/link"; import type { ComponentProps } from "react"; +import { NavigationPending } from "./NavigationProgress"; /** * Next.js preloads a link's page when the link scrolls into view or is hovered. The lead chose to - * load a page only when it's actually opened, so prefetching is off here; the page fade covers the + * load a page only when it's actually opened, so prefetching is off here; the progress bar covers the * wait. Lint stops other files importing next/link, so this default can't be bypassed by accident. */ -export function Link(props: ComponentProps) { - return ; +export function Link({ children, ...props }: ComponentProps) { + return ( + + {children} + + + ); } diff --git a/web/src/ui/NavigationProgress.tsx b/web/src/ui/NavigationProgress.tsx new file mode 100644 index 0000000..a97dde3 --- /dev/null +++ b/web/src/ui/NavigationProgress.tsx @@ -0,0 +1,75 @@ +"use client"; +// The accent bar across the top of the window while a link's page loads. +import { useLinkStatus } from "next/link"; +import { useEffect, useSyncExternalStore } from "react"; + +type Phase = "idle" | "start" | "loading" | "done"; + +let pending = 0; +let phase: Phase = "idle"; +let frame: number | undefined; +let timer: number | undefined; +const listeners = new Set<() => void>(); + +function show(next: Phase) { + phase = next; + for (const listener of listeners) listener(); +} + +function change(by: number) { + const before = pending > 0; + pending = Math.max(0, pending + by); + const now = pending > 0; + if (now === before) return; + window.clearTimeout(timer); + if (frame !== undefined) cancelAnimationFrame(frame); + if (now) { + show("start"); + frame = requestAnimationFrame(() => { + frame = requestAnimationFrame(() => show("loading")); + }); + } else { + show("done"); + timer = window.setTimeout(() => show("idle"), 500); + } +} + +function subscribe(listener: () => void) { + listeners.add(listener); + return () => listeners.delete(listener); +} + +/** Rendered inside every Link, to report its page loading. */ +export function NavigationPending() { + const { pending: loading } = useLinkStatus(); + useEffect(() => { + if (!loading) return; + change(1); + return () => change(-1); + }, [loading]); + return null; +} + +const styles: Record, string> = { + start: "scale-x-0 transition-none", + loading: + "scale-x-90 transition-[scale] duration-[10s] ease-[cubic-bezier(0.1,0.7,0.1,1)]", + done: "scale-x-100 opacity-0 transition-[scale,opacity] duration-200 ease-out [transition-delay:0s,200ms]", +}; + +export function NavigationProgress() { + const current = useSyncExternalStore( + subscribe, + () => phase, + () => "idle" as const, + ); + if (current === "idle") return null; + return ( +
+ ); +} diff --git a/web/src/ui/motion.css b/web/src/ui/motion.css index a8471d3..067d840 100644 --- a/web/src/ui/motion.css +++ b/web/src/ui/motion.css @@ -211,6 +211,20 @@ animation: none; } +/* The navigation progress bar stays live and above the header while pages fade. */ +::view-transition-group(navigation-progress) { + animation: none; + z-index: 20; +} + +::view-transition-old(navigation-progress) { + display: none; +} + +::view-transition-new(navigation-progress) { + animation: none; +} + /* Clicks during a fade reach the page instead of the transition overlay. */ ::view-transition { pointer-events: none;