Skip to content

docs(virtual-core): add a Vanilla JS guide and document the lifecycle methods - #1402

Open
officialasishkumar wants to merge 1 commit into
TanStack:mainfrom
officialasishkumar:docs/vanilla-core-lifecycle
Open

officialasishkumar wants to merge 1 commit into
TanStack:mainfrom
officialasishkumar:docs/vanilla-core-lifecycle

Conversation

@officialasishkumar

@officialasishkumar officialasishkumar commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Using @tanstack/virtual-core without a framework adapter currently means reading adapter source. The docs never mention _didMount or _willUpdate, so a plain new Virtualizer(...) never attaches to its scroll element and getVirtualItems() 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, observeElementRect and observeElementOffset are required without an adapter, and the guide shows the built-in exports to pass.
  • When to call _didMount and its cleanup, and when to call _willUpdate: once the scroll element is in the document, after setOptions, and after each render.
  • A complete render loop. It reuses rows by key, measures dynamic rows with data-index and measureElement, and drops removed rows with measureElement(null). It also has a guard for the synchronous onChange that measureElement fires when a row's size differs from its estimate. Without that guard, the outer loop would overwrite row positions with stale values.
  • setOptions replaces options instead of merging them, so the guide keeps one options object and spreads it.
  • Window scrolling with observeWindowRect, observeWindowOffset, windowScroll and scrollMargin.

It also documents setOptions, _didMount and _willUpdate in 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-core source: the element and window variants and setOptions with appended rows. Rows rendered with no gaps, followed scrolling and scrollToIndex, and stopped updating after cleanup. The snippets also type-check with tsc --strict.

Fixes #699

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Documentation
    • Added a guide for using Virtual Core without a framework, including setup, lifecycle, rendering, measurement, and window scrolling.
    • Expanded the virtualizer API documentation with details on options, lifecycle callbacks, scroll attachment, and behavior before attachment.
    • Added links to the Vanilla JS guide from the guides navigation and installation page.

… 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.
@changeset-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bbcc655

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T05:35:38.116317Z bbcc655 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The documentation adds a Vanilla JS guide for using @tanstack/virtual-core without a framework adapter. It describes setup, lifecycle calls, rendering and measuring items, updating options, and window scrolling. The installation guide and documentation navigation now link to the guide.

Changes: Vanilla JavaScript Virtualizer Guide

Layer / File(s) Summary
Setup and lifecycle
docs/api/virtualizer.md, docs/vanilla.md, docs/config.json, docs/installation.md
Documents setOptions, _didMount, and _willUpdate, including their use without a framework adapter. Adds setup examples and links to the guide from navigation and installation documentation.
Rendering and scrolling
docs/vanilla.md
Adds examples and guidance for rendering and measuring items, updating options, and configuring window scrolling.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other · Severity of issue fixed: Low

Suggested reviewers: piecyk

Merge Risk: Minimal · up to bbcc6

This pull request adds a Vanilla JS guide and documents the lifecycle methods. It changes no runtime behavior, so the risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a new Vanilla JS guide for virtual-core and documentation of the lifecycle methods. The changeset covers docs/vanilla.md, the Virtualizer API reference (setOptions, _d…
Description check Passed The description follows the template. It has a Changes section that explains the motivation, the guide, the API docs, and how the author tested the snippets. It links issue #699. The checklist is fill…
Linked Issues check Passed Directly linked issue #699 reports that getVirtualItems() returns [] when a plain Virtualizer is used without a framework adapter. The expected behavior is that the call returns more than zero items. …
Out of Scope Changes check Passed All changed files are documentation or navigation: docs/vanilla.md (new guide), docs/api/virtualizer.md (API reference for setOptions, _didMount, _willUpdate), docs/config.json (Guides sidebar entry),…
Full details: Title check

Explanation

The title names the main change: a new Vanilla JS guide for virtual-core and documentation of the lifecycle methods. The changeset covers docs/vanilla.md, the Virtualizer API reference (setOptions, _didMount, _willUpdate), the sidebar, and the installation link. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description follows the template. It has a Changes section that explains the motivation, the guide, the API docs, and how the author tested the snippets. It links issue #699. The checklist is filled in. One item is unchecked: the author did not tick that pnpm run test:pr was run. The release impact is marked as docs-only. The description is complete enough to pass. The unchecked test item should be confirmed or explained.

Full details: Linked Issues check

Explanation

Directly linked issue #699 reports that getVirtualItems() returns [] when a plain Virtualizer is used without a framework adapter. The expected behavior is that the call returns more than zero items. The PR adds docs/vanilla.md, which covers the required adapter callbacks (scrollToFn, observeElementRect, observeElementOffset), the _didMount and cleanup calls, the _willUpdate calls, and a keyed render loop with measureElement. It also documents setOptions, _didMount, and _willUpdate in docs/api/virtualizer.md and links the guide from docs/installation.md and docs/config.json. The PR description states that the guide's element and window snippets were run in Chromium and rendered rows. The issue's own snippet never calls _didMount, so it still returns [] unchanged. The fix is therefore documentation of the required lifecycle calls, and no library code changes. I did not confirm the library source behavior for the attachment path, because the source read was truncated. The verdict relies on the PR description and the docs content in the summary. The docs-only resolution is a judgment call and is not verified by an automated test; the PR checklist leaves pnpm run test:pr unchecked.

Full details: Out of Scope Changes check

Explanation

All changed files are documentation or navigation: docs/vanilla.md (new guide), docs/api/virtualizer.md (API reference for setOptions, _didMount, _willUpdate), docs/config.json (Guides sidebar entry), and docs/installation.md (link to the guide). Each change supports the objective of #699, which is to document the lifecycle calls needed without a framework adapter. No unrelated source, package, or configuration changes appear in the PR summary. The diff query for the packages path returned no content, so no source change is shown. The summary lists no declaration changes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7fddca61-6a9b-4cd6-a81d-538cb837bff9
Commits

Reviewing files that changed from the base of the PR and between 4f32cb3 and bbcc655.

Files selected for processing: 4

  • docs/api/virtualizer.md
  • docs/config.json
  • docs/installation.md
  • docs/vanilla.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
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.

virtualizer.getVirtualItems() return zero items for vanilla js project

1 participant