From 6458fb296b732f7685f363887ee142f86f26c404 Mon Sep 17 00:00:00 2001 From: sbwml Date: Mon, 19 Aug 2024 19:32:09 +0800 Subject: [PATCH] luci-app-mosdns: fix TypeError by checking DOM element existence before setting innerHTML * Added a check to confirm that the DOM element with ID 'service_status' exists before attempting to set its innerHTML. * Added a setTimeout to ensure the page is fully rendered before starting the polling process. Signed-off-by: sbwml --- luci-app-mosdns/Makefile | 2 +- .../luci-static/resources/view/mosdns/basic.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/luci-app-mosdns/Makefile b/luci-app-mosdns/Makefile index a6ecd85..8e08545 100644 --- a/luci-app-mosdns/Makefile +++ b/luci-app-mosdns/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-mosdns -PKG_VERSION:=1.6.1 +PKG_VERSION:=1.6.2 PKG_RELEASE:=1 LUCI_TITLE:=LuCI Support for mosdns diff --git a/luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/basic.js b/luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/basic.js index 719f478..e78931c 100644 --- a/luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/basic.js +++ b/luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/basic.js @@ -68,12 +68,18 @@ return view.extend({ s = m.section(form.TypedSection); s.anonymous = true; s.render = function () { - poll.add(function () { - return L.resolveDefault(getServiceStatus()).then(function (res) { - var view = document.getElementById('service_status'); - view.innerHTML = renderStatus(res); + setTimeout(function () { + poll.add(function () { + return L.resolveDefault(getServiceStatus()).then(function (res) { + var view = document.getElementById('service_status'); + if (view) { + view.innerHTML = renderStatus(res); + } else { + console.error('Element #service_status not found.'); + } + }); }); - }); + }, 100); return E('div', { class: 'cbi-section', id: 'status_bar' }, [ E('p', { id: 'service_status' }, _('Collecting data...'))