Skip to content

demo: virtual scroll with zero DOM measurement#31

Open
barry166 wants to merge 1 commit intochenglou:mainfrom
barry166:demo/virtual-scroll
Open

demo: virtual scroll with zero DOM measurement#31
barry166 wants to merge 1 commit intochenglou:mainfrom
barry166:demo/virtual-scroll

Conversation

@barry166
Copy link
Copy Markdown

Summary

A variable-height virtual scrolling demo that showcases the core README use case — "proper virtualization/occlusion without guesstimates & caching".

Every row height is predicted by prepare() + layout() with zero DOM measurements during scroll. 38k items rendered with only ~20 DOM nodes at any time.

How it works

  1. prepare() all texts upfront (one-time)
  2. layout() every item to get pixel heights (pure arithmetic, no DOM)
  3. Build cumulative rowTops[] array
  4. On scroll: binary search for first visible row, render only visible + overscan rows
  5. Row pooling / recycling for smooth scrolling

Stats bar

The fixed header shows live stats: total items, currently rendered DOM nodes, DOM measurement count (0), and total scroll height predicted by Pretext.

Verified

  • Instrumented getBoundingClientRect, offsetHeight, offsetWidth during 20 scroll jumps across 200,000px — 0 calls
  • clientWidth/offsetTop reads (container geometry, not text measurement): 1 per render frame, as expected
  • bun test — 61/61 pass
  • tsc --noEmit — 0 errors

Changes

  • pages/demos/virtual-scroll.html — markup + styles
  • pages/demos/virtual-scroll.ts — virtual scroll logic with Pretext height prediction
  • pages/demos/index.html — add Virtual Scroll card to demo index

A variable-height virtual scrolling list where every row height is
predicted by Pretext's prepare() + layout() — no DOM measurements
at all during scroll. Demonstrates the core README use case: "proper
virtualization/occlusion without guesstimates & caching".

- 38k items, only ~20 DOM nodes rendered at any time
- Binary search for first visible row
- Row pooling / recycling for smooth scrolling
- Stats bar showing items, rendered count, DOM reads, total height
- Reuses the existing shower-thoughts.json corpus from the masonry demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant