avoid merging text nodes when the node is a cloned slot node (fix #4209)

This commit is contained in:
Evan You 2016-11-15 23:07:50 -05:00
parent 02620c928f
commit eb92723df5
2 changed files with 26 additions and 1 deletions

View File

@ -28,7 +28,9 @@ export function normalizeChildren (
}
} else if (c instanceof VNode) {
if (c.text && last && last.text) {
if (!last.isCloned) {
last.text += c.text
}
} else {
// inherit parent namespace
if (ns) {

View File

@ -574,4 +574,27 @@ describe('Component slot', () => {
}).$mount()
expect(vm.$el.innerHTML.trim()).toBe('<div>two</div><div>one</div>')
})
// #4209
it('slot of multiple text nodes should not be infinitely merged', done => {
const wrap = {
template: `<inner ref="inner">foo<slot></slot></inner>`,
components: {
inner: {
data: () => ({ a: 1 }),
template: `<div>{{a}}<slot></slot></div>`
}
}
}
const vm = new Vue({
template: `<wrap ref="wrap">bar</wrap>`,
components: { wrap }
}).$mount()
expect(vm.$el.textContent).toBe('1foobar')
vm.$refs.wrap.$refs.inner.a++
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('2foobar')
}).then(done)
})
})