An open API service indexing awesome lists of open source software.

https://github.com/humanspeak/svelte-virtual-list

๐Ÿ“œ A performant virtual list/scrolling component for Svelte applications - efficiently render large scrollable lists with minimal memory usage
https://github.com/humanspeak/svelte-virtual-list

infinite-scroll javascript performance svelte sveltekit typescript ui-components virtual-list virtual-scroll web-components

Last synced: 15 days ago
JSON representation

๐Ÿ“œ A performant virtual list/scrolling component for Svelte applications - efficiently render large scrollable lists with minimal memory usage

Awesome Lists containing this project

README

        

# @humanspeak/svelte-virtual-list

[![NPM version](https://img.shields.io/npm/v/@humanspeak/svelte-virtual-list.svg)](https://www.npmjs.com/package/@humanspeak/svelte-virtual-list)
[![Build Status](https://github.com/humanspeak/svelte-virtual-list/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/humanspeak/svelte-virtual-list/actions/workflows/npm-publish.yml)
[![Coverage Status](https://coveralls.io/repos/github/humanspeak/svelte-virtual-list/badge.svg?branch=main)](https://coveralls.io/github/humanspeak/svelte-virtual-list?branch=main)
[![License](https://img.shields.io/npm/l/@humanspeak/svelte-virtual-list.svg)](https://github.com/humanspeak/svelte-virtual-list/blob/main/LICENSE)
[![Downloads](https://img.shields.io/npm/dm/@humanspeak/svelte-virtual-list.svg)](https://www.npmjs.com/package/@humanspeak/svelte-virtual-list)
[![CodeQL](https://github.com/humanspeak/svelte-virtual-list/actions/workflows/codeql.yml/badge.svg)](https://github.com/humanspeak/svelte-virtual-list/actions/workflows/codeql.yml)
[![Install size](https://packagephobia.com/badge?p=@humanspeak/svelte-virtual-list)](https://packagephobia.com/result?p=@humanspeak/svelte-virtual-list)
[![Code Style: Trunk](https://img.shields.io/badge/code%20style-trunk-blue.svg)](https://trunk.io)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
[![Types](https://img.shields.io/npm/types/@humanspeak/svelte-virtual-list.svg)](https://www.npmjs.com/package/@humanspeak/svelte-virtual-list)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/humanspeak/svelte-virtual-list/graphs/commit-activity)

A high-performance virtual list component for Svelte 5 applications that efficiently renders large datasets with minimal memory usage.

## Features

- ๐Ÿ“ Dynamic item height handling - no fixed height required
- ๐Ÿ”„ Bi-directional scrolling support (top-to-bottom and bottom-to-top)
- ๐Ÿ”„ Automatic resize handling for dynamic content
- ๐Ÿ“ TypeScript support with full type safety
- ๐Ÿš€ SSR compatible with hydration support
- โœจ Svelte 5 runes and snippets support
- ๐ŸŽจ Customizable styling with class props
- ๐Ÿ› Debug mode for development
- ๐ŸŽฏ Smooth scrolling with configurable buffer zones
- ๐Ÿง  Memory-optimized for 10k+ items
- ๐Ÿงช Comprehensive test coverage (vitest and playwright)
- ๐Ÿš€ Progressive initialization for large datasets

## Installation

```bash
npm install @humanspeak/svelte-virtual-list
```

## Basic Usage

```svelte

import SvelteVirtualList from '@humanspeak/svelte-virtual-list'

const items = Array.from({ length: 1000 }, (_, i) => ({
id: i,
text: `Item ${i}`
}))

{#snippet renderItem(item)}

{item.text}

{/snippet}

```

## Advanced Features

### Chat Application Example

```svelte

import SvelteVirtualList from '@humanspeak/svelte-virtual-list'

type Message = {
id: number
text: string
timestamp: Date
}

const messages: Message[] = Array.from({ length: 100 }, (_, i) => ({
id: i,
text: `Message ${i}`,
timestamp: new Date()
}))



{#snippet renderItem(message)}

{message.text}



{message.timestamp.toLocaleString()}


{/snippet}


```

## Props

| Prop | Type | Default | Description |
| ------------------- | -------------------------------- | --------------- | ------------------------------------------- |
| `items` | `T[]` | Required | Array of items to render |
| `defaultItemHeight` | `number` | `40` | Initial height for items before measurement |
| `mode` | `'topToBottom' \| 'bottomToTop'` | `'topToBottom'` | Scroll direction |
| `bufferSize` | `number` | `20` | Number of items to render outside viewport |
| `debug` | `boolean` | `false` | Enable debug logging and visualizations |
| `containerClass` | `string` | `''` | Class for outer container |
| `viewportClass` | `string` | `''` | Class for scrollable viewport |
| `contentClass` | `string` | `''` | Class for content wrapper |
| `itemsClass` | `string` | `''` | Class for items container |

## Performance Considerations

- The `bufferSize` prop affects memory usage and scroll smoothness
- Items are measured and cached for optimal performance
- Dynamic height calculations happen automatically
- Resize observers handle container/content changes
- Virtual DOM updates are batched for efficiency

## License

MIT ยฉ [Humanspeak, Inc.](LICENSE)

## Credits

Made with โ™ฅ by [Humanspeak](https://humanspeak.com)