react-fray
v1.1.0
Published
Headless React Fiber tracing agent that connects to a control-plane server via WebSocket with a crash-resilient WAL.
Readme
React Fiber graph
Injects a live force-directed graph of React's Fiber tree into any page that runs React. bippy reads the fibers, force-graph draws them.
Shown: the three pointers every fiber has.
| Link | Meaning | Drawn as |
| --- | --- | --- |
| child | parent to its first child | solid blue line |
| sibling | fiber to its next sibling | dashed grey line (toggle) |
| return | fiber to its parent | curved orange arrow (toggle, off by default) |
Run it
npm install
npm run dev # demo app at http://localhost:5173 with the panel already openCLI (Recommended)
The CLI uses Playwright to launch a browser instance with the Fiber Graph script pre-injected. This is the most reliable way to inspect any existing website without dealing with CSP issues or manual script tags.
npm run build
npx fiber-graph https://react.dev(You may need to run npx playwright install chromium first if you haven't used Playwright before).
Bookmarklet & Script Tag
If you cannot use the CLI, you can build the project and serve it locally:
npm run build # emits dist/fiber-graph.iife.js
npm run serve # serves dist/ at http://127.0.0.1:4173
npm run bookmarkletPaste the printed javascript: URL into a bookmark. Click it on a React page to open the panel; click again to toggle.
Alt+Shift+F also toggles. npm run watch rebuilds on change.
Injection modes
| Mode | How | Updates |
| --- | --- | --- |
| Live | bippy loaded before React (demo, your own app, or userscript/fiber-graph.user.js with @run-at document-start) | on every commit, throttled to about 6 per second |
| DOM scan | bookmarklet or console paste, after React already booted | on DOM mutations |
The panel status line says which mode is active. For your own app, add <script src="http://127.0.0.1:4173/fiber-graph.iife.js"></script> before your entry module to get live mode without a userscript.
How the edge cases are handled
- Hook timing. React only reports to the DevTools hook if the hook exists when React loads. Late injection can't get commit events, so roots are recovered from DOM properties (
__reactFiber$…,__reactContainer$…,_reactRootContainer) by climbingreturnto HostRoot. Open shadow roots are searched, iframes are not. - Existing DevTools. If the React DevTools extension already owns the hook, bippy wraps it and roots come from
hook.getFiberRoots. - Double buffering. Each fiber has a
currentand a work-in-progress twin. Traversal always starts atroot.current, and node identity comes from bippy'sgetFiberId, which stays stable across alternates, so nodes don't flicker or reset on each commit. - Unchanged structure. A signature of the visible tree is compared; if nothing structural changed, the layout is left alone.
- Large trees.
max nodes(default 1500) caps traversal and the status line warns when truncated. Hiding text, DOM elements, or fragments/modes re-links children to the nearest visible ancestor. - Self-pollution. The panel is plain DOM in a shadow root, so it never appears in the graph and page CSS can't touch it. force-graph's built-in tooltips are disabled because their CSS is injected into
<head>and would not reach the shadow root. - Multiple roots, portals, unmounts. Each root is a separate component in the graph; portals appear as pink nodes; disconnected roots are pruned.
Limitations
- CSP. Pages with a strict
script-srcblock the bookmarklet. Use the userscript, a console paste ofdist/fiber-graph.iife.js, or a browser extension. - HTTPS pages. Loading
http://127.0.0.1from HTTPS is allowed in Chromium and Firefox but some setups block it. Host the bundle over HTTPS if so. - Production builds. They work, but component names are minified, and any
Tag Nlabels may be approximate for tags added in newer React versions. - React DOM only. DOM scanning does not apply to React Native or other renderers. Live mode works for any renderer that reports to the hook, but DOM highlighting won't.
- Tree layout shows the logical hierarchy with real child and sibling links on top, so only each parent's first child has a vertical line.
- Not run in a real browser here. The project type-checks and builds, but I could not drive it in a browser from my sandbox. If something misbehaves, the status line and console are the first places to look.
Layout
src/fiber.ts root discovery, fiber -> graph conversion (bippy)
src/panel.ts force-graph rendering, controls, hover/click
src/main.ts entry, throttling, show/hide API (window.__FIBER_GRAPH__)
demo/main.tsx small app with context, memo, forwardRef, Suspense, a portal, a keyed list