From e84599d4f9f1c35c7643b96cfe2cdd9d665377ea Mon Sep 17 00:00:00 2001 From: vickydotbat Date: Fri, 17 Jul 2026 18:31:43 +0200 Subject: [PATCH] fix: server-render unread drawer static strings window.require is undefined in the NodeBB 4 webpack client build, so the translateText helper never ran and unread drawer strings rendered as raw [[unread:title]] / [[unread:no-unread-topics]]. Move the static strings into the benchpress template (translated at render time) and have client.js only manage the topic
  • rows. --- public/client.js | 56 +++++++++------------ templates/partials/header/unread-drawer.tpl | 4 +- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/public/client.js b/public/client.js index 86b9f58..6365ba4 100644 --- a/public/client.js +++ b/public/client.js @@ -159,37 +159,29 @@ }); } - function translateText(el) { - if (window.require) { - window.require(['translator'], function (translator) { - translator.translate(el.textContent, (translated) => { - el.textContent = translated; - }); - }); - } - } - function renderUnreadMenu(menuEl, topics) { if (!menuEl) { return; } - menuEl.textContent = ''; const relativePath = (window.config && window.config.relative_path) || ''; - function addItem(node) { - const li = document.createElement('li'); - li.appendChild(node); - menuEl.appendChild(li); + // remove the loading row and any previously injected topic rows; + // the empty-state and footer/divider rows are server-rendered and stay put + const loading = menuEl.querySelector('[data-wg-unread-loading]'); + if (loading) { + loading.remove(); } + toArray(menuEl.querySelectorAll('.wg-unread-topic')).forEach((li) => { + li.remove(); + }); + + const emptyEl = menuEl.querySelector('[data-wg-unread-empty]'); + const footerEl = menuEl.querySelector('[data-wg-unread-footer]'); const list = (topics || []).slice(0, 10); - if (!list.length) { - const empty = document.createElement('span'); - empty.className = 'dropdown-item disabled'; - empty.textContent = '[[unread:no-unread-topics]]'; - addItem(empty); - translateText(empty); + if (emptyEl) { + emptyEl.classList.toggle('hidden', list.length > 0); } list.forEach((topic) => { @@ -203,19 +195,17 @@ category.textContent = topic.category.name; link.appendChild(category); } - addItem(link); + + const li = document.createElement('li'); + li.className = 'wg-unread-topic'; + li.appendChild(link); + + if (footerEl) { + menuEl.insertBefore(li, footerEl); + } else { + menuEl.appendChild(li); + } }); - - const divider = document.createElement('hr'); - divider.className = 'dropdown-divider'; - addItem(divider); - - const seeAll = document.createElement('a'); - seeAll.className = 'dropdown-item wg-unread-item--all'; - seeAll.href = `${relativePath}/unread`; - seeAll.textContent = '[[unread:title]]'; - addItem(seeAll); - translateText(seeAll); } function getWestgateTopbar() { diff --git a/templates/partials/header/unread-drawer.tpl b/templates/partials/header/unread-drawer.tpl index da0f781..54b1b7a 100644 --- a/templates/partials/header/unread-drawer.tpl +++ b/templates/partials/header/unread-drawer.tpl @@ -3,5 +3,7 @@ {unreadCount.topic}