From 8d429221727a4da18568c2ef0153a665797d0dc1 Mon Sep 17 00:00:00 2001 From: JYC333 <22962980+JYC333@users.noreply.github.com> Date: Mon, 9 Mar 2026 09:57:08 +0000 Subject: [PATCH] refactor: fix cleanup to avoid DOM leaks --- apps/client/src/services/attribute_autocomplete.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/client/src/services/attribute_autocomplete.ts b/apps/client/src/services/attribute_autocomplete.ts index 0fbf78ec28..57f2e724b6 100644 --- a/apps/client/src/services/attribute_autocomplete.ts +++ b/apps/client/src/services/attribute_autocomplete.ts @@ -217,6 +217,9 @@ function initAttributeNameAutocomplete({ $el, attributeType, open, onValueChange inputEl.removeEventListener("blur", onBlur); inputEl.removeEventListener("keydown", onKeyDown); stopPositioning(); + if (panelEl.parentElement) { + panelEl.parentElement.removeChild(panelEl); + } }; instanceMap.set(inputEl, { autocomplete, panelEl, cleanup }); @@ -292,7 +295,17 @@ async function initLabelValueAutocomplete({ $el, open, nameCallback }: LabelValu } } +export function destroyAttributeNameAutocomplete($el: JQuery | HTMLElement) { + const inputEl = $el instanceof HTMLElement ? $el : $el[0] as HTMLInputElement; + const instance = instanceMap.get(inputEl); + if (instance) { + instance.cleanup(); + instanceMap.delete(inputEl); + } +} + export default { initAttributeNameAutocomplete, + destroyAttributeNameAutocomplete, initLabelValueAutocomplete, };