Repository navigation
v1.9.5: fix "Canvas is already in use" errors and leaked charts - #9
Merged
Merged
Conversation
Views draw charts in setTimeout(..., 0). Two renders before those timers run (loadFiles() then showView() at boot when the folder re-imports, or Reconnect re-rendering after an import) queue two charts per canvas, and Chart.js throws for the second. Separately, every render rebuilt the DOM without destroying the previous charts, so Chart.instances grew forever. ui.js now wraps the global Chart in a subclass that, before drawing, destroys any chart on the target canvas and any chart whose canvas is no longer in the page. No view code changes; statics are inherited. Tested headless: boot re-import, triple renderActive(), every view rendered twice in both themes, Forecast slider redraws, #7 Reconnect restore: no errors, charts == canvases, instances stay bounded. Before the fix, 5 of those 7 checks failed. Pre-existing on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt
This was referenced Oct 25, 2026
Open
Owner
Author
2 tasks done
gitluis
pushed a commit
that referenced
this pull request
Oct 26, 2026
PR #11 was branched before #9 (v1.9.5) merged, so the version strings, CHANGELOG.md and the CLAUDE.md footer conflicted. Resolved by keeping v1.9.6 everywhere, ordering the changelog 1.9.6 → 1.9.5 → 1.9.4, and keeping master's v1.9.5 entry in the CLAUDE.md "Last updated" line. No other changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019JQE8BsrWkojjpK1xAUMgr
3 tasks done
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.










The bug
The console showed errors like this:
They appeared once per Overview chart:
Found while investigating Luis's #3 review. It was already on
master.A second, quieter problem in the same area: every render leaked its charts.
Cause
setTimeout(…, 0)(CLAUDE.md §7). At startup,loadFiles()renders Overview, theninit.jscallsshowView('overview')before those timers run. Both batches look up the same canvas IDs and find the same new canvases, so the secondnew Chart()throws.Chart.instancesgrew by one per chart per render (8 → 12 → 20 in the test), and each one kept its detached canvas and data alive.Fix
A guard in
ui.js, next to the other chart helpers, enforces §7 rule 4 ("always destroy a chart before recreating it on the same canvas") in one place:new Chart(...)calls go through the guard.Chart.defaults,Chart.getChart,Chart.instances), including the theme color set inapplyTheme()(from v1.9.0: Settings → Data & Reset tab (clean up data, DB, logs; start over) #3).How it was tested
Headless Chromium, run before and after the fix:
renderActive()×3 in a row: no errors, no extra chartsChart.defaults.colorstill follows the themeAlso checked:
To check
Generated by Claude Code