Akryum / vue-virtual-scroller

⚡️ Blazing fast scrolling for any amount of data
https://vue-virtual-scroller-demo.netlify.app
9.43k stars 901 forks source link

Not reactive on items changes (splice) anymore? #866

Open souphuhn opened 5 months ago

souphuhn commented 5 months ago

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

BadWaka commented 4 months ago

Is...solved?

wongyat88 commented 4 months ago

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

chronicadventure commented 1 month ago

same issue here, any advice?