File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { type NextConfig } from "next";
33const nextConfig : NextConfig = {
44 reactStrictMode : true ,
55 serverExternalPackages : [ "libnpmdiff" , "npm-package-arg" , "pacote" ] ,
6+ cacheComponents : true ,
67} ;
78
89export default nextConfig ;
Original file line number Diff line number Diff line change 1+ "use cache: private" ;
2+
13import { type Metadata } from "next" ;
24import { redirect } from "next/navigation" ;
35import { type JSX } from "react" ;
@@ -16,6 +18,13 @@ import NpmDiff from "./_page/NpmDiff";
1618import PackagephobiaDiff from "./_page/PackagephobiaDiff" ;
1719import { type DIFF_TYPE_PARAM_NAME } from "./_page/paramNames" ;
1820
21+ // CACHE COMPONENTS: Using "use cache: private" to allow runtime prefetching
22+ // while keeping content dynamic (route params change per request)
23+ // Decision: This route displays package diffs based on dynamic params
24+ // - Same for all users with same params (prefetchable)
25+ // - Changes based on route params (needs dynamic data)
26+ // - Can be prefetched with actual runtime values for instant navigation
27+
1928export interface DiffPageProps {
2029 params : Promise < { parts : string | string [ ] } > ;
2130 searchParams : Promise < QueryParams & { [ DIFF_TYPE_PARAM_NAME ] : ViewType } > ;
Original file line number Diff line number Diff line change 11import Link from "next/link" ;
2- import { forwardRef , type HTMLAttributes } from "react" ;
2+ import { forwardRef , type HTMLAttributes , Suspense } from "react" ;
33import Heading from "^/components/ui/Heading" ;
44import { cx } from "^/lib/cva" ;
55import ColorModeToggle from "./ColorModeToggle" ;
@@ -33,11 +33,20 @@ const Header = forwardRef<HTMLElement, HeaderProps>(
3333 npm-diff.app 📦🔃
3434 </ Heading >
3535 </ Link >
36- < div className = "flex items-center justify-end" >
37- < NavLink href = "/about" > about</ NavLink >
38- < span > /</ span >
39- < NavLink href = "/about/api" > api</ NavLink >
40- </ div >
36+ { /* CACHE COMPONENTS: Wrap NavLink in Suspense because it uses usePathname() (dynamic API) */ }
37+ < Suspense
38+ fallback = {
39+ < div className = "flex items-center justify-end" >
40+ < span className = "opacity-60" > about / api</ span >
41+ </ div >
42+ }
43+ >
44+ < div className = "flex items-center justify-end" >
45+ < NavLink href = "/about" > about</ NavLink >
46+ < span > /</ span >
47+ < NavLink href = "/about/api" > api</ NavLink >
48+ </ div >
49+ </ Suspense >
4150 </ nav >
4251 ) ,
4352) ;
Original file line number Diff line number Diff line change @@ -23,8 +23,7 @@ export const metadata = {
2323 description : "API documentation for npm-diff.app" ,
2424} satisfies Metadata ;
2525
26- // We need nodejs since we use Npm libs https://beta.nextjs.org/docs/api-reference/segment-config#runtime
27- export const runtime = "nodejs" ;
26+ // MIGRATED: Removed export const runtime = "nodejs" (default runtime, not needed with Cache Components)
2827const AboutApiPage = async ( ) => {
2928 const specsOrVersions = splitParts ( EXAMPLE_QUERY ) ;
3029 const { canonicalSpecs : specs } = await destination ( specsOrVersions ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,8 @@ import { NextResponse } from "next/server";
22import getVersionData from "^/lib/api/npm/getVersionData" ;
33import { type Version , VERSIONS_PARAMETER_PACKAGE } from "./types" ;
44
5- export const runtime = "edge" ;
5+ // MIGRATED: Removed export const runtime = "edge" (incompatible with Cache Components)
6+ // TODO: Evaluate if edge runtime optimization is needed - can be configured differently with CC
67
78export async function GET ( request : Request ) {
89 const start = Date . now ( ) ;
Original file line number Diff line number Diff line change 11import { type Metadata , type Viewport } from "next" ;
2- import { type ReactNode } from "react" ;
2+ import { type ReactNode , Suspense } from "react" ;
33import { ThemeProvider } from "^/components/ThemeProvider" ;
44import Stack from "^/components/ui/Stack" ;
55import { TooltipProvider } from "^/components/ui/Tooltip" ;
@@ -31,18 +31,21 @@ export default function RootLayout({ children }: { children: ReactNode }) {
3131 < html lang = "en" suppressHydrationWarning >
3232 < head />
3333 < body className = "min-h-screen-s bg-background" >
34- < ThemeProvider >
35- < TooltipProvider >
36- < Stack
37- justify = "between"
38- className = "min-h-screen-s relative overflow-auto px-4"
39- >
40- < Header className = "bg-background" />
41- { children }
42- < Footer className = "bg-background" />
43- </ Stack >
44- </ TooltipProvider >
45- </ ThemeProvider >
34+ { /* CACHE COMPONENTS: Wrap ThemeProvider in Suspense because next-themes uses client-side APIs */ }
35+ < Suspense fallback = { null } >
36+ < ThemeProvider >
37+ < TooltipProvider >
38+ < Stack
39+ justify = "between"
40+ className = "min-h-screen-s relative overflow-auto px-4"
41+ >
42+ < Header className = "bg-background" />
43+ { children }
44+ < Footer className = "bg-background" />
45+ </ Stack >
46+ </ TooltipProvider >
47+ </ ThemeProvider >
48+ </ Suspense >
4649 </ body >
4750 </ html >
4851 ) ;
You can’t perform that action at this time.
0 commit comments