Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): ensure that errors in slot function execution do not affect block tracking (fix #5657) #5670

Merged
merged 3 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/runtime-core/__tests__/vnode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
cloneVNode,
mergeProps,
normalizeVNode,
transformVNodeArgs
transformVNodeArgs,
isBlockTreeEnabled
} from '../src/vnode'
import { Data } from '../src/component'
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 { setCurrentRenderingInstance } from '../src/componentRenderContext'

Expand Down Expand Up @@ -614,6 +615,29 @@ describe('vnode', () => {
]))
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', () => {
Expand Down
12 changes: 8 additions & 4 deletions packages/runtime-core/src/componentRenderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ export function withCtx(
setBlockTracking(-1)
}
const prevInstance = setCurrentRenderingInstance(ctx)
const res = fn(...args)
setCurrentRenderingInstance(prevInstance)
if (renderFnWithContext._d) {
setBlockTracking(1)
let res
try {
antfu marked this conversation as resolved.
Show resolved Hide resolved
res = fn(...args)
} finally {
setCurrentRenderingInstance(prevInstance)
if (renderFnWithContext._d) {
setBlockTracking(1)
}
}

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
Expand Down