From bd032be85fa3ba226ae074c32a8b49cc7aff3698 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Wed, 31 Dec 2025 11:48:18 +0100 Subject: [PATCH] fix(secubox): resolve race condition in appstore and modules data loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed issue where first page load would show empty apps/modules list, requiring a refresh to display data. Changes: - Added error handling in refreshData() for both apps.js and modules.js - Added null/empty data checks before storing results - Fixed render() to use data parameter first, then fallback to cached instance data - Added console logging for debugging empty responses - Added user-friendly error notifications when API calls fail The render function now properly uses: var apps = (data && data.apps) || this.appsData || []; var modules = (data && data.modules) || this.modulesData || []; This ensures the data passed from load() is used on first render, preventing the empty state on initial page load. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../htdocs/luci-static/resources/view/secubox/apps.js | 8 ++++++++ .../luci-static/resources/view/secubox/modules.js | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/luci-app-secubox/htdocs/luci-static/resources/view/secubox/apps.js b/luci-app-secubox/htdocs/luci-static/resources/view/secubox/apps.js index 34e7b9af..797734ab 100644 --- a/luci-app-secubox/htdocs/luci-static/resources/view/secubox/apps.js +++ b/luci-app-secubox/htdocs/luci-static/resources/view/secubox/apps.js @@ -44,9 +44,17 @@ return view.extend({ refreshData: function() { var self = this; return API.getAppstoreApps().then(function(data) { + if (!data) { + console.warn('getAppstoreApps returned empty data'); + return { apps: [], categories: {} }; + } self.appsData = data.apps || []; self.categoriesData = data.categories || {}; return data; + }).catch(function(err) { + console.error('Error loading appstore apps:', err); + ui.addNotification(null, E('p', _('Failed to load app store: ') + err.message), 'error'); + return { apps: [], categories: {} }; }); }, diff --git a/luci-app-secubox/htdocs/luci-static/resources/view/secubox/modules.js b/luci-app-secubox/htdocs/luci-static/resources/view/secubox/modules.js index be29f58b..f0aa26d1 100644 --- a/luci-app-secubox/htdocs/luci-static/resources/view/secubox/modules.js +++ b/luci-app-secubox/htdocs/luci-static/resources/view/secubox/modules.js @@ -43,14 +43,22 @@ return view.extend({ refreshData: function() { var self = this; return API.getModules().then(function(data) { + if (!data) { + console.warn('getModules returned empty data'); + return { modules: [] }; + } self.modulesData = data.modules || []; return data; + }).catch(function(err) { + console.error('Error loading modules:', err); + ui.addNotification(null, E('p', _('Failed to load modules: ') + err.message), 'error'); + return { modules: [] }; }); }, render: function(data) { var self = this; - var modules = this.modulesData; + var modules = (data && data.modules) || this.modulesData || []; var defaultFilter = this.currentFilter || 'all'; var container = E('div', {