diff --git a/src/lib/board/useDim.js b/src/lib/board/useDim.js index 9882822..b134ecb 100644 --- a/src/lib/board/useDim.js +++ b/src/lib/board/useDim.js @@ -329,17 +329,19 @@ const useDim = () => { (boundingBox, item) => { const elem = getItemElem(boardWrapper, item.id); - boundingBox.left = Math.min(item.x, boundingBox.left); - boundingBox.top = Math.min(item.y, boundingBox.top); - - boundingBox.right = Math.max( - item.x + elem.offsetWidth, - boundingBox.right - ); - boundingBox.bottom = Math.max( - item.y + elem.offsetHeight, - boundingBox.bottom - ); + if (elem) { + boundingBox.left = Math.min(item.x, boundingBox.left); + boundingBox.top = Math.min(item.y, boundingBox.top); + + boundingBox.right = Math.max( + item.x + elem.offsetWidth, + boundingBox.right + ); + boundingBox.bottom = Math.max( + item.y + elem.offsetHeight, + boundingBox.bottom + ); + } return boundingBox; }, diff --git a/src/lib/utils.js b/src/lib/utils.js index ab920f5..d59fcde 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -123,13 +123,20 @@ export const isItemInsideElement = (itemElement, otherElem) => { }; export const getItemElem = (wrapper, itemId) => { - const elems = wrapper.getElementsByClassName(`item ${itemId}`); - const elem = elems[0]; - if (!elem) { - // eslint-disable-next-line no-console - console.error(`Missing item ${itemId}`); + try { + const elems = wrapper.getElementsByClassName(`item ${itemId}`); + const elem = elems[0]; + if (!elem) { + console.error(`Missing item ${itemId}`); + } + return elem; + } catch (e) { + console.error( + `Error while getting item with id ${itemId} with wrapper`, + wrapper + ); + return undefined; } - return elem; }; export const getIdFromElem = (elem) => {