mirror of
https://github.com/zadam/trilium.git
synced 2026-03-13 20:03:36 +01:00
refactor: fix cleanup to avoid DOM leaks
This commit is contained in:
parent
1c79beaa57
commit
e74f619d06
@ -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> | 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,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user