Skip to content

Settings page blank — JS crash from module-level destructure when classifAISettings is undefined (NitroPack / script order #1073

@Atroci

Description

@Atroci

What's happening and why:

Three compounding causes, all confirmed from source code:

1. Module-level crash (critical). src/js/settings/components/classifai-settings/index.js line 34:

const { services, features } = window.classifAISettings;

This runs at module scope, before any React component. If window.classifAISettings is undefined for any reason, it throws a TypeError immediately — the React app never mounts, no error boundary catches it, blank page.

2. NitroPack breaks the injection order. ClassifAI injects the data via wp_add_inline_script(..., 'before'). NitroPack (active on the site) defers or reorders scripts, so settings.js can execute before the inline data block — triggering #1.

3. get_asset_info() silently returns null if dist/settings.asset.php doesn't exist, causing the script to be enqueued with no dependencies — @wordpress/data etc. may not be loaded when the module runs.

Proposed fixes:

  • Guard the destructure: const { services = {}, features = {} } = window.classifAISettings || {};
  • Wrap the app in a React error boundary
  • Exclude classifai-settings from NitroPack deferral (or drop the global entirely in favour of the REST fetch already in place)

Env: ClassifAI 3.8.0, WP 6.9.4, PHP 8.4.20, WP Engine, NitroPack 1.19.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions