Next.js SDK
The@instantschema/sdk package provides a <InstantSchemaHead> Server Component that fetches schemas and renders them into the HTML <head> before any JavaScript runs — giving you full SEO fidelity with no client-side requests.
Prerequisites
- Next.js 14+ (App Router)
- React 18+
Install
Setup
1. Add the pathname middleware
Createmiddleware.ts at your project root. This exposes the current pathname to Server Components via a request header:
2. Add <InstantSchemaHead> to your root layout
YOUR_PROJECT_ID with the Project ID from your InstantSchema dashboard.
How it works
<InstantSchemaHead> is an async Server Component. On each request it:
- Reads the
x-pathnameheader set by the middleware - Fetches schemas from the InstantSchema API for that pathname
- Renders them as
<script type="application/ld+json" data-instantschema="1">tags
data-instantschema="1" attribute is how the dashboard detects the npm integration automatically on the next scan. No manual confirmation needed.
Detection
Once deployed, return to your dashboard. The integration panel will show Integration active · via Next.js SDK on the next scan of your site (usually within the next scheduled scan, or immediately if you trigger one manually).API
InstantSchemaHead
| Prop | Type | Required | Description |
|---|---|---|---|
projectId | string | Yes | Your InstantSchema project ID |
pathname | string | No | Page path; auto-read from x-pathname header if omitted |
apiBase | string | No | Override API base URL |
fetchSchemas
The lower-level function used by <InstantSchemaHead>. Use this if you need schemas outside the <head>:
Cache-Control: s-maxage=3600).