fix: three bugs from second code review#26
Merged
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three bugs found and fixed by a second full-codebase review.
state.js— corrupt localStorage crashes the apploadLocalPlayers/loadLocalMatchescalledJSON.parsewithout a try/catch. A truncated or corrupt entry (e.g. from a storage-quota mid-write) would throw aSyntaxErrorthat 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 transitionrenderEloChartreturned early when there were no active players, but did not callchartInstance.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 inremoveMatchconst 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
npm test)localStorage.eloPlayersin DevTools → reload → app loads from server normally instead of crashinghttps://claude.ai/code/session_01TgxiTLy7fCh5xZPJT8eTVt
Generated by Claude Code