MCPcopy
hub / github.com/benjitaylor/agentation / getReactComponentName

Function getReactComponentName

package/src/utils/react-detection.ts:619–704  ·  view source on GitHub ↗
(
  element: HTMLElement,
  config?: ReactDetectionConfig,
)

Source from the content-addressed store, hash-verified

617 * @returns ReactComponentInfo with component path and array
618 */
619export function getReactComponentName(
620 element: HTMLElement,
621 config?: ReactDetectionConfig,
622): ReactComponentInfo {
623 const resolved = resolveConfig(config);
624
625 // Only use cache for 'all' mode - filtered modes must NOT cache because:
626 // - Cache lookup happens BEFORE filtering logic runs
627 // - Cached results from before filter updates would bypass new filters
628 // - This was causing "Root", "ErrorBoundaryHandler" to leak through
629 const useCache = resolved.mode === "all";
630
631 if (useCache) {
632 const cached = componentCacheAllRef.map.get(element);
633 if (cached !== undefined) {
634 return cached;
635 }
636 }
637
638 if (!isReactPage()) {
639 const result: ReactComponentInfo = { path: null, components: [] };
640 if (useCache) {
641 componentCacheAllRef.map.set(element, result);
642 }
643 return result;
644 }
645
646 // Collect DOM classes for smart mode
647 const domClasses =
648 resolved.mode === "smart" ? getAncestorClasses(element) : undefined;
649
650 const components: string[] = [];
651
652 try {
653 let fiber = getFiberFromElement(element);
654 let depth = 0;
655
656 while (
657 fiber &&
658 depth < resolved.maxDepth &&
659 components.length < resolved.maxComponents
660 ) {
661 const name = getComponentNameFromFiber(fiber);
662
663 // Skip minified names and apply filter
664 if (
665 name &&
666 !isMinifiedName(name) &&
667 shouldIncludeComponent(name, depth, resolved, domClasses)
668 ) {
669 components.push(name);
670 }
671
672 fiber = fiber.return;
673 depth++;
674 }
675 } catch {
676 // Fiber structure may be corrupted or inaccessible - return empty result

Callers 2

identifyElementWithReactFunction · 0.90

Calls 7

resolveConfigFunction · 0.85
isReactPageFunction · 0.85
getAncestorClassesFunction · 0.85
isMinifiedNameFunction · 0.85
shouldIncludeComponentFunction · 0.85
getFiberFromElementFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…