From d9523f23a052df7fb7515055c1ca68938cd6dce2 Mon Sep 17 00:00:00 2001 From: Kpa-clawbot <259247574+Kpa-clawbot@users.noreply.github.com> Date: Fri, 27 Mar 2026 21:28:50 -0700 Subject: [PATCH] fix: harden node detail rendering with Number() casts and Array.isArray guards, fixes #190 Add defensive type safety to node detail page rendering: - Wrap all .toFixed() calls with Number() to handle string values from Go backend - Use Array.isArray() for hash_sizes_seen instead of || [] fallback - Apply same fixes to both full-screen and side-panel views - Add 9 new tests for renderHashInconsistencyWarning and renderNodeBadges with hash_size_inconsistent data (including non-array edge cases) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- public/analytics.js | 2 +- public/index.html | 54 ++++++++-------- public/nodes.js | 56 +++++++++++++---- test-frontend-helpers.js | 131 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+), 40 deletions(-) diff --git a/public/analytics.js b/public/analytics.js index e7879002..fb4310e3 100644 --- a/public/analytics.js +++ b/public/analytics.js @@ -956,7 +956,7 @@
${inconsistent.map((n, i) => { const roleColor = window.ROLE_COLORS?.[n.role] || '#6b7280'; const prefix = n.hash_size ? n.public_key.slice(0, n.hash_size * 2).toUpperCase() : '?'; - const sizeBadges = (n.hash_sizes_seen || []).map(s => { + const sizeBadges = (Array.isArray(n.hash_sizes_seen) ? n.hash_sizes_seen : []).map(s => { const c = s >= 3 ? '#16a34a' : s === 2 ? '#86efac' : '#f97316'; const fg = s === 2 ? '#064e3b' : '#fff'; return '' + s + 'B'; diff --git a/public/index.html b/public/index.html index 89172197..26799465 100644 --- a/public/index.html +++ b/public/index.html @@ -22,9 +22,9 @@ - - - + + + @@ -81,29 +81,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +