Skip to content

Add fallback if NexT.boot.motion is failed#953

Open
wherewhere wants to merge 2 commits intonext-theme:masterfrom
wherewhere:motion-fallback
Open

Add fallback if NexT.boot.motion is failed#953
wherewhere wants to merge 2 commits intonext-theme:masterfrom
wherewhere:motion-fallback

Conversation

@wherewhere
Copy link
Contributor

PR Checklist

  • The changes have been tested (for bug fixes / features).
  • Docs in NexT website have been added / updated (for features).

PR Type

  • Bugfix.
  • Feature.
  • Improvement.
  • Code style update (e.g. formatting, linting).
  • Refactoring (no changes to functionality and APIs).
  • Documentation.
  • Translation.
  • Other... Please describe:

What is the current behavior?

Document will empty if NexT.boot.motion is not run or failed.

What is the new behavior?

Add try catch to ensure NexT.boot.motion run and remove use-motion if it failed.

Add fallback if NexT.boot.motion is failed
Copilot AI review requested due to automatic review settings March 15, 2026 08:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds defensive fallbacks around NexT’s client-side boot pipeline to prevent the page from remaining hidden when motion initialization fails (notably due to the use-motion CSS gating).

Changes:

  • Wraps NexT.boot.registerEvents() and NexT.boot.refresh() in try/catch blocks with error logging.
  • Wraps NexT.boot.motion() integrator bootstrap in try/catch; on failure logs an error, removes use-motion, and disables motion at runtime.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 5 to +13
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');
Comment on lines +48 to +63
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));
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds runtime fallbacks to prevent pages from remaining hidden when NexT Motion fails, particularly under PJAX navigation, by catching motion bootstrap errors and switching to a static rendering mode.

Changes:

  • Wrap Motion integrator bootstrapping in try/catch (initial load and PJAX success) and disable motion on failure.
  • Remove the use-motion body class on motion failure to restore element visibility.
  • Add broad error handling around NexT.boot.registerEvents() and NexT.boot.refresh() to avoid stopping later boot steps.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
source/js/pjax.js Adds try/catch around PJAX motion bootstrap and falls back to static mode on errors.
source/js/next-boot.js Adds try/catch around boot phases and motion bootstrap to avoid blank pages when motion fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 5 to +13
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');
Comment on lines 42 to +52
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
.add(NexT.motion.middleWares.postList)
.bootstrap();
} catch (error) {
console.error('NexT Motion Error, fallback to static mode', error);
.add(NexT.motion.middleWares.footer)
.bootstrap();
} catch (error) {
console.error('NexT Motion Error, fallback to static mode', error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants