Skip to main content

Overview

React Grab uses a combination of React Fiber introspection, source mapping, element detection, and an interactive overlay system to let you inspect and copy React components directly from your browser.

React Fiber Debugging

React Grab taps into React’s internal Fiber architecture to extract component information and source locations.

Component Discovery

When you hover over an element, React Grab:
  1. Finds the Fiber node using getFiberFromHostInstance(element) from the bippy library
  2. Traverses the Fiber tree to locate composite (component) Fibers
  3. Extracts the component name using getDisplayName(fiber.type)
The system filters out internal components like Next.js internals and React primitives:

Stack Trace Extraction

React Grab uses React’s debug stack to determine where components are defined:
The stack contains frames with:
  • functionName - The component or function name
  • fileName - Source file path (normalized)
  • lineNumber and columnNumber - Exact source location

Source Mapping

Next.js Server Components

For Next.js applications, React Grab handles server component source mapping specially:
  1. Detects server component URLs like rsc://React/Server/webpack-internal://...
  2. Symbolicates frames by posting to Next.js dev server endpoint:
  1. Enriches frames with original source locations from bundler source maps

Source File Detection

The isSourceFile() function from bippy/source determines if a file path is user code (not node_modules or bundler internals):

Element Detection

React Grab continuously tracks the element under your cursor using a throttled detection system:

Detection Pipeline

Valid Element Criteria

Elements must pass validation through isValidGrabbableElement():
  • Not a root element (html, body, #root, #__next)
  • Not part of React Grab’s own overlay UI
  • Connected to the DOM
  • Not marked with data-react-grab-ignore attribute

Multi-Element Selection

When dragging to select multiple elements:
  1. Calculate drag rectangle from start/end coordinates
  2. Sample points within the rectangle using a grid pattern:

Overlay System

The overlay provides visual feedback using a canvas-based rendering system.

Overlay Layers

React Grab uses multiple overlay layers with precise z-index management:

Selection Box Rendering

Selection boxes are drawn with:
  1. Bounds calculation from element’s getBoundingClientRect()
  2. Transform handling for CSS transforms up to 6 ancestor levels
  3. Smooth interpolation using lerp for visual smoothness:

Visual Components

Selection Box: Highlights the currently hovered element
Drag Box: Shows the rectangular selection area during drag
Grabbed Boxes: Temporary flash effects after successful copy
Crosshair: Precision cursor overlay for accurate targeting

Element Labels

Floating labels display component information:
Labels automatically position above or below elements with intelligent arrow placement based on viewport constraints.

State Management

React Grab uses SolidJS signals for reactive state management:

Reactive Updates

Effects automatically respond to state changes:

Performance Optimizations

Caching

  • Stack cache: WeakMap<Element, Promise<StackFrame[]>> prevents redundant Fiber traversal
  • Bounds cache: Element bounds cached for 16ms (BOUNDS_CACHE_TTL_MS)
  • Component name debouncing: 100ms delay before resolving component names

Throttling

Animation Freezing

When activated, React Grab can freeze React updates to prevent UI changes:
This uses React DevTools internals to pause component updates during inspection.