Skip to content

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

Merged
stevenjoezhang merged 3 commits into
next-theme:masterfrom
wherewhere:motion-fallback
Jun 23, 2026
Merged

Add fallback if NexT.boot.motion is failed#953
stevenjoezhang merged 3 commits into
next-theme:masterfrom
wherewhere:motion-fallback

Conversation

@wherewhere

Copy link
Copy Markdown
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

Copilot AI left a comment

Copy link
Copy Markdown

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 thread source/js/next-boot.js Outdated
Comment thread source/js/next-boot.js
Comment thread source/js/next-boot.js Outdated
Comment thread source/js/next-boot.js
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 thread source/js/next-boot.js
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));
Comment thread source/js/next-boot.js Outdated

Copilot AI left a comment

Copy link
Copy Markdown

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 thread source/js/next-boot.js
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 thread source/js/next-boot.js
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
Comment thread source/js/pjax.js Outdated
.add(NexT.motion.middleWares.postList)
.bootstrap();
} catch (error) {
console.error('NexT Motion Error, fallback to static mode', error);
Comment thread source/js/next-boot.js Outdated
.add(NexT.motion.middleWares.footer)
.bootstrap();
} catch (error) {
console.error('NexT Motion Error, fallback to static mode', error);
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28000114515

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 97.451%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 405
Covered Lines: 400
Line Coverage: 98.77%
Relevant Branches: 105
Covered Branches: 97
Branch Coverage: 92.38%
Branches in Coverage %: Yes
Coverage Strength: 3.63 hits per line

💛 - Coveralls

@stevenjoezhang stevenjoezhang added this to the 8.28.0 milestone Jun 23, 2026
@stevenjoezhang stevenjoezhang merged commit 1746ed1 into next-theme:master Jun 23, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants