Successfully implemented Vercel Speed Insights for Next.js
## Changes Made
### 1. Installed @vercel/speed-insights package
- Used pnpm (the project's package manager) to install @vercel/speed-insights@1.3.1
- Updated package.json with the new dependency
- Updated pnpm-lock.yaml with the complete dependency tree
### 2. Integrated SpeedInsights component into root layout
- Modified: docs/src/app/layout.tsx
- Added import: `import { SpeedInsights } from "@vercel/speed-insights/next"`
- Added `<SpeedInsights />` component inside the `<body>` tag, placed after all other content
- This follows the recommended pattern for Next.js 13.5+ with App Router
## Implementation Details
The project uses:
- Next.js 16.1.1 with App Router
- TypeScript
- pnpm as the package manager
The SpeedInsights component was added to the root layout (app/layout.tsx) which is the correct approach for Next.js 13.5+ projects using the App Router. The component is placed at the end of the body tag to ensure it loads after the main content.
## Verification
✅ Build completed successfully - no compilation errors
✅ All changes staged with git including the lockfile
✅ Package installed and integrated correctly
Note: Pre-existing linter warnings in mobile-nav-context.tsx and theme-toggle.tsx were not introduced by these changes and remain unchanged.
## Files Modified
1. docs/package.json - Added @vercel/speed-insights dependency
2. docs/pnpm-lock.yaml - Updated with new package dependencies
3. docs/src/app/layout.tsx - Added SpeedInsights import and component
The implementation follows Vercel's official documentation and best practices for Next.js App Router applications.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { Geist, Geist_Mono } from "next/font/google";
|
|
import "./globals.css";
|
|
import { ThemeProvider } from "@/components/theme-provider";
|
|
import { MobileNavProvider } from "@/components/mobile-nav-context";
|
|
import { Header } from "@/components/header";
|
|
import { Sidebar } from "@/components/sidebar";
|
|
import { DocsChat } from "@/components/docs-chat";
|
|
import { cookies } from "next/headers";
|
|
import { SpeedInsights } from "@vercel/speed-insights/next";
|
|
|
|
const geist = Geist({
|
|
variable: "--font-geist",
|
|
subsets: ["latin"],
|
|
});
|
|
|
|
const geistMono = Geist_Mono({
|
|
variable: "--font-geist-mono",
|
|
subsets: ["latin"],
|
|
});
|
|
|
|
export const metadata: Metadata = {
|
|
title: "agent-browser",
|
|
description: "Headless browser automation CLI for AI agents",
|
|
};
|
|
|
|
export default async function RootLayout({
|
|
children,
|
|
}: Readonly<{
|
|
children: React.ReactNode;
|
|
}>) {
|
|
const cookieStore = await cookies();
|
|
const chatOpen = cookieStore.get("docs-chat-open")?.value === "true";
|
|
const chatWidth = Number(cookieStore.get("docs-chat-width")?.value) || 400;
|
|
|
|
return (
|
|
<html lang="en" suppressHydrationWarning>
|
|
<head>
|
|
{chatOpen && (
|
|
<style
|
|
dangerouslySetInnerHTML={{
|
|
__html: `@media(min-width:640px){body{padding-right:${chatWidth}px}}`,
|
|
}}
|
|
/>
|
|
)}
|
|
</head>
|
|
<body
|
|
className={`${geist.variable} ${geistMono.variable} antialiased bg-background text-foreground`}
|
|
>
|
|
<ThemeProvider>
|
|
<MobileNavProvider>
|
|
<Header />
|
|
<div className="flex min-h-[calc(100vh-3.5rem)]">
|
|
<Sidebar />
|
|
<main className="flex-1 overflow-auto">
|
|
<div className="max-w-2xl mx-auto px-4 sm:px-6 py-8 sm:py-12">
|
|
<div className="prose">
|
|
{children}
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
<DocsChat defaultOpen={chatOpen} defaultWidth={chatWidth} />
|
|
</MobileNavProvider>
|
|
</ThemeProvider>
|
|
<SpeedInsights />
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|