Parcourir la source

fix hot-reload not updating static nodes

Evan You il y a 9 ans
Parent
commit
f6b1a51729
3 fichiers modifiés avec 15 ajouts et 5 suppressions
  1. 1 1
      src/core/instance/render.js
  2. 8 1
      src/core/vdom/patch.js
  3. 6 3
      src/core/vdom/vnode.js

+ 1 - 1
src/core/instance/render.js

@@ -102,7 +102,7 @@ export function renderMixin (Vue: Class<Component>) {
   ): VNode | Array<VNode> {
     let tree = this._staticTrees[index]
     // if has already-rendered static tree and not inside v-for,
-    // we can reuse the same tree by indentity.
+    // we can reuse the same tree by doing a shallow clone.
     if (tree && !isInFor) {
       return Array.isArray(tree)
         ? cloneVNodes(tree)

+ 8 - 1
src/core/vdom/patch.js

@@ -329,7 +329,14 @@ export function createPatchFunction (backend) {
     if (oldVnode === vnode) {
       return
     }
-    if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {
+    // reuse element for static trees.
+    // note we only do this if the vnode is cloned -
+    // if the new node is not cloned it means the render functions have been
+    // reset by the hot-reload-api and we need to a proper re-render.
+    if (vnode.isStatic &&
+        oldVnode.isStatic &&
+        vnode.key === oldVnode.key &&
+        vnode.isCloned) {
       vnode.elm = oldVnode.elm
       return
     }

+ 6 - 3
src/core/vdom/vnode.js

@@ -12,10 +12,11 @@ export default class VNode {
   componentOptions: VNodeComponentOptions | void;
   child: Component | void; // component instance
   parent: VNode | void; // compoennt placeholder node
-  raw: ?boolean; // contains raw HTML? (server only)
-  isStatic: ?boolean; // hoisted static node
+  raw: boolean; // contains raw HTML? (server only)
+  isStatic: boolean; // hoisted static node
   isRootInsert: boolean; // necessary for enter transition check
-  isComment: boolean;
+  isComment: boolean; // empty comment placeholder?
+  isCloned: boolean; // is a cloned node?
 
   constructor (
     tag?: string,
@@ -42,6 +43,7 @@ export default class VNode {
     this.isStatic = false
     this.isRootInsert = true
     this.isComment = false
+    this.isCloned = false
     // apply construct hook.
     // this is applied during render, before patch happens.
     // unlike other hooks, this is applied on both client and server.
@@ -76,6 +78,7 @@ export function cloneVNode (vnode: VNode): VNode {
   )
   cloned.isStatic = vnode.isStatic
   cloned.key = vnode.key
+  cloned.isCloned = true
   return cloned
 }