From f49dd4b00fe853316814963b89794d3fcdb4ab15 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 12 Oct 2026 01:52:43 +0200 Subject: [PATCH] u --- src/FillSpace.jsx | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/FillSpace.jsx b/src/FillSpace.jsx index 1ff6cf4..05ffe65 100644 --- a/src/FillSpace.jsx +++ b/src/FillSpace.jsx @@ -121,6 +121,9 @@ class FillSpace extends Component { prevProps.items !== this.props.items || prevProps.header !== this.props.header ) { + if (this.state.unitHeight <= 0) { + this._probeMeasure(); + } this._observe(); this._viewportMeasure(); } @@ -361,7 +364,14 @@ class FillSpace extends Component { } const minSize = Math.max(1, Number(minPageSize) || 10); const maxSize = Number(this.props.maxPageSize) > 0 ? Number(this.props.maxPageSize) : Infinity; - const { unitHeight } = this.state; + let { unitHeight } = this.state; + if (unitHeight <= 0) { + const firstRow = this.ref?.querySelector('[data-fill-row]'); + const h = this.probeRef?.offsetHeight || firstRow?.offsetHeight; + if (h > 0) { + unitHeight = h; + } + } const calculated = unitHeight > 0 ? Math.max(minSize, Math.floor(available / unitHeight)) : minSize; const nextPageSize = Math.min(maxSize, calculated); @@ -369,11 +379,18 @@ class FillSpace extends Component { Number.isFinite(maxSize) && unitHeight > 0 ? Math.min(available, nextPageSize * unitHeight) : available; - if ( - nextViewportHeight !== this.state.viewportHeight || - nextPageSize !== this.state.pageSize - ) { - this.setState({ viewportHeight: nextViewportHeight, pageSize: nextPageSize }); + const updates = {}; + if (nextViewportHeight !== this.state.viewportHeight) { + updates.viewportHeight = nextViewportHeight; + } + if (nextPageSize !== this.state.pageSize) { + updates.pageSize = nextPageSize; + } + if (unitHeight > 0 && unitHeight !== this.state.unitHeight) { + updates.unitHeight = unitHeight; + } + if (Object.keys(updates).length > 0) { + this.setState(updates); } }