From 36e1c59d8d2964dac84724a2c834603f69e42732 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 14 Mar 2026 11:08:29 +0100 Subject: [PATCH] More robust JS (#8595) Avoid JS errors: * Following an SQL / paging issue * When using a limited view such as `&ajax=1` --- p/scripts/main.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index b6c09a5da..354a0a090 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1048,7 +1048,11 @@ function init_column_categories() { } } - document.getElementById('aside_feed').onclick = function (ev) { + const asideFeed = document.getElementById('aside_feed'); + if (!asideFeed) { + return; + } + asideFeed.onclick = function (ev) { let a = ev.target.closest('.tree-folder > .tree-folder-title > button.dropdown-toggle'); if (a) { const icon = a.querySelector('.icon'); @@ -2158,7 +2162,9 @@ function load_more_posts() { const streamFooterOld = streamFooter.querySelector('.stream-footer-inner'); const streamFooterNew = streamAdopted.querySelector('.stream-footer-inner'); - streamFooter.replaceChild(streamFooterNew, streamFooterOld); + if (streamFooterOld !== null && streamFooterNew !== null) { + streamFooter.replaceChild(streamFooterNew, streamFooterOld); + } const bigMarkAsRead = document.getElementById('bigMarkAsRead'); const readAll = document.querySelector('#nav_menu_read_all .read_all'); @@ -2234,8 +2240,12 @@ function faviconNbUnread(n) { const t = document.querySelector('.category.all .title'); n = t ? str2int(t.getAttribute('data-unread')) : 0; } - const svgBase = document.querySelector('template#dynamic_favicon_base').innerHTML; - const link = document.getElementById('favicon').cloneNode(true); + const dynamicFaviconBase = document.querySelector('template#dynamic_favicon_base'); + if (!dynamicFaviconBase) { + return; + } + const svgBase = dynamicFaviconBase.innerHTML; + const link = document.getElementById('favicon')?.cloneNode(true); if (link) { let svgOutput = ''; if (n > 0) {