Skip to main content

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

Create middleware.ts at your project root. This exposes the current pathname to Server Components via a request header:

2. Add <InstantSchemaHead> to your root layout

Replace YOUR_PROJECT_ID with the Project ID from your InstantSchema dashboard.

How it works

<InstantSchemaHead> is an async Server Component. On each request it:
  1. Reads the x-pathname header set by the middleware
  2. Fetches schemas from the InstantSchema API for that pathname
  3. Renders them as <script type="application/ld+json" data-instantschema="1"> tags
The 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

fetchSchemas

The lower-level function used by <InstantSchemaHead>. Use this if you need schemas outside the <head>:
Schemas are cached for 1 hour at the CDN layer (Cache-Control: s-maxage=3600).