From cb2fe733dd674e601d073c736ed1274086e8347e Mon Sep 17 00:00:00 2001 From: cg-scorpio <90409381+cg-scorpio@users.noreply.github.com> Date: Sun, 16 Oct 2022 15:43:58 +0200 Subject: [PATCH] Fix fit to content (#841) * Fix: avoid to select defs or title as parentElement * Fix: fix problem when nothing is drawing --- packages/svgcanvas/utilities.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/svgcanvas/utilities.js b/packages/svgcanvas/utilities.js index 5ab4388e..bc36281f 100644 --- a/packages/svgcanvas/utilities.js +++ b/packages/svgcanvas/utilities.js @@ -974,13 +974,15 @@ export const getVisibleElements = (parentElement) => { } const contentElems = [] - const children = parentElement.children - // eslint-disable-next-line array-callback-return - Array.from(children, (elem) => { - if (elem.getBBox) { - contentElems.push(elem) - } - }) + if (parentElement) { + const children = parentElement.children + // eslint-disable-next-line array-callback-return + Array.from(children, (elem) => { + if (elem.getBBox) { + contentElems.push(elem) + } + }) + } return contentElems.reverse() }