Skip to content

Commit 3b1e7ce

Browse files
authored
fix ths hot reload problem when use keep-alive wrap router-view with a dynamic key vuejs/vue-loader#1332
1 parent 0ff1356 commit 3b1e7ce

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/core/components/keep-alive.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ export default {
115115
const slot = this.$slots.default
116116
const vnode: VNode = getFirstComponentChild(slot)
117117
const componentOptions: ?VNodeComponentOptions = vnode && vnode.componentOptions
118+
if (vnode) {
119+
vnode._cid = componentOptions.Ctor.cid;
120+
}
118121
if (componentOptions) {
119122
// check pattern
120123
const name: ?string = getComponentName(componentOptions)
@@ -135,10 +138,14 @@ export default {
135138
? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
136139
: vnode.key
137140
if (cache[key]) {
138-
vnode.componentInstance = cache[key].componentInstance
139-
// make current key freshest
140-
remove(keys, key)
141-
keys.push(key)
141+
if (vnode._cid === cache[key]._cid) {
142+
vnode.componentInstance = cache[key].componentInstance;
143+
// make current key freshest
144+
remove(keys, key);
145+
keys.push(key);
146+
} else {
147+
cache[key] = vnode;
148+
}
142149
} else {
143150
// delay setting the cache until update
144151
this.vnodeToCache = vnode

0 commit comments

Comments
 (0)