From d1551872ffeb08c34f59dc2042b43562c499b620 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 11 Nov 2023 20:46:57 -0800 Subject: [PATCH] fix: check if popover exists after fetching and before inserting --- quartz/components/scripts/popover.inline.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/quartz/components/scripts/popover.inline.ts b/quartz/components/scripts/popover.inline.ts index ed3c925ce..9506ec412 100644 --- a/quartz/components/scripts/popover.inline.ts +++ b/quartz/components/scripts/popover.inline.ts @@ -28,8 +28,11 @@ async function mouseEnterHandler( }) } + const hasAlreadyBeenFetched = () => + [...link.children].some((child) => child.classList.contains("popover")) + // dont refetch if there's already a popover - if ([...link.children].some((child) => child.classList.contains("popover"))) { + if (hasAlreadyBeenFetched()) { return setPosition(link.lastChild as HTMLElement) } @@ -49,6 +52,11 @@ async function mouseEnterHandler( console.error(err) }) + // bailout if another popover exists + if (hasAlreadyBeenFetched()) { + return + } + if (!contents) return const html = p.parseFromString(contents, "text/html") normalizeRelativeURLs(html, targetUrl)