feat(virtual-core): add deferLaneAssignment option#1115
feat(virtual-core): add deferLaneAssignment option#11152wheeh wants to merge 7 commits intoTanStack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 8496f50 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
There was a problem hiding this comment.
Pull request overview
Adds a new deferLaneAssignment option to @tanstack/virtual-core to support masonry-style layouts where lane assignment should be derived from measured sizes (via measureElement/resizeItem) rather than estimateSize, while keeping the existing “stable lanes via caching” behavior as the default.
Changes:
- Introduces
deferLaneAssignment?: boolean(defaultfalse) and conditionally skips lane caching until an item has been measured. - Adds tests covering deferred vs immediate lane caching behavior.
- Updates API docs and adds a changeset for release.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/virtual-core/src/index.ts | Adds deferLaneAssignment option + logic to skip caching lanes for unmeasured items |
| packages/virtual-core/tests/index.test.ts | Adds regression tests for deferred/immediate lane caching |
| docs/api/virtualizer.md | Documents new option and clarifies lane caching behavior |
| docs/api/virtual-item.md | Updates lane documentation to mention caching + deferral option |
| .changeset/loud-insects-itch.md | Publishes the change as a patch release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/virtual-core/src/index.ts:732
deferLaneAssignmentis now part of the memo deps, but toggling it fromfalse→trueviasetOptionswill still keep any existinglaneAssignmentscached fromestimateSize, becausegetMeasurementspreferscachedLaneregardless ofdeferLaneAssignment. Consider detecting changes todeferLaneAssignment(similar tolanesChangedFlag) and clearinglaneAssignmentswhen it changes (at least when switching totrue) so the new mode can take effect at runtime.
this.options.deferLaneAssignment,
],
(count, paddingStart, scrollMargin, getItemKey, enabled, lanes, deferLaneAssignment) => {
const lanesChanged =
this.prevLanes !== undefined && this.prevLanes !== lanes
if (lanesChanged) {
// Set flag for getMeasurements to handle
this.lanesChangedFlag = true
}
this.prevLanes = lanes
this.pendingMeasuredCacheIndexes = []
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
🎯 Changes
resolves #1114
Adds
deferLaneAssignmentoption to defer lane caching until items are measured viameasureElement.#1080 introduced lane assignment caching based on
estimateSizefor visual stability. However, this broke a core use case for masonry layouts where lane assignments should be based on actual measured sizes, not estimates.This PR adds a new option
deferLaneAssignment(default:false):false(default): Current behavior - lanes cached immediately fromestimateSizetrue: Lanes are calculated but not cached until first measurement, then cached based on actual sizes✅ Checklist
pnpm run test:pr.🚀 Release Impact