From f8656f9afb015a40d2cac9c91dea79f2219fde82 Mon Sep 17 00:00:00 2001 From: AI Engineer Date: Wed, 20 May 2026 08:54:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=BF=AB=E9=80=9F=E6=BB=91=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=BA=E6=B5=8B=E8=AF=95=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=87=E9=A2=98=20(by=20AI)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TEST.md | 12 ++++++------ package.json | 3 +-- src/list.js | 15 +++++++++------ test/index.html | 34 +++++++++++++++++++++++----------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/TEST.md b/TEST.md index 277f788..a8f4ae5 100644 --- a/TEST.md +++ b/TEST.md @@ -3,12 +3,12 @@ ## 基准测试 (Benchmark) *测试环境: Playwright / Chromium* -| 指标 | v1.0.0 | v1.0.1 | v1.0.3 | -| :--- | :--- | :--- | :--- | -| **FastList Render & Scroll (10k items)** | ~535ms | ~473ms | ~1513ms | -| **FastGroupedList Render & Scroll (10k)** | ~705ms | ~51ms | ~51ms | -| **FastTree Render & Scroll (10k items)** | ~927ms | ~50ms | ~51ms | -| **CollapseTree Render & Scroll (1.2k)** | ~51ms | ~50ms | ~50ms | +| 指标 | v1.0.0 | v1.0.1 | v1.0.3 | v1.0.4 | +| :--- | :--- | :--- | :--- | :--- | +| **FastList Render & Scroll (10k items)** | ~535ms | ~473ms | ~1513ms | ~54ms | +| **FastGroupedList Render & Scroll (10k)** | ~705ms | ~51ms | ~51ms | ~1550ms | +| **FastTree Render & Scroll (10k items)** | ~927ms | ~50ms | ~51ms | ~1560ms | +| **CollapseTree Render & Scroll (1.2k)** | ~51ms | ~50ms | ~50ms | ~51ms | ## 测试覆盖 (Coverage) - [x] HTTP Request (GET/POST) diff --git a/package.json b/package.json index 3576511..639702b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "@web/base", - "version": "1.0.3", - "type": "module", + "version": "1.0.4", "type": "module", "main": "dist/base.js", "module": "dist/base.js", "files": [ diff --git a/src/list.js b/src/list.js index 9d0e68d..c43420b 100644 --- a/src/list.js +++ b/src/list.js @@ -43,25 +43,28 @@ export const VirtualScroll = () => { }, calc: (container, list) => { if (!listInited || !list) return null; - const size = list.length, visibleCount = Math.ceil((container.clientHeight || 100) / (avg.get() || 32)); + const size = list.length, visibleCount = Math.max(10, Math.ceil((container.clientHeight || 100) / (avg.get() || 32))); let prev = padTop + topMargin + rowGap, post = 0, status = 0, listStartIndex = 0, listEndIndex = 0; + const scrollTop = container.scrollTop; + for (let i = 0; i < size; i++) { if (status === 0) { const gh = groupHeights.get(i); - if (gh && prev + gh < container.scrollTop) { prev += gh; i += Math.min(groupItemCount, size - i) - 1; } + if (gh && prev + gh < scrollTop && i + groupItemCount <= size) { prev += gh; i += groupItemCount - 1; } else { const ih = itemHeights.get(i); - if (prev + ih < container.scrollTop) prev += ih; + if (prev + ih < scrollTop && i < size - 1) prev += ih; else { - status = 1; let visibleStartIndex = Math.max(0, i); + status = 1; let visibleStartIndex = i; listStartIndex = Math.max(0, visibleStartIndex - visibleCount); listEndIndex = Math.min(listStartIndex + visibleCount * 3, size); i = listEndIndex - 1; for (let j = listStartIndex; j < visibleStartIndex; j++) prev -= itemHeights.get(j); } } - } else if (status === 1) { + } else { const gh = groupHeights.get(i); - if (gh) { post += gh; i += groupItemCount - 1; } else post += itemHeights.get(i); + if (gh && i + groupItemCount <= size) { post += gh; i += groupItemCount - 1; } + else post += itemHeights.get(i); } } return { prevHeight: Math.max(0, prev - padTop - topMargin - rowGap), postHeight: post, renderedList: list.slice(listStartIndex, listEndIndex), listStartIndex }; diff --git a/test/index.html b/test/index.html index 0c079d0..0531422 100644 --- a/test/index.html +++ b/test/index.html @@ -28,17 +28,29 @@ }
- - - - - - - - +
+
Fast List (Variable Height)
+ + + +
+
+
Fast Grouped List
+ + +
+
+
Fast Tree List
+ +
+
+
Normal Tree List (Collapsible)
+ + +