Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion VirtualList.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { onMount, tick } from 'svelte';
import { onMount, tick, onDestroy } from 'svelte';

// props
export let items;
Expand Down Expand Up @@ -36,6 +36,7 @@
const { scrollTop } = viewport;

await tick(); // wait until the DOM is up to date
if (!mounted) return;

let content_height = top - scrollTop;
let i = start;
Expand All @@ -46,6 +47,7 @@
if (!row) {
end = i + 1;
await tick(); // render the newly visible row
if (!mounted) return;
row = rows[i - start];
}

Expand Down Expand Up @@ -132,6 +134,11 @@
rows = contents.getElementsByTagName('svelte-virtual-list-row');
mounted = true;
});

// mark as unmounted for pending tasks
onDestroy(() => {
mounted = false;
});
</script>

<style>
Expand Down