From 13445d574c47f20932c7918f579b3e17a1da1a80 Mon Sep 17 00:00:00 2001 From: PaulVua Date: Wed, 7 Jan 2026 15:27:37 +0100 Subject: [PATCH] Fix device name not showing in page title and sidebar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed race condition issues where device name wasn't displaying properly: Page title fixes: - Added document.title update to sensors.html (was missing) - wifi.html already had it but improved reliability Sidebar device name fixes: - Created updateSidebarDeviceName() function with retry logic - Attempts update immediately, then at 100ms and 500ms delays - Handles async sidebar loading timing issues - Added console logging for debugging - Both sensors.html and wifi.html now reliably show device name This ensures the device ID/name always appears in: 1. Browser tab title (e.g., "NebuleAir_001") 2. Sidebar footer (bottom of navigation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- html/sensors.html | 26 +++++++++++++++++++++----- html/wifi.html | 30 +++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/html/sensors.html b/html/sensors.html index 241a013..6323602 100755 --- a/html/sensors.html +++ b/html/sensors.html @@ -319,11 +319,27 @@ $.ajax({ mainConfig = response; // Store for later use - //device name_side bar - const elements = document.querySelectorAll('.sideBar_sensorName'); - elements.forEach((element) => { - element.innerText = response.deviceName; - }); + // Function to update sidebar device name + function updateSidebarDeviceName(deviceName) { + const elements = document.querySelectorAll('.sideBar_sensorName'); + if (elements.length > 0) { + elements.forEach((element) => { + element.innerText = deviceName; + }); + console.log("Device name updated in sidebar:", deviceName); + } + } + + // Update device name immediately and with retries to handle async sidebar loading + if (response.deviceName) { + updateSidebarDeviceName(response.deviceName); + // Retry after delays to catch async sidebar load + setTimeout(() => updateSidebarDeviceName(response.deviceName), 100); + setTimeout(() => updateSidebarDeviceName(response.deviceName), 500); + + // Set page title + document.title = response.deviceName; + } // After getting main config, create sensor cards createSensorCards(mainConfig); diff --git a/html/wifi.html b/html/wifi.html index 6c28779..32ace1a 100755 --- a/html/wifi.html +++ b/html/wifi.html @@ -298,16 +298,28 @@ function get_internet(){ //get device Name const deviceName = data.deviceName; - - const elements = document.querySelectorAll('.sideBar_sensorName'); - elements.forEach((element) => { - element.innerText = deviceName; - }); - //device name html page title - if (response.deviceName) { - document.title = response.deviceName; - } + // Function to update sidebar device name + function updateSidebarDeviceName(deviceName) { + const elements = document.querySelectorAll('.sideBar_sensorName'); + if (elements.length > 0) { + elements.forEach((element) => { + element.innerText = deviceName; + }); + console.log("Device name updated in sidebar:", deviceName); + } + } + + // Update device name immediately and with retries to handle async sidebar loading + if (deviceName) { + updateSidebarDeviceName(deviceName); + // Retry after delays to catch async sidebar load + setTimeout(() => updateSidebarDeviceName(deviceName), 100); + setTimeout(() => updateSidebarDeviceName(deviceName), 500); + + //device name html page title + document.title = deviceName; + } //get wifi connection status