From ea069b98da943c1fd7db2f9485e9d38afa118044 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Fri, 21 Aug 2026 01:53:39 +0000 Subject: [PATCH] Fix analytics app not mounting on fetch-navigation to /_a MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit load() queried the live document for the pagerite:analytics-src meta, but the swap never touches — the meta only exists in the fetched doc, so the app never mounted unless /_a was loaded directly. Also cache the fetched HTML so the post-swap preload doesn't re-GET the page we just navigated to. --- frontend/src/pagerite.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/pagerite.js b/frontend/src/pagerite.js index eea24e2..fb383f1 100644 --- a/frontend/src/pagerite.js +++ b/frontend/src/pagerite.js @@ -425,7 +425,11 @@ import "overlayscrollbars/overlayscrollbars.css"; if (!res.ok || !type.includes("text/html")) throw new Error("not a page"); // Reflect any redirect the server issued. if (res.redirected) finalUrl = res.url; - doc = new DOMParser().parseFromString(await res.text(), "text/html"); + const html = await res.text(); + // Populate the cache too, or the post-swap preload (which includes + // location.pathname) would fetch the very page we just loaded again. + pageCache.set(new URL(finalUrl, location.href).pathname, html); + doc = new DOMParser().parseFromString(html, "text/html"); } catch { location.href = url; // fall back to a normal navigation return false; @@ -471,7 +475,9 @@ import "overlayscrollbars/overlayscrollbars.css"; runScripts(document.getElementById("page-banner")); runScripts(document.getElementById("main")); applyEffects(); - mountAnalytics(document); + // The fetched doc carries the analytics meta; the live document's + // is never swapped, so querying it would never find the entry. + mountAnalytics(doc); }; // Rotating cube page transition (see the FRAGILE block in pagerite.css); // mirrored when navigating back through history. Navigation within the