Skip to content

Commit f6b1a51

Browse files
committed
fix hot-reload not updating static nodes
1 parent 22b3645 commit f6b1a51

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/core/instance/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function renderMixin (Vue: Class<Component>) {
102102
): VNode | Array<VNode> {
103103
let tree = this._staticTrees[index]
104104
// if has already-rendered static tree and not inside v-for,
105-
// we can reuse the same tree by indentity.
105+
// we can reuse the same tree by doing a shallow clone.
106106
if (tree && !isInFor) {
107107
return Array.isArray(tree)
108108
? cloneVNodes(tree)

src/core/vdom/patch.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,14 @@ export function createPatchFunction (backend) {
329329
if (oldVnode === vnode) {
330330
return
331331
}
332-
if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {
332+
// reuse element for static trees.
333+
// note we only do this if the vnode is cloned -
334+
// if the new node is not cloned it means the render functions have been
335+
// reset by the hot-reload-api and we need to a proper re-render.
336+
if (vnode.isStatic &&
337+
oldVnode.isStatic &&
338+
vnode.key === oldVnode.key &&
339+
vnode.isCloned) {
333340
vnode.elm = oldVnode.elm
334341
return
335342
}

src/core/vdom/vnode.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export default class VNode {
1212
componentOptions: VNodeComponentOptions | void;
1313
child: Component | void; // component instance
1414
parent: VNode | void; // compoennt placeholder node
15-
raw: ?boolean; // contains raw HTML? (server only)
16-
isStatic: ?boolean; // hoisted static node
15+
raw: boolean; // contains raw HTML? (server only)
16+
isStatic: boolean; // hoisted static node
1717
isRootInsert: boolean; // necessary for enter transition check
18-
isComment: boolean;
18+
isComment: boolean; // empty comment placeholder?
19+
isCloned: boolean; // is a cloned node?
1920

2021
constructor (
2122
tag?: string,
@@ -42,6 +43,7 @@ export default class VNode {
4243
this.isStatic = false
4344
this.isRootInsert = true
4445
this.isComment = false
46+
this.isCloned = false
4547
// apply construct hook.
4648
// this is applied during render, before patch happens.
4749
// unlike other hooks, this is applied on both client and server.
@@ -76,6 +78,7 @@ export function cloneVNode (vnode: VNode): VNode {
7678
)
7779
cloned.isStatic = vnode.isStatic
7880
cloned.key = vnode.key
81+
cloned.isCloned = true
7982
return cloned
8083
}
8184

0 commit comments

Comments
 (0)