Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unmount on destroy invalidating pending tasks #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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