angular/components · error · Error
cdk-virtual-scroll: scrollToIndex is currently not supported
Error message
cdk-virtual-scroll: scrollToIndex is currently not supported for the autosize scroll strategy
What it means
AutoSizeVirtualScrollStrategy also does not implement scrollToIndex; calling it throws this error in dev mode. The method is required by the VirtualScrollStrategy interface but remains a TODO in the experimental autosize strategy. Production builds silently do nothing.
Source
Thrown at src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts:171
/** @docs-private Implemented as part of VirtualScrollStrategy. */
onContentRendered() {
if (this._viewport) {
this._checkRenderedContentSize();
}
}
/** @docs-private Implemented as part of VirtualScrollStrategy. */
onRenderedOffsetChanged() {
if (this._viewport) {
this._checkRenderedContentOffset();
}
}
/** Scroll to the offset for the given index. */
scrollToIndex(): void {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
// TODO(mmalerba): Implement.
throw Error(
'cdk-virtual-scroll: scrollToIndex is currently not supported for the autosize' +
' scroll strategy',
);
}
}
/**
* Update the buffer parameters.
* @param minBufferPx The minimum amount of buffer rendered beyond the viewport (in pixels).
* @param maxBufferPx The number of buffer items to render beyond the edge of the viewport (in
* pixels).
*/
updateBufferSize(minBufferPx: number, maxBufferPx: number) {
if (maxBufferPx < minBufferPx) {
throw Error('CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx');
}
this._minBufferPx = minBufferPx;
this._maxBufferPx = maxBufferPx;View on GitHub (pinned to 0411926e7d)
Solutions
- Scroll the viewport's native element manually: viewport.elementRef.nativeElement.scrollTop = offset, using an offset you track yourself.
- Switch to a strategy that supports scrollToIndex (fixed-size itemSize or the non-experimental variable-size strategy).
- Avoid programmatic index-based scrolling with autosize until the TODO is implemented upstream.
Example fix
// before viewport.scrollToIndex(targetIndex); // throws with autosize // after viewport.elementRef.nativeElement.scrollTop = savedPixelOffset;
Defensive patterns
Strategy: validation
Validate before calling
if (viewport.strategy instanceof AutoSizeVirtualScrollStrategy) {
// scrollToIndex unsupported; set scrollTop manually instead
viewport.elementRef.nativeElement.scrollTop = targetOffset;
} else {
viewport.scrollToIndex(targetIndex);
} Try / catch
try {
viewport.scrollToIndex(i);
} catch {
viewport.elementRef.nativeElement.scrollTop = savedOffsetForIndex(i);
} Prevention
- Avoid programmatic index-based scrolling with the autosize experimental strategy.
- Persist scroll offsets in pixels, not indices, when restoring positions with autosize.
- Prefer stable strategies (fixed-size/variable-size) when you need scrollToIndex.
When it happens
Trigger: Calling CdkVirtualScrollViewport.scrollToIndex() (or scrollToOffset, which delegates per strategy) when the viewport uses AutoSizeVirtualScrollStrategy in a development build.
Common situations: Programmatic scrolling: jumping to a saved scroll position, scroll-to-top buttons, navigating back to a list and restoring position; code that worked with fixed-size strategy moved to autosize.
Related errors
- cdk-virtual-scroll: scrolledIndexChange is currently not sup
- CDK virtual scroll: maxBufferPx must be greater than or equa
- CdkSelectAll: missing CdkSelection in the parent
- CdkSelectAll: CdkSelection must have cdkSelectionMultiple se
- CDK virtual scroll: maxBufferPx must be greater than or equa
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/f70531f60a234ec1.
Report an issue: GitHub.