Browse Source

handle component root patch edge case (transition + keep-alive + HOC) (fix #4590)

dev
Evan You 8 years ago
parent
commit
104b940689
  1. 53
      src/core/vdom/patch.js

53
src/core/vdom/patch.js

@ -178,6 +178,23 @@ export function createPatchFunction (backend) {
} }
} }
function initComponent (vnode, insertedVnodeQueue) {
if (vnode.data.pendingInsert) {
insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert)
}
vnode.elm = vnode.componentInstance.$el
if (isPatchable(vnode)) {
invokeCreateHooks(vnode, insertedVnodeQueue)
setScope(vnode)
} else {
// empty component root.
// skip all element-related modules except for ref (#3455)
registerRef(vnode)
// make sure to invoke the insert hook
insertedVnodeQueue.push(vnode)
}
}
function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) { function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) {
let i let i
// hack for #4339: a reactivated component with inner transition // hack for #4339: a reactivated component with inner transition
@ -238,23 +255,6 @@ export function createPatchFunction (backend) {
} }
} }
function initComponent (vnode, insertedVnodeQueue) {
if (vnode.data.pendingInsert) {
insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert)
}
vnode.elm = vnode.componentInstance.$el
if (isPatchable(vnode)) {
invokeCreateHooks(vnode, insertedVnodeQueue)
setScope(vnode)
} else {
// empty component root.
// skip all element-related modules except for ref (#3455)
registerRef(vnode)
// make sure to invoke the insert hook
insertedVnodeQueue.push(vnode)
}
}
// set scope id attribute for scoped CSS. // set scope id attribute for scoped CSS.
// this is implemented as a special case to avoid the overhead // this is implemented as a special case to avoid the overhead
// of going through the normal attribute patching process. // of going through the normal attribute patching process.
@ -549,7 +549,6 @@ export function createPatchFunction (backend) {
return return
} }
let elm, parent
let isInitialPatch = false let isInitialPatch = false
const insertedVnodeQueue = [] const insertedVnodeQueue = []
@ -590,9 +589,17 @@ export function createPatchFunction (backend) {
oldVnode = emptyNodeAt(oldVnode) oldVnode = emptyNodeAt(oldVnode)
} }
// replacing existing element // replacing existing element
elm = oldVnode.elm const oldElm = oldVnode.elm
parent = nodeOps.parentNode(elm) const parentElm = nodeOps.parentNode(oldElm)
createElm(vnode, insertedVnodeQueue, parent, nodeOps.nextSibling(elm)) createElm(
vnode,
insertedVnodeQueue,
// extremely rare edge case: do not insert if old element is in a
// leaving transition. Only happens when combining transition +
// keep-alive + HOCs. (#4590)
oldElm._leaveCb ? null : parentElm,
nodeOps.nextSibling(oldElm)
)
if (vnode.parent) { if (vnode.parent) {
// component root element replaced. // component root element replaced.
@ -609,8 +616,8 @@ export function createPatchFunction (backend) {
} }
} }
if (parent !== null) { if (parentElm !== null) {
removeVnodes(parent, [oldVnode], 0, 0) removeVnodes(parentElm, [oldVnode], 0, 0)
} else if (isDef(oldVnode.tag)) { } else if (isDef(oldVnode.tag)) {
invokeDestroyHook(oldVnode) invokeDestroyHook(oldVnode)
} }

Loading…
Cancel
Save