Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions packages/client-devtools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,32 @@ teach.
```ts
import { mountOverlay } from '@forge-go/client-devtools/overlay';

const unmount = mountOverlay(forge);
const unmount = mountOverlay(forge, { open: true });
```

This is the whole panel: the causal trace, the network view, the overlay stack,
the control rail, the detail pane and the actions. `/overlay` and `/panel` are
the same implementation under two names, so it does not matter which you reach
for.

It used to be the other way round. `/overlay` was six read-only tables and
`/panel` was everything, which meant that following your instincts got you the
least capable UI in the package with nothing telling you a better one existed
one subpath away. If you were on `/overlay` before 1.11 and it looked thin,
that is why, and updating is the whole fix.

The lean view is still here and still worth having. It is `/mini` now:

```ts
import { mountMini } from '@forge-go/client-devtools/mini';

const unmount = mountMini(forge);
```

Six read-only tables and a filter box in 3.5 kB gzipped, which is the right
trade for a demo, a production-adjacent build, or anything that wants to see
the cache without shipping a debugger.

A DOM panel in a shadow root: `document.createElement` and nothing else.
Deliberately **not a component** — a React panel forces React on a Vue
application, and a Vue one forces Vue on an Angular application. It is also
Expand All @@ -270,9 +293,6 @@ plain panel beats the reverse: the API is what you call from the console at
three in the morning, what a test asserts on, and what somebody else's panel is
built from.

If you want the detail pane, the actions and the stream views, import
`/panel` instead. They are two entry points, not a base and an extension.

## The panel

```ts
Expand All @@ -281,9 +301,8 @@ import { mountPanel } from '@forge-go/client-devtools/panel';
const unmount = mountPanel(forge, { open: true });
```

The other entry point, and you pick one. `/overlay` is six read-only tables
and a filter box; `/panel` is that plus everything the overlay deliberately
does not have:
The same thing `/overlay` gives you, under the name it had first. Both are the
full panel; `/mini` is the lean one. What the panel has that `/mini` does not:

- **A detail pane.** Click a query and get its status, its mounts, its
provides, tags and deps, and its last settled response as a `<details>`
Expand Down
91 changes: 91 additions & 0 deletions packages/client-devtools/__tests__/entrypoints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
import { attach } from '../src/devtools';
import { mountOverlay } from '../src/overlay';
import { mountMini } from '../src/mini';
import { mountPanel } from '../src/panel';
import { counter, harness } from './harness';

function shadow(): ShadowRoot {
const host = document.body.lastElementChild;

if (host?.shadowRoot == null) throw new Error('nothing attached a shadow root');

return host.shadowRoot;
}

beforeEach(() => {
vi.stubGlobal('requestAnimationFrame', (cb: () => void) => {
queueMicrotask(cb);

return 0;
});
});

afterEach(() => {
vi.unstubAllGlobals();
});

function tabs(): string[] {
return [...shadow().querySelectorAll('.bar button')]
.map((node) => node.textContent ?? '')
.filter((text) => text !== '');
}

/**
* `/overlay` is the name people reach for, so it is the one that has to carry
* the full panel. The lean six-table view is still here and still cheap; it
* just no longer owns the obvious name.
*/
describe('the entry points', () => {
it('gives the full panel from /overlay', () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const unmount = mountOverlay(devtools, { parent: document.body, open: true });

expect(tabs()).toContain('trace');
expect(tabs()).toContain('network');
expect(tabs()).toContain('overlay');
expect(shadow().querySelector('.vitals')).not.toBeNull();

unmount();
devtools.dispose();
});

it('gives the same thing from /panel, so nobody on it changes', () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const unmount = mountPanel(devtools, { parent: document.body, open: true });

expect(tabs()).toContain('trace');
expect(shadow().querySelector('.vitals')).not.toBeNull();

unmount();
devtools.dispose();
});

it('keeps the lean six-table view available from /mini', () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const unmount = mountMini(devtools, { parent: document.body, open: true });

// The six it has always had, and none of the ones the panel added. The
// close button is in the same bar, so this is a containment check.
for (const name of ['queries', 'entities', 'tags', 'sockets', 'log', 'explain']) {
expect(tabs()).toContain(name);
}

for (const name of ['trace', 'network', 'overlay']) {
expect(tabs()).not.toContain(name);
}
// Lean means lean: no vitals strip, no rail, no detail pane.
expect(shadow().querySelector('.vitals')).toBeNull();
expect(shadow().querySelector('.rail')).toBeNull();

unmount();
devtools.dispose();
});

it('mounts the same implementation from /overlay and /panel', () => {
expect(mountOverlay).toBe(mountPanel);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
import { attach } from '../src/devtools';
import { mountOverlay } from '../src/overlay';
import { mountMini } from '../src/mini';
import { TransportControls } from '../src/control';
import { counter, harness, ops } from './harness';

Expand All @@ -12,7 +12,7 @@ import { counter, harness, ops } from './harness';
function shadow(): ShadowRoot {
const host = document.body.lastElementChild;

if (host?.shadowRoot == null) throw new Error('the overlay did not attach a shadow root');
if (host?.shadowRoot == null) throw new Error('the lean view did not attach a shadow root');

return host.shadowRoot;
}
Expand All @@ -34,7 +34,7 @@ describe('the launcher', () => {
it('shows the forge mark rather than the word "forge"', () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const unmount = mountOverlay(devtools, { parent: document.body });
const unmount = mountMini(devtools, { parent: document.body });

const button = shadow().querySelector('button');

Expand All @@ -47,11 +47,11 @@ describe('the launcher', () => {
});
});

describe('the overlay', () => {
describe('the lean view', () => {
it('starts closed, opens, and shows the queries', async () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const unmount = mountOverlay(devtools, { parent: document.body });
const unmount = mountMini(devtools, { parent: document.body });

const stop = h.cache.subscribe(ops.orderList, undefined, () => undefined);
await h.settle();
Expand All @@ -75,7 +75,7 @@ describe('the overlay', () => {
it('renders the near-miss explanation for a query key', async () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const unmount = mountOverlay(devtools, { parent: document.body, open: true });
const unmount = mountMini(devtools, { parent: document.body, open: true });

const stop = h.cache.subscribe(ops.orderList, undefined, () => undefined);
await h.settle();
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('the overlay', () => {
const h = harness();
const devtools = attach(h.cache, { now: counter() });
const before = document.body.childElementCount;
const unmount = mountOverlay(devtools, { parent: document.body, open: true });
const unmount = mountMini(devtools, { parent: document.body, open: true });

expect(document.body.childElementCount).toBe(before + 1);
// Scoped: the stylesheet is inside the shadow root, not in the document.
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('the launcher ring', () => {
h.fail('GET /orders', new Error('nope'));

const devtools = attach(h.cache, { now: counter(), controls });
const unmount = mountOverlay(devtools, { parent: document.body });
const unmount = mountMini(devtools, { parent: document.body });

const stop = h.cache.subscribe(ops.orderList, undefined, () => undefined);
await h.settle();
Expand Down
19 changes: 16 additions & 3 deletions packages/client-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"types": "./dist/panel.d.ts",
"import": "./dist/panel.js"
},
"./mini": {
"types": "./dist/mini.d.ts",
"import": "./dist/mini.js"
},
"./requests": {
"types": "./dist/requests.d.ts",
"import": "./dist/requests.js"
Expand Down Expand Up @@ -57,8 +61,17 @@
]
},
{
"name": "overlay",
"name": "overlay (the full panel)",
"path": "dist/overlay.js",
"limit": "16 kB",
"gzip": true,
"ignore": [
"@forge-go/client-core"
]
},
{
"name": "the lean view",
"path": "dist/mini.js",
"limit": "3.5 kB",
"gzip": true,
"ignore": [
Expand Down Expand Up @@ -93,10 +106,10 @@
]
},
{
"name": "inspector and overlay together",
"name": "inspector and the lean view together",
"path": [
"dist/index.js",
"dist/overlay.js"
"dist/mini.js"
],
"limit": "10 kB",
"gzip": true,
Expand Down
17 changes: 12 additions & 5 deletions packages/client-devtools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@
* off unless asked for.
*
* The UI is deliberately secondary, and there are two of them, chosen rather
* than layered. `./overlay` is the lean one, six read-only tables and a filter
* box. `./panel` adds the detail pane, the action bar and the stream and frame
* views. Both are `document.createElement` in a shadow root -- no framework, no
* React tree, nothing an Angular or a Vue application has to take a dependency
* on -- and both are views over this API and nothing more.
* than layered. `./overlay` and `./panel` are the same full panel under two
* names: the causal trace, the network view, the overlay stack, the control
* rail, the detail pane and the actions. `./mini` is the lean one, six
* read-only tables and a filter box in a fraction of the bytes.
*
* The lean view used to own `./overlay`, which was the wrong way round.
* `overlay` is the import people reach for, so leaving the smallest UI on it
* meant that following your instincts got you the least capable one with
* nothing to say a better one existed. Both are `document.createElement` in a
* shadow root -- no framework, no React tree, nothing an Angular or a Vue
* application has to take a dependency on -- and both are views over this API
* and nothing more.
*/

export { createActions } from './actions.js';
Expand Down
Loading
Loading