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:- Finds the Fiber node using
getFiberFromHostInstance(element)from thebippylibrary - Traverses the Fiber tree to locate composite (component) Fibers
- Extracts the component name using
getDisplayName(fiber.type)
Stack Trace Extraction
React Grab uses React’s debug stack to determine where components are defined:functionName- The component or function namefileName- Source file path (normalized)lineNumberandcolumnNumber- Exact source location
Source Mapping
Next.js Server Components
For Next.js applications, React Grab handles server component source mapping specially:- Detects server component URLs like
rsc://React/Server/webpack-internal://... - Symbolicates frames by posting to Next.js dev server endpoint:
- Enriches frames with original source locations from bundler source maps
Source File Detection
TheisSourceFile() 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 throughisValidGrabbableElement():
- 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-ignoreattribute
Multi-Element Selection
When dragging to select multiple elements:- Calculate drag rectangle from start/end coordinates
- 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:- Bounds calculation from element’s
getBoundingClientRect() - Transform handling for CSS transforms up to 6 ancestor levels
- Smooth interpolation using lerp for visual smoothness:
Visual Components
Selection Box: Highlights the currently hovered elementElement Labels
Floating labels display component information: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
