Skip to content

Commit 1a7b910

Browse files
committed
inherit child reference from old node when patching static nodes (fix vuejs#4288)
1 parent f4647b0 commit 1a7b910

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/core/vdom/patch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export function createPatchFunction (backend) {
342342
vnode.key === oldVnode.key &&
343343
(vnode.isCloned || vnode.isOnce)) {
344344
vnode.elm = oldVnode.elm
345+
vnode.child = oldVnode.child
345346
return
346347
}
347348
let i

test/unit/features/directives/once.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,28 @@ describe('Directive v-once', () => {
313313
expect(vm.$el.textContent).toBe('aabbcc')
314314
expect(`v-once can only be used inside v-for that is keyed.`).toHaveBeenWarned()
315315
})
316+
317+
// #4288
318+
it('should inherit child reference for v-once', done => {
319+
const vm = new Vue({
320+
template: `<div>{{a}}<test v-if="ok" v-once></test></div>`,
321+
data: {
322+
a: 0,
323+
ok: true
324+
},
325+
components: {
326+
test: {
327+
template: '<div>foo</div>'
328+
}
329+
}
330+
}).$mount()
331+
vm.a++ // first update to force a patch
332+
waitForUpdate(() => {
333+
expect(vm.$el.textContent).toBe('1foo')
334+
}).then(() => {
335+
vm.ok = false // teardown component with v-once
336+
}).then(done) // should not throw
337+
})
316338
})
317339

318340
function expectTextContent (vm, text) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy