Fix for patching node with text over node with children

pull/407/head
Marius Muja 6 years ago
parent 80603c28f3
commit 6a632c2872

@ -276,6 +276,9 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
api.setTextContent(elm, ''); api.setTextContent(elm, '');
} }
} else if (oldVnode.text !== vnode.text) { } else if (oldVnode.text !== vnode.text) {
if (isDef(oldCh)) {
removeVnodes(elm, oldCh as Array<VNode>, 0, (oldCh as Array<VNode>).length - 1);
}
api.setTextContent(elm, vnode.text as string); api.setTextContent(elm, vnode.text as string);
} }
if (isDef(hook) && isDef(i = hook.postpatch)) { if (isDef(hook) && isDef(i = hook.postpatch)) {

@ -918,6 +918,21 @@ describe('snabbdom', function() {
patch(vnode1, vnode2); patch(vnode1, vnode2);
assert.equal(1, result.length); assert.equal(1, result.length);
}); });
it('calls `destroy` listener when patching text node over node with children', function() {
var calls = 0;
function cb(vnode) {
calls++;
}
var vnode1 = h('div', [
h('div', {hook: {destroy: cb}}, [
h('span', 'Child 1'),
]),
]);
var vnode2 = h('div', 'Text node')
patch(vnode0, vnode1);
patch(vnode1, vnode2);
assert.equal(calls, 1);
});
it('calls `init` and `prepatch` listeners on root', function() { it('calls `init` and `prepatch` listeners on root', function() {
var count = 0; var count = 0;
function init(vnode) { function init(vnode) {

Loading…
Cancel
Save