diff --git a/CHANGELOG.md b/CHANGELOG.md index 60037b977..9cf8556c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file, per [the Ke ## [Unreleased] - TBD +### Fixed + +- Settings page no longer crashes to a blank screen when `window.classifAISettings` is undefined (for example when a caching or optimization plugin changes script order); the settings data is now read defensively (props [@thisismyurl](https://github.com/thisismyurl) via [#1135](https://github.com/10up/classifai/pull/1135)). + ## [3.8.0] - 2026-03-20 ### Added diff --git a/src/js/settings/components/classifai-settings/index.js b/src/js/settings/components/classifai-settings/index.js index 05cf1678d..5c2fa53a2 100644 --- a/src/js/settings/components/classifai-settings/index.js +++ b/src/js/settings/components/classifai-settings/index.js @@ -31,7 +31,7 @@ import { ClassifAIRegistration } from '../classifai-registration'; import { ClassifAIWelcomeGuide } from './welcome-guide'; import { Notices } from '../feature-settings/notices'; -const { services, features } = window.classifAISettings; +const { services = {}, features = {} } = window.classifAISettings || {}; /** * FeatureSettingsWrapper component to render the feature settings. @@ -43,6 +43,13 @@ const FeatureSettingsWrapper = () => { const { service, feature } = useParams(); const serviceFeatures = Object.keys( features[ service ] || {} ); + // When the settings data is unavailable (for example the global was + // missing) there is no feature to route to, so render nothing rather than + // navigating to an undefined path. + if ( ! serviceFeatures.length ) { + return null; + } + if ( ! serviceFeatures.includes( feature ) ) { return ; }