fix(virtual-core): read shouldAdjustScrollPositionOnItemSizeChange from options by xianjianlf2 · Pull Request #1232 · TanStack/virtual · GitHub
Skip to content

fix(virtual-core): read shouldAdjustScrollPositionOnItemSizeChange from options - #1232

Closed
xianjianlf2 wants to merge 1 commit into
TanStack:mainfrom
xianjianlf2:fix/should-adjust-option-1227
Closed

xianjianlf2 wants to merge 1 commit into
TanStack:mainfrom
xianjianlf2:fix/should-adjust-option-1227

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Closes #1227.

Problem: The documented option shouldAdjustScrollPositionOnItemSizeChange is dead code. Passing it to a virtualizer has no effect: resizeItem never sees it.

Root cause: resizeItem reads this.shouldAdjustScrollPositionOnItemSizeChange — an instance field that setOptions never assigns — and the option is missing from VirtualizerOptions entirely. The CHANGELOG (around line 110) documents the option as public API, so this is a wiring bug rather than a design change.

Fix: Adds shouldAdjustScrollPositionOnItemSizeChange to VirtualizerOptions, and makes resizeItem read it options-first with a fallback to the instance field for backward compatibility with code that assigned the field directly.

Testing: 3 new tests — overriding the default backward-scroll adjustment, the predicate receiving (item, delta, instance), and returning false suppressing the default adjustment. 122/122 vitest passing; tsc, eslint and prettier clean.

Scope note: The issue also asks to revisit the backward-skip default behavior (part 2). This PR deliberately does not touch that — it only wires the documented option so users can opt out today. The default-behavior discussion can proceed separately.

✅ 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

    • Added a configuration option to control whether scroll position adjusts when item sizes change.
    • The callback receives the affected item, size difference, and virtualizer instance for custom behavior.
  • Bug Fixes

    • Fixed the documented scroll-adjustment option so it now takes effect.
    • Preserved existing behavior when the new option is not provided.

…om options

The predicate was documented as the escape hatch to restore pre-3.14
scroll compensation behavior, but resizeItem read it from an instance
field that setOptions never assigned, so supplying it through options
silently did nothing and there was no working way to opt out of the
backward-scroll compensation skip.

Read it from options first (and expose it on VirtualizerOptions),
falling back to a directly-assigned instance field for back-compat.

Closes TanStack#1227
@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

@piecyk

piecyk commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

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.

Up-scroll jank from uncompensated above-viewport resizes

2 participants