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

Function findDebugSourceReact19

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

* Attempts to find source location using React 19's potentially different structure * * @param fiber - Starting fiber node * @returns Source location info or null

(
  fiber: ReactFiber
)

Source from the content-addressed store, hash-verified

320 * @returns Source location info or null
321 */
322function findDebugSourceReact19(
323 fiber: ReactFiber
324): { source: ReactFiber["_debugSource"]; componentName: string | null } | null {
325 // React 19 may store debug info differently
326 // This is a forward-compatible attempt based on React 19 RFCs
327
328 let current: ReactFiber | null | undefined = fiber;
329 let depth = 0;
330 const maxDepth = 50;
331
332 while (current && depth < maxDepth) {
333 // Check for new React 19 debug patterns
334 const anyFiber = current as unknown as Record<string, unknown>;
335
336 // Possible React 19 locations for debug info
337 const possibleSourceKeys = [
338 "_debugSource",
339 "__source",
340 "_source",
341 "debugSource",
342 ];
343
344 for (const key of possibleSourceKeys) {
345 const source = anyFiber[key];
346 if (source && typeof source === "object" && "fileName" in source) {
347 return {
348 source: source as ReactFiber["_debugSource"],
349 componentName: getComponentName(current),
350 };
351 }
352 }
353
354 // Check if debug info is in the element itself
355 if (current.memoizedProps) {
356 const props = current.memoizedProps as Record<string, unknown>;
357 if (props.__source && typeof props.__source === "object") {
358 const source = props.__source as { fileName?: string; lineNumber?: number };
359 if (source.fileName && source.lineNumber) {
360 return {
361 source: {
362 fileName: source.fileName,
363 lineNumber: source.lineNumber,
364 columnNumber: (source as { columnNumber?: number }).columnNumber,
365 },
366 componentName: getComponentName(current),
367 };
368 }
369 }
370 }
371
372 current = current.return;
373 depth++;
374 }
375
376 return null;
377}
378
379// =============================================================================

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…