Repository navigation
docs(virtual-core): add a Vanilla JS guide and document the lifecycle methods - #1402
officialasishkumar wants to merge 1 commit into
Conversation
… methods Using `@tanstack/virtual-core` without a framework adapter currently requires reading adapter source: nothing in the docs says that `_didMount` and `_willUpdate` exist, so a bare `new Virtualizer(...)` never attaches to its scroll element and `getVirtualItems()` keeps returning an empty array (TanStack#699). Add a "Vanilla JS" guide that covers what an adapter otherwise does: - passing `scrollToFn`, `observeElementRect` and `observeElementOffset`, which are required without an adapter, - when to call `_didMount` (and its cleanup) and `_willUpdate`, - a complete keyed render loop that measures dynamic rows, including a guard against the synchronous `onChange` that `measureElement` fires when a row's size differs from its estimate, - `setOptions` replacing options wholesale rather than merging them, - the window-scrolling variant with `scrollMargin`. Document `setOptions`, `_didMount` and `_willUpdate` in the Virtualizer API reference, link the guide from the docs sidebar and from the "Virtual Core (no framework)" installation section.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🎯 Changes
Using
@tanstack/virtual-corewithout a framework adapter currently means reading adapter source. The docs never mention_didMountor_willUpdate, so a plainnew Virtualizer(...)never attaches to its scroll element andgetVirtualItems()keeps returning[]. #699 is that report, and its comments ask for these methods to be documented with an example.This PR adds a Vanilla JS guide (
docs/vanilla.md, listed under Guides) that covers what an adapter normally does for you:scrollToFn,observeElementRectandobserveElementOffsetare required without an adapter, and the guide shows the built-in exports to pass._didMountand its cleanup, and when to call_willUpdate: once the scroll element is in the document, aftersetOptions, and after each render.data-indexandmeasureElement, and drops removed rows withmeasureElement(null). It also has a guard for the synchronousonChangethatmeasureElementfires when a row's size differs from its estimate. Without that guard, the outer loop would overwrite row positions with stale values.setOptionsreplaces options instead of merging them, so the guide keeps one options object and spreads it.observeWindowRect,observeWindowOffset,windowScrollandscrollMargin.It also documents
setOptions,_didMountand_willUpdatein the Virtualizer API reference, and links the guide from the "Virtual Core (no framework)" section of the installation page.I ran the guide's snippets in Chromium against the current
virtual-coresource: the element and window variants andsetOptionswith appended rows. Rows rendered with no gaps, followed scrolling andscrollToIndex, and stopped updating after cleanup. The snippets also type-check withtsc --strict.Fixes #699
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit