debug: Add detailed logging to customer SPA asset loading

Added comprehensive logging to track:
- should_load_assets() decision flow
- SPA mode setting
- Post ID and content
- Shortcode detection
- Asset enqueue URLs
- Dev vs production mode

This will help identify why customer SPA is not loading.
This commit is contained in:
Dwindi Ramadhana
2025-12-30 17:51:04 +07:00
parent 0609c6e3d8
commit 3260c8c112

View File

@@ -34,11 +34,15 @@ class Assets {
public static function enqueue_assets() { public static function enqueue_assets() {
// Only load on pages with WooNooW shortcodes or in full SPA mode // Only load on pages with WooNooW shortcodes or in full SPA mode
if (!self::should_load_assets()) { if (!self::should_load_assets()) {
error_log('[WooNooW Customer] should_load_assets returned false - not loading');
return; return;
} }
error_log('[WooNooW Customer] should_load_assets returned true - loading assets');
// Check if dev mode is enabled // Check if dev mode is enabled
$is_dev = defined('WOONOOW_CUSTOMER_DEV') && WOONOOW_CUSTOMER_DEV; $is_dev = defined('WOONOOW_CUSTOMER_DEV') && WOONOOW_CUSTOMER_DEV;
error_log('[WooNooW Customer] Dev mode: ' . ($is_dev ? 'true' : 'false'));
if ($is_dev) { if ($is_dev) {
// Dev mode: Load from Vite dev server // Dev mode: Load from Vite dev server
@@ -76,9 +80,15 @@ class Assets {
} }
// Production build - load app.js and app.css directly // Production build - load app.js and app.css directly
$js_url = $plugin_url . 'customer-spa/dist/app.js';
$css_url = $plugin_url . 'customer-spa/dist/app.css';
error_log('[WooNooW Customer] Enqueuing JS: ' . $js_url);
error_log('[WooNooW Customer] Enqueuing CSS: ' . $css_url);
wp_enqueue_script( wp_enqueue_script(
'woonoow-customer-spa', 'woonoow-customer-spa',
$plugin_url . 'customer-spa/dist/app.js', $js_url,
[], [],
null, null,
true true
@@ -94,10 +104,12 @@ class Assets {
wp_enqueue_style( wp_enqueue_style(
'woonoow-customer-spa', 'woonoow-customer-spa',
$plugin_url . 'customer-spa/dist/app.css', $css_url,
[], [],
null null
); );
error_log('[WooNooW Customer] Assets enqueued successfully');
} }
} }
@@ -221,22 +233,39 @@ class Assets {
private static function should_load_assets() { private static function should_load_assets() {
global $post; global $post;
error_log('[WooNooW Customer] should_load_assets check - Post ID: ' . ($post ? $post->ID : 'none'));
// Get Customer SPA settings // Get Customer SPA settings
$spa_settings = get_option('woonoow_customer_spa_settings', []); $spa_settings = get_option('woonoow_customer_spa_settings', []);
$mode = isset($spa_settings['mode']) ? $spa_settings['mode'] : 'disabled'; $mode = isset($spa_settings['mode']) ? $spa_settings['mode'] : 'disabled';
error_log('[WooNooW Customer] SPA mode: ' . $mode);
// If disabled, don't load // If disabled, don't load
if ($mode === 'disabled') { if ($mode === 'disabled') {
// Still check for shortcodes // Still check for shortcodes
if ($post && has_shortcode($post->post_content, 'woonoow_shop')) { if ($post) {
error_log('[WooNooW Customer] Checking post content for shortcodes');
error_log('[WooNooW Customer] Post content: ' . substr($post->post_content, 0, 200));
if (has_shortcode($post->post_content, 'woonoow_shop')) {
error_log('[WooNooW Customer] Found woonoow_shop shortcode');
return true; return true;
} }
if ($post && has_shortcode($post->post_content, 'woonoow_cart')) { if (has_shortcode($post->post_content, 'woonoow_cart')) {
error_log('[WooNooW Customer] Found woonoow_cart shortcode');
return true; return true;
} }
if ($post && has_shortcode($post->post_content, 'woonoow_checkout')) { if (has_shortcode($post->post_content, 'woonoow_checkout')) {
error_log('[WooNooW Customer] Found woonoow_checkout shortcode');
return true; return true;
} }
if (has_shortcode($post->post_content, 'woonoow_account')) {
error_log('[WooNooW Customer] Found woonoow_account shortcode');
return true;
}
}
error_log('[WooNooW Customer] No shortcodes found, not loading');
return false; return false;
} }