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

fix(runtime-core): should also inherit the DOM el of the text nodes (… #6858

Merged
merged 3 commits into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/runtime-core/__tests__/rendererFragment.spec.ts
Expand Up @@ -315,4 +315,40 @@ describe('renderer: fragment', () => {
`<!--comment--><span></span><div>two</div><!--comment--><span></span><div>one</div>`
)
})

// #6852
test('`template` keyed fragment w/ text', () => {
const root = nodeOps.createElement('div')

const renderFn = (items: string[]) => {
return (
openBlock(true),
createBlock(
Fragment,
null,
renderList(items, item => {
return (
openBlock(),
createBlock(
Fragment,
{ key: item },
[
createTextVNode('text'),
createVNode('div', null, item, PatchFlags.TEXT)
],
PatchFlags.STABLE_FRAGMENT
)
)
}),
PatchFlags.KEYED_FRAGMENT
)
)
}

render(renderFn(['one', 'two']), root)
expect(serializeInner(root)).toBe(`text<div>one</div>text<div>two</div>`)

render(renderFn(['two', 'one']), root)
expect(serializeInner(root)).toBe(`text<div>two</div>text<div>one</div>`)
})
})
4 changes: 4 additions & 0 deletions packages/runtime-core/src/renderer.ts
Expand Up @@ -2386,6 +2386,10 @@ export function traverseStaticChildren(n1: VNode, n2: VNode, shallow = false) {
}
if (!shallow) traverseStaticChildren(c1, c2)
}
// #6852 also inherit for text nodes
if (c2.type === Text) {
c2.el = c1.el
}
// also inherit for comment nodes, but not placeholders (e.g. v-if which
// would have received .el during block patch)
if (__DEV__ && c2.type === Comment && !c2.el) {
Expand Down