Menu
NextToolbar

Configuration

The theme prop, the recommended next.config options, basePath and assetPrefix.

NextToolbar needs no configuration to work. This page lists what you can configure, in the component and in next.config.

Props

tsx
<NextToolbar theme="system" />
PropTypeDefaultDescription
theme'system' | 'light' | 'dark''system'Initial theme. system follows the OS preference. The theme button in the toolbar overrides it and remembers the choice per browser.
securityCheckbooleantrueCheck your Next.js version against GitHub's security advisories. See Security.

The package also exports the types NextToolbarProps and Theme.

next.config options

OptionRecommendedWhy
experimental.requestInsightstrue (Next 16.3+)Unlocks server timing, fetches with cache outcome, server errors, exact route patterns, the no-store render-mode correction and the profiler.
devIndicators{ position: 'top-right' } or falseNext's indicator sits bottom-left by default, on top of the toolbar's logo.
next.config.ts
ts
import type { NextConfig } from 'next'
 
const nextConfig: NextConfig = {
  devIndicators: { position: 'top-right' },
  experimental: { requestInsights: true },
}
 
export default nextConfig

requestInsights only exists from Next 16.3. On older versions TypeScript flags it as an unknown option in next.config.ts, so only add it on 16.3+.

basePath and assetPrefix

Both work without extra configuration:

  • The toolbar finds the dev server's socket the same way Next's own client does: from the path of Next's scripts (everything before /_next/). That covers basePath, and assetPrefix including a CDN URL.
  • Next writes basePath into the toolbar's code at build time (process.env.__NEXT_ROUTER_BASEPATH), so it can match URLs that include it (/docs/blog/hello) with the paths Next reports without it (/blog/hello).

Persisted preferences

The toolbar stores two small preferences in the browser's localStorage, per origin:

KeyValuesSet by
next-toolbar:collapsed'1' or '0'Minimizing / expanding the toolbar
next-toolbar:theme'system', 'light', 'dark'The theme button
next-toolbar:seenJSON list of segment namesOpening a segment that has the new badge

Clear them to go back to the defaults. If localStorage is unavailable (private mode, blocked storage), the toolbar still works and simply doesn't remember.

Other devtools on the page

While the bar is expanded, the toolbar sets --next-kit-inset-bottom on <html> to the room it takes at the bottom edge (its height plus its margin, 53px by default). Minimized to a circle, or unmounted, it removes it.

It's a contract shared by the @angelitolm devtools: next-query's button and panel add it to their bottom offset, so they float above the bar instead of covering it. Any floating widget of your own can do the same:

css
.my-widget { bottom: calc(16px + var(--next-kit-inset-bottom, 0px)); }

Server route

Optional. @angelitolm/next-toolbar/server exports two route handlers; mount them at /api/next-toolbar:

app/api/next-toolbar/route.ts
ts
export { GET, POST } from '@angelitolm/next-toolbar/server'
MethodDoes
GETReturns the Server Action names, read from Next's server-reference-manifest.json files in .next.
POSTRuns revalidatePath or revalidateTag with what the toolbar sends.
  • Both answer 404 outside next dev, so deploying the file is harmless (unless you opt in on a staging server).
  • They also answer 404 unless the request carries the x-next-toolbar header. Browsers only send a custom header to another origin after a CORS preflight, which this route never approves, so another site open in your browser can't call it.
  • The path is fixed. If a middleware/proxy guards /api, let /api/next-toolbar through in development.
  • It reads the manifests from .next in the directory next dev runs in: with a custom distDir, action names won't be found (revalidating still works).

Error boundary

Not a toolbar option, but worth repeating: add app/error.tsx so a render error doesn't take the root layout, and the toolbar, down with it. See Getting started.

Demo component

NextToolbarDemo renders the same toolbar from data you pass in, in any environment, production included. It's what powers the live demo; use it for documentation, screenshots or showcases, not in your app.

app/showcase/page.tsx
tsx
'use client'
import { NextToolbarDemo } from '@angelitolm/next-toolbar/demo'
 
export default function Showcase() {
  return <NextToolbarDemo pathname="/blog/hello" params={{ slug: 'hello' }} status={200} timingMs={42} isStatic />
}
PropDescription
pathname, paramsThe simulated page
status, timingMs, viaHTTP status and TTFB ('document') or navigation time ('rsc')
isStaticWhat Next's dev data says: true, false, or omitted for "Rendering…"
insightsSimulated request insights (types Insight, InsightFetch, InsightSpan are exported)
clientErrorsClient errors with message and optional stack
nextVersion, themeDefaults: '16.4.1' and 'system'

Production

There is nothing to switch off. In a production build the toolbar renders null, makes no request and opens no connection. Its code sits in a separate chunk that pages never load for your visitors.

Staging (self-hosted QA)

NextToolbar is a development tool. It does not belong in a production environment, and nothing in the package turns it on there by itself.

A staging server used for specific QA testing is the one exception, and it is a decision your development team makes on purpose: the toolbar stays off until someone sets the secret below on that server. Do it only on staging, only for the time QA needs it, and never on the environment your users reach.

Never in production

Do not set NEXT_TOOLBAR_SECRET in production, not even temporarily to debug. With the server route mounted, whoever holds the secret can list your Server Actions and revalidate your cache.

To enable it on a self-hosted staging server (next build + next start):

  1. Mount the server route: it is what decides who gets in.

  2. Set a secret of at least 16 characters on the server:

    bash
    NEXT_TOOLBAR_SECRET=a-long-random-string
  3. In the browser that should see the toolbar, set the same value as the next-toolbar cookie (once, from the DevTools console):

    js
    document.cookie = 'next-toolbar=a-long-random-string; path=/; max-age=2592000; samesite=strict'
  4. Reload the page. The toolbar appears for that browser only.

What QA sees on staging

A production build has no Next dev server, so everything that comes from it is missing. The rest works as in development.

WorksMissing, and why
HTTP status, TTFB and client navigation timeRender mode (Static / Dynamic): Next only sends it over the dev server's HMR socket
Cached fetches: every fetch in Next's data cache, newest first, with HTTP status, freshness, tags, response headers and revalidate buttons (details)Fetches per request, their time and HIT / MISS / SKIP: they come from experimental.requestInsights, which only next dev emits
Server Actions with their names (read from the build's manifests), status, time, revalidation and redirectsServer render time and the span profiler: also request insights. The profiler falls back to the page visits the browser recorded
Revalidate by tag or pathExact route pattern: rebuilt from the URL and useParams() instead
SEO, broken links, client errors, security checkThe HMR socket row in the info panel reads none (production build)

How the access check works

  • Without the variable, or with one shorter than 16 characters, production behaves exactly as described in Production.
  • On every page load, <NextToolbar> looks for a next-toolbar cookie. Without it, it does nothing: no request, no toolbar code downloaded. Your visitors never pay for the toolbar.
  • With the cookie, it calls the server route once. The server compares the cookie with the secret in constant time and answers 200 or 404. Only on 200 does the browser download the toolbar's chunk.
  • The server route checks the secret on every GET and POST, so the revalidate buttons can't be used without it either. A wrong cookie gets the same 404 as none.

Turn it off

  • For one browser: delete the cookie, document.cookie = 'next-toolbar=; path=/; max-age=0', and reload.
  • For everyone: remove NEXT_TOOLBAR_SECRET from the server and restart it. Rotate the value whenever someone who knew it leaves the team.
  • Treat the secret like a password: never put it in a NEXT_PUBLIC_ variable (that ships it to every browser), a URL or the repository.

Limits

  • Self-hosted only. The cached-fetch list reads .next/cache/fetch-cache from the server's disk, so it needs one next start process with Next's default cache. On Vercel, other serverless platforms or with a custom cacheHandler (Redis…), the list is empty or partial; the rest of the toolbar still works.
  • The route reads the manifests and the cache from .next in the directory next start runs in. With a custom distDir, action names and cached fetches won't be found.
  • If a middleware/proxy guards /api, let /api/next-toolbar through on staging too.

Not showing up? See Troubleshooting.