diff --git a/site/src/includes/components/header.njk b/site/src/includes/components/header.njk index 21319f23..a51d88aa 100644 --- a/site/src/includes/components/header.njk +++ b/site/src/includes/components/header.njk @@ -9,7 +9,7 @@
- + diff --git a/site/src/includes/inline.js b/site/src/includes/inline.js index c9ba4ef7..9526f3ab 100644 --- a/site/src/includes/inline.js +++ b/site/src/includes/inline.js @@ -7,14 +7,25 @@ if ((theme && theme === 'dark') || (!theme && mq.matches)) { // fetch the latest release version client-side so the badge tracks releases // without needing a site rebuild. GitHub serves this with Cache-Control: -// public, max-age=60 so the per-visitor cost is bounded. fallback stays -// empty on any failure — graceful degradation, no broken UI. +// public, max-age=60 so the per-visitor cost is bounded. placeholder is +// `hidden` in the template so a failed/blocked fetch leaves no stray gap. fetch('https://api.github.com/repos/umputun/remark42/releases/latest') - .then((r) => (r.ok ? r.json() : null)) + .then((r) => (r.ok ? r.json() : Promise.reject(new Error('HTTP ' + r.status)))) .then((d) => { if (!d || !d.tag_name) return - document.querySelectorAll('[data-remark42-version]').forEach((el) => { - el.textContent = d.tag_name - }) + // script is loaded synchronously in , so a cache hit can resolve + // before is parsed and [data-remark42-version] exists. defer the + // DOM update until the document is ready. + const apply = () => { + document.querySelectorAll('[data-remark42-version]').forEach((el) => { + el.textContent = d.tag_name + el.hidden = false + }) + } + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', apply) + } else { + apply() + } }) - .catch(() => {}) + .catch((err) => console.warn('remark42-site: latest version fetch failed', err))