Next.js

The @domscribe/next package provides a drop-in withDomscribe() config wrapper for Next.js 15 and 16. It automatically configures both Turbopack and Webpack bundler paths, so it works regardless of which bundler you use.

Install

npm install -D @domscribe/next

Basic Setup

// next.config.ts
import type { NextConfig } from 'next';
import { withDomscribe } from '@domscribe/next';

const nextConfig: NextConfig = {};

export default withDomscribe()(nextConfig);

That is all you need. Domscribe is zero-config by default -- it auto-detects your bundler, starts the relay daemon, and injects data-ds attributes into your JSX/TSX files.

Advanced Configuration

// next.config.ts
import type { NextConfig } from 'next';
import { withDomscribe } from '@domscribe/next';

const nextConfig: NextConfig = {
  reactStrictMode: true,
};

export default withDomscribe({
  debug: true,
  overlay: {
    initialMode: 'expanded',
    debug: true,
  },
  relay: {
    port: 4400,
    host: '127.0.0.1',
  },
})(nextConfig);

Configuration Options

The withDomscribe() function accepts a DomscribeNextOptions object:

OptionTypeDefaultDescription
enabledbooleantrueEnable transformation. Automatically disabled in production.
includeRegExp/\.(jsx|tsx)$/iFile pattern to include for transformation.
excludeRegExp/node_modules|\.test\.|\.spec\./iFile pattern to exclude from transformation.
debugbooleanfalseEnable debug logging.
relayobject{}Relay server configuration (see below).
overlayboolean | objecttrueOverlay UI configuration (see below).

Relay Options

OptionTypeDefaultDescription
relay.autoStartbooleantrueAuto-start the relay daemon if not running.
relay.portnumber0 (dynamic)Port for the relay server.
relay.hoststring'127.0.0.1'Host for the relay server.

Overlay Options

When overlay is an object:

OptionTypeDefaultDescription
overlay.initialMode'collapsed' | 'expanded''collapsed'Initial display mode for the overlay.
overlay.debugbooleanfalseEnable debug logging in the overlay.

Supported Versions

Both bundler paths are configured automatically by withDomscribe(). You do not need to do anything different for Turbopack vs Webpack.

How It Works

The withDomscribe() wrapper:

  1. In development, injects a self-initializing loader that transforms JSX/TSX files to add data-ds attributes. The loader runs on both server and client compilations so that server-rendered HTML and client hydration produce matching attributes (no hydration mismatches).

  2. In production, replaces @domscribe/overlay imports with a no-op stub as a safety net against accidental imports. All instrumentation is stripped.

The integration uses the same turbopack-compatible loader for both bundler paths, which handles its own singleton management (manifest writer, relay lifecycle) via process exit handlers. This avoids the race conditions that can occur with Next.js's dual server/client compilation model.

Composing with Other Wrappers

withDomscribe() returns a standard Next.js config function, so it composes naturally with other config wrappers:

import { withDomscribe } from '@domscribe/next';
import { withSentryConfig } from '@sentry/nextjs';

const nextConfig = {};

export default withSentryConfig(
  withDomscribe()(nextConfig),
  { /* sentry options */ }
);