Contentful Personalization & Analytics
    Preparing search index...

    Contentful Logo

    Contentful Personalization & Analytics

    Next.js SDK App Router Edge Runtime Reference Implementation

    Readme · Guides · Reference · Contributing

    Reference implementation for actual Edge runtime handoff routes in @contentful/optimization-nextjs. Routes export runtime = 'edge', avoid Node-only APIs, and use @contentful/optimization-nextjs/edge from @/lib/edge-optimization.

    This implementation is separate from the App Router Cache Components reference implementation. It does not cover ISR, route-level revalidate, or Cache Components.

    • Request-personalized Edge runtime handoff from app/edge-request/route.ts
    • Public permutation Edge runtime handoff from app/edge-selection/[segment]/route.ts
    • Edge runtime assertion with globalThis.EdgeRuntime === 'edge-runtime'
    • Browser handoff state created without Node-only APIs
    • Node.js >= 20.19.0 (24.15.0 recommended to match .nvmrc)
    • pnpm

    Run these commands from the monorepo root:

    pnpm install
    pnpm build:pkgs
    pnpm implementation:run -- nextjs-sdk_app-router_edge-runtime implementation:install

    Run these commands from the monorepo root:

    pnpm implementation:run -- nextjs-sdk_app-router_edge-runtime dev
    pnpm implementation:run -- nextjs-sdk_app-router_edge-runtime build
    pnpm implementation:run -- nextjs-sdk_app-router_edge-runtime typecheck
    pnpm implementation:run -- nextjs-sdk_app-router_edge-runtime lint

    The development server runs on http://localhost:3003.

    Run the full E2E setup and test suite from the monorepo root:

    pnpm setup:e2e:nextjs-sdk_app-router_edge-runtime
    pnpm test:e2e:nextjs-sdk_app-router_edge-runtime

    The E2E suite uses the shared lib/e2e-web Edge runtime scenarios with E2E_FLAGS=EDGE.