@ecopages/dev-toolbar 0.2.0-beta.37 → 0.2.0-beta.39

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
@@ -1,6 +1,6 @@
1
1
  # @ecopages/dev-toolbar
2
2
 
3
- Development-only browser toolbar for Ecopages, inspired by [Astro's dev toolbar](https://docs.astro.build/en/guides/dev-toolbar/).
3
+ Development-only browser toolbar for Ecopages. Mounts during `ecopages dev` and does not ship to production builds.
4
4
 
5
5
  User-facing docs: [Dev toolbar](https://ecopages.dev/docs/core/dev-toolbar) (enablement, manifest, built-in apps).
6
6
 
@@ -54,7 +54,8 @@ To replace this reference toolbar:
54
54
 
55
55
  ## Package layout
56
56
 
57
- - `src/bootstrap.ts` — injects toolbar CSS into `document.head`, boots navigation telemetry, and mounts `eco-dev-toolbar`
57
+ - `src/bootstrap.ts` — injects toolbar CSS into `document.head`, boots navigation telemetry, and mounts `eco-dev-toolbar`; reload-safe telemetry ownership prevents HMR bundle re-evaluation from adding duplicate document listeners
58
+ - `src/runtime/navigation-events.ts` — shares the three navigation lifecycle listeners across toolbar apps and removes them when the final subscriber unmounts
58
59
  - `src/shell/eco-dev-toolbar.tsx` — Radiant light-DOM host (JSX `render()`, no shadow root); panel positioning is pure CSS
59
60
  - `src/shell/motion.ts` — WAAPI motion for stealth dock reveal only; panel show/hide is CSS
60
61
  - `src/apps/*-panel.tsx` — Radiant JSX panels (navigation, deps, islands, a11y, settings)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/dev-toolbar",
3
- "version": "0.2.0-beta.37",
3
+ "version": "0.2.0-beta.39",
4
4
  "description": "Development toolbar for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -37,9 +37,9 @@
37
37
  "directory": "packages/dev-toolbar"
38
38
  },
39
39
  "dependencies": {
40
- "@ecopages/jsx": "0.3.0-beta.3",
41
- "@ecopages/radiant": "0.3.0-beta.3",
42
- "@ecopages/signals": "0.3.0-beta.3",
40
+ "@ecopages/jsx": "0.3.0-beta.6",
41
+ "@ecopages/radiant": "0.3.0-beta.6",
42
+ "@ecopages/signals": "0.3.0-beta.6",
43
43
  "axe-core": "^4.10.3"
44
44
  },
45
45
  "types": "./src/bootstrap.d.ts"
@@ -10,6 +10,7 @@ export declare class EcoDevToolbarA11y extends RadiantElement {
10
10
  private auditGeneration;
11
11
  private auditDebounceTimer;
12
12
  private clearHighlight;
13
+ private unsubscribeNavigationEvents;
13
14
  private get toolbar();
14
15
  connectedCallback(): void;
15
16
  disconnectedCallback(): void;
@@ -13,6 +13,7 @@ import { toA11yBadge } from './a11y/a11y-badge.js';
13
13
  import { resolveA11yIssueElement, runA11yChecks, toA11yIssueView } from './a11y/run-a11y-checks.js';
14
14
  import { groupA11yIssues } from './a11y/a11y-issue-groups.js';
15
15
  import { highlightElement } from '../runtime/highlight-element.js';
16
+ import { subscribeToNavigationEvents } from '../runtime/navigation-events.js';
16
17
  const auditCache = new Map();
17
18
  function auditCacheKey(doc) {
18
19
  return doc.defaultView?.location.href ?? '';
@@ -34,18 +35,18 @@ let EcoDevToolbarA11y = class EcoDevToolbarA11y extends RadiantElement {
34
35
  auditGeneration = 0;
35
36
  auditDebounceTimer;
36
37
  clearHighlight;
38
+ unsubscribeNavigationEvents;
37
39
  get toolbar() {
38
40
  return this.closest('eco-dev-toolbar');
39
41
  }
40
42
  connectedCallback() {
41
43
  super.connectedCallback();
42
- this.ownerDocument.addEventListener('eco:page-load', this.scheduleAudit);
43
- this.ownerDocument.addEventListener('eco:after-swap', this.scheduleAudit);
44
+ this.unsubscribeNavigationEvents = subscribeToNavigationEvents(this.ownerDocument, ['eco:page-load', 'eco:after-swap'], this.scheduleAudit);
44
45
  void this.runAudit();
45
46
  }
46
47
  disconnectedCallback() {
47
- this.ownerDocument.removeEventListener('eco:page-load', this.scheduleAudit);
48
- this.ownerDocument.removeEventListener('eco:after-swap', this.scheduleAudit);
48
+ this.unsubscribeNavigationEvents?.();
49
+ this.unsubscribeNavigationEvents = undefined;
49
50
  if (this.auditDebounceTimer !== undefined) {
50
51
  clearTimeout(this.auditDebounceTimer);
51
52
  this.auditDebounceTimer = undefined;
@@ -9,6 +9,7 @@ export declare class EcoDevToolbarDeps extends RadiantElement {
9
9
  private loadGeneration;
10
10
  private refreshDebounceTimer;
11
11
  private disconnectVisibilityObserver;
12
+ private unsubscribeNavigationEvents;
12
13
  connectedCallback(): void;
13
14
  disconnectedCallback(): void;
14
15
  private wireVisibilityObserver;
@@ -12,6 +12,7 @@ import { state } from '@ecopages/radiant/decorators/state';
12
12
  import { DEV_TOOLBAR_DEPS_REFRESH_DEBOUNCE_MS } from '../runtime/constants.js';
13
13
  import { isPanelSlotVisible, observePanelSlotVisibility } from '../shell/panel-slot-visibility.js';
14
14
  import { loadDepsInsights } from './deps/load-deps-insights.js';
15
+ import { subscribeToNavigationEvents } from '../runtime/navigation-events.js';
15
16
  let EcoDevToolbarDeps = class EcoDevToolbarDeps extends RadiantElement {
16
17
  loading = true;
17
18
  refreshing = false;
@@ -24,16 +25,16 @@ let EcoDevToolbarDeps = class EcoDevToolbarDeps extends RadiantElement {
24
25
  loadGeneration = 0;
25
26
  refreshDebounceTimer;
26
27
  disconnectVisibilityObserver;
28
+ unsubscribeNavigationEvents;
27
29
  connectedCallback() {
28
30
  super.connectedCallback();
29
- this.ownerDocument.addEventListener('eco:page-load', this.scheduleRefresh);
30
- this.ownerDocument.addEventListener('eco:after-swap', this.scheduleRefresh);
31
+ this.unsubscribeNavigationEvents = subscribeToNavigationEvents(this.ownerDocument, ['eco:page-load', 'eco:after-swap'], this.scheduleRefresh);
31
32
  this.wireVisibilityObserver();
32
33
  void this.refresh();
33
34
  }
34
35
  disconnectedCallback() {
35
- this.ownerDocument.removeEventListener('eco:page-load', this.scheduleRefresh);
36
- this.ownerDocument.removeEventListener('eco:after-swap', this.scheduleRefresh);
36
+ this.unsubscribeNavigationEvents?.();
37
+ this.unsubscribeNavigationEvents = undefined;
37
38
  this.disconnectVisibilityObserver?.();
38
39
  this.disconnectVisibilityObserver = undefined;
39
40
  if (this.refreshDebounceTimer !== undefined) {
@@ -10,6 +10,7 @@ export declare class EcoDevToolbarIslands extends RadiantElement {
10
10
  private clearHighlight;
11
11
  private liveIslandTargets;
12
12
  private suppressRefreshUntil;
13
+ private unsubscribeNavigationEvents;
13
14
  connectedCallback(): void;
14
15
  disconnectedCallback(): void;
15
16
  private wireMutationObserver;
@@ -11,6 +11,7 @@ import { customElement } from '@ecopages/radiant/decorators/custom-element';
11
11
  import { state } from '@ecopages/radiant/decorators/state';
12
12
  import { readIslandRecords, resolveIslandElement, toIslandRecordView, } from '../islands/read-island-records.js';
13
13
  import { highlightElement } from '../runtime/highlight-element.js';
14
+ import { subscribeToNavigationEvents } from '../runtime/navigation-events.js';
14
15
  function islandsSignature(islands) {
15
16
  return islands.map((island) => `${island.id}|${island.hostTag}|${island.hydrated}|${island.kind}`).join('\n');
16
17
  }
@@ -22,16 +23,16 @@ let EcoDevToolbarIslands = class EcoDevToolbarIslands extends RadiantElement {
22
23
  clearHighlight;
23
24
  liveIslandTargets = [];
24
25
  suppressRefreshUntil = 0;
26
+ unsubscribeNavigationEvents;
25
27
  connectedCallback() {
26
28
  super.connectedCallback();
27
29
  this.refresh();
28
30
  this.wireMutationObserver();
29
- this.ownerDocument.addEventListener('eco:page-load', this.scheduleRefresh);
30
- this.ownerDocument.addEventListener('eco:after-swap', this.scheduleRefresh);
31
+ this.unsubscribeNavigationEvents = subscribeToNavigationEvents(this.ownerDocument, ['eco:page-load', 'eco:after-swap'], this.scheduleRefresh);
31
32
  }
32
33
  disconnectedCallback() {
33
- this.ownerDocument.removeEventListener('eco:page-load', this.scheduleRefresh);
34
- this.ownerDocument.removeEventListener('eco:after-swap', this.scheduleRefresh);
34
+ this.unsubscribeNavigationEvents?.();
35
+ this.unsubscribeNavigationEvents = undefined;
35
36
  this.mutationObserver?.disconnect();
36
37
  this.mutationObserver = undefined;
37
38
  if (this.refreshFrame !== undefined) {
@@ -7,6 +7,7 @@ export declare class EcoDevToolbarNavigation extends RadiantElement {
7
7
  snapshot: NavigationTelemetrySnapshot | undefined;
8
8
  manifest: EcoDevManifest | undefined;
9
9
  historyPage: number;
10
+ private unsubscribeNavigationEvents;
10
11
  connectedCallback(): void;
11
12
  disconnectedCallback(): void;
12
13
  refreshSnapshot(): void;
@@ -12,6 +12,7 @@ import { state } from '@ecopages/radiant/decorators/state';
12
12
  import { readDevManifestFromDocument } from '../api/dev-manifest.js';
13
13
  import { DEV_TOOLBAR_NAV_HISTORY_PAGE_SIZE } from '../runtime/constants.js';
14
14
  import { clearNavigationTelemetryHistory, readNavigationTelemetrySnapshot, } from '../runtime/navigation-telemetry.js';
15
+ import { subscribeToNavigationEvents } from '../runtime/navigation-events.js';
15
16
  function formatMs(value) {
16
17
  return typeof value === 'number' ? `${value}ms` : 'n/a';
17
18
  }
@@ -25,14 +26,14 @@ let EcoDevToolbarNavigation = class EcoDevToolbarNavigation extends RadiantEleme
25
26
  snapshot = readNavigationTelemetrySnapshot();
26
27
  manifest = readDevManifestFromDocument();
27
28
  historyPage = 0;
29
+ unsubscribeNavigationEvents;
28
30
  connectedCallback() {
29
31
  super.connectedCallback();
30
- this.ownerDocument.addEventListener('eco:page-load', this.refresh);
31
- this.ownerDocument.addEventListener('eco:after-swap', this.refresh);
32
+ this.unsubscribeNavigationEvents = subscribeToNavigationEvents(this.ownerDocument, ['eco:page-load', 'eco:after-swap'], this.refresh);
32
33
  }
33
34
  disconnectedCallback() {
34
- this.ownerDocument.removeEventListener('eco:page-load', this.refresh);
35
- this.ownerDocument.removeEventListener('eco:after-swap', this.refresh);
35
+ this.unsubscribeNavigationEvents?.();
36
+ this.unsubscribeNavigationEvents = undefined;
36
37
  super.disconnectedCallback();
37
38
  }
38
39
  refreshSnapshot() {
@@ -0,0 +1,12 @@
1
+ export type NavigationLifecycleEvent = 'eco:before-swap' | 'eco:after-swap' | 'eco:page-load';
2
+ type NavigationListener = () => void;
3
+ /**
4
+ * Shares one DOM listener per navigation event while allowing toolbar panels to subscribe independently.
5
+ *
6
+ * @remarks
7
+ * The toolbar has several panels that observe the same lifecycle. Keeping the
8
+ * dispatcher on the document avoids exceeding the browser/Node EventTarget
9
+ * listener limit while preserving per-panel teardown.
10
+ */
11
+ export declare function subscribeToNavigationEvents(doc: Document, events: readonly NavigationLifecycleEvent[], listener: NavigationListener): () => void;
12
+ export {};
@@ -0,0 +1,45 @@
1
+ const subscriptionsByDocument = new WeakMap();
2
+ /**
3
+ * Shares one DOM listener per navigation event while allowing toolbar panels to subscribe independently.
4
+ *
5
+ * @remarks
6
+ * The toolbar has several panels that observe the same lifecycle. Keeping the
7
+ * dispatcher on the document avoids exceeding the browser/Node EventTarget
8
+ * listener limit while preserving per-panel teardown.
9
+ */
10
+ export function subscribeToNavigationEvents(doc, events, listener) {
11
+ const subscriptions = subscriptionsByDocument.get(doc) ?? new Map();
12
+ subscriptionsByDocument.set(doc, subscriptions);
13
+ const attached = [];
14
+ for (const event of events) {
15
+ let subscription = subscriptions.get(event);
16
+ if (!subscription) {
17
+ const listeners = new Set();
18
+ const dispatch = () => {
19
+ for (const subscriber of [...listeners]) {
20
+ subscriber();
21
+ }
22
+ };
23
+ subscription = { listeners, dispatch };
24
+ subscriptions.set(event, subscription);
25
+ doc.addEventListener(event, dispatch);
26
+ }
27
+ subscription.listeners.add(listener);
28
+ attached.push(subscription);
29
+ }
30
+ return () => {
31
+ for (const subscription of attached) {
32
+ subscription.listeners.delete(listener);
33
+ }
34
+ for (const [event, subscription] of subscriptions) {
35
+ if (subscription.listeners.size > 0) {
36
+ continue;
37
+ }
38
+ doc.removeEventListener(event, subscription.dispatch);
39
+ subscriptions.delete(event);
40
+ }
41
+ if (subscriptions.size === 0) {
42
+ subscriptionsByDocument.delete(doc);
43
+ }
44
+ };
45
+ }
@@ -1,4 +1,5 @@
1
1
  import { DEV_TOOLBAR_NAV_TELEMETRY_PERSIST_KEY } from './constants.js';
2
+ import { subscribeToNavigationEvents } from './navigation-events.js';
2
3
  export const NAV_TELEMETRY_ELEMENT_ID = '__ECO_DEV_NAV_TELEMETRY__';
3
4
  export const NAV_TELEMETRY_STORAGE_KEY = 'ecopages:dev-toolbar:nav-telemetry';
4
5
  export const NAV_TELEMETRY_MAX_ENTRIES = 50;
@@ -8,8 +9,17 @@ let history = [];
8
9
  let swapStartedAt = null;
9
10
  let initialized = false;
10
11
  let telemetryDocument;
12
+ let disposeTelemetryListeners;
11
13
  /** @internal */
12
14
  export function resetNavigationTelemetryForTests() {
15
+ disposeTelemetryListeners?.();
16
+ disposeTelemetryListeners = undefined;
17
+ if (typeof window !== 'undefined') {
18
+ const telemetryWindow = window;
19
+ telemetryWindow.__ECO_DEV_NAV_TELEMETRY_RUNTIME__?.dispose();
20
+ delete telemetryWindow.__ECO_DEV_NAV_TELEMETRY_RUNTIME__;
21
+ delete telemetryWindow.__ECO_DEV_NAV_TELEMETRY__;
22
+ }
13
23
  initialized = false;
14
24
  telemetryDocument = undefined;
15
25
  nextEntryId = 0;
@@ -210,8 +220,16 @@ function createNavigationTelemetryApi() {
210
220
  * Boots route timing collection, DOM JSON trace export, and `window.__ECO_DEV_NAV_TELEMETRY__`.
211
221
  */
212
222
  export function initNavigationTelemetry(doc = document) {
223
+ const telemetryWindow = window;
224
+ const existingRuntime = telemetryWindow.__ECO_DEV_NAV_TELEMETRY_RUNTIME__;
225
+ if (existingRuntime?.document === doc) {
226
+ return existingRuntime.api;
227
+ }
228
+ existingRuntime?.dispose();
229
+ disposeTelemetryListeners?.();
230
+ disposeTelemetryListeners = undefined;
213
231
  if (initialized) {
214
- return createNavigationTelemetryApi();
232
+ initialized = false;
215
233
  }
216
234
  initialized = true;
217
235
  telemetryDocument = doc;
@@ -231,17 +249,26 @@ export function initNavigationTelemetry(doc = document) {
231
249
  }
232
250
  recordInitialLoad(doc);
233
251
  };
234
- doc.addEventListener('eco:before-swap', handleBeforeSwap);
235
- doc.addEventListener('eco:after-swap', handleAfterSwap);
236
- doc.addEventListener('eco:page-load', handlePageLoad);
252
+ const handleDomContentLoaded = () => recordInitialLoad(doc);
253
+ const unsubscribeBeforeSwap = subscribeToNavigationEvents(doc, ['eco:before-swap'], handleBeforeSwap);
254
+ const unsubscribeAfterSwap = subscribeToNavigationEvents(doc, ['eco:after-swap'], handleAfterSwap);
255
+ const unsubscribePageLoad = subscribeToNavigationEvents(doc, ['eco:page-load'], handlePageLoad);
237
256
  if (doc.readyState === 'complete' || doc.readyState === 'interactive') {
238
257
  recordInitialLoad(doc);
239
258
  }
240
259
  else {
241
- doc.addEventListener('DOMContentLoaded', () => recordInitialLoad(doc), { once: true });
260
+ doc.addEventListener('DOMContentLoaded', handleDomContentLoaded, { once: true });
242
261
  }
243
262
  const api = createNavigationTelemetryApi();
244
- window.__ECO_DEV_NAV_TELEMETRY__ = api;
263
+ const dispose = () => {
264
+ unsubscribeBeforeSwap();
265
+ unsubscribeAfterSwap();
266
+ unsubscribePageLoad();
267
+ doc.removeEventListener('DOMContentLoaded', handleDomContentLoaded);
268
+ };
269
+ disposeTelemetryListeners = dispose;
270
+ telemetryWindow.__ECO_DEV_NAV_TELEMETRY_RUNTIME__ = { api, dispose, document: doc };
271
+ telemetryWindow.__ECO_DEV_NAV_TELEMETRY__ = api;
245
272
  syncTelemetryElement(doc);
246
273
  return api;
247
274
  }
@@ -29,6 +29,7 @@ export declare class EcoDevToolbar extends RadiantElement {
29
29
  legacyPanel?: HTMLElement;
30
30
  private cleanupActiveApp;
31
31
  private documentListenersWired;
32
+ private unsubscribeNavigationEvents;
32
33
  private readonly routeListeners;
33
34
  private readonly legacyAppHost;
34
35
  private readonly stealthController;
@@ -25,6 +25,7 @@ import { badgesEqual } from './badges.js';
25
25
  import { DevToolbarLegacyAppHost } from './legacy-app-host.js';
26
26
  import { DevToolbarNavigationLoading } from './navigation-loading.js';
27
27
  import { DevToolbarStealthController } from './stealth-controller.js';
28
+ import { subscribeToNavigationEvents } from '../runtime/navigation-events.js';
28
29
  const BUILT_IN_APPS = [
29
30
  { id: 'navigation', label: 'Navigation' },
30
31
  { id: 'deps', label: 'Deps' },
@@ -48,6 +49,7 @@ let EcoDevToolbar = class EcoDevToolbar extends RadiantElement {
48
49
  legacyPanel;
49
50
  cleanupActiveApp;
50
51
  documentListenersWired = false;
52
+ unsubscribeNavigationEvents;
51
53
  routeListeners = new Set();
52
54
  legacyAppHost = new DevToolbarLegacyAppHost();
53
55
  stealthController;
@@ -191,11 +193,15 @@ let EcoDevToolbar = class EcoDevToolbar extends RadiantElement {
191
193
  return;
192
194
  }
193
195
  document.addEventListener('click', this.handleOutsideClick, true);
194
- document.addEventListener('eco:before-swap', this.handleNavigationStart);
195
- document.addEventListener('eco:after-swap', this.handleNavigationEnd);
196
- document.addEventListener('eco:page-load', this.handleNavigationEnd);
197
- document.addEventListener('eco:page-load', this.handleRouteChange);
198
- document.addEventListener('eco:after-swap', this.handleRouteChange);
196
+ this.unsubscribeNavigationEvents = subscribeToNavigationEvents(document, ['eco:before-swap'], this.handleNavigationStart);
197
+ const unsubscribeNavigationEnd = subscribeToNavigationEvents(document, ['eco:after-swap', 'eco:page-load'], this.handleNavigationEnd);
198
+ const unsubscribeRouteChange = subscribeToNavigationEvents(document, ['eco:after-swap', 'eco:page-load'], this.handleRouteChange);
199
+ const unsubscribeExisting = this.unsubscribeNavigationEvents;
200
+ this.unsubscribeNavigationEvents = () => {
201
+ unsubscribeExisting();
202
+ unsubscribeNavigationEnd();
203
+ unsubscribeRouteChange();
204
+ };
199
205
  this.documentListenersWired = true;
200
206
  }
201
207
  unwireDocumentListeners() {
@@ -203,11 +209,8 @@ let EcoDevToolbar = class EcoDevToolbar extends RadiantElement {
203
209
  return;
204
210
  }
205
211
  document.removeEventListener('click', this.handleOutsideClick, true);
206
- document.removeEventListener('eco:before-swap', this.handleNavigationStart);
207
- document.removeEventListener('eco:after-swap', this.handleNavigationEnd);
208
- document.removeEventListener('eco:page-load', this.handleNavigationEnd);
209
- document.removeEventListener('eco:page-load', this.handleRouteChange);
210
- document.removeEventListener('eco:after-swap', this.handleRouteChange);
212
+ this.unsubscribeNavigationEvents?.();
213
+ this.unsubscribeNavigationEvents = undefined;
211
214
  this.documentListenersWired = false;
212
215
  }
213
216
  handleOutsideClick = (event) => {