From 0c58ea1adeb3ef0e91075e6abb6d078c82177861 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 21 Nov 2023 13:25:55 +0100 Subject: [PATCH] fix(editor): don't crash when the component isn't completely mounted --- src/components/input/editor/TipTap.vue | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/input/editor/TipTap.vue b/src/components/input/editor/TipTap.vue index 7a8391b1a..8dc4d0442 100644 --- a/src/components/input/editor/TipTap.vue +++ b/src/components/input/editor/TipTap.vue @@ -494,8 +494,8 @@ function setLink() { onMounted(() => { internalMode.value = initialMode nextTick(() => { - const input = tiptapInstanceRef.value.querySelectorAll('.tiptap__editor')[0].children[0] - input.addEventListener('paste', handleImagePaste) + const input = tiptapInstanceRef.value?.querySelectorAll('.tiptap__editor')[0]?.children[0] + input?.addEventListener('paste', handleImagePaste) }) if (editShortcut !== '') { document.addEventListener('keydown', setFocusToEditor) @@ -504,8 +504,8 @@ onMounted(() => { onBeforeUnmount(() => { nextTick(() => { - const input = tiptapInstanceRef.value.querySelectorAll('.tiptap__editor')[0].children[0] - input.removeEventListener('paste', handleImagePaste) + const input = tiptapInstanceRef.value?.querySelectorAll('.tiptap__editor')[0]?.children[0] + input?.removeEventListener('paste', handleImagePaste) }) if (editShortcut !== '') { document.removeEventListener('keydown', setFocusToEditor) @@ -554,7 +554,10 @@ watch( () => isEditing.value, editing => { nextTick(() => { - const checkboxes = tiptapInstanceRef.value.querySelectorAll('[data-checked]') + const checkboxes = tiptapInstanceRef.value?.querySelectorAll('[data-checked]') + if (typeof checkboxes === 'undefined' || checkboxes.length === 0) { + return + } if (editing) { checkboxes.forEach(check => { if (check.children.length < 2) {