From d400b275452d5d639933e37e831795df9c55169b Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:59:10 +0000 Subject: [PATCH] Fix observer console errors --- internal/glance/static/js/main.js | 4 ++-- internal/glance/static/js/popover.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/glance/static/js/main.js b/internal/glance/static/js/main.js index 58a8c2d..ac8c0b0 100644 --- a/internal/glance/static/js/main.js +++ b/internal/glance/static/js/main.js @@ -439,7 +439,7 @@ function setupCollapsibleGrids() { let cardsPerRow; - const resolveCollapsibleItems = () => { + const resolveCollapsibleItems = () => requestAnimationFrame(() => { const hideItemsAfterIndex = cardsPerRow * collapseAfterRows; if (hideItemsAfterIndex >= gridElement.children.length) { @@ -465,7 +465,7 @@ function setupCollapsibleGrids() { child.style.removeProperty("animation-delay"); } } - }; + }); const observer = new ResizeObserver(() => { if (!isElementVisible(gridElement)) { diff --git a/internal/glance/static/js/popover.js b/internal/glance/static/js/popover.js index 26d1850..91c69e3 100644 --- a/internal/glance/static/js/popover.js +++ b/internal/glance/static/js/popover.js @@ -25,7 +25,8 @@ frameElement.append(contentElement); containerElement.append(frameElement); document.body.append(containerElement); -const observer = new ResizeObserver(repositionContainer); +const queueRepositionContainer = () => requestAnimationFrame(repositionContainer); +const observer = new ResizeObserver(queueRepositionContainer); function handleMouseEnter(event) { clearTogglePopoverTimeout(); @@ -100,7 +101,7 @@ function showPopover() { containerElement.style.display = "block"; activeTarget.classList.add("popover-active"); document.addEventListener("keydown", handleHidePopoverOnEscape); - window.addEventListener("resize", repositionContainer); + window.addEventListener("resize", queueRepositionContainer); observer.observe(containerElement); } @@ -156,7 +157,7 @@ function hidePopover() { activeTarget.classList.remove("popover-active"); containerElement.style.display = "none"; document.removeEventListener("keydown", handleHidePopoverOnEscape); - window.removeEventListener("resize", repositionContainer); + window.removeEventListener("resize", queueRepositionContainer); observer.unobserve(containerElement); if (cleanupOnHidePopover !== null) {