Skip to content

Commit ab59bed

Browse files
Alfred-Skyblueautofix-ci[bot]haoqunjiang
authoredMar 19, 2024··
fix(runtime-core): fix errorHandler causes an infinite loop during execution (#9575)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
1 parent 31ed1f4 commit ab59bed

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎packages/runtime-core/__tests__/errorHandling.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -583,5 +583,31 @@ describe('error handling', () => {
583583
expect(handler).toHaveBeenCalledTimes(4)
584584
})
585585

586+
// #9574
587+
test('should pause tracking in error handler', async () => {
588+
const error = new Error('error')
589+
const x = ref(Math.random())
590+
591+
const handler = vi.fn(() => {
592+
x.value
593+
x.value = Math.random()
594+
})
595+
596+
const app = createApp({
597+
setup() {
598+
return () => {
599+
throw error
600+
}
601+
},
602+
})
603+
604+
app.config.errorHandler = handler
605+
app.mount(nodeOps.createElement('div'))
606+
607+
await nextTick()
608+
expect(handler).toHaveBeenCalledWith(error, {}, 'render function')
609+
expect(handler).toHaveBeenCalledTimes(1)
610+
})
611+
586612
// native event handler handling should be tested in respective renderers
587613
})

‎packages/runtime-core/src/errorHandling.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { pauseTracking, resetTracking } from '@vue/reactivity'
12
import type { VNode } from './vnode'
23
import type { ComponentInternalInstance } from './component'
34
import { popWarningContext, pushWarningContext, warn } from './warning'
@@ -127,12 +128,14 @@ export function handleError(
127128
// app-level handling
128129
const appErrorHandler = instance.appContext.config.errorHandler
129130
if (appErrorHandler) {
131+
pauseTracking()
130132
callWithErrorHandling(
131133
appErrorHandler,
132134
null,
133135
ErrorCodes.APP_ERROR_HANDLER,
134136
[err, exposedInstance, errorInfo],
135137
)
138+
resetTracking()
136139
return
137140
}
138141
}

0 commit comments

Comments
 (0)
Please sign in to comment.