Skip to content

fix: three bugs from second code review#26

Merged
daimpad merged 1 commit into
mainfrom
fix/code-review-2
Jun 7, 2026
Merged

fix: three bugs from second code review#26
daimpad merged 1 commit into
mainfrom
fix/code-review-2

Conversation

@daimpad

@daimpad daimpad commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Three bugs found and fixed by a second full-codebase review.

state.js — corrupt localStorage crashes the app

loadLocalPlayers / loadLocalMatches called JSON.parse without a try/catch. A truncated or corrupt entry (e.g. from a storage-quota mid-write) would throw a SyntaxError that propagated into the caller's catch block, which showed a misleading "Netzwerkfehler" and skipped the remote fetch entirely — leaving the app permanently stuck with no data. Fixed: wrap in try/catch, remove the corrupt entry, return false so the remote fetch proceeds normally.

chart.js — stale Chart.js instance on empty → data transition

renderEloChart returned early when there were no active players, but did not call chartInstance.destroy() first. On the next call with data, destroy() ran — but Chart.js had never formally released the canvas during the empty-state path, causing a "Canvas is already in use" warning and potentially a blank chart. Fixed: destroy the instance before the early return.

app.js — dead variable in removeMatch

const match = state.matches.find(...) was left over from the targeted-write optimisation that was reverted in PR #25. The variable was assigned but never read. Removed.

Test plan

  • 56 unit tests pass (npm test)
  • Manually corrupt localStorage.eloPlayers in DevTools → reload → app loads from server normally instead of crashing
  • Delete all matches → switch chart type → add a match → chart renders correctly (no "Canvas already in use" warning)

https://claude.ai/code/session_01TgxiTLy7fCh5xZPJT8eTVt


Generated by Claude Code

- 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
@daimpad daimpad merged commit ad2bbe0 into main Jun 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants