Skip to content

Commit a21e191

Browse files
committed
fix(DynamicScroller): gaps caused by DOM reusing not triggering ResizeObserver
1 parent cef8860 commit a21e191

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

packages/vue-virtual-scroller/src/components/DynamicScrollerItem.vue

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,21 @@ export default {
7474
watch: {
7575
watchData: 'updateWatchData',
7676
77-
id () {
77+
id (value, oldValue) {
7878
this.$el.$_vs_id = this.id
7979
if (!this.size) {
8080
this.onDataUpdate()
8181
}
82+
83+
if (this.$_sizeObserved) {
84+
// In case the old item had the same size, it won't trigger the ResizeObserver
85+
// since we are reusing the same DOM node
86+
const oldSize = this.vscrollData.sizes[oldValue]
87+
const size = this.vscrollData.sizes[value]
88+
if (oldSize != null && oldSize !== size) {
89+
this._applySize(oldSize)
90+
}
91+
}
8292
},
8393
8494
finalActive (value) {
@@ -124,10 +134,8 @@ export default {
124134
},
125135
126136
mounted () {
127-
if (this.vscrollData.active) {
128-
if (!this.vscrollResizeObserver) {
129-
this.updateSize()
130-
}
137+
if (this.finalActive) {
138+
this.updateSize()
131139
this.observeSize()
132140
}
133141
},
@@ -193,26 +201,34 @@ export default {
193201
applySize (width, height) {
194202
const size = ~~(this.vscrollParent.direction === 'vertical' ? height : width)
195203
if (size && this.size !== size) {
196-
if (this.vscrollParent.$_undefinedMap[this.id]) {
197-
this.vscrollParent.$_undefinedSizes--
198-
this.vscrollParent.$_undefinedMap[this.id] = undefined
199-
}
200-
this.vscrollData.sizes[this.id] = size
201-
if (this.emitResize) this.$emit('resize', this.id)
204+
this._applySize(size)
205+
}
206+
},
207+
208+
_applySize (size) {
209+
if (this.vscrollParent.$_undefinedMap[this.id]) {
210+
this.vscrollParent.$_undefinedSizes--
211+
this.vscrollParent.$_undefinedMap[this.id] = undefined
202212
}
213+
this.vscrollData.sizes[this.id] = size
214+
if (this.emitResize) this.$emit('resize', this.id)
203215
},
204216
205217
observeSize () {
206218
if (!this.vscrollResizeObserver) return
219+
if (this.$_sizeObserved) return
207220
this.vscrollResizeObserver.observe(this.$el)
208221
this.$el.$_vs_id = this.id
209222
this.$el.$_vs_onResize = this.onResize
223+
this.$_sizeObserved = true
210224
},
211225
212226
unobserveSize () {
213227
if (!this.vscrollResizeObserver) return
228+
if (!this.$_sizeObserved) return
214229
this.vscrollResizeObserver.unobserve(this.$el)
215230
this.$el.$_vs_onResize = undefined
231+
this.$_sizeObserved = false
216232
},
217233
218234
onResize (id, width, height) {

0 commit comments

Comments
 (0)