Skip to content

Commit 305d9eb

Browse files
committed
fix: DOM node key duplicate after switching to virtual list when animation is on
1 parent ec4f63f commit 305d9eb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wsfe/ctree",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"main": "./dist/ctree.umd.min.js",
55
"types": "./types",
66
"description": "A vue tree component using virtual list.",

src/components/Tree.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ export default (Vue as VueConstructor<Vue & {
458458
ready: false,
459459
currentExpandState: false,
460460
461+
expandRenderStart: 0,
461462
topNodes: [] as TreeNode[],
462463
middleNodes: [] as TreeNode[],
463464
bottomNodes: [] as TreeNode[],
@@ -945,6 +946,7 @@ export default (Vue as VueConstructor<Vue & {
945946
this.expandAnimation.index = -1
946947
this.expandAnimation.level = -1
947948
949+
this.expandAnimation.expandRenderStart = 0
948950
this.expandAnimation.topNodes = []
949951
this.expandAnimation.middleNodes = []
950952
this.expandAnimation.bottomNodes = []
@@ -954,7 +956,8 @@ export default (Vue as VueConstructor<Vue & {
954956
const nodeToExpandLevel = this.expandAnimation.level
955957
const middleNodes: TreeNode[] = []
956958
const renderNodesLength = this.renderNodes.length
957-
for (let i = this.expandAnimation.index + 1; i < renderNodesLength; i++) {
959+
const expandRenderStartDiff = this.renderStart - this.expandAnimation.expandRenderStart
960+
for (let i = this.expandAnimation.index - expandRenderStartDiff + 1; i < renderNodesLength; i++) {
958961
if (this.renderNodes[i]._level > nodeToExpandLevel) {
959962
middleNodes.push(this.renderNodes[i])
960963
} else break
@@ -974,6 +977,7 @@ export default (Vue as VueConstructor<Vue & {
974977
this.expandAnimation.start = true
975978
this.expandAnimation.currentExpandState = nodeToExpand.expand
976979
this.expandAnimation.nextState = !nodeToExpand.expand
980+
this.expandAnimation.expandRenderStart = this.renderStart
977981
978982
if (this.expandAnimation.nextState) {
979983
this.expandAnimation.bottomNodes = this.renderNodes.slice(this.expandAnimation.index + 1)
@@ -994,11 +998,12 @@ export default (Vue as VueConstructor<Vue & {
994998
if (this.expandAnimation.index === -1) return
995999
9961000
this.$nextTick(() => {
997-
this.expandAnimation.topNodes = this.renderNodes.slice(0, this.expandAnimation.index + 1)
1001+
const expandRenderStartDiff = this.renderStart - this.expandAnimation.expandRenderStart
1002+
this.expandAnimation.topNodes = this.renderNodes.slice(0, this.expandAnimation.index - expandRenderStartDiff + 1)
9981003
if (this.expandAnimation.nextState) {
9991004
this.updateMiddleNodes()
10001005
} else {
1001-
this.expandAnimation.bottomNodes = this.renderNodes.slice(this.expandAnimation.index + 1)
1006+
this.expandAnimation.bottomNodes = this.renderNodes.slice(this.expandAnimation.index - expandRenderStartDiff + 1)
10021007
}
10031008
this.expandAnimation.ready = true
10041009
this.$nextTick(() => {

0 commit comments

Comments
 (0)