Skip to content

Commit 6f64123

Browse files
committed
fix(charts): prevent scroll jump by fixing container height during swap
Pin container min-height before chart destroy, release via requestAnimationFrame after recreate. Prevents DOM reflow from shifting scroll position during the 10s auto-refresh cycle.
1 parent 427a63e commit 6f64123

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/static/js/chart-engine.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ function renderChart(canvasId, labels, datasets, type, zones, opts) {
205205
// Save zoom state before potential destroy — restore after recreate
206206
var savedZoom = existing && existing._zoomRange ? existing._zoomRange : null;
207207

208+
// Fix container height before destroy to prevent scroll jump from DOM reflow
209+
var containerEl = document.getElementById(canvasId);
210+
var savedHeight = 0;
211+
if (existing && containerEl) {
212+
savedHeight = containerEl.offsetHeight;
213+
containerEl.style.minHeight = savedHeight + 'px';
214+
}
215+
208216
if (existing) { existing.destroy(); delete charts[canvasId]; }
209217
var container = prepareContainer(canvasId);
210218
if (!container) return;
@@ -452,6 +460,13 @@ function renderChart(canvasId, labels, datasets, type, zones, opts) {
452460
chart.setScale('x', savedZoom);
453461
}
454462

463+
/* Release fixed container height after chart is rendered */
464+
if (savedHeight > 0) {
465+
requestAnimationFrame(function() {
466+
container.style.minHeight = '';
467+
});
468+
}
469+
455470
/* Responsive resize */
456471
var resizeObserver = new ResizeObserver(function(entries) {
457472
var entry = entries[0];

0 commit comments

Comments
 (0)