From 215fad8676f01895b9e5bf08d6c87d80a59c3e81 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 May 2025 15:45:02 -0700 Subject: [PATCH] fix: Remove un-typesafe cast. (#9052) --- core/utils/dom.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/utils/dom.ts b/core/utils/dom.ts index 87019dbb2..408798415 100644 --- a/core/utils/dom.ts +++ b/core/utils/dom.ts @@ -289,13 +289,13 @@ export function getFastTextWidthWithSizeString( // Initialize the HTML canvas context and set the font. // The context font must match blocklyText's fontsize and font-family // set in CSS. - canvasContext = computeCanvas.getContext('2d') as CanvasRenderingContext2D; + canvasContext = computeCanvas.getContext('2d'); } - // Set the desired font size and family. - canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; // Measure the text width using the helper canvas context. - if (text) { + if (text && canvasContext) { + // Set the desired font size and family. + canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; width = canvasContext.measureText(text).width; } else { width = 0;