Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Overview

react-render-recorder captures per-commit React hook value changes and formats them for AI-assisted analysis with models like GPT, Claude, and Gemini.

Suspense updates are not supported.

How to use

Paste the recorder script into your app before the React app runs.

<script
  crossorigin="anonymous"
  src="https://unpkg.com/react-render-recorder@0.1.5/dist/react-render-recorder.js"
></script>

Examples

Examples live in the example directory.

Vite + React

The Vite example loads the recorder script in index.html.

<script
  crossorigin="anonymous"
  src="https://unpkg.com/react-render-recorder@0.1.5/dist/react-render-recorder.js"
></script>

Next.js App Router

In the App Router, load the recorder from the root layout with next/script.

import Script from "next/script";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Script
          crossOrigin="anonymous"
          src="https://unpkg.com/react-render-recorder@0.1.5/dist/react-render-recorder.js"
          strategy="beforeInteractive"
        />
        {children}
      </body>
    </html>
  );
}

Next.js Pages Router

In the Pages Router, load the recorder from the custom document with next/script.

import { Head, Html, Main, NextScript } from "next/document";
import Script from "next/script";

export default function Document() {
  return (
    <Html lang="en">
      <Head>
        <Script
          crossOrigin="anonymous"
          src="https://unpkg.com/react-render-recorder@0.1.5/dist/react-render-recorder.js"
          strategy="beforeInteractive"
        />
      </Head>
      <body>
        <Main />
        <NextScript />
      </body>
    </Html>
  );
}

Browser API

The recorder exposes window.__REACT_RENDER_RECORDER__ after initialization. Use start() and end() to record an interaction, then read the output:

const recorder = window.__REACT_RENDER_RECORDER__;
recorder.start();
// Perform the interaction to inspect.
recorder.end();

const text = recorder.getCommitHistoryText({ includeSource: true });

getCommitHistoryText() accepts includeSource, includeCallerSource, includeHookPath, includeRenderDuration, and includeAllRenders (all default to false). These API options are independent of the panel and URL options.

Source maps resolve asynchronously after end(), which returns immediately. While resolution is pending, source output shows Source: Resolving… (and Called at: Resolving…); read the text again after resolution completes. If mapping fails, the generated location is marked (unmapped). getFiberChanges() returns JSON-safe raw changes with generated hookSource and hookCallerSource locations; it does not include resolved source locations.

Sources resolve when the generated file can be fetched and ends with a sourceMappingURL comment. webpack's eval devtool family (including the development default eval-source-map) is not supported; its webpack-internal:/// locations stay (unmapped). Bundler prefixes such as webpack://<name>/./ and file:// are stripped from resolved paths, and Turbopack's absolute paths are shown relative to its project root (the workspace root in a monorepo). Two kinds of location are not a place to edit in your repo:

Output Meaning
library (<pkg>) The source map ignore-lists the file (typically node_modules); the path is replaced by its package name, or just library when the path has none
(unmapped) No source map was found; the location is the generated, bundler-space file and position

URL options

Enable Show source in the recording panel options to show the original file, line, and column beneath each hook change. Source locations resolve asynchronously; unavailable source maps fall back to the generated location marked (unmapped). Both views and copied text include sources when enabled. Use ?source=true to enable it by default.

Enable Show caller source to add a Called at: line with the place in the component that started the custom hook chain leading to the changed hook — for useA() → useB() → useState(), the useA() call. Use ?callerSource=true to enable it by default.

Append boolean query parameters to the page URL to enable recorder options by default: ?record=true&shortcut=true.

Option Effect
record Start recording automatically when the first React commit is available
shortcut Start with the Ctrl+R recording shortcut already enabled
source Show source locations beneath hook changes
callerSource Show the component line that started the custom hook chain of each changed hook

Notes

  • Record one suspicious interaction at a time so the captured hook changes are easier to analyze.
  • If the commit count is higher than expected, first check whether the same component and hook changed repeatedly in Hook history.
  • Use the component name filter when you only want to send one part of the render flow to an AI model.
  • react-render-recorder captures hook value changes only. It does not directly capture other re-render causes such as prop changes, parent re-renders, context changes, or memoization misses.
  • This is a development tool for render analysis and debugging. Avoid shipping it in production user-facing paths.

Experimental

  • Paint grouping only works when React yields through MessageChannel. If React does not use MessageChannel for the recorded flow, paint grouping may be missing or inaccurate.

Development

The recorder depends on react-devtools-custom, which lives in the mdm317/react fork and is wired in as a git submodule under react. The fork's devtools-custom branch already ships a pre-built packages/react-devtools-custom/dist/, so no separate build step is needed for the submodule.

# Clone with submodule (or init after clone)
git clone --recurse-submodules <this-repo>
# or, for an existing clone:
git submodule update --init --recursive

# Install workspace deps and build the recorder
pnpm install
pnpm build

To iterate on the custom devtools, edit sources under react/packages/react-devtools-custom/src/, rebuild its dist/ in the fork, commit the new dist/ on devtools-custom, then bump the submodule pointer here with git submodule update --remote react and rerun pnpm install && pnpm build.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages