From 543623731729ebdecc9ac7867ff824e38878ec93 Mon Sep 17 00:00:00 2001 From: osmarks Date: Tue, 23 Jul 2024 09:40:02 +0100 Subject: [PATCH] Fix bug in prefetch --- src/page.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/page.js b/src/page.js index daee58a..bb22f7a 100644 --- a/src/page.js +++ b/src/page.js @@ -6,7 +6,11 @@ const prefetchHook = () => { let lastFetch = 0 const prefetch = event => { if (Date.now() - lastFetch >= 200) { - const href = new URL(event.target.getAttribute("href"), window.location) + let target = event.target + while (!target.hasAttribute("href")) { + target = target.parentElement + } + const href = new URL(target.getAttribute("href"), window.location) if (href.origin === window.location.origin) { for (const ignorePath of ignorePaths) { if (href.pathname.startsWith(ignorePath)) return