Skip to content

Commit

Permalink
fix(runtime-core): fix errorHandler causes an infinite loop during ex…
Browse files Browse the repository at this point in the history
…ecution (#9575)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent 31ed1f4 commit ab59bed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/runtime-core/__tests__/errorHandling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
3 changes: 3 additions & 0 deletions packages/runtime-core/src/errorHandling.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit ab59bed

Please sign in to comment.