Skip to content

fix: read the current axis in the window initialOffset default - #1395

Merged
piecyk merged 2 commits into
TanStack:mainfrom
harrismalik:harrismalik/fix-1390-initial-offset
Nov 26, 2026
Merged

piecyk merged 2 commits into
TanStack:mainfrom
harrismalik:harrismalik/fix-1390-initial-offset

Conversation

@harrismalik

@harrismalik harrismalik commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Fixes #1390

Core now passes the virtualizer to initialOffset, and the Lit and Svelte window virtualizers use it to read the current horizontal option instead of the one captured at creation. Callbacks that take no parameters still type-check. The other adapters already read the current option.

The Lit and Svelte tests change the axis while the list is disabled, with different scrollX and scrollY, then enable it again; they also check that an explicit initialOffset still wins. The core test checks that the callback sees the current options.

✅ 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

  • New Features
    • The initial scroll offset callback now receives the virtualizer instance, so the starting offset can reflect its current options.
  • Bug Fixes
    • Lit and Svelte window virtualizers now use the current scroll direction to determine the window offset after being re-enabled, including after switching between horizontal and vertical scrolling. Explicit initial offsets remain respected.

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6fc2ed8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@tanstack/virtual-core Patch
@tanstack/lit-virtual Patch
@tanstack/marko-virtual Patch
@tanstack/svelte-virtual Patch
@tanstack/angular-virtual Patch
@tanstack/react-virtual Patch
@tanstack/solid-virtual Patch
@tanstack/vue-virtual Patch
@tanstack/virtual-benchmarks Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The initialOffset callback now receives the virtualizer instance. Lit and Svelte window adapters use its current horizontal option to select the window scroll position after the virtualizer is disabled and re-enabled. Marko input types and documentation reflect the callback signature change.

Changes: Window initial offset

Layer / File(s) Summary
Pass the virtualizer to initialOffset
packages/virtual-core/src/index.ts, packages/virtual-core/tests/index.test.ts, docs/api/virtualizer.md, packages/marko-virtual/src/tags/virtualizer/*, packages/marko-virtual/src/tags/window-virtualizer/*, docs/framework/marko/marko-virtual.md, .changeset/window-initial-offset-current-axis.md
The callback accepts the current virtualizer, and getScrollOffset passes it when invoking the callback. Tests check that the callback sees current options. API documentation and Marko input types describe the callback argument. The changeset records patch releases for four packages.
Select the current window axis
packages/lit-virtual/src/index.ts, packages/lit-virtual/tests/set-options.test.ts, packages/svelte-virtual/src/index.ts, packages/svelte-virtual/tests/window-initial-offset.test.ts
The Lit and Svelte window adapters use the virtualizer’s current horizontal option to select scrollX or scrollY. Tests cover changing the axis while disabled and preserving an explicit initialOffset.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • TanStack/virtual#1383: Added the window default initialOffset behavior that this change updates to use the current axis.
  • TanStack/virtual#1334: Added the Lit setOptions path used by the new test to disable the virtualizer, change its axis, and re-enable it.

Suggested reviewers: piecyk, defunkt-dev

Merge Risk: Minimal · up to 6fc2e

This fixes the window virtualizers' default initial offset after the axis changes while the list is disabled. Existing callbacks keep working, and tests cover the changed behavior. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix: read the current axis in the window initialOffset default" matches the main change. The Lit and Svelte window virtualizers now read the current horizontal option from the virtualizer i…
Description check Passed The description follows the template. The Changes section explains the fix, its motivation (issue #1390), the tests, and the behavior of callbacks with no parameters. The checklist items are marked. T…
Linked Issues check Passed Issue #1390 requires: (1) core calls initialOffset(this); (2) window adapters read instance.options.horizontal; (3) zero-argument callbacks remain valid; (4) a test that changes the axis while disable…
Out of Scope Changes check Passed All changed files relate to #1390. Core: initialOffset type and invocation, which the adapter change requires. Lit and Svelte: window initialOffset callbacks. Tests: Lit, Svelte, and core tests for th…
Full details: Title check

Explanation

The title "fix: read the current axis in the window initialOffset default" matches the main change. The Lit and Svelte window virtualizers now read the current horizontal option from the virtualizer instance when computing the default initialOffset, and core passes the instance to initialOffset callbacks. The title names the fix and the affected code path.

Full details: Description check

Explanation

The description follows the template. The Changes section explains the fix, its motivation (issue #1390), the tests, and the behavior of callbacks with no parameters. The checklist items are marked. The release impact item is checked, which matches the changeset included in the PR. The description does not list the Marko type updates, but this omission is minor.

Full details: Linked Issues check

Explanation

Issue #1390 requires: (1) core calls initialOffset(this); (2) window adapters read instance.options.horizontal; (3) zero-argument callbacks remain valid; (4) a test that changes the axis while disabled, with distinct scrollX and scrollY, then re-enables; (5) a test that an explicit initialOffset still wins. The Svelte diff at the whole-PR merge base confirms requirement (2): createWindowVirtualizer's initialOffset is now (instance) => typeof document !== 'undefined' ? (instance.options.horizontal ? window.scrollX : window.scrollY) : 0. The Lit change (per the change summary) uses the same pattern. The core type in packages/virtual-core/src/index.ts accepts (instance) => number, and a zero-argument callback is assignable to it. Tests: Lit set-options.test.ts (current-axis resume to offset 300; explicit initialOffset 150 preserved), Svelte window-initial-offset.test.ts (matching pair), and core index.test.ts (callback sees current options). Uncertainty: the core getScrollOffset invocation (passing this) could not be read directly. The diff tool reported changed blobs unavailable for packages/virtual-core/src/index.ts. This requirement rests on the change summary and the type signature.

Full details: Out of Scope Changes check

Explanation

All changed files relate to #1390. Core: initialOffset type and invocation, which the adapter change requires. Lit and Svelte: window initialOffset callbacks. Tests: Lit, Svelte, and core tests for the required scenarios. Marko: input types widened to match the new core callback type, which keeps the public type consistent across adapters. Docs: docs/api/virtualizer.md and the Marko reference update the signature. The changeset lists patch releases for the affected published packages. No unrelated behavior change was identified. The core getScrollOffset hunk could not be read directly, so this verdict relies on the change summary for that hunk.

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: 5ee394a1-2a48-4742-9aaf-12419986ab28
Commits

Reviewing files that changed from the base of the PR and between 1dbbae7 and 6fc2ed8.

Files selected for processing: 6

  • .changeset/window-initial-offset-current-axis.md
  • docs/framework/marko/marko-virtual.md
  • packages/marko-virtual/src/tags/virtualizer/index.marko
  • packages/marko-virtual/src/tags/virtualizer/options.ts
  • packages/marko-virtual/src/tags/window-virtualizer/index.marko
  • packages/marko-virtual/src/tags/window-virtualizer/options.ts
Files skipped from review as they are similar to previous changes: 1

  • .changeset/window-initial-offset-current-axis.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.

@nx-cloud

nx-cloud Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 6fc2ed8

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 44s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 16s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-26 12:57:16 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@1395

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@1395

@tanstack/marko-virtual

npm i https://pkg.pr.new/@tanstack/marko-virtual@1395

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@1395

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@1395

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@1395

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@1395

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@1395

commit: 6fc2ed8

@piecyk piecyk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks @harrismalik! Checked it locally, core, lit and svelte all green, and the two new axis tests fail on main without the adapter change, so they cover the bug.

Went through the other adapters too, they rebuild the callback from the current options, so only Lit and Svelte needed it. The docs note about not calling getVirtualItems from the callback is a good call.

Pushed one small commit on top, 6fc2ed8: the Marko input types still said () => number, so Marko users couldn't use the new argument. Types, docs table and changeset only.

CI is green, good to merge 🚀

@piecyk
piecyk merged commit 4f32cb3 into TanStack:main Nov 26, 2026
10 checks passed
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.

Window virtualizer initialOffset default uses the axis from creation (Lit, Svelte)

2 participants