{"record":{"id":"d63037afc459ee8a","repo":"angular/components","slug":"cdk-virtual-scroll-maxbufferpx-must-be-greater-th-d63037","errorCode":null,"errorMessage":"CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx","messagePattern":"CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cdk/scrolling/fixed-size-virtual-scroll.ts","lineNumber":70,"sourceCode":"    this._updateTotalContentSize();\n    this._updateRenderedRange();\n  }\n\n  /** Detaches this scroll strategy from the currently attached viewport. */\n  detach() {\n    this._scrolledIndexChange.complete();\n    this._viewport = null;\n  }\n\n  /**\n   * Update the item size and buffer size.\n   * @param itemSize The size of the items in the virtually scrolling list.\n   * @param minBufferPx The minimum amount of buffer (in pixels) before needing to render more\n   * @param maxBufferPx The amount of buffer (in pixels) to render when rendering more.\n   */\n  updateItemAndBufferSize(itemSize: number, minBufferPx: number, maxBufferPx: number) {\n    if (maxBufferPx < minBufferPx && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw Error('CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx');\n    }\n    this._itemSize = itemSize;\n    this._minBufferPx = minBufferPx;\n    this._maxBufferPx = maxBufferPx;\n    this._updateTotalContentSize();\n    this._updateRenderedRange();\n  }\n\n  /** @docs-private Implemented as part of VirtualScrollStrategy. */\n  onContentScrolled() {\n    this._updateRenderedRange();\n  }\n\n  /** @docs-private Implemented as part of VirtualScrollStrategy. */\n  onDataLengthChanged() {\n    this._updateTotalContentSize();\n    this._updateRenderedRange();\n  }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/scrolling/fixed-size-virtual-scroll.ts#L52-L88","documentation":"The CDK virtual scrolling viewport keeps extra rendered content around the visible area. minBufferPx is how much buffer must be exhausted before more is rendered, and maxBufferPx is how much is rendered at that point; if max is smaller than min, the buffering logic cannot function, so the FixedSizeVirtualScrollStrategy rejects the configuration at update time.","triggerScenarios":"Calling updateItemAndBufferSize(itemSize, minBufferPx, maxBufferPx) with maxBufferPx < minBufferPx; binding [maxBufferPx] to a value smaller than [minBufferPx] on cdk-virtual-scroll-viewport; dynamically shrinking maxBufferPx below minBufferPx at runtime.","commonSituations":"Copy-pasted buffer values with the names swapped; computing buffer sizes from viewport dimensions where max ends up smaller on small screens; setting minBufferPx=500 but maxBufferPx=200.","solutions":["Ensure maxBufferPx >= minBufferPx in the template bindings or strategy configuration","If values are dynamic, clamp before applying: maxBufferPx = Math.max(minBufferPx, computedMax)","Swap the values if they were accidentally reversed","Remove explicit buffer bindings to use defaults (minBufferPx=100px, maxBufferPx=200px) if custom buffering is not required"],"exampleFix":"<!-- before -->\n<cdk-virtual-scroll-viewport [itemSize]=\"50\" [minBufferPx]=\"500\" [maxBufferPx]=\"200\">\n<!-- after -->\n<cdk-virtual-scroll-viewport [itemSize]=\"50\" [minBufferPx]=\"200\" [maxBufferPx]=\"500\">","handlingStrategy":"validation","validationCode":"if (maxBufferPx < minBufferPx) {\n  throw new Error('maxBufferPx must be >= minBufferPx (got ' + minBufferPx + '/' + maxBufferPx + ')');\n}\nstrategy.updateItemAndBufferSize(itemSize, minBufferPx, maxBufferPx);","typeGuard":"function hasValidBuffers(config: { minBufferPx: number; maxBufferPx: number }): boolean {\n  return config.maxBufferPx >= config.minBufferPx && config.minBufferPx >= 0;\n}","tryCatchPattern":"try {\n  viewport.scrollStrategy.updateItemAndBufferSize(itemSize, min, max);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('maxBufferPx')) {\n    viewport.scrollStrategy.updateItemAndBufferSize(itemSize, Math.min(min, max), Math.max(min, max));\n  } else {\n    throw e;\n  }\n}","preventionTips":["Assert maxBufferPx >= minBufferPx in any computed/dynamic buffer logic","Don't swap the two bindings in templates; name them explicitly","Clamp dynamic values: max = Math.max(min, max)","Use the defaults (100/200) unless custom buffering is truly needed"],"tags":["angular","cdk","virtual-scroll","configuration","validation"],"backgroundTag":"invalid-buffer-configuration","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}