mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-05-28 12:14:09 +00:00
fix: measure VSCROLL_ROW_HEIGHT and theadHeight dynamically (#625)
## Summary Replaces hardcoded `VSCROLL_ROW_HEIGHT = 36` and `theadHeight = 40` in the virtual scroll logic with dynamic DOM measurement, so the values stay correct if CSS changes. ## Changes - `VSCROLL_ROW_HEIGHT`: measured once from the first rendered data row's `offsetHeight` after the initial full rebuild. Falls back to 36px until measurement occurs. - `theadHeight`: measured from the actual `<thead>` element's `offsetHeight` on every `renderVisibleRows` call. Falls back to 40px if no thead is found. - Both variables are now `let` instead of `const` to allow runtime updates. ## Performance No performance impact — both measurements are single `offsetHeight` reads (no reflow triggered since the DOM was just written). Row height measurement runs only once (guarded by `_vscrollRowHeightMeasured` flag). Thead measurement is a single property read per scroll event. Fixes #407 Co-authored-by: you <you@example.com>
This commit is contained in:
+15
-3
@@ -63,7 +63,9 @@
|
||||
const getParsedDecoded = window.getParsedDecoded;
|
||||
|
||||
// --- Virtual scroll state ---
|
||||
const VSCROLL_ROW_HEIGHT = 36; // estimated row height in px
|
||||
let VSCROLL_ROW_HEIGHT = 36; // measured dynamically on first render; fallback 36px
|
||||
let _vscrollRowHeightMeasured = false;
|
||||
let _vscrollTheadHeight = 40; // measured dynamically on first render; fallback 40px
|
||||
const VSCROLL_BUFFER = 30; // extra rows above/below viewport
|
||||
let _displayPackets = []; // filtered packets for current view
|
||||
let _displayGrouped = false; // whether _displayPackets is in grouped mode
|
||||
@@ -1277,8 +1279,10 @@
|
||||
// Calculate visible range based on scroll position
|
||||
const scrollTop = scrollContainer.scrollTop;
|
||||
const viewportHeight = scrollContainer.clientHeight;
|
||||
// Account for thead height (~40px)
|
||||
const theadHeight = 40;
|
||||
// Account for thead height (measured dynamically)
|
||||
const theadEl = scrollContainer.querySelector('thead');
|
||||
if (theadEl) _vscrollTheadHeight = theadEl.offsetHeight || _vscrollTheadHeight;
|
||||
const theadHeight = _vscrollTheadHeight;
|
||||
const adjustedScrollTop = Math.max(0, scrollTop - theadHeight);
|
||||
|
||||
// Find the first entry whose cumulative row offset covers the scroll position
|
||||
@@ -1336,6 +1340,14 @@
|
||||
tbody.appendChild(topSpacer);
|
||||
tbody.insertAdjacentHTML('beforeend', visibleHtml);
|
||||
tbody.appendChild(bottomSpacer);
|
||||
// Measure actual row height from first rendered data row (#407)
|
||||
if (!_vscrollRowHeightMeasured) {
|
||||
const firstRow = topSpacer.nextElementSibling;
|
||||
if (firstRow && firstRow !== bottomSpacer) {
|
||||
const h = firstRow.offsetHeight;
|
||||
if (h > 0) { VSCROLL_ROW_HEIGHT = h; _vscrollRowHeightMeasured = true; }
|
||||
}
|
||||
}
|
||||
if (window.__PERF_LOG_RENDER) console.log('[perf] renderVisibleRows: full rebuild %d entries, %.2fms', endIdx - startIdx, performance.now() - _rvr_t0);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user