From cc07992e47a32e75184ee6500314cdbad38b2ff7 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:41:48 +0530 Subject: [PATCH] [WEB-2424] fix: add optional chaining for parent node (#5571) * fix: add optional chaining for parent node * chore: revert yarn lock changes --- .../src/core/extensions/custom-link/helpers/clickHandler.ts | 4 ++-- packages/editor/src/core/extensions/slash-commands.tsx | 2 +- yarn.lock | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts b/packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts index ec6c540dac..1b084d1ac5 100644 --- a/packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts +++ b/packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts @@ -18,9 +18,9 @@ export function clickHandler(options: ClickHandlerOptions): Plugin { let a = event.target as HTMLElement; const els = []; - while (a.nodeName !== "DIV") { + while (a?.nodeName !== "DIV") { els.push(a); - a = a.parentNode as HTMLElement; + a = a?.parentNode as HTMLElement; } if (!els.find((value) => value.nodeName === "A")) { diff --git a/packages/editor/src/core/extensions/slash-commands.tsx b/packages/editor/src/core/extensions/slash-commands.tsx index a61198db2b..78aa379576 100644 --- a/packages/editor/src/core/extensions/slash-commands.tsx +++ b/packages/editor/src/core/extensions/slash-commands.tsx @@ -63,7 +63,7 @@ const Command = Extension.create({ const { selection } = editor.state; const parentNode = selection.$from.node(selection.$from.depth); - const blockType = parentNode.type.name; + const blockType = parentNode?.type?.name; if (blockType === "codeBlock") { return false; diff --git a/yarn.lock b/yarn.lock index cc59ff6ff5..cec3a100ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13146,4 +13146,4 @@ zeed-dom@^0.10.9: zxcvbn@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/zxcvbn/-/zxcvbn-4.4.2.tgz#28ec17cf09743edcab056ddd8b1b06262cc73c30" - integrity sha512-Bq0B+ixT/DMyG8kgX2xWcI5jUvCwqrMxSFam7m0lAf78nf04hv6lNCsyLYdyYTrCVMqNDY/206K7eExYCeSyUQ== + integrity sha512-Bq0B+ixT/DMyG8kgX2xWcI5jUvCwqrMxSFam7m0lAf78nf04hv6lNCsyLYdyYTrCVMqNDY/206K7eExYCeSyUQ== \ No newline at end of file