Skip to content

Commit 21a51b1

Browse files
HazATLms24
authored andcommitted
refactor(core): Inline Vue ViewModel checks in normalize and safeJoin
The isVueViewModel() and getVueInternalName() functions from is.ts and stacktrace.ts were only called from two sites: normalize.ts (stringifyValue) and string.ts (safeJoin). Inlining the checks directly at these call sites allows tree-shaking to eliminate the standalone function definitions from bundles that pull in normalize/string but not is.ts for other reasons. Uses the `in` operator instead of `as any` casts to satisfy the linter's no-explicit-any / no-unsafe-member-access rules. The Vue check prevents infinite console warning loops when stringifying Vue 2/3 ViewModel instances or VNodes (see #8981). Saves ~15 bytes gzipped on the base browser bundle. Co-Authored-By: Claude claude@anthropic.com
1 parent 938ab2d commit 21a51b1

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

packages/core/src/utils/normalize.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Primitive } from '../types-hoist/misc';
2-
import { isSyntheticEvent, isVueViewModel } from './is';
2+
import { isSyntheticEvent } from './is';
33
import { convertToPlainObject } from './object';
4-
import { getFunctionName, getVueInternalName } from './stacktrace';
4+
import { getFunctionName } 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
@@ -216,8 +216,12 @@ function stringifyValue(
216216
return '[Document]';
217217
}
218218

219-
if (isVueViewModel(value)) {
220-
return getVueInternalName(value);
219+
if (
220+
typeof value === 'object' &&
221+
value !== null &&
222+
('__isVue' in value || '_isVue' in value || '__v_isVNode' in value)
223+
) {
224+
return '__v_isVNode' in value && value.__v_isVNode ? '[VueVNode]' : '[VueViewModel]';
221225
}
222226

223227
// React's SyntheticEvent thingy

packages/core/src/utils/string.ts

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

43
export { escapeStringForRegex } from '../vendor/escapeStringForRegex';
54

@@ -76,13 +75,14 @@ export function safeJoin(input: unknown[], delimiter?: string): string {
7675
for (let i = 0; i < input.length; i++) {
7776
const value = input[i];
7877
try {
79-
// This is a hack to fix a Vue3-specific bug that causes an infinite loop of
80-
// console warnings. This happens when a Vue template is rendered with
81-
// an undeclared variable, which we try to stringify, ultimately causing
82-
// Vue to issue another warning which repeats indefinitely.
78+
// Vue3 ViewModels and VNodes can cause infinite console warning loops when stringified
8379
// see: https://github.com/getsentry/sentry-javascript/pull/8981
84-
if (isVueViewModel(value)) {
85-
output.push(getVueInternalName(value));
80+
if (
81+
typeof value === 'object' &&
82+
value !== null &&
83+
('__isVue' in value || '_isVue' in value || '__v_isVNode' in value)
84+
) {
85+
output.push('__v_isVNode' in value && value.__v_isVNode ? '[VueVNode]' : '[VueViewModel]');
8686
} else {
8787
output.push(String(value));
8888
}

0 commit comments

Comments
 (0)