@ecopages/dev-toolbar 0.2.0-rc.6 → 0.2.0-rc.7

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/README.md CHANGED
@@ -32,7 +32,7 @@ Disable per project with `devToolbar: { enabled: false }`, or per process with `
32
32
 
33
33
  - **Navigation** — route timing archive, initial load, client navigation latency, HMR status, page Integration (route owner); writes `#__ECO_DEV_NAV_TELEMETRY__` in `document.head` (with `data-eco-persist`) and exposes `window.__ECO_DEV_NAV_TELEMETRY__` for machine/AI debug
34
34
  - **Deps** — Page Browser Graph entry/chunk assets, vendor URLs, lazy-load hints
35
- - **Islands** — inspect island hosts stamped with `data-eco-island` (plus legacy React `eco-island` roots); click a row to highlight the live DOM node
35
+ - **Islands** — inspect island hosts stamped with `data-eco-island`, including SSR-emitted React `<eco-island>` hosts; repeated component instances are shown independently and hydration status reports `hydrated` (via `data-eco-hydrated` or verified component update completion), `registered` (for defined custom elements awaiting update completion), or `ssr-only`
36
36
  - **A11y** — axe-core audit (with built-in fallback checks) and in-page highlights
37
37
  - **Settings** — dock placement (top, bottom, left, right), stealth mode, and documentation link
38
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/dev-toolbar",
3
- "version": "0.2.0-rc.6",
3
+ "version": "0.2.0-rc.7",
4
4
  "description": "Development toolbar for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -40,9 +40,9 @@
40
40
  "directory": "packages/dev-toolbar"
41
41
  },
42
42
  "dependencies": {
43
- "@ecopages/jsx": "^0.3.0-rc.2",
44
- "@ecopages/radiant": "^0.3.0-rc.2",
45
- "@ecopages/signals": "^0.3.0-rc.2",
43
+ "@ecopages/jsx": "^0.3.0-rc.9",
44
+ "@ecopages/radiant": "^0.3.0-rc.9",
45
+ "@ecopages/signals": "^0.3.0-rc.9",
46
46
  "axe-core": "^4.10.3"
47
47
  },
48
48
  "types": "./src/bootstrap.d.ts"
@@ -13,7 +13,7 @@ import { readIslandRecords, resolveIslandElement, toIslandRecordView, } from '..
13
13
  import { highlightElement } from '../runtime/highlight-element.js';
14
14
  import { subscribeToNavigationEvents } from '../runtime/navigation-events.js';
15
15
  function islandsSignature(islands) {
16
- return islands.map((island) => `${island.id}|${island.hostTag}|${island.hydrated}|${island.kind}`).join('\n');
16
+ return islands.map((island) => `${island.id}|${island.hostTag}|${island.status}|${island.kind}`).join('\n');
17
17
  }
18
18
  let EcoDevToolbarIslands = class EcoDevToolbarIslands extends RadiantElement {
19
19
  islands = [];
@@ -112,7 +112,7 @@ let EcoDevToolbarIslands = class EcoDevToolbarIslands extends RadiantElement {
112
112
  this.wireMutationObserver();
113
113
  }
114
114
  render() {
115
- return (_jsxs("section", { class: "eco-dev-toolbar__panel", children: [_jsxs("header", { class: "eco-dev-toolbar__settings-header", children: [_jsx("h2", { children: "Islands" }), _jsx("p", { class: "eco-dev-toolbar__muted", children: "React islands, integration counters, and custom elements on this page." })] }), _jsxs("p", { class: "eco-dev-toolbar__muted", children: [this.islands.length, " island", this.islands.length === 1 ? '' : 's', " on this page"] }), _jsx("ul", { class: "eco-dev-toolbar__list", children: this.islands.length > 0 ? (this.islands.map((island, index) => (_jsx("li", { children: _jsxs("button", { type: "button", class: "eco-dev-toolbar__list-item", "data-highlighted": this.highlightedIndex === index ? 'true' : undefined, "on:click": () => this.highlightIsland(index), children: [_jsx("strong", { children: island.label }), _jsxs("span", { class: "eco-dev-toolbar__muted", children: [island.hostTag, island.integration ? ` · ${island.integration}` : '', " \u00B7", ' ', island.hydrated ? 'hydrated' : 'ssr-only', " \u00B7 ", island.kind] }), island.componentKey ? (_jsxs("span", { class: "eco-dev-toolbar__mono", children: ["key=", island.componentKey] })) : null, island.propsPreview ? (_jsx("span", { class: "eco-dev-toolbar__mono", children: island.propsPreview })) : null] }) }, `${island.id}-${island.hostTag}-${index}`)))) : (_jsx("li", { class: "eco-dev-toolbar__muted", children: "No islands detected on this page." })) })] }));
115
+ return (_jsxs("section", { class: "eco-dev-toolbar__panel", children: [_jsxs("header", { class: "eco-dev-toolbar__settings-header", children: [_jsx("h2", { children: "Islands" }), _jsx("p", { class: "eco-dev-toolbar__muted", children: "React islands, integration counters, and custom elements on this page." })] }), _jsxs("p", { class: "eco-dev-toolbar__muted", children: [this.islands.length, " island", this.islands.length === 1 ? '' : 's', " on this page"] }), _jsx("ul", { class: "eco-dev-toolbar__list", children: this.islands.length > 0 ? (this.islands.map((island, index) => (_jsx("li", { children: _jsxs("button", { type: "button", class: "eco-dev-toolbar__list-item", "data-highlighted": this.highlightedIndex === index ? 'true' : undefined, "on:click": () => this.highlightIsland(index), children: [_jsx("strong", { children: island.label }), _jsxs("span", { class: "eco-dev-toolbar__muted", children: [island.hostTag, island.integration ? ` · ${island.integration}` : '', " \u00B7 ", island.status, " \u00B7", ' ', island.kind] }), island.componentKey ? (_jsxs("span", { class: "eco-dev-toolbar__mono", children: ["key=", island.componentKey] })) : null, island.propsPreview ? (_jsx("span", { class: "eco-dev-toolbar__mono", children: island.propsPreview })) : null] }) }, `${island.id}-${island.hostTag}-${index}`)))) : (_jsx("li", { class: "eco-dev-toolbar__muted", children: "No islands detected on this page." })) })] }));
116
116
  }
117
117
  };
118
118
  __decorate([
@@ -1,5 +1,21 @@
1
1
  /**
2
2
  * Collects unique island host elements from the live document.
3
+ *
4
+ * @remarks
5
+ * Discovery merges framework markers, custom-element hosts, and the React
6
+ * registry because navigation can temporarily leave only one of those signals
7
+ * in the document. Repeated instances sharing a component ID are deduplicated
8
+ * in favor of dedicated island containers, while standalone hosts retain their
9
+ * element identity. Results are ordered by document position for stable toolbar
10
+ * presentation.
11
+ *
12
+ * @param doc - Document to inspect.
13
+ * @returns Unique connected island host elements in document order.
3
14
  */
4
15
  export declare function discoverIslandElements(doc: Document): HTMLElement[];
16
+ /**
17
+ * Reads the live React island-root index used to enrich toolbar records.
18
+ *
19
+ * @returns Instance-keyed roots currently registered by the browser runtime.
20
+ */
5
21
  export declare function readIslandRoots(): Record<string, unknown>;
@@ -20,26 +20,6 @@ function islandPriority(element) {
20
20
  }
21
21
  return 10;
22
22
  }
23
- function getDedupeKey(element, doc) {
24
- const componentKey = element.getAttribute('data-eco-component-key');
25
- if (componentKey) {
26
- return `key:${componentKey}`;
27
- }
28
- const componentId = element.getAttribute('data-eco-component-id');
29
- if (componentId) {
30
- return `id:${componentId}`;
31
- }
32
- if (element.id) {
33
- return `dom-id:${element.id}`;
34
- }
35
- const tag = element.tagName.toLowerCase();
36
- if (tag.includes('-')) {
37
- const index = [...(element.parentElement?.children ?? [])].indexOf(element);
38
- return `custom:${tag}:${index}`;
39
- }
40
- const index = [...doc.querySelectorAll(tag)].indexOf(element);
41
- return `tag:${tag}:${index}`;
42
- }
43
23
  function addCandidate(candidates, element) {
44
24
  if (!isToolbarElement(element)) {
45
25
  candidates.add(element);
@@ -47,40 +27,49 @@ function addCandidate(candidates, element) {
47
27
  }
48
28
  /**
49
29
  * Collects unique island host elements from the live document.
30
+ *
31
+ * @remarks
32
+ * Discovery merges framework markers, custom-element hosts, and the React
33
+ * registry because navigation can temporarily leave only one of those signals
34
+ * in the document. Repeated instances sharing a component ID are deduplicated
35
+ * in favor of dedicated island containers, while standalone hosts retain their
36
+ * element identity. Results are ordered by document position for stable toolbar
37
+ * presentation.
38
+ *
39
+ * @param doc - Document to inspect.
40
+ * @returns Unique connected island host elements in document order.
50
41
  */
51
42
  export function discoverIslandElements(doc) {
52
43
  const candidates = new Set();
53
- for (const element of doc.querySelectorAll('[data-eco-island]')) {
54
- addCandidate(candidates, element);
55
- }
56
- for (const element of doc.querySelectorAll('[data-eco-component-key]')) {
57
- addCandidate(candidates, element);
58
- }
59
- for (const element of doc.querySelectorAll('eco-island')) {
44
+ for (const element of doc.querySelectorAll('[data-eco-island], [data-eco-component-key], eco-island')) {
60
45
  addCandidate(candidates, element);
61
46
  }
62
47
  const islandRoots = window.__ECO_PAGES__?.islandRoots ?? {};
63
- for (const componentKey of Object.keys(islandRoots)) {
64
- const escapedKey = CSS.escape(componentKey);
65
- for (const element of doc.querySelectorAll(`[data-eco-component-key="${escapedKey}"]`)) {
66
- addCandidate(candidates, element);
67
- }
68
- for (const element of doc.querySelectorAll(`eco-island[data-eco-component-key="${escapedKey}"]`)) {
48
+ for (const componentId of Object.keys(islandRoots)) {
49
+ const escapedId = CSS.escape(componentId);
50
+ for (const element of doc.querySelectorAll(`[data-eco-component-id="${escapedId}"]`)) {
69
51
  addCandidate(candidates, element);
70
52
  }
71
53
  }
72
- const deduped = new Map();
54
+ const dedupedByInstance = new Map();
55
+ const standaloneElements = new Set();
73
56
  for (const element of candidates) {
74
57
  if (!element.isConnected) {
75
58
  continue;
76
59
  }
77
- const key = getDedupeKey(element, doc);
78
- const existing = deduped.get(key);
79
- if (!existing || islandPriority(element) > islandPriority(existing)) {
80
- deduped.set(key, element);
60
+ const componentId = element.getAttribute('data-eco-component-id');
61
+ if (componentId) {
62
+ const existing = dedupedByInstance.get(componentId);
63
+ if (!existing || islandPriority(element) > islandPriority(existing)) {
64
+ dedupedByInstance.set(componentId, element);
65
+ }
66
+ }
67
+ else {
68
+ standaloneElements.add(element);
81
69
  }
82
70
  }
83
- return [...deduped.values()].sort((left, right) => {
71
+ const elements = [...dedupedByInstance.values(), ...standaloneElements];
72
+ return elements.sort((left, right) => {
84
73
  if (left === right) {
85
74
  return 0;
86
75
  }
@@ -94,6 +83,11 @@ export function discoverIslandElements(doc) {
94
83
  return 0;
95
84
  });
96
85
  }
86
+ /**
87
+ * Reads the live React island-root index used to enrich toolbar records.
88
+ *
89
+ * @returns Instance-keyed roots currently registered by the browser runtime.
90
+ */
97
91
  export function readIslandRoots() {
98
92
  return window.__ECO_PAGES__?.islandRoots ?? {};
99
93
  }
@@ -1,3 +1,4 @@
1
+ export type IslandStatus = 'hydrated' | 'registered' | 'ssr-only';
1
2
  export type IslandRecord = {
2
3
  id: string;
3
4
  label: string;
@@ -5,6 +6,7 @@ export type IslandRecord = {
5
6
  componentId?: string;
6
7
  hostTag: string;
7
8
  kind: 'react-island' | 'integration' | 'custom-element';
9
+ status: IslandStatus;
8
10
  integration?: string;
9
11
  propsPreview: string;
10
12
  hydrated: boolean;
@@ -13,9 +15,32 @@ export type IslandRecord = {
13
15
  export type IslandRecordView = Omit<IslandRecord, 'element'> & {
14
16
  targetSelector: string;
15
17
  };
18
+ /**
19
+ * Builds the selector used to resolve a record after navigation or rerender.
20
+ *
21
+ * @remarks
22
+ * Instance IDs take precedence over component keys so repeated instances never
23
+ * resolve to a sibling that happens to use the same component entry.
24
+ *
25
+ * @param element - Current host element.
26
+ * @param record - Identity fields from the discovered record.
27
+ * @returns A selector that targets the same host instance when possible.
28
+ */
16
29
  export declare function buildIslandTargetSelector(element: HTMLElement, record: Pick<IslandRecord, 'componentKey' | 'componentId'>): string;
30
+ /**
31
+ * Converts an internal record into the serializable toolbar-facing view.
32
+ *
33
+ * @param record - Record containing the live element reference.
34
+ * @returns Record view with a selector instead of the DOM node.
35
+ */
17
36
  export declare function toIslandRecordView(record: IslandRecord): IslandRecordView;
18
37
  /**
19
38
  * Builds one island record from a discovered host element.
39
+ * The explicit React hydration marker is preserved as the toolbar's completion
40
+ * signal while SSR-only hosts remain visibly unhydrated.
41
+ *
42
+ * @param element - Discovered island host.
43
+ * @param islandRoots - Instance-keyed runtime registry.
44
+ * @returns Toolbar record containing identity, status, and live element.
20
45
  */
21
46
  export declare function buildIslandRecord(element: HTMLElement, islandRoots: Record<string, unknown>): IslandRecord;
@@ -9,14 +9,42 @@ function parsePropsPreview(encoded) {
9
9
  return '(invalid props)';
10
10
  }
11
11
  }
12
- function isHydratedIsland(element, componentKey, islandRoots) {
13
- if (componentKey && islandRoots[componentKey]) {
14
- return true;
12
+ /**
13
+ * Resolves the integration-specific lifecycle status for one host element.
14
+ *
15
+ * @remarks
16
+ * Explicit hydration markers (`data-eco-hydrated`) indicate completed hydration
17
+ * across all integrations. React hosts require this post-commit marker. Lit
18
+ * elements require custom-element registration, clearance of `defer-hydration`,
19
+ * and verified initial update completion via `hasUpdated`. Custom elements
20
+ * registered in the browser but lacking an update completion signal are reported
21
+ * as 'registered' rather than 'hydrated'. Unregistered hosts are 'ssr-only'.
22
+ */
23
+ function resolveIslandStatus(element, componentId, islandRoots) {
24
+ if (element.hasAttribute('data-eco-hydrated')) {
25
+ return 'hydrated';
26
+ }
27
+ const integration = element.getAttribute('data-eco-island-integration');
28
+ if (integration === 'react' || (!integration && element.tagName.toLowerCase() === 'eco-island')) {
29
+ return 'ssr-only';
30
+ }
31
+ const tag = element.tagName.toLowerCase();
32
+ const isCustomElement = tag.includes('-');
33
+ if (isCustomElement && typeof customElements !== 'undefined') {
34
+ const isDefined = Boolean(customElements.get(tag));
35
+ if (isDefined) {
36
+ const isDeferred = element.hasAttribute('defer-hydration');
37
+ const hasUpdated = element.hasUpdated === true;
38
+ if (!isDeferred && hasUpdated) {
39
+ return 'hydrated';
40
+ }
41
+ return 'registered';
42
+ }
15
43
  }
16
- if (element.tagName.toLowerCase() === 'eco-island') {
17
- return element.childElementCount > 0;
44
+ if (componentId && islandRoots[componentId]) {
45
+ return 'hydrated';
18
46
  }
19
- return false;
47
+ return 'ssr-only';
20
48
  }
21
49
  function buildLabel(element, componentKey, componentId, integration) {
22
50
  if (componentId) {
@@ -35,7 +63,7 @@ function buildLabel(element, componentKey, componentId, integration) {
35
63
  return element.tagName.toLowerCase();
36
64
  }
37
65
  function getIslandKind(element, componentKey, integration) {
38
- if (integration === 'react' || componentKey || element.tagName.toLowerCase() === 'eco-island') {
66
+ if (integration === 'react' || (!integration && (element.tagName.toLowerCase() === 'eco-island' || componentKey))) {
39
67
  return 'react-island';
40
68
  }
41
69
  if (integration) {
@@ -43,13 +71,24 @@ function getIslandKind(element, componentKey, integration) {
43
71
  }
44
72
  return 'custom-element';
45
73
  }
74
+ /**
75
+ * Builds the selector used to resolve a record after navigation or rerender.
76
+ *
77
+ * @remarks
78
+ * Instance IDs take precedence over component keys so repeated instances never
79
+ * resolve to a sibling that happens to use the same component entry.
80
+ *
81
+ * @param element - Current host element.
82
+ * @param record - Identity fields from the discovered record.
83
+ * @returns A selector that targets the same host instance when possible.
84
+ */
46
85
  export function buildIslandTargetSelector(element, record) {
47
- if (record.componentKey) {
48
- return `[data-eco-component-key="${CSS.escape(record.componentKey)}"]`;
49
- }
50
86
  if (record.componentId) {
51
87
  return `[data-eco-component-id="${CSS.escape(record.componentId)}"]`;
52
88
  }
89
+ if (record.componentKey) {
90
+ return `[data-eco-component-key="${CSS.escape(record.componentKey)}"]`;
91
+ }
53
92
  if (element.id) {
54
93
  return `#${CSS.escape(element.id)}`;
55
94
  }
@@ -69,6 +108,12 @@ export function buildIslandTargetSelector(element, record) {
69
108
  }
70
109
  return segments.join(' > ');
71
110
  }
111
+ /**
112
+ * Converts an internal record into the serializable toolbar-facing view.
113
+ *
114
+ * @param record - Record containing the live element reference.
115
+ * @returns Record view with a selector instead of the DOM node.
116
+ */
72
117
  export function toIslandRecordView(record) {
73
118
  const { element, ...view } = record;
74
119
  return {
@@ -78,6 +123,12 @@ export function toIslandRecordView(record) {
78
123
  }
79
124
  /**
80
125
  * Builds one island record from a discovered host element.
126
+ * The explicit React hydration marker is preserved as the toolbar's completion
127
+ * signal while SSR-only hosts remain visibly unhydrated.
128
+ *
129
+ * @param element - Discovered island host.
130
+ * @param islandRoots - Instance-keyed runtime registry.
131
+ * @returns Toolbar record containing identity, status, and live element.
81
132
  */
82
133
  export function buildIslandRecord(element, islandRoots) {
83
134
  const componentKey = element.getAttribute('data-eco-component-key') ?? undefined;
@@ -85,6 +136,7 @@ export function buildIslandRecord(element, islandRoots) {
85
136
  const integration = element.getAttribute('data-eco-island-integration') ?? undefined;
86
137
  const label = buildLabel(element, componentKey, componentId, integration);
87
138
  const id = componentId ?? componentKey ?? label;
139
+ const status = resolveIslandStatus(element, componentId, islandRoots);
88
140
  return {
89
141
  id,
90
142
  label,
@@ -94,7 +146,8 @@ export function buildIslandRecord(element, islandRoots) {
94
146
  hostTag: element.tagName.toLowerCase(),
95
147
  kind: getIslandKind(element, componentKey, integration),
96
148
  propsPreview: parsePropsPreview(element.getAttribute('data-eco-props')),
97
- hydrated: isHydratedIsland(element, componentKey, islandRoots),
149
+ status,
150
+ hydrated: status === 'hydrated',
98
151
  element,
99
152
  };
100
153
  }
@@ -1,11 +1,24 @@
1
1
  import { type IslandRecord, type IslandRecordView } from './island-record-builder.js';
2
- export type { IslandRecord, IslandRecordView } from './island-record-builder.js';
2
+ export type { IslandRecord, IslandRecordView, IslandStatus } from './island-record-builder.js';
3
3
  export { toIslandRecordView } from './island-record-builder.js';
4
4
  /**
5
5
  * Resolves the live DOM node for an island record after hydration or route swaps.
6
+ *
7
+ * @remarks
8
+ * Component IDs are instance identities and therefore resolve before shared
9
+ * component keys. When an instance ID is present but gone, resolution stops
10
+ * instead of falling through to a sibling that shares the component key.
11
+ * Selector fallback is retained for legacy integrations without an instance ID.
12
+ *
13
+ * @param record - Toolbar record to resolve.
14
+ * @param doc - Document containing the current host.
15
+ * @returns The connected host element, or `null` when it is gone.
6
16
  */
7
17
  export declare function resolveIslandElement(record: IslandRecordView, doc?: Document): HTMLElement | null;
8
18
  /**
9
- * Collects island hosts stamped by core (`data-eco-island`) plus legacy React hydration roots.
19
+ * Discovers current hosts and builds records against the live root registry.
20
+ *
21
+ * @param doc - Document to inspect.
22
+ * @returns Current toolbar records in document order.
10
23
  */
11
24
  export declare function readIslandRecords(doc?: Document): IslandRecord[];
@@ -3,8 +3,26 @@ import { buildIslandRecord } from './island-record-builder.js';
3
3
  export { toIslandRecordView } from './island-record-builder.js';
4
4
  /**
5
5
  * Resolves the live DOM node for an island record after hydration or route swaps.
6
+ *
7
+ * @remarks
8
+ * Component IDs are instance identities and therefore resolve before shared
9
+ * component keys. When an instance ID is present but gone, resolution stops
10
+ * instead of falling through to a sibling that shares the component key.
11
+ * Selector fallback is retained for legacy integrations without an instance ID.
12
+ *
13
+ * @param record - Toolbar record to resolve.
14
+ * @param doc - Document containing the current host.
15
+ * @returns The connected host element, or `null` when it is gone.
6
16
  */
7
17
  export function resolveIslandElement(record, doc = document) {
18
+ if (record.componentId) {
19
+ const escapedId = CSS.escape(record.componentId);
20
+ const hostById = doc.querySelector(`[data-eco-component-id="${escapedId}"]`);
21
+ if (hostById instanceof HTMLElement && hostById.isConnected) {
22
+ return hostById;
23
+ }
24
+ return null;
25
+ }
8
26
  if (record.componentKey) {
9
27
  const escapedKey = CSS.escape(record.componentKey);
10
28
  const hydratedIsland = doc.querySelector(`eco-island[data-eco-component-key="${escapedKey}"]`);
@@ -16,13 +34,6 @@ export function resolveIslandElement(record, doc = document) {
16
34
  return keyedHost;
17
35
  }
18
36
  }
19
- if (record.componentId) {
20
- const escapedId = CSS.escape(record.componentId);
21
- const hostById = doc.querySelector(`[data-eco-component-id="${escapedId}"]`);
22
- if (hostById instanceof HTMLElement && hostById.isConnected) {
23
- return hostById;
24
- }
25
- }
26
37
  try {
27
38
  const fallback = doc.querySelector(record.targetSelector);
28
39
  if (fallback instanceof HTMLElement && fallback.isConnected) {
@@ -35,7 +46,10 @@ export function resolveIslandElement(record, doc = document) {
35
46
  return null;
36
47
  }
37
48
  /**
38
- * Collects island hosts stamped by core (`data-eco-island`) plus legacy React hydration roots.
49
+ * Discovers current hosts and builds records against the live root registry.
50
+ *
51
+ * @param doc - Document to inspect.
52
+ * @returns Current toolbar records in document order.
39
53
  */
40
54
  export function readIslandRecords(doc = document) {
41
55
  const islandRoots = readIslandRoots();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,95 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { readIslandRecords, resolveIslandElement } from './read-island-records.js';
3
+ describe('readIslandRecords', () => {
4
+ it('deduplicates by component ID in favor of island container and preserves standalone elements', () => {
5
+ document.body.innerHTML = `
6
+ <div data-eco-island data-eco-component-id="inst-1">
7
+ <eco-island data-eco-island data-eco-component-id="inst-1"></eco-island>
8
+ </div>
9
+ <eco-island data-eco-island data-eco-component-key="standalone-1"></eco-island>
10
+ <eco-island data-eco-island data-eco-component-key="standalone-2"></eco-island>
11
+ `;
12
+ const records = readIslandRecords(document);
13
+ expect(records).toHaveLength(3);
14
+ expect(records[0].componentId).toBe('inst-1');
15
+ expect(records[0].hostTag).toBe('eco-island');
16
+ expect(records[1].componentKey).toBe('standalone-1');
17
+ expect(records[2].componentKey).toBe('standalone-2');
18
+ });
19
+ it('respects integration metadata over componentKey for island kind', () => {
20
+ document.body.innerHTML = `
21
+ <my-lit-island data-eco-island data-eco-island-integration="lit" data-eco-component-key="lit-counter"></my-lit-island>
22
+ <eco-island data-eco-island data-eco-component-key="react-counter"></eco-island>
23
+ `;
24
+ const records = readIslandRecords(document);
25
+ expect(records).toHaveLength(2);
26
+ expect(records[0].kind).toBe('integration');
27
+ expect(records[0].integration).toBe('lit');
28
+ expect(records[1].kind).toBe('react-island');
29
+ });
30
+ it('determines integration-specific lifecycle status for React, Lit, and custom elements', () => {
31
+ class TestRegisteredCustomElement extends HTMLElement {
32
+ }
33
+ if (!customElements.get('test-toolbar-registered')) {
34
+ customElements.define('test-toolbar-registered', TestRegisteredCustomElement);
35
+ }
36
+ class TestLitHydratedElement extends HTMLElement {
37
+ hasUpdated = true;
38
+ }
39
+ if (!customElements.get('test-toolbar-lit-hydrated')) {
40
+ customElements.define('test-toolbar-lit-hydrated', TestLitHydratedElement);
41
+ }
42
+ document.body.innerHTML = `
43
+ <eco-island data-eco-island data-eco-island-integration="react" data-eco-component-id="react-unhydrated"></eco-island>
44
+ <eco-island data-eco-island data-eco-island-integration="react" data-eco-hydrated="true" data-eco-component-id="react-hydrated"></eco-island>
45
+ <test-toolbar-lit-hydrated data-eco-island data-eco-island-integration="lit" defer-hydration></test-toolbar-lit-hydrated>
46
+ <test-toolbar-lit-hydrated data-eco-island data-eco-island-integration="lit"></test-toolbar-lit-hydrated>
47
+ <test-toolbar-registered data-eco-island data-eco-island-integration="ecopages-jsx"></test-toolbar-registered>
48
+ <test-toolbar-unregistered data-eco-island data-eco-island-integration="ecopages-jsx"></test-toolbar-unregistered>
49
+ `;
50
+ const records = readIslandRecords(document);
51
+ expect(records).toHaveLength(6);
52
+ // React without data-eco-hydrated
53
+ expect(records[0].status).toBe('ssr-only');
54
+ expect(records[0].hydrated).toBe(false);
55
+ // React with data-eco-hydrated
56
+ expect(records[1].status).toBe('hydrated');
57
+ expect(records[1].hydrated).toBe(true);
58
+ // Lit with defer-hydration
59
+ expect(records[2].status).toBe('registered');
60
+ expect(records[2].hydrated).toBe(false);
61
+ // Lit with completed initial update (hasUpdated = true)
62
+ expect(records[3].status).toBe('hydrated');
63
+ expect(records[3].hydrated).toBe(true);
64
+ // Custom element registered without update completion signal: registered, not hydrated
65
+ expect(records[4].status).toBe('registered');
66
+ expect(records[4].hydrated).toBe(false);
67
+ // Custom element not registered in customElements
68
+ expect(records[5].status).toBe('ssr-only');
69
+ expect(records[5].hydrated).toBe(false);
70
+ });
71
+ });
72
+ describe('resolveIslandElement', () => {
73
+ it('does not resolve a removed instance to a sibling with the same component key', () => {
74
+ document.body.innerHTML = `
75
+ <eco-island data-eco-component-id="first" data-eco-component-key="shared"></eco-island>
76
+ <eco-island data-eco-component-id="second" data-eco-component-key="shared"></eco-island>
77
+ `;
78
+ const first = document.querySelector('[data-eco-component-id="first"]');
79
+ if (!(first instanceof HTMLElement))
80
+ throw new Error('missing first island');
81
+ first.remove();
82
+ expect(resolveIslandElement({
83
+ id: 'first',
84
+ label: 'first',
85
+ componentId: 'first',
86
+ componentKey: 'shared',
87
+ hostTag: 'eco-island',
88
+ kind: 'react-island',
89
+ propsPreview: '',
90
+ status: 'ssr-only',
91
+ hydrated: false,
92
+ targetSelector: '[data-eco-component-key="shared"]',
93
+ }, document)).toBeNull();
94
+ });
95
+ });