vue-virtual-scroller icon indicating copy to clipboard operation
vue-virtual-scroller copied to clipboard

Not reactive on items changes (splice) anymore?

Open souphuhn opened this issue 10 months ago • 3 comments

Describe the bug

Hi, I just figured out that my <recycle-scroller :items="items"> does not reactivley updates if I use splice on my reactive items in order to add or remove some elements. My array is provided as const items = ref([]) and I use items.value.splice.

The very same approach for the vue2 version is working fine.

In vue2, an (not deep) array watcher triggers on push, pop and splice, but in vue3 they have changed/corrected it to only trigger on shallow changes.

@Akryum Do you think you may change your array watcher to a deep watch or are you going to keep it how it is?

Please see the minimal reproduction example.

A re-render only happens for example on resize or if I use the <dynamic-scroller> or if it re-reference the items again..

Reproduction

<template>
    <recycle-scroller v-slot="{ item }" class="scroller" :items="items" :item-size="48">
        <div>{{ item.id }}</div>
    </recycle-scroller>
</template>

<script lang="ts" setup>
/* eslint-disable import/first */
import { Ref, ref, onBeforeMount } from 'vue';
import { RecycleScroller } from 'vue-virtual-scroller';

const items: Ref<{ id: string }[]> = ref([]);

onBeforeMount(() => {
    for (let i = 0; i < 2; i += 1) {
        items.value.push({ id: `id-${i.toString()}` });
    }

    window.setInterval(() => {
        items.value.push({ id: `id-${items.value.length.toString()}` });
    }, 1000);
});
</script>

<style lang="scss" scoped>
.scroller {
    width: 100%;
    height: 100%;
    scrollbar-gutter: stable;
}
</style>

System Info

"vue": "3.3.7"

Used Package Manager

npm

Validations

souphuhn avatar Apr 08 '24 11:04 souphuhn

Is...solved?

BadWaka avatar May 27 '24 08:05 BadWaka

Same here, it not updating the data whatever i use emit-update or page-mode via push or splice.

wongyat88 avatar May 31 '24 04:05 wongyat88

same issue here, any advice?

chronicadventure avatar Sep 04 '24 18:09 chronicadventure