Getting started
Install the package, add it to your root layout and run next dev.
1. Install
pnpm add -D @angelitolm/next-toolbarnpm and yarn work the same way (npm i -D …, yarn add -D …). Install it as a dev dependency: it never renders in production.
2. Add it to the root layout
import { NextToolbar } from '@angelitolm/next-toolbar'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<NextToolbar />
</body>
</html>
)
}NextToolbar is a client component (the package ships with the 'use client' directive), so you can render it from a Server Component layout without wrapping it.
Put it in the root layout so it survives navigation between routes and keeps its connection to the dev server.
3. Recommended next.config.ts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
// Next's own dev indicator sits bottom-left by default and overlaps the toolbar.
devIndicators: { position: 'top-right' },
// Next 16.3+ only: server timing, fetches, exact route patterns and the profiler.
experimental: { requestInsights: true },
}
export default nextConfigBoth options are optional:
- Without
devIndicators.position, Next's round "N" indicator sits on top of the toolbar's left edge. You can also turn it off withdevIndicators: false. - Without
requestInsights(or before Next 16.3) the toolbar still shows status, route, render mode, client timing, client errors and versions, but not server timing, fetches, the no-store render-mode correction or the profiler. See Compatibility.
4. Keep it on screen when a page crashes
Recommended
If a page throws while rendering and no error.tsx catches it, Next replaces the whole root layout with its own error page ("This page couldn't load"), and the toolbar goes with it. That's exactly when you need it most.
Render the toolbar in app/global-error.tsx too. Next uses this file in place of the root layout for uncaught errors, so the toolbar comes back with the status (500), the failing request and its error:
'use client'
import { NextToolbar } from '@angelitolm/next-toolbar'
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
return (
<html lang="en">
<body>
<h1>Something went wrong</h1>
<p>{error.digest ?? error.message}</p>
<NextToolbar />
</body>
</html>
)
}Optionally, an app/error.tsx (or one per route segment, e.g. app/[locale]/error.tsx) catches errors inside the root layout, so the layout and its toolbar never go away:
'use client'
export default function Error({ error }: { error: Error }) {
return <h1>Something went wrong: {error.message}</h1>
}5. Run
pnpm devOpen any page. The toolbar appears as a strip across the bottom of the window:
- hover any segment for details;
- click the request id (
# f9b45c) to open the profiler; - click the logo or the close button to minimize it to a circle.
6. Optional: the server route
To revalidate paths and tags from the toolbar, and to see Server Action names instead of ids, add one route handler:
export { GET, POST } from '@angelitolm/next-toolbar/server'It only answers in next dev. See Server Actions.
Production
Nothing to do. In production the component renders nothing, makes no request and never opens a connection, and the toolbar's code sits in a separate chunk that pages don't load. You don't need to import it conditionally. For QA on a staging server there is a deliberate, opt-in exception: see Staging.