From 1d0b2db972bf4b2229845af5c82942d8ee293833 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 25 Dec 2023 09:56:18 -0500 Subject: [PATCH] fix: Cannot read properties of undefined (reading 'getAttribute') with some pasted content --- shared/editor/nodes/Image.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shared/editor/nodes/Image.tsx b/shared/editor/nodes/Image.tsx index 952a5a81d..f68a0a5c6 100644 --- a/shared/editor/nodes/Image.tsx +++ b/shared/editor/nodes/Image.tsx @@ -105,7 +105,9 @@ export default class Image extends SimpleImage { { tag: "div[class~=image]", getAttrs: (dom: HTMLDivElement) => { - const img = dom.getElementsByTagName("img")[0]; + const img = dom.getElementsByTagName("img")[0] as + | HTMLImageElement + | undefined; const className = dom.className; const layoutClassMatched = className && className.match(/image-(.*)$/); @@ -113,8 +115,8 @@ export default class Image extends SimpleImage { ? layoutClassMatched[1] : null; - const width = img.getAttribute("width"); - const height = img.getAttribute("height"); + const width = img?.getAttribute("width"); + const height = img?.getAttribute("height"); return { src: img?.getAttribute("src"), alt: img?.getAttribute("alt"),