Skip to content

Commit 1ad6814

Browse files
fix: guard disconnectedCallback against undefined aplayer and prevent duplicate initialization (#105)
- 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: Cursor Agent <cursoragent@cursor.com> Co-authored-by: METO <metowolf@users.noreply.github.com>
1 parent f1ed5a9 commit 1ad6814

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Meting.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
class MetingJSElement extends HTMLElement {
22

33
connectedCallback() {
4-
if (window.APlayer && window.fetch) {
4+
if (window.APlayer && window.fetch && !this._initialized) {
5+
this._initialized = true
56
this._init()
67
this._parse()
78
}
89
}
910

1011
disconnectedCallback() {
11-
if (!this.lock) {
12+
if (!this.lock && this.aplayer) {
1213
this.aplayer.destroy()
14+
this._initialized = false
1315
}
1416
}
1517

0 commit comments

Comments
 (0)