From: Olli Asikainen Date: Tue, 29 Jun 2021 23:03:00 +0000 (+0300) Subject: luci-base: batch DOM updates to prevent slowdown X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=f919635310286b3b905aedb716d707da1ea2c811;p=project%2Fluci.git luci-base: batch DOM updates to prevent slowdown Signed-off-by: Olli Asikainen --- diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 22cbecc864..2fc2f09632 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -752,7 +752,7 @@ function cbi_update_table(table, data, placeholder) { }); if (Array.isArray(data)) { - var n = 0, rows = target.querySelectorAll('tr, .tr'); + var n = 0, rows = target.querySelectorAll('tr, .tr'), trows = []; data.forEach(function(row) { var trow = E('tr', { 'class': 'tr' }); @@ -770,12 +770,16 @@ function cbi_update_table(table, data, placeholder) { trow.classList.add('cbi-rowstyle-%d'.format((n++ % 2) ? 2 : 1)); - if (rows[n]) - target.replaceChild(trow, rows[n]); - else - target.appendChild(trow); + trows[n] = trow; }); + for (var i = 1; i < n; i++) { + if (rows[i]) + target.replaceChild(trows[i], rows[i]); + else + target.appendChild(trows[i]); + } + while (rows[++n]) target.removeChild(rows[n]);