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 3 commits into
base: vapor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -178,6 +178,19 @@ export function render(_ctx) {
}"
`;

exports[`compiler: element transform > component > v-for on component should not mark as single root 1`] = `
"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
const t0 = _template("<template></template>", true)

export function render(_ctx) {
const _component_Comp = _resolveComponent("Comp")
const n1 = t0()
_setInsertionState(n1)
const n0 = _createComponentWithFallback(_component_Comp)
return n1
}"
`;

exports[`compiler: element transform > component > v-on expression is a function call 1`] = `
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ 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).not.contains('_createComponent(_ctx.Comp, null, null, true)')
})

test('static props', () => {
const { code, ir } = compileWithElementTransform(
`<Foo id="foo" class="bar" />`,
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,18 @@ function transformComponentElement(
}
}

const hasVFor = node.props.some(
p => p.type === NodeTypes.DIRECTIVE && p.name === 'for',
)

context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT
context.dynamic.operation = {
type: IRNodeTypes.CREATE_COMPONENT_NODE,
id: context.reference(),
tag,
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
asset,
root: singleRoot,
root: singleRoot && !hasVFor,
slots: [...context.slots],
once: context.inVOnce,
dynamic: dynamicComponent,
Expand Down