Skip to content

fix(compiler-vapor): prevent v-for components from being single root #13149

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

Open
wants to merge 4 commits into
base: vapor
Choose a base branch
from
Open
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
@@ -178,6 +178,18 @@ export function render(_ctx) {
}"
`;

exports[`compiler: element transform > component > v-for on component should not mark as single root 1`] = `
"import { createComponent as _createComponent, createFor as _createFor } from 'vue';
export function render(_ctx, $props, $emit, $attrs, $slots) {
const n0 = _createFor(() => (_ctx.items), (_for_item0) => {
const n2 = _createComponent(_ctx.Comp)
return n2
}, (item) => (item), 2)
return n0
}"
`;

exports[`compiler: element transform > component > v-on expression is a function call 1`] = `
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import {
transformElement,
transformText,
transformVBind,
transformVFor,
transformVOn,
} from '../../src'
import {
@@ -15,7 +16,12 @@ import {
} from '@vue/compiler-core'

const compileWithElementTransform = makeCompile({
nodeTransforms: [transformElement, transformChildren, transformText],
nodeTransforms: [
transformVFor,
transformElement,
transformChildren,
transformText,
],
directiveTransforms: {
bind: transformVBind,
on: transformVOn,
@@ -169,6 +175,17 @@ describe('compiler: element transform', () => {
expect(code).contains('_createComponent(_ctx.Comp)')
})

test('v-for on component should not mark as single root', () => {
const { code } = compileWithElementTransform(
`<Comp v-for="item in items" :key="item"/>`,
{
bindingMetadata: { Comp: BindingTypes.SETUP_CONST },
},
)
expect(code).toMatchSnapshot()
expect(code).contains('_createComponent(_ctx.Comp)')
})

test('static props', () => {
const { code, ir } = compileWithElementTransform(
`<Foo id="foo" class="bar" />`,
2 changes: 1 addition & 1 deletion packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ function transformComponentElement(
tag,
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
asset,
root: singleRoot,
root: singleRoot && !context.inVFor,
slots: [...context.slots],
once: context.inVOnce,
dynamic: dynamicComponent,
582 changes: 323 additions & 259 deletions pnpm-lock.yaml

Large diffs are not rendered by default.