Skip to content

fix(runtime-core): modify the patchFlag of the label containing the ref attribute #9240

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

Closed
wants to merge 2 commits into from
Closed
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 @@ -991,6 +991,14 @@ describe('compiler: element transform', () => {
expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_PATCH))
})

// #9239
test('NEED_PATCH (vfor ref)', () => {
const { node } = parseWithBind(
`<div v-for="item in 3" :key="3" ref="foo" />`
)
expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_PATCH))
})

test('NEED_PATCH (custom directives)', () => {
const { node } = parseWithBind(`<div v-foo />`)
expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_PATCH))
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ export function buildProps(
}

if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
hasRef = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests all seem to pass even if this line is omitted. Perhaps there should be another test case added to cover this scenario too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is to address the issue at #9239 (comment), the function cannot be resolved in compile so I can't add a unit test for it.

properties.push(
createObjectProperty(
createSimpleExpression('ref_for', true),
Expand Down Expand Up @@ -747,7 +748,7 @@ export function buildProps(
}
}
if (
!shouldUseBlock &&
!(shouldUseBlock && !hasRef) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear why hasRef has been singled out for special treatment. Two lines down from here, we check for hasRef || hasVnodeHook || runtimeDirectives.length > 0. Don't we have the same problem for hasVnodeHook and runtimeDirectives.length > 0?

In both cases, the key seems to prevent unmounted being triggered.

(patchFlag === 0 || patchFlag === PatchFlags.HYDRATE_EVENTS) &&
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)
) {
Expand Down