Skip to content

Commit e5768ca

Browse files
committed
Limit getComponentName traverse depth
1 parent 56e005c commit e5768ca

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

packages/browser/src/integrations/view-hierarchy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const viewHierarchyIntegration = defineIntegration((options: Options = {}
6262
continue;
6363
}
6464

65-
const componentName = getComponentName(child) || undefined;
65+
const componentName = getComponentName(child, 1) || undefined;
6666
const tagName = child.tagName.toLowerCase();
6767

6868
if (skipHtmlTags.includes(tagName)) {

packages/core/src/utils/browser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,14 @@ export function getLocationHref(): string {
145145
*
146146
* @returns a string representation of the component for the provided DOM element, or `null` if not found
147147
*/
148-
export function getComponentName(elem: unknown): string | null {
148+
export function getComponentName(elem: unknown, maxTraverseHeight: number = 5): string | null {
149149
// @ts-expect-error WINDOW has HTMLElement
150150
if (!WINDOW.HTMLElement) {
151151
return null;
152152
}
153153

154154
let currentElem = elem as SimpleNode;
155-
const MAX_TRAVERSE_HEIGHT = 5;
156-
for (let i = 0; i < MAX_TRAVERSE_HEIGHT; i++) {
155+
for (let i = 0; i < maxTraverseHeight; i++) {
157156
if (!currentElem) {
158157
return null;
159158
}

0 commit comments

Comments
 (0)