Skip to content

Commit 4049ffc

Browse files
authored
fix(runtime-core): fix move/removal of static fragments containing text nodes (#6858)
fix #6852
1 parent a54bff2 commit 4049ffc

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/runtime-core/__tests__/rendererFragment.spec.ts

+36
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,40 @@ describe('renderer: fragment', () => {
315315
`<!--comment--><span></span><div>two</div><!--comment--><span></span><div>one</div>`
316316
)
317317
})
318+
319+
// #6852
320+
test('`template` keyed fragment w/ text', () => {
321+
const root = nodeOps.createElement('div')
322+
323+
const renderFn = (items: string[]) => {
324+
return (
325+
openBlock(true),
326+
createBlock(
327+
Fragment,
328+
null,
329+
renderList(items, item => {
330+
return (
331+
openBlock(),
332+
createBlock(
333+
Fragment,
334+
{ key: item },
335+
[
336+
createTextVNode('text'),
337+
createVNode('div', null, item, PatchFlags.TEXT)
338+
],
339+
PatchFlags.STABLE_FRAGMENT
340+
)
341+
)
342+
}),
343+
PatchFlags.KEYED_FRAGMENT
344+
)
345+
)
346+
}
347+
348+
render(renderFn(['one', 'two']), root)
349+
expect(serializeInner(root)).toBe(`text<div>one</div>text<div>two</div>`)
350+
351+
render(renderFn(['two', 'one']), root)
352+
expect(serializeInner(root)).toBe(`text<div>two</div>text<div>one</div>`)
353+
})
318354
})

packages/runtime-core/src/renderer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,10 @@ export function traverseStaticChildren(n1: VNode, n2: VNode, shallow = false) {
23862386
}
23872387
if (!shallow) traverseStaticChildren(c1, c2)
23882388
}
2389+
// #6852 also inherit for text nodes
2390+
if (c2.type === Text) {
2391+
c2.el = c1.el
2392+
}
23892393
// also inherit for comment nodes, but not placeholders (e.g. v-if which
23902394
// would have received .el during block patch)
23912395
if (__DEV__ && c2.type === Comment && !c2.el) {

0 commit comments

Comments
 (0)