Skip to content

Commit 4108e9e

Browse files
committed
refactor: extract name resolution to a util
1 parent 059b535 commit 4108e9e

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

packages/core/src/utils/is.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ interface VueViewModel {
194194
_isVue?: boolean;
195195
}
196196
/**
197-
* Checks whether given value's type is a Vue ViewModel.
197+
* Checks whether given value's type is a Vue ViewModel or a VNode.
198198
*
199199
* @param wat A value to be checked.
200200
* @returns A boolean representing the result.
201201
*/
202202
export function isVueViewModel(wat: unknown): boolean {
203203
// Not using Object.prototype.toString because in Vue 3 it would read the instance's Symbol(Symbol.toStringTag) property.
204+
// We also need to check for __v_isVNode because Vue 3 component render instances have an internal __v_isVNode property.
205+
// https://github.com/vuejs/core/blob/main/packages/runtime-core/src/vnode.ts#L168
204206
return !!(
205207
typeof wat === 'object' &&
206208
wat !== null &&

packages/core/src/utils/normalize.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Primitive } from '../types-hoist/misc';
22
import { isSyntheticEvent, isVueViewModel } from './is';
33
import { convertToPlainObject } from './object';
4-
import { getFunctionName } from './stacktrace';
4+
import { getFunctionName, getVueInternalName } from './stacktrace';
55

66
type Prototype = { constructor?: (...args: unknown[]) => unknown };
77
// This is a hack to placate TS, relying on the fact that technically, arrays are objects with integer keys. Normally we
@@ -217,10 +217,7 @@ function stringifyValue(
217217
}
218218

219219
if (isVueViewModel(value)) {
220-
// Check if it's a VNode (has __v_isVNode) vs a component instance (has _isVue/__isVue)
221-
const isVNode = (value as { __v_isVNode?: boolean }).__v_isVNode;
222-
223-
return isVNode ? '[VueVNode]' : '[VueViewModel]';
220+
return getVueInternalName(value);
224221
}
225222

226223
// React's SyntheticEvent thingy

packages/core/src/utils/stacktrace.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,16 @@ export function getFramesFromEvent(event: Event): StackFrame[] | undefined {
164164
}
165165
return undefined;
166166
}
167+
168+
/**
169+
* Get the internal name of an internal Vue value, to represent it in a stacktrace.
170+
*
171+
* @param value The value to get the internal name of.
172+
*/
173+
export function getVueInternalName(value: unknown): string {
174+
// Check if it's a VNode (has __v_isVNode) vs a component instance (has _isVue/__isVue)
175+
// https://github.com/vuejs/core/blob/main/packages/runtime-core/src/vnode.ts#L168
176+
const isVNode = (value as { __v_isVNode?: boolean }).__v_isVNode;
177+
178+
return isVNode ? '[VueVNode]' : '[VueViewModel]';
179+
}

packages/core/src/utils/string.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isRegExp, isString, isVueViewModel } from './is';
2+
import { getVueInternalName } from './stacktrace';
23

34
export { escapeStringForRegex } from '../vendor/escapeStringForRegex';
45

@@ -81,7 +82,7 @@ export function safeJoin(input: unknown[], delimiter?: string): string {
8182
// Vue to issue another warning which repeats indefinitely.
8283
// see: https://github.com/getsentry/sentry-javascript/pull/8981
8384
if (isVueViewModel(value)) {
84-
output.push('[VueViewModel]');
85+
output.push(getVueInternalName(value));
8586
} else {
8687
output.push(String(value));
8788
}

0 commit comments

Comments
 (0)