fix: lazily initialize canvas element in ProgressGauge service#89
Closed
Kunal1522 wants to merge 1 commit intom-lab:mainfrom
Closed
fix: lazily initialize canvas element in ProgressGauge service#89Kunal1522 wants to merge 1 commit intom-lab:mainfrom
Kunal1522 wants to merge 1 commit intom-lab:mainfrom
Conversation
The ProgressGauge factory accessed document.getElementById('activeProgress')
at service creation time, before Angular's router had rendered the view
containing that element. This caused aProgress to be null and crashed on
aProgress.getContext('2d') with a TypeError.
Fix by introducing a getCanvas() helper that initializes aProgress and
barCTX on first use. All public functions call getCanvas() before
accessing the canvas, ensuring the DOM element exists by the time it
is needed.
Contributor
|
Thanks for the contribution. Closing this as it is superseded by #83, which rewrites the codebase removing Angular, jQuery, Gulp, and the old We aim to merge #83 next week, which will give contributors a stable, modern base to work from. Thoughtful, targeted contributions that build on where the project is heading are much more valuable. We'd encourage you to review #83 and open any future PRs on top of that. |
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.
Fixes #90
gaugeService.jscalleddocument.getElementById('activeProgress')at factory creation time — before Angular's router rendered the view containing that element. This caused aTypeError: Cannot read properties of null (reading 'getContext')crash.Fix
Introduced a
getCanvas()helper that initializesaProgressandbarCTXon first use. All public functions callgetCanvas()before accessing the canvas.By the time any of the public functions (
create,reset,progress) are called from the controller, Angular has already rendered the view and#activeProgressexists in the DOM.Testing
Verified by reviewing call sites in
measure.js—ProgressGauge.create()is called inside the controller after Angular bootstraps, ensuring the element is present.