From db3c40645d3aea2cf06c4e013ac4f4146deca3fc Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Fri, 30 May 2025 13:56:49 +0100 Subject: [PATCH] fix: resolve undefined property access error in settings modal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add safe default structure for configuration properties - Ensure currentConfig never remains undefined/null - Always render form even if config loading fails - Replace unsafe property access with safe variable references - Prevent "Cannot read properties of undefined (reading 'host')" errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/public/js/ui/settings.js | 53 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/public/js/ui/settings.js b/src/public/js/ui/settings.js index b2190de61..2d4704c58 100644 --- a/src/public/js/ui/settings.js +++ b/src/public/js/ui/settings.js @@ -72,11 +72,14 @@ PulseApp.ui.settings = (() => { // Load current configuration try { await loadCurrentConfig(); - renderConfigurationForm(); } catch (error) { console.error('[Settings] Failed to load configuration:', error); - body.innerHTML = `
Failed to load configuration: ${error.message}
`; + // Initialize with empty config to prevent errors + currentConfig = {}; } + + // Always render the form, even if config loading failed + renderConfigurationForm(); } function closeModal() { @@ -96,7 +99,8 @@ PulseApp.ui.settings = (() => { throw new Error(`HTTP ${response.status}`); } - currentConfig = await response.json(); + const configData = await response.json(); + currentConfig = configData || {}; // Ensure we never have null/undefined console.log('[Settings] Current config loaded:', currentConfig); } catch (error) { @@ -109,6 +113,13 @@ PulseApp.ui.settings = (() => { const body = document.getElementById('settings-modal-body'); if (!body) return; + // Ensure currentConfig has a safe default structure + const safeConfig = currentConfig || {}; + const proxmox = safeConfig.proxmox || {}; + const pbs = safeConfig.pbs || {}; + const advanced = safeConfig.advanced || {}; + const alerts = advanced.alerts || {}; + const html = `
@@ -120,14 +131,14 @@ PulseApp.ui.settings = (() => { Host Address *
@@ -136,7 +147,7 @@ PulseApp.ui.settings = (() => { Node Name @@ -145,7 +156,7 @@ PulseApp.ui.settings = (() => { API Token ID * @@ -159,7 +170,7 @@ PulseApp.ui.settings = (() => {
-
@@ -184,14 +195,14 @@ PulseApp.ui.settings = (() => {
@@ -200,14 +211,14 @@ PulseApp.ui.settings = (() => { Node Name
@@ -241,7 +252,7 @@ PulseApp.ui.settings = (() => { Metric Update Interval (ms) @@ -252,7 +263,7 @@ PulseApp.ui.settings = (() => { Discovery Interval (ms) @@ -267,22 +278,22 @@ PulseApp.ui.settings = (() => {
@@ -294,7 +305,7 @@ PulseApp.ui.settings = (() => { CPU Threshold (%) @@ -304,7 +315,7 @@ PulseApp.ui.settings = (() => { Memory Threshold (%) @@ -314,7 +325,7 @@ PulseApp.ui.settings = (() => { Disk Threshold (%)