From 8a6a348771ab35caa1166174b7cfc3089d7fe792 Mon Sep 17 00:00:00 2001 From: hamki Date: Mon, 26 Jan 2026 17:28:20 +0800 Subject: [PATCH] perf: optimize ResizeObserver to only observe necessary element Change ResizeObserver from observing document.body (too broad) to only observing the segment element. This reduces unnecessary position update callbacks when unrelated parts of the page resize. --- web_src/js/features/file-view.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/file-view.ts b/web_src/js/features/file-view.ts index 064d8b4852..0747bc429d 100644 --- a/web_src/js/features/file-view.ts +++ b/web_src/js/features/file-view.ts @@ -166,11 +166,14 @@ function initSidebarToggle(elFileView: HTMLElement): void { hideSidebar(); } - // Update sidebar position on resize/scroll to keep aligned with file content + // Update sidebar position on resize to keep aligned with file content + // Only observe the segment element to avoid unnecessary updates from unrelated page changes const resizeObserver = new ResizeObserver(() => { updatePosition(); }); - resizeObserver.observe(document.body); + if (segment) { + resizeObserver.observe(segment); + } // Update position using IntersectionObserver instead of scroll event // This provides better performance and avoids scroll event issues