@blackbirdjs/component 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/component.js +19 -2
package/package.json
CHANGED
package/src/component.js
CHANGED
|
@@ -10,6 +10,9 @@ export class BlackbirdComponent extends HTMLElement {
|
|
|
10
10
|
// Add an internal register array to capture cleanup tokens safely
|
|
11
11
|
#unsubscribers = [];
|
|
12
12
|
|
|
13
|
+
// A strict private guard to track if mounting has already occurred
|
|
14
|
+
#isMounted = false;
|
|
15
|
+
|
|
13
16
|
constructor() {
|
|
14
17
|
super();
|
|
15
18
|
this.attachShadow({ mode: 'open' });
|
|
@@ -27,22 +30,36 @@ export class BlackbirdComponent extends HTMLElement {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
async connectedCallback() {
|
|
33
|
+
// MOUNT GUARD: If this instance has already run its template loading setup, block it instantly.
|
|
34
|
+
if (this.#isMounted) return;
|
|
35
|
+
this.#isMounted = true;
|
|
36
|
+
|
|
30
37
|
// Check if the developer provided an external template file path string
|
|
31
38
|
const path = this.constructor.templatePath;
|
|
32
39
|
|
|
33
40
|
if (path) {
|
|
34
41
|
try {
|
|
35
42
|
const response = await fetch(path);
|
|
43
|
+
|
|
44
|
+
// If the path is broken (404, 500, etc.), do not parse it!
|
|
45
|
+
if (!response) {
|
|
46
|
+
throw new Error(`Server responded with status: ${response.status}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
const htmlText = await response.text();
|
|
37
50
|
|
|
51
|
+
if (htmlText.includes('<html') && htmlText.includes(this.tagName.toLowerCase())) {
|
|
52
|
+
throw new Error(`SPA Fallback detected. Dev server returned index.html instead of template asset.`);
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
// Convert the fetched raw text string into browser-executable DOM elements
|
|
39
56
|
const parser = new DOMParser();
|
|
40
57
|
const doc = parser.parseFromString(htmlText, 'text/html');
|
|
41
58
|
|
|
42
59
|
// Append it cleanly inside the isolated Shadow DOM
|
|
43
|
-
this.shadowRoot.innerHTML = doc.
|
|
60
|
+
this.shadowRoot.innerHTML = doc.documentElement.innerHTML;
|
|
44
61
|
} catch (err) {
|
|
45
|
-
console.error(`[Blackbird] Failed to fetch external template at: ${path}`, err);
|
|
62
|
+
console.error(`[Blackbird] Failed to fetch external template at: ${path}\n`, err);
|
|
46
63
|
}
|
|
47
64
|
}
|
|
48
65
|
|