MCPcopy Create free account
hub / github.com/benjitaylor/agentation / findDebugSource

Function findDebugSource

package/src/utils/source-location.ts:284–314  ·  view source on GitHub ↗

* Walks up the fiber tree to find the nearest component with _debugSource * * @param fiber - Starting fiber node * @param maxDepth - Maximum tree depth to traverse (default: 50) * @returns Object with source info and component name, or null

(
  fiber: ReactFiber,
  maxDepth = 50
)

Source from the content-addressed store, hash-verified

282 * @returns Object with source info and component name, or null
283 */
284function findDebugSource(
285 fiber: ReactFiber,
286 maxDepth = 50
287): { source: ReactFiber["_debugSource"]; componentName: string | null } | null {
288 let current: ReactFiber | null | undefined = fiber;
289 let depth = 0;
290
291 while (current && depth < maxDepth) {
292 // Check current fiber for debug source
293 if (current._debugSource) {
294 return {
295 source: current._debugSource,
296 componentName: getComponentName(current),
297 };
298 }
299
300 // Check debug owner (for components that wrap the element)
301 if (current._debugOwner?._debugSource) {
302 return {
303 source: current._debugOwner._debugSource,
304 componentName: getComponentName(current._debugOwner),
305 };
306 }
307
308 // Move up the tree
309 current = current.return;
310 depth++;
311 }
312
313 return null;
314}
315
316/**
317 * Attempts to find source location using React 19's potentially different structure

Callers 1

getSourceLocationFunction · 0.85

Calls 1

getComponentNameFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…