Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

Commit 8da4e56

Browse files
author
NOPR9D ☄️
authored
Merge pull request #17 from NOPR9D/20211205_importFixFromAlvinTCHRepo
🐛 try to force new key if force update fails (usually fails when …
2 parents 9691ec1 + 0c6540d commit 8da4e56

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/mixin.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { warn } from "./util";
22
import { Subject, Subscription, isObservable } from "rxjs";
3+
import { getCurrentInstance } from "vue";
34

5+
import { v4 as uuidv4 } from "uuid";
46
export default {
57
created() {
68
var vm = this;
@@ -48,8 +50,21 @@ export default {
4850
vm._subscription.add(
4951
obs[key].subscribe(
5052
(value) => {
51-
Object.assign(vm, { [key]: value });
52-
this.$forceUpdate();
53+
vm[key] = value;
54+
const currentInst = getCurrentInstance();
55+
const newKey = uuidv4();
56+
try {
57+
vm.$forceUpdate();
58+
} catch (e) {
59+
// try to force new key if force update fails (usually fails when it is created on created hook)
60+
if (currentInst && currentInst.vnode) {
61+
currentInst.vnode.key = newKey;
62+
} else if (vm.$ && vm.$.subTree) {
63+
vm.$.subTree.key = newKey;
64+
} else if (currentInst && currentInst.subTree) {
65+
currentInst.subTree.key = newKey;
66+
}
67+
}
5368
},
5469
(error) => {
5570
throw error;

0 commit comments

Comments
 (0)