Skip to content

Commit 1e1ce02

Browse files
committed
refactor: fix cleanup to avoid DOM leaks
1 parent a1898c4 commit 1e1ce02

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

apps/client/src/services/attribute_autocomplete.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ function initAttributeNameAutocomplete({ $el, attributeType, open, onValueChange
217217
inputEl.removeEventListener("blur", onBlur);
218218
inputEl.removeEventListener("keydown", onKeyDown);
219219
stopPositioning();
220+
if (panelEl.parentElement) {
221+
panelEl.parentElement.removeChild(panelEl);
222+
}
220223
};
221224

222225
instanceMap.set(inputEl, { autocomplete, panelEl, cleanup });
@@ -292,7 +295,17 @@ async function initLabelValueAutocomplete({ $el, open, nameCallback }: LabelValu
292295
}
293296
}
294297

298+
export function destroyAttributeNameAutocomplete($el: JQuery<HTMLElement> | HTMLElement) {
299+
const inputEl = $el instanceof HTMLElement ? $el : $el[0] as HTMLInputElement;
300+
const instance = instanceMap.get(inputEl);
301+
if (instance) {
302+
instance.cleanup();
303+
instanceMap.delete(inputEl);
304+
}
305+
}
306+
295307
export default {
296308
initAttributeNameAutocomplete,
309+
destroyAttributeNameAutocomplete,
297310
initLabelValueAutocomplete,
298311
};

0 commit comments

Comments
 (0)