@tanstack/virtual-core 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/virtual-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "3.0.3",
4
+ "version": "3.0.4",
5
5
  "description": "Headless UI for virtualizing scrollable elements in TS/JS + Frameworks",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/virtual#readme",
package/src/index.ts CHANGED
@@ -867,11 +867,24 @@ export class Virtualizer<
867
867
  })
868
868
  }
869
869
 
870
- getTotalSize = () =>
871
- (this.getMeasurements()[this.options.count - 1]?.end ||
872
- this.options.paddingStart) -
870
+ getTotalSize = () => {
871
+ const measurements = this.getMeasurements();
872
+
873
+ let end: number;
874
+ // If there are no measurements, set the end to paddingStart
875
+ if (measurements.length === 0) {
876
+ end = this.options.paddingStart;
877
+ } else {
878
+ // If lanes is 1, use the last measurement's end, otherwise find the maximum end value among all measurements
879
+ end = this.options.lanes === 1
880
+ ? (measurements[measurements.length - 1]?.end ?? 0)
881
+ : Math.max(...measurements.slice(-this.options.lanes).map((m) => m.end));
882
+ }
883
+
884
+ return end -
873
885
  this.options.scrollMargin +
874
886
  this.options.paddingEnd
887
+ }
875
888
 
876
889
  private _scrollToOffset = (
877
890
  offset: number,