From 4f22176b8fa69e14b69c06585e83267bc88682cc Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 17 Jul 2023 14:10:40 +0900 Subject: [PATCH] perf(frontend): improve performance of contextmenu Resolve #11303 --- CHANGELOG.md | 1 + packages/frontend/src/components/MkAutocomplete.vue | 8 ++------ packages/frontend/src/components/MkContextMenu.vue | 8 ++------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2028a1883..85e459b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - オフライン時の画面にリロードボタンを追加 - Deckで非ルートページにアクセスした際に簡易UIで表示しない設定を追加 - ロール設定画面でロールIDを確認できるように +- コンテキストメニュー表示時のパフォーマンスを改善 - Fix: サーバーメトリクスが90度傾いている - Fix: 非ログイン時にクレデンシャルが必要なページに行くとエラーが出る問題を修正 - Fix: sparkle内にリンクを入れるとクリック不能になる問題の修正 diff --git a/packages/frontend/src/components/MkAutocomplete.vue b/packages/frontend/src/components/MkAutocomplete.vue index fd892d817..9211d92df 100644 --- a/packages/frontend/src/components/MkAutocomplete.vue +++ b/packages/frontend/src/components/MkAutocomplete.vue @@ -356,9 +356,7 @@ onMounted(() => { props.textarea.addEventListener('keydown', onKeydown); - for (const el of Array.from(document.querySelectorAll('body *'))) { - el.addEventListener('mousedown', onMousedown); - } + document.body.addEventListener('mousedown', onMousedown); nextTick(() => { exec(); @@ -374,9 +372,7 @@ onMounted(() => { onBeforeUnmount(() => { props.textarea.removeEventListener('keydown', onKeydown); - for (const el of Array.from(document.querySelectorAll('body *'))) { - el.removeEventListener('mousedown', onMousedown); - } + document.body.removeEventListener('mousedown', onMousedown); }); diff --git a/packages/frontend/src/components/MkContextMenu.vue b/packages/frontend/src/components/MkContextMenu.vue index fb11834f4..f39c94419 100644 --- a/packages/frontend/src/components/MkContextMenu.vue +++ b/packages/frontend/src/components/MkContextMenu.vue @@ -61,15 +61,11 @@ onMounted(() => { rootEl.style.top = `${top}px`; rootEl.style.left = `${left}px`; - for (const el of Array.from(document.querySelectorAll('body *'))) { - el.addEventListener('mousedown', onMousedown); - } + document.body.addEventListener('mousedown', onMousedown); }); onBeforeUnmount(() => { - for (const el of Array.from(document.querySelectorAll('body *'))) { - el.removeEventListener('mousedown', onMousedown); - } + document.body.removeEventListener('mousedown', onMousedown); }); function onMousedown(evt: Event) {