yew-virtual
A headless virtualization engine for Yew applications, aligned in spirit with TanStack Virtual. It is built for very large lists and grids in WebAssembly: you keep full control of markup and styling while the engine computes visible ranges, overscan, and scroll alignment.
Live demo
- Tailwind example — vertical and horizontal virtual lists with Tailwind, live stats, and copy aimed at real integrations.
Overview
yew-virtual splits a headless core (Virtualizer, options, and measurement math) from Yew hooks (use_virtualizer, use_window_virtualizer) that attach passive scroll listeners and resize observers. Use the core alone for tests or non-DOM simulations, or pair hooks with your own absolutely positioned rows or columns.
- Headless engine — Range extraction, overscan, padding, gap, dynamic measurement, scroll-to-index.
- Container and window hooks — Ref-based scroll container or document-level scroll.
- Sizing modes — Fixed, estimated, and dynamic strategies with optional per-item observers.
- Safe Rust — No
unsafe,unwrap(), orexpect()in the library crate.
Features
| Area | Capabilities |
|---|---|
| Layout | Vertical and horizontal axes, RTL-aware horizontal scrollLeft |
| Sizing | Fixed, Estimated, Dynamic; optional runtime measurement |
| Scrolling | Overscan; programmatic scroll-to-index (Start / Center / End / Auto) |
| Spacing | Gap between items; padding at start and end |
| Hooks | Passive scroll listeners; ResizeObserver on the scroll container |
| Quality | Explicit error types; integration tests and CI coverage gate |
Installation
[]
= { = "0.21", = ["csr"] }
= "0.1"
Enable yew’s csr feature for browser (WASM) apps, or ssr / hydration when you follow Yew’s server-side rendering setup. yew-virtual does not define its own csr / ssr flags.
Quick start
Core engine (no DOM)
use Virtualizer;
use VirtualizerOptions;
use ItemSizeMode;
let options = VirtualizerOptions ;
let mut virt = new.expect;
virt.update_scroll_offset;
for item in virt.get_virtual_items
With Yew hooks (WASM)
use *;
use use_virtualizer;
use VirtualizerOptions;
use ItemSizeMode;
Scroll alignment
When using scroll_to_index, four alignment modes are available:
| Alignment | Behavior |
|---|---|
Start |
Item aligned to the viewport start |
Center |
Item centered in the viewport |
End |
Item aligned to the viewport end |
Auto |
Minimal scroll so the item becomes visible |
Item size modes
| Mode | Description |
|---|---|
Fixed(f64) |
Uniform item size; no measurement |
Estimated(f64) |
Initial guess; refined when measured |
Dynamic(f64) |
Fallback size; measured at runtime |
Running the example
The Tailwind demo uses Trunk:
Running tests
New tests should follow TEST_RULES.md. CI runs cargo-tarpaulin on the yew-virtual package with --fail-under 90 and uploads results to Codecov.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md before opening a pull request.
License
Distributed under the MIT license.