8000 fix(runtime-core): modify the `patchFlag` of the label containing the ref attribute by Alfred-Skyblue · Pull Request #9240 · vuejs/core · GitHub
[go: up one dir, main page]

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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations 8000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(runtime-core): add patchFlag to element containing ref attributes
  • Loading branch information
Alfred-Skyblue committed Sep 19, 2023
commit 27168fa45d5d3896826bd141070ec1df7d52080c
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
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,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
0