@domscribe/react

中文文档
0.7.0发布于 2026/10/28TypeScriptES Module构建来源已验证近 30 天下载 14万

React adapter for Domscribe

原始使用文档
文档目录9 节
  1. Install
  2. Vite
  3. Webpack
  4. Plugin Options
  5. Style Capture (RFC 0001)
  6. Runtime Options
  7. Capture Options
  8. Hook State Extraction
  9. Subpath Exports

@domscribe/react

React adapter for Domscribe — fiber walking, props/state extraction, and bundler plugins.

Install

npm install -D @domscribe/react

Vite

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

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

Webpack

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

// Add to plugins array + add webpack loader rule
// (see @domscribe/transform README for full webpack config)

Plugin Options

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

interface DomscribeReactPluginOptions {
  // Base transform options
  include?: RegExp;
  exclude?: RegExp;
  debug?: boolean;
  relay?: { autoStart?: boolean; port?: number; host?: string };
  overlay?:
    | boolean
    | { initialMode?: 'collapsed' | 'expanded'; debug?: boolean };
  captureStyles?: boolean;

  // React-specific
  runtime?: DomscribeRuntimeOptions;
  capture?: DomscribeReactCaptureOptions;
}

Style Capture (RFC 0001)

captureStyles: true enables both style-capture tiers with one flag: build-time styleSource attribution in the manifest and runtime componentStyles snapshots (computed-style allowlist + CSS custom properties). This powers styling-aware agent workflows — domscribe.query.bySource returns the element's resolved styles, and the domscribe.verify.* MCP tools can compute per-property deltas after an edit. Off by default in v0.x. runtime.captureStyles overrides the runtime tier independently.

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
serializationSerializationConstraintsundefinedSerialization bounds (maxDepth, maxArrayLength, maxTotalBytes, etc.) — see @domscribe/runtime README
captureStylesbooleanfalseRuntime-tier style capture (overrides the top-level flag when set)
styleOptionsStyleCaptureOptionsundefinedStyle capturer tuning (allowlist, maxCustomProperties, maxBytes)

Capture Options

OptionTypeDefaultDescription
strategy'devtools' | 'fiber' | 'best-effort''best-effort'Capture strategy. devtools uses React DevTools hook (most reliable), fiber accesses Fiber tree directly (fast), best-effort tries multiple strategies
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. Keys are component names, values map hook index to name. Converted to Map<string, Map<number, string>> at runtime.

Hook State Extraction

The React adapter classifies hooks by inspecting the structure of each hook's memoizedState and applies smart extraction:

  • Effect hooks (useEffect, useLayoutEffect) are excluded from captured state — they contain only internal scheduling data ({tag, create, destroy, deps}), not application state.
  • Memo/callback hooks (useMemo, useCallback) return only the cached value — the dependency array is discarded.
  • Ref hooks (useRef) are captured as {current: value}.
  • State/reducer hooks (useState, useReducer) are captured as-is.

Hooks use semantic names based on their inferred type: state_0, ref_0, memo_0, unknown_0.

Subpath Exports

  • @domscribe/react/vite — Vite plugin with React adapter
  • @domscribe/react/webpack — Webpack plugin with React adapter
  • @domscribe/react/auto-init — Auto-initialization module

Part of the Domscribe monorepo. License: MIT.

版本与发布记录

@domscribe/react 共发布 16 个版本,首次发布于 2026/03/18;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/10/2816 天前
0.6.12026/10/2519 天前
0.5.22026/04/017 个月前
0.5.12026/04/017 个月前
0.5.02026/03/277 个月前
0.4.02026/03/277 个月前

关于 @domscribe/react 的常见问题

@domscribe/react 是什么?

React adapter for Domscribe

如何安装 @domscribe/react?

在项目目录运行 npm install @domscribe/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@domscribe/react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@domscribe/react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@domscribe/react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@domscribe/react 可以商用吗?

@domscribe/react 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@domscribe/react 的下载量有多少?

根据 npm 官方下载统计,@domscribe/react 在 2026/10/13 – 2026/11/11 这 30 天内被下载 140,402 次,日均约 4,680 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@domscribe/react 还在维护吗?

最新版本 0.7.0 发布于 2026/10/28(16 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/03/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。