From b5eb61d5419aee5f439457e53bd0f89a02d2842a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 7 Jun 2026 20:51:58 +0000 Subject: [PATCH] fix: three bugs from second code review - state.js: wrap JSON.parse in try/catch in loadLocalPlayers/loadLocalMatches; corrupt localStorage no longer crashes the app or blocks the remote fetch - chart.js: destroy chartInstance before early-returning on empty data in renderEloChart to avoid Chart.js "canvas already in use" on next render - app.js: remove dead `match` variable in removeMatch (leftover from the targeted-write optimisation that was reverted in PR #25) https://claude.ai/code/session_01TgxiTLy7fCh5xZPJT8eTVt --- app.js | 1 - src/chart.js | 4 ++++ src/state.js | 20 ++++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index c5d8016..1cfc8ca 100644 --- a/app.js +++ b/app.js @@ -341,7 +341,6 @@ async function removeMatch(id) { toggleLoading(true); try { - const match = state.matches.find(m => m.id === id); await deleteMatch(id); state.matches = state.matches.filter(m => m.id !== id); diff --git a/src/chart.js b/src/chart.js index ca2b539..14b5359 100644 --- a/src/chart.js +++ b/src/chart.js @@ -184,6 +184,10 @@ export function renderEloChart(type = 'singles') { .sort((a, b) => a[1].name.localeCompare(b[1].name)); if (activePlayers.length === 0) { + if (chartInstance) { + chartInstance.destroy(); + chartInstance = null; + } let msg = canvas.parentElement.querySelector('.chart-empty-msg'); if (!msg) { msg = document.createElement('p'); diff --git a/src/state.js b/src/state.js index 72d177d..147ab53 100644 --- a/src/state.js +++ b/src/state.js @@ -41,14 +41,26 @@ export function persistMatches() { export function loadLocalPlayers() { const raw = localStorage.getItem('eloPlayers'); - if (raw) state.players = JSON.parse(raw); - return !!raw; + if (!raw) return false; + try { + state.players = JSON.parse(raw); + return true; + } catch { + localStorage.removeItem('eloPlayers'); + return false; + } } export function loadLocalMatches() { const raw = localStorage.getItem('eloMatches'); - if (raw) state.matches = JSON.parse(raw); - return !!raw; + if (!raw) return false; + try { + state.matches = JSON.parse(raw); + return true; + } catch { + localStorage.removeItem('eloMatches'); + return false; + } } // ================= STATISTIK-NEUBERECHNUNG =================