Skip to content

Commit eb92723

Browse files
committed
avoid merging text nodes when the node is a cloned slot node (fix vuejs#4209)
1 parent 02620c9 commit eb92723

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/core/vdom/helpers/normalize-children.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export function normalizeChildren (
2828
}
2929
} else if (c instanceof VNode) {
3030
if (c.text && last && last.text) {
31-
last.text += c.text
31+
if (!last.isCloned) {
32+
last.text += c.text
33+
}
3234
} else {
3335
// inherit parent namespace
3436
if (ns) {

test/unit/features/component/component-slot.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,4 +574,27 @@ describe('Component slot', () => {
574574
}).$mount()
575575
expect(vm.$el.innerHTML.trim()).toBe('<div>two</div><div>one</div>')
576576
})
577+
578+
// #4209
579+
it('slot of multiple text nodes should not be infinitely merged', done => {
580+
const wrap = {
581+
template: `<inner ref="inner">foo<slot></slot></inner>`,
582+
components: {
583+
inner: {
584+
data: () => ({ a: 1 }),
585+
template: `<div>{{a}}<slot></slot></div>`
586+
}
587+
}
588+
}
589+
const vm = new Vue({
590+
template: `<wrap ref="wrap">bar</wrap>`,
591+
components: { wrap }
592+
}).$mount()
593+
594+
expect(vm.$el.textContent).toBe('1foobar')
595+
vm.$refs.wrap.$refs.inner.a++
596+
waitForUpdate(() => {
597+
expect(vm.$el.textContent).toBe('2foobar')
598+
}).then(done)
599+
})
577600
})

0 commit comments

Comments
 (0)