mirror of https://github.com/vuejs/core.git
fix(runtime-core): ensure that errors in slot function execution do not affect block tracking (#5670)
fix #5657
This commit is contained in:
parent
5ee40532a6
commit
82a73da351
|
@ -8,11 +8,12 @@ import {
|
||||||
cloneVNode,
|
cloneVNode,
|
||||||
mergeProps,
|
mergeProps,
|
||||||
normalizeVNode,
|
normalizeVNode,
|
||||||
transformVNodeArgs
|
transformVNodeArgs,
|
||||||
|
isBlockTreeEnabled
|
||||||
} from '../src/vnode'
|
} from '../src/vnode'
|
||||||
import { Data } from '../src/component'
|
import { Data } from '../src/component'
|
||||||
import { ShapeFlags, PatchFlags } from '@vue/shared'
|
import { ShapeFlags, PatchFlags } from '@vue/shared'
|
||||||
import { h, reactive, isReactive, setBlockTracking, ref } from '../src'
|
import { h, reactive, isReactive, setBlockTracking, ref, withCtx } from '../src'
|
||||||
import { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
|
import { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
|
||||||
import { setCurrentRenderingInstance } from '../src/componentRenderContext'
|
import { setCurrentRenderingInstance } from '../src/componentRenderContext'
|
||||||
|
|
||||||
|
@ -614,6 +615,29 @@ describe('vnode', () => {
|
||||||
]))
|
]))
|
||||||
expect(vnode.dynamicChildren).toStrictEqual([])
|
expect(vnode.dynamicChildren).toStrictEqual([])
|
||||||
})
|
})
|
||||||
|
// #5657
|
||||||
|
test('error of slot function execution should not affect block tracking', () => {
|
||||||
|
expect(isBlockTreeEnabled).toStrictEqual(1)
|
||||||
|
const slotFn = withCtx(
|
||||||
|
() => {
|
||||||
|
throw new Error('slot execution error')
|
||||||
|
},
|
||||||
|
{ type: {}, appContext: {} } as any
|
||||||
|
)
|
||||||
|
const Parent = {
|
||||||
|
setup(_: any, { slots }: any) {
|
||||||
|
return () => {
|
||||||
|
try {
|
||||||
|
slots.default()
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const vnode =
|
||||||
|
(openBlock(), createBlock(Parent, null, { default: slotFn }))
|
||||||
|
createApp(vnode).mount(nodeOps.createElement('div'))
|
||||||
|
expect(isBlockTreeEnabled).toStrictEqual(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('transformVNodeArgs', () => {
|
describe('transformVNodeArgs', () => {
|
||||||
|
|
|
@ -89,11 +89,15 @@ export function withCtx(
|
||||||
setBlockTracking(-1)
|
setBlockTracking(-1)
|
||||||
}
|
}
|
||||||
const prevInstance = setCurrentRenderingInstance(ctx)
|
const prevInstance = setCurrentRenderingInstance(ctx)
|
||||||
const res = fn(...args)
|
let res
|
||||||
|
try {
|
||||||
|
res = fn(...args)
|
||||||
|
} finally {
|
||||||
setCurrentRenderingInstance(prevInstance)
|
setCurrentRenderingInstance(prevInstance)
|
||||||
if (renderFnWithContext._d) {
|
if (renderFnWithContext._d) {
|
||||||
setBlockTracking(1)
|
setBlockTracking(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
|
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
|
||||||
devtoolsComponentUpdated(ctx)
|
devtoolsComponentUpdated(ctx)
|
||||||
|
|
Loading…
Reference in New Issue