fix(utils): add null safety guards to canvasPixelRatio - #7974
Open
karankumar1106 wants to merge 1 commit into
Open
fix(utils): add null safety guards to canvasPixelRatio#7974karankumar1106 wants to merge 1 commit into
karankumar1106 wants to merge 1 commit into
Conversation
karankumar1106
requested review from
Ashutoshx7,
omsuneri and
walterbender
as code owners
August 5, 2026 19:12
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7974 +/- ##
=======================================
Coverage 62.05% 62.06%
=======================================
Files 187 187
Lines 58377 58382 +5
=======================================
+ Hits 36227 36232 +5
Misses 22150 22150 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Hi @walterbender Just following up on this PR. When you have time, could you please review it? I'm happy to make any changes if needed. Thanks for your time! |
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.
Description
Refactors
canvasPixelRatio()injs/utils/browser-utils.jsto include null-safety guards for missing#myCanvasDOM element orgetContext("2d")returningnull.Previously,
canvasPixelRatio()executeddocument.querySelector("#myCanvas").getContext("2d")directly. If#myCanvaswas not present in the DOM (e.g. before full DOM load or in headless test/embedded canvas environments), calling.getContext("2d")threw an unhandledTypeError: Cannot read properties of null (reading 'getContext').Related Issue
N/A
PR Category
Changes Made
js/utils/browser-utils.js:canvasPixelRatio()with null checks fordocument.querySelector("#myCanvas")andcanvas.getContext("2d"), returningdevicePixelRatioas a fallback.js/utils/__tests__/browser-utils.test.js:canvasPixelRatio()safely returnsdevicePixelRatiowhen#myCanvasis not present in DOM.canvasPixelRatio()safely returnsdevicePixelRatiowhencanvas.getContext("2d")returnsnull.Testing Performed
npx.cmd jest js/utils/__tests__/browser-utils.test.js --coverage=falseChecklist
npm run lintandnpx prettier --check .with no errors.Additional Notes for Reviewers
None.