0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-04-09 08:45:45 +02:00

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.
This commit is contained in:
hamki 2026-01-26 17:28:20 +08:00
parent 0068f7cd4d
commit 8a6a348771
No known key found for this signature in database
GPG Key ID: 092D4EC7F4DECB68

View File

@ -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