8000 feat: fix vue3 render warning loop (#6014) · vaind/sentry-javascript@d8751dc · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d8751dc

Browse files
authored
feat: fix vue3 render warning loop (getsentry#6014)
This patch fixes an infinite loop that would occur in Vue 3 apps with undeclared refs. Why this happens: 1. Vue3 supports the property `ref` in the second arg of `h` method (see https://cn.vuejs.org/guide/essentials/template-refs.html) 2. When a with an undeclared variable is rendered, Vue3 will call `console.warn` to print the error stack. 3. Sentry instruments `console` (for the `BreadCrumbs` integration), and adds the message to the `Breadcrumb` with `safeJoin`. 4. `safeJoin` converts variables to string. The ref variable is a proxied object via `Proxy` by Vue. so, when `String(value)` is called upon the undefined ref, it will trigger the getter of the Proxy, and which causes Vue3 to call `console.warn` again. 5. This repeats infinitely. Solutions: Because there's no reliable way of testing if an object is a `Proxy`, the solution in this case is tailored to this exact scenario. In the breadcrumbs integration code, we check if the passed arguments to the `console.warn` match the specific warning described above. In case of a match, we alter the following argument to not trigger a warning again, thus leaving us with the one warning we want and getting rid of the infinite loop.
1 parent 6df7632 commit d8751dc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ function _domBreadcrumb(dom: BreadcrumbsOptions['dom']): (handlerData: { [key: s
135135
*/
136136
// eslint-disable-next-line @typescript-eslint/no-explicit-any
137137
function _consoleBreadcrumb(handlerData: { [key: string]: any }): void {
138+
// This is a hack to fix a Vue3-specific bug that causes an infinite loop of
139+
// console warnings. This happens when a Vue template is rendered with
140+
// an undeclared variable, which we try to stringify, ultimately causing
141+
// Vue to issue another warning which repeats indefinitely.
142+
// see: https://github.com/getsentry/sentry-javascript/pull/6010
143+
// see: https://github.com/getsentry/sentry-javascript/issues/5916
144+
for (let i = 0; i < handlerData.args.length; i++) {
145+
if (handlerData.args[i] === 'ref=Ref<') {
146+
handlerData.args[i + 1] = 'viewRef';
147+
break;
148+
}
149+
}
138150
const breadcrumb = {
139151
category: 'console',
140152
data: {

0 commit comments

Comments
 (0)
0