From 90755a5ce9fc7245288881c54164f01ae71b3862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 28 Oct 2026 19:51:52 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20after=20a=20deploy,=20the?= =?UTF-8?q?=20first=20in-page=20navigation=20no=20longer=20collapses=20the?= =?UTF-8?q?=20repo=20tabs=20and=20the=20CI=20runs=20list:=20the=20old=20st?= =?UTF-8?q?ylesheet=20stays=20until=20the=20new=20one=20has=20loaded,=20an?= =?UTF-8?q?d=20the=20layout=20is=20measured=20again=20once=20it=20applies;?= =?UTF-8?q?=20a=20CI=20badge=20(in=20a=20README=20too)=20is=20fetched=20ag?= =?UTF-8?q?ain=20on=20every=20in-page=20navigation,=20so=20it=20no=20longe?= =?UTF-8?q?r=20shows=20a=20finished=20run=20as=20running=20until=20a=20rel?= =?UTF-8?q?oad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/assets/nav.js | 41 +++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 475379d..d6cc4c6 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -125,23 +125,38 @@ } // Stylesheets in follow the new page: missing ones are added, extra ones removed. Matched by - // href, so main.css and the highlight sheet stay in place when they are the same. + // href, so main.css and the highlight sheet stay in place when they are the same. After a deploy + // main.css has a new href: the old sheet stays until the new one has loaded, so the page is never + // unstyled, and the layout measured from it (--shell-top) is taken again once it applies. function syncStyles(doc) { var sheets = 'link[rel="stylesheet"]'; var wanted = {}; doc.head.querySelectorAll(sheets).forEach(function (l) { wanted[l.getAttribute('href') || ''] = true; }); var have = {}; document.head.querySelectorAll(sheets).forEach(function (l) { have[l.getAttribute('href') || ''] = true; }); + var pending = 0; + function dropExtras() { + document.head.querySelectorAll(sheets).forEach(function (l) { + if (!wanted[l.getAttribute('href') || '']) { l.remove(); } + }); + queueShellTop(); + } + function settled() { + pending -= 1; + if (pending === 0) { dropExtras(); } + } doc.head.querySelectorAll(sheets).forEach(function (l) { var href = l.getAttribute('href') || ''; if (!have[href]) { have[href] = true; - document.head.appendChild(document.importNode(l, true)); + var link = document.importNode(l, true); + pending += 1; + link.addEventListener('load', settled, { once: true }); + link.addEventListener('error', settled, { once: true }); + document.head.appendChild(link); } }); - document.head.querySelectorAll(sheets).forEach(function (l) { - if (!wanted[l.getAttribute('href') || '']) { l.remove(); } - }); + if (pending === 0) { dropExtras(); } } function adopt(doc, keepFields, dd, jobs) { @@ -176,6 +191,7 @@ syncRel(); syncBannerExpiry(); syncShellTop(); + syncBadges(); syncDrafts(); } @@ -1960,6 +1976,21 @@ document.documentElement.style.setProperty('--shell-top', Math.round(shell.getBoundingClientRect().top) + 'px'); } + // A CI badge (`/{owner}/{repo}/badge.svg`, often in a README) is fetched again after a swap. The + // document stays the same across a soft navigation, and the browser reuses an image it already + // has at the same URL whatever its Cache-Control says, so the badge would keep an old state until + // a reload. The badge ignores query keys it does not know, so `_r` only makes the URL new. + function syncBadges() { + var stamp = String(Date.now()); + document.querySelectorAll('img[src*="/badge.svg"]').forEach(function (img) { + var url; + try { url = new URL(img.getAttribute('src'), location.href); } catch (err) { return; } + if (url.origin !== location.origin || !/\/badge\.svg$/.test(url.pathname)) { return; } + url.searchParams.set('_r', stamp); + img.src = url.pathname + url.search; + }); + } + function queueShellTop() { if (!shellFrame) { shellFrame = requestAnimationFrame(syncShellTop); } }