fix: scope htmx:beforeSwap and clear searchDebounce on teardown
This commit is contained in:
@@ -101,7 +101,7 @@ const initPlayer = (): void => {
|
||||
currentContainer = container;
|
||||
const abortController = new AbortController();
|
||||
const signal = abortController.signal;
|
||||
cleanup = () => abortController.abort();
|
||||
cleanup = null;
|
||||
|
||||
const loading = container.querySelector("[data-loading]") as HTMLElement | null;
|
||||
const progressWrap = container.querySelector("[data-progress-wrap]") as HTMLElement | null;
|
||||
@@ -396,6 +396,22 @@ const initPlayer = (): void => {
|
||||
|
||||
setupThumbnails();
|
||||
void hydrateAlternateMode(signal);
|
||||
|
||||
document.body.addEventListener(
|
||||
"htmx:beforeSwap",
|
||||
(e: Event) => {
|
||||
const target = (e as CustomEvent).detail?.target as HTMLElement | null;
|
||||
if (target && currentContainer && target.contains(currentContainer)) {
|
||||
teardownPlayer();
|
||||
}
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
|
||||
cleanup = () => {
|
||||
clearTimeout(searchDebounce);
|
||||
abortController.abort();
|
||||
};
|
||||
};
|
||||
|
||||
onReady(initPlayer);
|
||||
@@ -404,10 +420,3 @@ onHtmxLoad((root) => {
|
||||
initPlayer();
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener("htmx:beforeSwap", (e: Event) => {
|
||||
const target = (e as CustomEvent).detail?.target as HTMLElement | null;
|
||||
if (target && currentContainer && target.contains(currentContainer)) {
|
||||
teardownPlayer();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user