From bc880cabfd114df7d67417e3006162d9dd8f5dfc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 12 Apr 2026 14:19:01 +0000 Subject: [PATCH] fix: guard disconnectedCallback against undefined aplayer and prevent duplicate initialization - Add null check for this.aplayer in disconnectedCallback to prevent 'Cannot read properties of undefined (reading destroy)' error when the element is moved in the DOM before the async fetch completes - Add _initialized flag to prevent connectedCallback from running _init() and _parse() multiple times when the element is re-inserted into the DOM (e.g., by jQuery DOM manipulation libraries) - Reset _initialized on proper disconnect so the element can be reused Fixes #66 Co-authored-by: METO --- src/Meting.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Meting.js b/src/Meting.js index d499e23..1d43e28 100644 --- a/src/Meting.js +++ b/src/Meting.js @@ -1,15 +1,17 @@ class MetingJSElement extends HTMLElement { connectedCallback() { - if (window.APlayer && window.fetch) { + if (window.APlayer && window.fetch && !this._initialized) { + this._initialized = true this._init() this._parse() } } disconnectedCallback() { - if (!this.lock) { + if (!this.lock && this.aplayer) { this.aplayer.destroy() + this._initialized = false } }