fix(virtual-core): read shouldAdjustScrollPositionOnItemSizeChange from options#1232
fix(virtual-core): read shouldAdjustScrollPositionOnItemSizeChange from options#1232xianjianlf2 wants to merge 1 commit into
Conversation
…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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
ChangesScroll adjustment option
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant VirtualizerOptions
participant resizeItem
participant Predicate
participant applyScrollAdjustment
VirtualizerOptions->>resizeItem: configured predicate
resizeItem->>Predicate: item, delta, virtualizer
Predicate-->>resizeItem: adjustment decision
resizeItem->>applyScrollAdjustment: delta when enabled
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/virtual-core/tests/index.test.tsParsing error: "parserOptions.project" has been provided for 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. Comment |
|
@xianjianlf2 Thanks for the PR and the thorough write-up! One correction on framing: this isn't dead code. shouldAdjustScrollPositionOnItemSizeChange is by design a property on the virtualizer instance, not a VirtualizerOptions field — it's documented under Virtualizer Instance and is meant to be assigned imperatively The intent behind making it an instance field (rather than an option) is that it's a rarely-used escape hatch that's convenient to set or clear imperatively from an event handler, without threading it through the options object on every render. So the reported problem is really that passing it via options doesn't work — which is expected, since it was never an option. I'll grant that the CHANGELOG's "supply" wording is ambiguous and reads like an option, so I understand how this happened. Given that, I'd lean toward fixing this as a documentation clarification rather than expanding the API surface. |
🎯 Changes
Closes #1227.
Problem: The documented option
shouldAdjustScrollPositionOnItemSizeChangeis dead code. Passing it to a virtualizer has no effect:resizeItemnever sees it.Root cause:
resizeItemreadsthis.shouldAdjustScrollPositionOnItemSizeChange— an instance field thatsetOptionsnever assigns — and the option is missing fromVirtualizerOptionsentirely. The CHANGELOG (around line 110) documents the option as public API, so this is a wiring bug rather than a design change.Fix: Adds
shouldAdjustScrollPositionOnItemSizeChangetoVirtualizerOptions, and makesresizeItemread 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 returningfalsesuppressing 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
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
Bug Fixes