Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
_withDirectives((_openBlock(), _createElementBlock("svg", null, _cache[0] || (_cache[0] = [
_createElementVNode("path", { d: "M2,3H5.5L12" }, null, -1 /* HOISTED */)
]))), [
]), 512 /* NEED_PATCH */)), [
[_directive_foo]
])
]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ return function render(_ctx, _cache) {

return _withDirectives((_openBlock(), _createElementBlock("p", null, [
_createTextVNode(_toDisplayString(foo), 1 /* TEXT */)
])), [
], 512 /* NEED_PATCH */)), [
[_directive_foo]
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,46 @@ describe('compiler: element transform', () => {
expect(node.patchFlag).toBe(PatchFlags.NEED_PATCH)
})

test('NEED_PATCH (vFor + static ref)', () => {
const { node } = parseWithBind(
`<div v-for="item in arr" :key="item" ref="foo" />`,
)
expect(node.patchFlag).toBe(PatchFlags.NEED_PATCH)
})

test('NEED_PATCH (vFor + custom directives)', () => {
const { node } = parseWithBind(
`<div v-for="item in arr" :key="item" v-dir />`,
)
expect(node.patchFlag).toBe(PatchFlags.NEED_PATCH)
})

test('NEED_PATCH (vFor + vnode hooks)', () => {
const root = baseCompile(
`<div v-for="item in arr" :key="item" @vue:updated="foo" />`,
{
prefixIdentifiers: true,
cacheHandlers: true,
},
).ast
const node = (root as any).children[0].children[0].codegenNode
expect(node.patchFlag).toBe(PatchFlags.NEED_PATCH)
})

test('NEED_PATCH (vFor + setRef function)', () => {
const root = baseCompile(
`<div v-for="item in arr" :key="item" :ref="setRefFn" />`,
{
prefixIdentifiers: true,
bindingMetadata: {
setRefFn: BindingTypes.SETUP_CONST,
},
},
).ast
const node = (root as any).children[0].children[0].codegenNode
expect(node.patchFlag).toBe(PatchFlags.NEED_PATCH)
})

test('script setup inline mode template ref (binding exists)', () => {
const { node } = parseWithElementTransform(`<input ref="input"/>`, {
inline: true,
Expand Down
8 changes: 5 additions & 3 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,12 @@ export function buildProps(
value.type === NodeTypes.JS_CACHE_EXPRESSION ||
((value.type === NodeTypes.SIMPLE_EXPRESSION ||
value.type === NodeTypes.COMPOUND_EXPRESSION) &&
getConstantType(value, context) > 0)
getConstantType(value, context) > 0 &&
name !== 'ref')
) {
// skip if the prop is a cached handler or has constant value
// skip if:
// 1. the prop is a cached handler
// 2. has constant value (excluding :ref="setRefFn", setRefFn is a setup-const)
return
}

Expand Down Expand Up @@ -738,7 +741,6 @@ export function buildProps(
}
}
if (
!shouldUseBlock &&
(patchFlag === 0 || patchFlag === PatchFlags.NEED_HYDRATION) &&
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)
) {
Expand Down