Skip to content
Closed
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
22 changes: 20 additions & 2 deletions packages/runtime-core/src/componentRenderContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ShapeFlags } from 'packages/shared/src/shapeFlags'
import { ComponentInternalInstance } from './component'
import { isRenderingCompiledSlot } from './helpers/renderSlot'
import { closeBlock, openBlock } from './vnode'
import { closeBlock, openBlock, VNode } from './vnode'

/**
* mark the current rendering instance for asset resolution (e.g.
Expand Down Expand Up @@ -68,11 +69,15 @@ export function withCtx(
openBlock(true /* null block that disables tracking */)
}
const prevInstance = setCurrentRenderingInstance(ctx)
const res = fn(...args)
const res: VNode[] = fn(...args)
setCurrentRenderingInstance(prevInstance)
if (!isRenderingCompiledSlot) {
closeBlock()
}
// #3569
if (!isRenderingCompiledSlot && res) {
forceBailout(res)
}
return res
}
// mark this as a compiled slot function.
Expand All @@ -81,3 +86,16 @@ export function withCtx(
renderFnWithContext._c = true
return renderFnWithContext
}

function forceBailout(vnodes: VNode[]) {
vnodes.forEach(vnode => {
// when the user manually renders the compiled slot,
// it will be able to easily break the optimization update mode,
// so here we force to exit the optimization mode
vnode.dynamicChildren = null
vnode.patchFlag = 0
if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
forceBailout(vnode.children as VNode[])
}
})
}