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

Adds the key: number property to a slot props if this slot has v-if #11724

Open
artmakarov opened this issue Aug 27, 2024 · 3 comments
Open

Adds the key: number property to a slot props if this slot has v-if #11724

artmakarov opened this issue Aug 27, 2024 · 3 comments

Comments

@linzhe141
Copy link
Contributor

linzhe141 commented Aug 28, 2024

Vue internally sets a key for elements using v-if
It might be related to this pull request.

return processIf(node, dir, context, (ifNode, branch, isRoot) => {
// #1587: We need to dynamically increment the key based on the current
// node's sibling nodes, since chained v-if/else branches are
// rendered at the same depth
const siblings = context.parent!.children
let i = siblings.indexOf(ifNode)
let key = 0
while (i-- >= 0) {
const sibling = siblings[i]
if (sibling && sibling.type === NodeTypes.IF) {
key += sibling.branches.length
}
}
// Exit callback. Complete the codegenNode when all children have been
// transformed.
return () => {
if (isRoot) {
ifNode.codegenNode = createCodegenNodeForBranch(
branch,
key,
context,
) as IfConditionalExpression
} else {

@edison1105 edison1105 added 🔩 p2-edge-case and removed 🐞 bug Something isn't working labels Aug 28, 2024
@Procrustes5
Copy link
Contributor

I want to contribute to this issue.
But before that, is it correct that to solve this problem, we still need to set a key when using v-if, and the goal is to not expose that key as a prop of the slot?

@artmakarov
Copy link
Author

artmakarov commented Aug 29, 2024

I want to contribute to this issue. But before that, is it correct that to solve this problem, we still need to set a key when using v-if, and the goal is to not expose that key as a prop of the slot?

Yes, that's right. But the physically set key prop must be passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants