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

Function getComponentNameFromFiber

package/src/utils/react-detection.ts:466–585  ·  view source on GitHub ↗
(fiber: ReactFiber)

Source from the content-addressed store, hash-verified

464}
465
466function getComponentNameFromFiber(fiber: ReactFiber): string | null {
467 const { tag, type, elementType } = fiber;
468
469 // Skip DOM elements and host types
470 if (
471 tag === FiberTags.HostComponent ||
472 tag === FiberTags.HostText ||
473 tag === FiberTags.HostHoistable ||
474 tag === FiberTags.HostSingleton
475 ) {
476 return null;
477 }
478
479 // Skip Fragment, Mode, Profiler, and related internal types
480 if (
481 tag === FiberTags.Fragment ||
482 tag === FiberTags.Mode ||
483 tag === FiberTags.Profiler ||
484 tag === FiberTags.DehydratedFragment
485 ) {
486 return null;
487 }
488
489 // Skip React internal infrastructure types (these are internal implementation details)
490 if (
491 tag === FiberTags.HostRoot ||
492 tag === FiberTags.HostPortal ||
493 tag === FiberTags.ScopeComponent ||
494 tag === FiberTags.OffscreenComponent ||
495 tag === FiberTags.LegacyHiddenComponent ||
496 tag === FiberTags.CacheComponent ||
497 tag === FiberTags.TracingMarkerComponent ||
498 tag === FiberTags.Throw ||
499 tag === FiberTags.ViewTransitionComponent ||
500 tag === FiberTags.ActivityComponent
501 ) {
502 return null;
503 }
504
505 // Handle ForwardRef
506 if (tag === FiberTags.ForwardRef) {
507 const elType = elementType as ComponentType | null;
508 if (elType?.render) {
509 const innerName = getComponentNameFromType(elType.render);
510 if (innerName) return innerName;
511 }
512 if (elType?.displayName) return elType.displayName;
513 return getComponentNameFromType(type as ComponentType);
514 }
515
516 // Handle Memo
517 if (
518 tag === FiberTags.MemoComponent ||
519 tag === FiberTags.SimpleMemoComponent
520 ) {
521 const elType = elementType as ComponentType | null;
522 if (elType?.type) {
523 const innerName = getComponentNameFromType(elType.type);

Callers 1

getReactComponentNameFunction · 0.85

Calls 1

getComponentNameFromTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…