From e1470dfb663ee2cbff0941b1d9962831e57d1936 Mon Sep 17 00:00:00 2001 From: where where Date: Sun, 15 Mar 2026 15:48:54 +0800 Subject: [PATCH 1/2] Add try catch to ensure NexT.boot.motion run Add fallback if NexT.boot.motion is failed --- source/js/next-boot.js | 136 ++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 62 deletions(-) diff --git a/source/js/next-boot.js b/source/js/next-boot.js index 1f347a0882..c4e8140505 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -3,83 +3,95 @@ NexT.boot = {}; NexT.boot.registerEvents = function() { + try { + NexT.utils.registerScrollPercent(); + NexT.utils.registerCanIUseTag(); + NexT.utils.updateFooterPosition(); - NexT.utils.registerScrollPercent(); - NexT.utils.registerCanIUseTag(); - NexT.utils.updateFooterPosition(); - - // Mobile top menu bar. - document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => { - event.currentTarget.classList.toggle('toggle-close'); - const siteNav = document.querySelector('.site-nav'); - if (!siteNav) return; - siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px'); - document.body.classList.toggle('site-nav-on'); - }); + // Mobile top menu bar. + document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => { + event.currentTarget.classList.toggle('toggle-close'); + const siteNav = document.querySelector('.site-nav'); + if (!siteNav) return; + siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px'); + document.body.classList.toggle('site-nav-on'); + }); - document.querySelectorAll('.sidebar-nav li').forEach((element, index) => { - element.addEventListener('click', () => { - NexT.utils.activateSidebarPanel(index); + document.querySelectorAll('.sidebar-nav li').forEach((element, index) => { + element.addEventListener('click', () => { + NexT.utils.activateSidebarPanel(index); + }); }); - }); - window.addEventListener('hashchange', () => { - const tHash = location.hash; - if (tHash !== '' && !tHash.match(/%\S{2}/)) { - const target = document.querySelector(`.tabs ul.nav-tabs li a[href="${tHash}"]`); - target?.click(); - } - }); + window.addEventListener('hashchange', () => { + const tHash = location.hash; + if (tHash !== '' && !tHash.match(/%\S{2}/)) { + const target = document.querySelector(`.tabs ul.nav-tabs li a[href="${tHash}"]`); + target?.click(); + } + }); - window.addEventListener('tabs:click', e => { - NexT.utils.registerCodeblock(e.target); - }); + window.addEventListener('tabs:click', e => { + NexT.utils.registerCodeblock(e.target); + }); + } catch (error) { + console.error('Something went wrong when NexT registering events', error); + } }; NexT.boot.refresh = function() { - - /** - * Register JS handlers by condition option. - * Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. - */ - CONFIG.prism && window.Prism.highlightAll(); - CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', { - background: 'var(--content-bg-color)' - }); - CONFIG.lazyload && window.lozad('.post-body img').observe(); - if (CONFIG.pangu) { - // Polyfill for requestIdleCallback if not supported - if (!window.requestIdleCallback) { - window.requestIdleCallback = function(cb) { - cb({ - didTimeout : false, - timeRemaining: () => 100 - }); - }; + try { + /** + * Register JS handlers by condition option. + * Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. + */ + CONFIG.prism && window.Prism.highlightAll(); + CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', { + background: 'var(--content-bg-color)' + }); + CONFIG.lazyload && window.lozad('.post-body img').observe(); + if (CONFIG.pangu) { + // Polyfill for requestIdleCallback if not supported + if (!window.requestIdleCallback) { + window.requestIdleCallback = function(cb) { + cb({ + didTimeout : false, + timeRemaining: () => 100 + }); + }; + } + [...document.getElementsByTagName('main')].forEach(e => window.pangu.spacingNode(e)); } - [...document.getElementsByTagName('main')].forEach(e => window.pangu.spacingNode(e)); - } - CONFIG.exturl && NexT.utils.registerExtURL(); - NexT.utils.wrapTableWithBox(); - NexT.utils.registerCodeblock(); - NexT.utils.registerTabsTag(); - NexT.utils.registerActiveMenuItem(); - NexT.utils.registerLangSelect(); - NexT.utils.registerSidebarTOC(); - NexT.utils.registerPostReward(); - NexT.utils.registerVideoIframe(); + CONFIG.exturl && NexT.utils.registerExtURL(); + NexT.utils.wrapTableWithBox(); + NexT.utils.registerCodeblock(); + NexT.utils.registerTabsTag(); + NexT.utils.registerActiveMenuItem(); + NexT.utils.registerLangSelect(); + NexT.utils.registerSidebarTOC(); + NexT.utils.registerPostReward(); + NexT.utils.registerVideoIframe(); + } catch (error) { + console.error('Something went wrong when NexT refresh', error); + } }; NexT.boot.motion = function() { // Define Motion Sequence & Bootstrap Motion. if (CONFIG.motion.enable) { - NexT.motion.integrator - .add(NexT.motion.middleWares.header) - .add(NexT.motion.middleWares.sidebar) - .add(NexT.motion.middleWares.postList) - .add(NexT.motion.middleWares.footer) - .bootstrap(); + try { + NexT.motion.integrator + .add(NexT.motion.middleWares.header) + .add(NexT.motion.middleWares.sidebar) + .add(NexT.motion.middleWares.postList) + .add(NexT.motion.middleWares.footer) + .bootstrap(); + } catch (error) { + console.error('NexT Motion Error, fallback to static mode', error); + document.body.classList.remove("use-motion"); + CONFIG.motion.enable = false; + } } NexT.utils.updateSidebarPosition(); }; From 8b0778ae645794a9979504419adc116356527915 Mon Sep 17 00:00:00 2001 From: where where Date: Sun, 15 Mar 2026 16:17:24 +0800 Subject: [PATCH 2/2] Improve NexT error handling and logging --- source/js/next-boot.js | 12 +++++------- source/js/pjax.js | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/js/next-boot.js b/source/js/next-boot.js index c4e8140505..c17e8aba88 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -35,16 +35,14 @@ NexT.boot.registerEvents = function() { NexT.utils.registerCodeblock(e.target); }); } catch (error) { - console.error('Something went wrong when NexT registering events', error); + console.error('Something went wrong while NexT registering events', error); } }; NexT.boot.refresh = function() { try { - /** - * Register JS handlers by condition option. - * Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. - */ + // Register JS handlers by condition option. + // Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. CONFIG.prism && window.Prism.highlightAll(); CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', { background: 'var(--content-bg-color)' @@ -73,7 +71,7 @@ NexT.boot.refresh = function() { NexT.utils.registerPostReward(); NexT.utils.registerVideoIframe(); } catch (error) { - console.error('Something went wrong when NexT refresh', error); + console.error('Something went wrong during NexT refresh', error); } }; @@ -89,7 +87,7 @@ NexT.boot.motion = function() { .bootstrap(); } catch (error) { console.error('NexT Motion Error, fallback to static mode', error); - document.body.classList.remove("use-motion"); + document.body.classList.remove('use-motion'); CONFIG.motion.enable = false; } } diff --git a/source/js/pjax.js b/source/js/pjax.js index 9b7713a627..d38f3c7a5f 100644 --- a/source/js/pjax.js +++ b/source/js/pjax.js @@ -34,13 +34,19 @@ document.addEventListener('pjax:success', () => { NexT.boot.refresh(); // Define Motion Sequence & Bootstrap Motion. if (CONFIG.motion.enable) { - NexT.motion.integrator - .init() - .add(NexT.motion.middleWares.subMenu) - // Add sidebar-post-related transition. - .add(NexT.motion.middleWares.sidebar) - .add(NexT.motion.middleWares.postList) - .bootstrap(); + try { + NexT.motion.integrator + .init() + .add(NexT.motion.middleWares.subMenu) + // Add sidebar-post-related transition. + .add(NexT.motion.middleWares.sidebar) + .add(NexT.motion.middleWares.postList) + .bootstrap(); + } catch (error) { + console.error('NexT Motion Error, fallback to static mode', error); + document.body.classList.remove('use-motion'); + CONFIG.motion.enable = false; + } } if (CONFIG.sidebar.display !== 'remove') { const hasTOC = document.querySelector('.post-toc:not(.placeholder-toc)');