React

The @domscribe/react package provides React fiber walking, props/state extraction, and bundler plugins for Vite and Webpack.

Install

npm install -D @domscribe/react

Vite Setup

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { domscribe } from '@domscribe/react/vite';

export default defineConfig({
  plugins: [react(), domscribe()],
});

Webpack Setup

Webpack requires both a loader (for AST transformation) and a plugin (for relay and overlay coordination):

// webpack.config.js
const { DomscribeWebpackPlugin } = require('@domscribe/react/webpack');

const isDevelopment = process.env.NODE_ENV !== 'production';

module.exports = {
  module: {
    rules: [
      {
        test: /\.[jt]sx?$/,
        exclude: /node_modules/,
        enforce: 'pre',
        use: [
          {
            loader: '@domscribe/transform/webpack-loader',
            options: { enabled: isDevelopment },
          },
        ],
      },
    ],
  },
  plugins: [
    new DomscribeWebpackPlugin({
      enabled: isDevelopment,
      overlay: true,
    }),
  ],
};

Supported Versions

Plugin Options

The React plugin extends the base transform options with runtime and capture namespaces:

domscribe({
  // Base transform options
  include: /\.(jsx|tsx)$/,
  exclude: /node_modules/,
  debug: false,
  relay: { autoStart: true, port: 0, host: '127.0.0.1' },
  overlay: true,

  // React-specific
  runtime: { /* ... */ },
  capture: { /* ... */ },
})

Runtime Options

OptionTypeDefaultDescription
phase1 | 21Feature phase gate. Phase 1: props/state. Phase 2: events/perf.
redactPIIbooleantrueRedact sensitive values in captured data.
blockSelectorsstring[][]CSS selectors to exclude from capture.

Capture Options

OptionTypeDefaultDescription
strategy'devtools' | 'fiber' | 'best-effort''best-effort'Capture strategy (see below).
maxTreeDepthnumber50Maximum component tree depth to traverse.
includeWrappersbooleantrueInclude HOC/memo/forwardRef wrapper components.
hookNameResolversRecord<string, Record<number, string>>undefinedMap component names to hook index to semantic name mappings.

Capture Strategies

The React adapter supports three strategies for accessing component data:

Hook Name Resolvers

By default, React hook state appears as indexed values (hook 0, hook 1, etc.). You can provide semantic names for better readability:

domscribe({
  capture: {
    hookNameResolvers: {
      Counter: { 0: 'count', 1: 'setCount' },
      TodoList: { 0: 'items', 1: 'filter' },
    },
  },
})

Subpath Exports