]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix errorHandler causes an infinite loop during execution (#9575)
author丶远方 <yangpanteng@gmail.com>
Tue, 19 Mar 2024 12:47:52 +0000 (20:47 +0800)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2024 12:47:52 +0000 (20:47 +0800)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
packages/runtime-core/__tests__/errorHandling.spec.ts
packages/runtime-core/src/errorHandling.ts

index d995c5fa057f8280f2850f692734b453d7248056..085127677baedc134585d2be4823ff04c61da9dc 100644 (file)
@@ -583,5 +583,31 @@ describe('error handling', () => {
     expect(handler).toHaveBeenCalledTimes(4)
   })
 
+  // #9574
+  test('should pause tracking in error handler', async () => {
+    const error = new Error('error')
+    const x = ref(Math.random())
+
+    const handler = vi.fn(() => {
+      x.value
+      x.value = Math.random()
+    })
+
+    const app = createApp({
+      setup() {
+        return () => {
+          throw error
+        }
+      },
+    })
+
+    app.config.errorHandler = handler
+    app.mount(nodeOps.createElement('div'))
+
+    await nextTick()
+    expect(handler).toHaveBeenCalledWith(error, {}, 'render function')
+    expect(handler).toHaveBeenCalledTimes(1)
+  })
+
   // native event handler handling should be tested in respective renderers
 })
index 041eb123938447b48ac360baecd1d4b90b3a272d..dda6480385b22180af0f8ffd222768ae26c5f443 100644 (file)
@@ -1,3 +1,4 @@
+import { pauseTracking, resetTracking } from '@vue/reactivity'
 import type { VNode } from './vnode'
 import type { ComponentInternalInstance } from './component'
 import { popWarningContext, pushWarningContext, warn } from './warning'
@@ -127,12 +128,14 @@ export function handleError(
     // app-level handling
     const appErrorHandler = instance.appContext.config.errorHandler
     if (appErrorHandler) {
+      pauseTracking()
       callWithErrorHandling(
         appErrorHandler,
         null,
         ErrorCodes.APP_ERROR_HANDLER,
         [err, exposedInstance, errorInfo],
       )
+      resetTracking()
       return
     }
   }