diff --git a/.changeset/cold-ads-lose.md b/.changeset/cold-ads-lose.md new file mode 100644 index 00000000..262cb5a3 --- /dev/null +++ b/.changeset/cold-ads-lose.md @@ -0,0 +1,5 @@ +--- +'@tanstack/virtual-core': patch +--- + +Fixed observeElementOffset to prevent continuous rerenders during or after scrolling diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index 7af791d1..1b180804 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -779,6 +779,13 @@ export class Virtualizer< // self-write — by the time the user has moved 1.5 px, the // intended value will already have been consumed by a prior // scroll event and cleared. + if (offset === this.scrollOffset && isScrolling === true) { + // this prevents continous rerenders + isScrolling = false; + this.isScrolling = false; + this.scrollOffset = offset + this.maybeNotify(); + } if ( this._intendedScrollOffset !== null && Math.abs(offset - this._intendedScrollOffset) < 1.5 @@ -804,7 +811,6 @@ export class Virtualizer< if (this.scrollState) { this.scheduleScrollReconcile() } - this.maybeNotify() }), )