Skip to content

Commit

Permalink
refactor: remove unneeded try/catch.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfunko committed Sep 11, 2024
1 parent e033632 commit 65d8528
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions core/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,14 @@ export function getTextWidth(textElement: SVGTextElement): number {
}
}

// Attempt to compute fetch the width of the SVG text element.
try {
const style = window.getComputedStyle(textElement);
width = getFastTextWidthWithSizeString(
textElement,
style.fontSize,
style.fontWeight,
style.fontFamily,
);
} catch (e) {
// In other cases where we fail to get the computed text. Instead, use an
// approximation and do not cache the result. At some later point in time
// when the block is inserted into the visible DOM, this method will be
// called again and, at that point in time, will not throw an exception.
return textElement.textContent!.length * 8;
}
// Compute the width of the SVG text element.
const style = window.getComputedStyle(textElement);
width = getFastTextWidthWithSizeString(
textElement,
style.fontSize,
style.fontWeight,
style.fontFamily,
);

// Cache the computed width and return.
if (cacheWidths) {
Expand Down

0 comments on commit 65d8528

Please sign in to comment.