From 0c9c2a2863211432f232e3b14ccf62adea6ebe67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Thu, 9 Nov 2023 13:35:25 +0800 Subject: [PATCH 1/3] fix(runtime-core): fix errorHandler causes an infinite loop during execution --- packages/runtime-core/src/errorHandling.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/runtime-core/src/errorHandling.ts b/packages/runtime-core/src/errorHandling.ts index afbd226c4c6..7222871d58a 100644 --- a/packages/runtime-core/src/errorHandling.ts +++ b/packages/runtime-core/src/errorHandling.ts @@ -1,3 +1,4 @@ +import { pauseTracking, resetTracking } from '@vue/reactivity' import { VNode } from './vnode' import { ComponentInternalInstance } from './component' import { warn, pushWarningContext, popWarningContext } 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 } } From 8d2aad8dd33b1291b13813c75ae34f5309c3d595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Thu, 23 Nov 2023 11:14:24 +0800 Subject: [PATCH 2/3] test(runtime-core): add unit test --- .../__tests__/errorHandling.spec.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/runtime-core/__tests__/errorHandling.spec.ts b/packages/runtime-core/__tests__/errorHandling.spec.ts index ebbfeb1d08e..f8ba1e82ea9 100644 --- a/packages/runtime-core/__tests__/errorHandling.spec.ts +++ b/packages/runtime-core/__tests__/errorHandling.spec.ts @@ -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 }) From fb0e9d9f68f63814bfbea1c10f755833d657a094 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 28 Dec 2023 13:58:44 +0000 Subject: [PATCH 3/3] [autofix.ci] apply automated fixes --- packages/runtime-core/__tests__/errorHandling.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/errorHandling.spec.ts b/packages/runtime-core/__tests__/errorHandling.spec.ts index 1b076040827..085127677ba 100644 --- a/packages/runtime-core/__tests__/errorHandling.spec.ts +++ b/packages/runtime-core/__tests__/errorHandling.spec.ts @@ -598,7 +598,7 @@ describe('error handling', () => { return () => { throw error } - } + }, }) app.config.errorHandler = handler