Skip to content

Commit

Permalink
fix(runtime-core): handle static node move in production
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 30, 2020
1 parent 2a9ba0c commit bf16a57
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,32 +632,28 @@ function baseCreateRenderer(
}
}

/**
* Dev / HMR only
*/
const moveStaticNode = (
vnode: VNode,
{ el, anchor }: VNode,
container: RendererElement,
anchor: RendererNode | null
nextSibling: RendererNode | null
) => {
let cur = vnode.el
const end = vnode.anchor!
while (cur && cur !== end) {
const next = hostNextSibling(cur)
hostInsert(cur, container, anchor)
cur = next
let next
while (el && el !== anchor) {
next = hostNextSibling(el)
hostInsert(el, container, nextSibling)
el = next
}
hostInsert(end, container, anchor)
hostInsert(anchor!, container, nextSibling)
}

const removeStaticNode = (vnode: VNode) => {
let cur = vnode.el
while (cur && cur !== vnode.anchor) {
const next = hostNextSibling(cur)
hostRemove(cur)
cur = next
const removeStaticNode = ({ el, anchor }: VNode) => {
let next
while (el && el !== anchor) {
next = hostNextSibling(el)
hostRemove(el)
el = next
}
hostRemove(vnode.anchor!)
hostRemove(anchor!)
}

const processElement = (
Expand Down Expand Up @@ -1934,8 +1930,7 @@ function baseCreateRenderer(
return
}

// static node move can only happen when force updating HMR
if (__DEV__ && type === Static) {
if (type === Static) {
moveStaticNode(vnode, container, anchor)
return
}
Expand Down

0 comments on commit bf16a57

Please sign in to comment.