From b12e4bc5e06705f9cd5eb7f9dac2fc25bcb6f1f6 Mon Sep 17 00:00:00 2001 From: Rex Raphael Date: Tue, 8 Sep 2026 12:10:10 -0500 Subject: [PATCH 1/2] feat(client-devtools)!: make /overlay the full panel, move the lean view to /mini The publish workflow was fine. 1.10.2 shipped every byte of the new panel. The problem was that `mountOverlay` was never the thing that got rewritten. `overlay` is the import people reach for. Leaving the smallest UI in the package on the most obvious name meant that following your instincts got you six read-only tables and nothing telling you a better one existed one subpath away. That is a naming bug and it wasted a release. So `/overlay` is the full panel now, and `/panel` is the same module under the name it had first. Nobody already on `/panel` sees any change at all. The lean view has not gone anywhere and is still worth having: six tables and a filter box in 3.5 kB is the right trade for a demo or a production-adjacent build. It answers to `/mini` and `mountMini`. client-react-devtools needed the same correction. Its `panel={false}` escape hatch reached for `/overlay`, so after this it would have quietly stopped meaning anything and handed you the full panel either way. It reaches for `/mini` now, and there is a test for each branch. BREAKING CHANGE: `mountOverlay` from `@forge-go/client-devtools/overlay` now renders the full panel rather than the lean six-table view, and the bundle it pulls in grows accordingly. If you wanted the small one, import `mountMini` from `@forge-go/client-devtools/mini`. `/panel` is unchanged. --- packages/client-devtools/README.md | 33 +- .../__tests__/entrypoints.test.ts | 91 +++ .../{overlay.test.ts => mini.test.ts} | 16 +- packages/client-devtools/package.json | 19 +- packages/client-devtools/src/index.ts | 17 +- packages/client-devtools/src/mini.ts | 519 ++++++++++++++++++ packages/client-devtools/src/overlay.ts | 516 +---------------- .../__tests__/mount.test.tsx | 69 +++ packages/client-react-devtools/src/dev.ts | 13 +- 9 files changed, 763 insertions(+), 530 deletions(-) create mode 100644 packages/client-devtools/__tests__/entrypoints.test.ts rename packages/client-devtools/__tests__/{overlay.test.ts => mini.test.ts} (89%) create mode 100644 packages/client-devtools/src/mini.ts diff --git a/packages/client-devtools/README.md b/packages/client-devtools/README.md index 768a638ba..25838bba1 100644 --- a/packages/client-devtools/README.md +++ b/packages/client-devtools/README.md @@ -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 @@ -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 @@ -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 `
` diff --git a/packages/client-devtools/__tests__/entrypoints.test.ts b/packages/client-devtools/__tests__/entrypoints.test.ts new file mode 100644 index 000000000..cee499f85 --- /dev/null +++ b/packages/client-devtools/__tests__/entrypoints.test.ts @@ -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); + }); +}); diff --git a/packages/client-devtools/__tests__/overlay.test.ts b/packages/client-devtools/__tests__/mini.test.ts similarity index 89% rename from packages/client-devtools/__tests__/overlay.test.ts rename to packages/client-devtools/__tests__/mini.test.ts index 50f5fcc38..e877210cc 100644 --- a/packages/client-devtools/__tests__/overlay.test.ts +++ b/packages/client-devtools/__tests__/mini.test.ts @@ -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'; @@ -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; } @@ -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'); @@ -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(); @@ -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(); @@ -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. @@ -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(); diff --git a/packages/client-devtools/package.json b/packages/client-devtools/package.json index 963b0bf4c..75e2e13aa 100644 --- a/packages/client-devtools/package.json +++ b/packages/client-devtools/package.json @@ -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" @@ -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": [ @@ -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, diff --git a/packages/client-devtools/src/index.ts b/packages/client-devtools/src/index.ts index cfe68ed40..b2e2ca0f6 100644 --- a/packages/client-devtools/src/index.ts +++ b/packages/client-devtools/src/index.ts @@ -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'; diff --git a/packages/client-devtools/src/mini.ts b/packages/client-devtools/src/mini.ts new file mode 100644 index 000000000..8804f1fe4 --- /dev/null +++ b/packages/client-devtools/src/mini.ts @@ -0,0 +1,519 @@ +import type { Devtools } from './devtools.js'; +import type { LogEntry, MissReport, RefetchReport } from './types.js'; + +/** + * The lean view: six read-only tables and a filter box. + * + * This used to be `/overlay`, which was the wrong name for it. `overlay` is + * what people reach for when they want the devtools, and what they wanted was + * the full panel; leaving the smallest view on the most obvious import meant + * everyone who followed their instincts got the least. So the full panel + * answers to `/overlay` now and this answers to `/mini`, which says what it is. + * + * It is still worth having. Six tables and a filter box in 3.5 kB is the right + * trade for a production-adjacent build, a demo, or anything that wants to see + * the cache without shipping a debugger. + * + * **Deliberately not a component.** A React devtools panel forces React on a + * Vue application; a Vue one forces Vue on an Angular application. This is + * `document.createElement` and a shadow root, so it costs whichever framework + * is present exactly nothing and works in an application that has none. + * + * The shadow root is not decoration either: an overlay whose styles leak into + * the application it is inspecting, or whose styles are overridden by it, is a + * debugging tool that introduces its own bugs. Everything inside is scoped, and + * nothing outside is touched. + * + * It is also, on purpose, thinner than the API beneath it. A superb inspection + * API with a plain panel is more useful than a beautiful panel over a thin one: + * the API is what a developer calls from the console at three in the morning, + * what a test asserts on, and what somebody else's panel is built from. + */ +export interface MiniOptions { + /** Where to attach. Defaults to `document.body`. */ + readonly parent?: Element; + /** Start with the panel open. Defaults to false -- a button in the corner. */ + readonly open?: boolean; +} + +type Tab = 'queries' | 'entities' | 'tags' | 'sockets' | 'log' | 'explain'; + +const TABS: readonly Tab[] = ['queries', 'entities', 'tags', 'sockets', 'log', 'explain']; + +/** + * The forge mark, as markup. + * + * Inlined rather than linked, for the same reason everything else in this file + * is: an inspector that needs a network request to draw its own button is an + * inspector that does not draw when you are debugging the network. `fill` is + * `currentColor` so one copy serves every state the launcher has. + * + * A constant string through `innerHTML` rather than five `createElementNS` + * calls. There is no interpolation here and never will be -- the whole value is + * a literal in this file -- and the calls cost more bytes than the budget for + * this module has to spare. + */ +const MARK = + ''; + +const CSS = ` +:host { all: initial; } +.root { + position: fixed; right: 12px; bottom: 12px; z-index: 2147483000; + font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: #e6e6e6; +} +.launcher { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; + position: relative; border-radius: 8px; background: #14181f; border: 1px solid #2e3542; + box-shadow: 0 6px 22px rgba(0,0,0,.34); color: #e3e7ee; } +.launcher:hover { background: #1a1f28; } +.launcher svg { width: 15px; height: 15px; display: block; } +.launcher::after { content: ""; position: absolute; inset: -2px; border-radius: 10px; + border: 1.5px solid #3fd39c; opacity: .55; pointer-events: none; } +.launcher[data-pulse="fetching"]::after { border-color: #62a8ff; } +.launcher[data-pulse="error"]::after { border-color: #ff6b6b; opacity: .9; } +.launcher[data-pulse="offline"]::after { border-color: #ff6a2b; opacity: .95; } +.launcher[data-pulse="slow"]::after { border-color: #ff6a2b; opacity: .5; } +.launcher .badge { position: absolute; top: -5px; right: -5px; min-width: 16px; height: 16px; + border-radius: 8px; background: #ff6b6b; color: #12151b; font-size: 10px; font-weight: 600; + display: grid; place-items: center; padding: 0 4px; border: 2px solid #14181f; } +button { font: inherit; color: inherit; background: #2c2c34; border: 1px solid #45454f; + border-radius: 4px; padding: 3px 8px; cursor: pointer; } +button:hover { background: #3a3a44; } +button[aria-selected="true"] { background: #4b5bd6; border-color: #4b5bd6; } +.panel { width: min(720px, 92vw); height: min(460px, 70vh); background: #1c1c22; + border: 1px solid #45454f; border-radius: 6px; display: flex; flex-direction: column; + box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: hidden; } +.bar { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid #35353d; + align-items: center; flex-wrap: wrap; } +.bar .spacer { flex: 1; } +.body { overflow: auto; padding: 8px; flex: 1; } +table { border-collapse: collapse; width: 100%; } +th, td { text-align: left; padding: 3px 6px; border-bottom: 1px solid #2b2b33; + vertical-align: top; word-break: break-word; } +th { color: #9a9aa8; font-weight: normal; position: sticky; top: -8px; background: #1c1c22; } +tr.hot td { background: #2a2233; } +code { color: #9fd0ff; } +.dim { color: #8a8a98; } +.warn { color: #ffb86b; } +.good { color: #8ce99a; } +.bad { color: #ff8f8f; } +h4 { margin: 10px 0 4px; font-size: 12px; color: #9a9aa8; font-weight: normal; } +ul { margin: 4px 0; padding-left: 18px; } +li { margin: 3px 0; } +input { font: inherit; color: inherit; background: #14141a; border: 1px solid #45454f; + border-radius: 4px; padding: 3px 6px; min-width: 240px; } +.pill { display: inline-block; padding: 0 5px; border-radius: 3px; background: #2c2c34; + margin: 0 3px 3px 0; } +`; + +/** + * Mount the panel. Returns the unmount. + * + * Refreshes on log activity, coalesced to one repaint per animation frame: a + * channel at 200 messages a second must not repaint a table 200 times, and an + * inspector that makes the application it is inspecting janky is measuring + * itself. + */ +export function mountMini(devtools: Devtools, options: MiniOptions = {}): () => void { + const doc = globalThis.document as Document | undefined; + + if (doc === undefined) { + throw new Error('[forge] mountMini needs a DOM; there is no document here'); + } + + const parent = options.parent ?? doc.body; + const host = doc.createElement('div'); + const shadow = host.attachShadow({ mode: 'open' }); + const style = doc.createElement('style'); + + style.textContent = CSS; + shadow.append(style); + + const root = doc.createElement('div'); + root.className = 'root'; + shadow.append(root); + parent.append(host); + + let open = options.open ?? false; + let tab: Tab = 'queries'; + let filter = ''; + let scheduled = false; + + const el = (tag: string, className?: string, text?: string): HTMLElement => { + const node = doc.createElement(tag); + + if (className !== undefined) node.className = className; + if (text !== undefined) node.textContent = text; + + return node; + }; + + const table = (headers: readonly string[], rows: readonly (readonly string[])[]): HTMLElement => { + const node = doc.createElement('table'); + const head = doc.createElement('tr'); + + for (const header of headers) head.append(el('th', undefined, header)); + node.append(head); + + for (const row of rows) { + const tr = doc.createElement('tr'); + + for (const cell of row) tr.append(el('td', undefined, cell)); + node.append(tr); + } + + if (rows.length === 0) { + const tr = doc.createElement('tr'); + const td = el('td', 'dim', 'nothing here'); + + td.setAttribute('colspan', String(headers.length)); + tr.append(td); + node.append(tr); + } + + return node; + }; + + const matches = (text: string): boolean => + filter === '' || text.toLowerCase().includes(filter.toLowerCase()); + + const renderExplain = (body: HTMLElement): void => { + if (filter === '') { + body.append( + el( + 'p', + 'dim', + 'Type a query key above and press Enter. The key is what queries() lists: ' + + 'operation plus arguments.', + ), + ); + + return; + } + + const report = devtools.explain(filter); + + if ('outcome' in report) renderMiss(body, report); + else renderRefetch(body, report); + }; + + const renderMiss = (body: HTMLElement, report: MissReport): void => { + const tone = + report.outcome === 'missed' ? 'bad' : report.outcome === 'refetched' ? 'good' : 'warn'; + + body.append(el('h4', undefined, `outcome: ${report.outcome}`)); + body.append(el('p', tone, report.reason)); + body.append(el('h4', undefined, `cause: ${report.cause.label}`)); + body.append(pills(report.invalidated, 'invalidated')); + body.append(pills(report.carried, 'carried')); + body.append(pills(report.matched, 'matched')); + + if (report.cause.unresolved.length > 0) { + body.append(pills(report.cause.unresolved, 'unresolved templates')); + } + + if (report.nearest.length > 0) { + body.append(el('h4', undefined, 'where they nearly meet')); + const list = doc.createElement('ul'); + + for (const miss of report.nearest) { + list.append( + el('li', undefined, `${miss.invalidated} vs ${miss.carried} (${miss.relation})`), + ); + } + + body.append(list); + } + + if (report.suggestions.length > 0) { + body.append(el('h4', undefined, 'what to change')); + const list = doc.createElement('ul'); + + for (const suggestion of report.suggestions) list.append(el('li', undefined, suggestion)); + + body.append(list); + } + }; + + const renderRefetch = (body: HTMLElement, report: RefetchReport): void => { + body.append(el('h4', undefined, `refetched (${report.reason})`)); + body.append(el('p', 'good', report.summary)); + + if (report.cause !== undefined) { + body.append(pills(report.cause.tags, `cause: ${report.cause.label} raised`)); + } + + body.append(pills(report.matched, 'matched')); + }; + + const pills = (values: readonly string[], label: string): HTMLElement => { + const wrap = el('div'); + + wrap.append(el('span', 'dim', `${label}: `)); + + if (values.length === 0) wrap.append(el('span', 'dim', 'none')); + else for (const value of values) wrap.append(el('span', 'pill', value)); + + return wrap; + }; + + const describe = (entry: LogEntry): string => { + switch (entry.kind) { + case 'mutation': + return `${entry.operation} -> ${entry.tags.join(', ') || 'no tags'}${ + entry.unresolved.length > 0 ? ` (skipped ${entry.unresolved.join(', ')})` : '' + }`; + case 'frames': + return `${String(entry.frames)} frame(s) -> ${entry.tags.join(', ') || 'no tags'}`; + case 'invalidated': + return `${entry.query} hit by ${entry.matched.join(', ')}`; + case 'placed': + return `${entry.query} answered by placement`; + case 'fetch': + return `${entry.query} (${entry.reason})`; + case 'settle': + return `${entry.query} at store v${String(entry.version)}`; + case 'error': + return `${entry.query}: ${entry.message}`; + case 'principal': + return 'identity changed; the cache was dropped'; + case 'action': + return `${entry.action} ${entry.target}`; + } + }; + + const renderBody = (body: HTMLElement): void => { + switch (tab) { + case 'queries': { + const rows = devtools + .queries() + .filter((entry) => matches(entry.key)) + .map((entry) => [ + entry.key, + String(entry.mounts), + entry.stale ? 'stale' : entry.settled ? 'fresh' : 'empty', + entry.tags.join(' '), + ]); + + body.append(table(['key', 'mounts', 'state', 'tags'], rows)); + break; + } + + case 'entities': { + const rows = devtools + .entities({ limit: 300 }) + .filter((record) => matches(record.key)) + .map((record) => [ + record.key, + `v${String(record.version)}`, + record.frameAt > 0 ? `frame ${String(record.frameAt)}` : '', + Object.keys(record.fields).join(' '), + ]); + + body.append(table(['entity', 'version', 'frame', 'fields'], rows)); + break; + } + + case 'tags': { + const rows = devtools + .tags() + .filter((row) => matches(row.tag)) + .map((row) => [ + row.tag, + String(row.mounted.length), + String(row.carriers.length), + row.carriers.join(' '), + ]); + + body.append(table(['tag', 'mounted', 'carriers', 'queries'], rows)); + break; + } + + case 'sockets': { + const rows = devtools + .sockets() + .filter((socket) => matches(socket.endpoint)) + .map((socket) => [ + socket.endpoint, + socket.connected ? 'open' : socket.reconnecting ? 'reconnecting' : 'closed', + String(socket.refs), + String(socket.opens), + socket.channels.map((c) => `${c.channel}(${String(c.handlers)})`).join(' '), + ]); + + body.append(table(['endpoint', 'state', 'refs', 'opens', 'channels'], rows)); + break; + } + + case 'log': { + const entries = devtools.log().filter((entry) => matches(describe(entry))); + const rows = entries + .slice(-300) + .reverse() + .map((entry) => [String(entry.seq), entry.kind, describe(entry)]); + + if (devtools.dropped > 0) { + body.append( + el( + 'p', + 'dim', + `${String(devtools.dropped)} earlier event(s) have been overwritten; the log holds ` + + `the most recent ${String(devtools.capacity)}.`, + ), + ); + } + + body.append(table(['#', 'kind', 'what'], rows)); + break; + } + + case 'explain': + renderExplain(body); + break; + } + }; + + /** + * The closed state: the mark, a status ring and an error count. + * + * This button is the only part of the inspector most people see most of the + * time, and a launcher that cannot say whether anything is in flight or + * anything has failed is one you have to open in order to learn nothing. Both + * readings come from `records()`, which carries the scalar fields for every + * tracked query and no response bodies, so drawing the button stays O(tracked + * queries) and never O(bytes in the cache). + */ + const launcher = (): HTMLElement => { + const button = el('button', 'launcher'); + let fetching = false; + let errors = 0; + + for (const record of devtools.records()) { + if (record.fetching) fetching = true; + if (record.status === 'error') errors += 1; + } + + // Offline outranks the errors it causes: every request fails while the + // rail is offline, and a red ring over failures you switched on yourself + // sends you debugging a request that was never sent. Slow ranks below a + // real error, because unlike offline it stops nothing from succeeding. + const mode = devtools.controls?.mode; + + button.innerHTML = MARK; + button.setAttribute('aria-label', 'Open Forge devtools'); + button.setAttribute( + 'data-pulse', + mode === 'offline' + ? 'offline' + : errors > 0 + ? 'error' + : fetching + ? 'fetching' + : mode === 'slow' + ? 'slow' + : 'idle', + ); + + if (errors > 0) button.append(el('span', 'badge', String(errors))); + + button.addEventListener('click', () => { + open = true; + render(); + }); + + return button; + }; + + const render = (): void => { + root.replaceChildren(); + + if (!open) { + root.append(launcher()); + + return; + } + + const panel = el('div', 'panel'); + const bar = el('div', 'bar'); + + for (const name of TABS) { + const button = el('button', undefined, name); + + button.setAttribute('aria-selected', String(name === tab)); + button.addEventListener('click', () => { + tab = name; + render(); + }); + bar.append(button); + } + + const search = doc.createElement('input'); + + search.value = filter; + search.placeholder = tab === 'explain' ? 'query key, then Enter' : 'filter'; + search.addEventListener('change', () => { + filter = search.value; + render(); + }); + bar.append(search); + + const spacer = el('div', 'spacer'); + bar.append(spacer); + + const counts = devtools.store(); + bar.append( + el( + 'span', + 'dim', + `${String(counts.records)} entities / ${String(counts.mounted)} mounted / v${String( + counts.version, + )}`, + ), + ); + + const close = el('button', undefined, 'x'); + close.addEventListener('click', () => { + open = false; + render(); + }); + bar.append(close); + + const body = el('div', 'body'); + + renderBody(body); + panel.append(bar, body); + root.append(panel); + }; + + const schedule = (): void => { + // Not gated on `open`: the launcher carries a status ring, and one drawn + // only when the panel was mounted is decoration rather than status. + if (scheduled) return; + + scheduled = true; + + const raf = (globalThis as { requestAnimationFrame?: (cb: () => void) => unknown }) + .requestAnimationFrame; + const run = (): void => { + scheduled = false; + render(); + }; + + if (typeof raf === 'function') raf(run); + else void Promise.resolve().then(run); + }; + + const unsubscribe = devtools.subscribe(schedule); + + render(); + + return () => { + unsubscribe(); + host.remove(); + }; +} diff --git a/packages/client-devtools/src/overlay.ts b/packages/client-devtools/src/overlay.ts index 7e9d10d8b..d31ba3a47 100644 --- a/packages/client-devtools/src/overlay.ts +++ b/packages/client-devtools/src/overlay.ts @@ -1,509 +1,17 @@ -import type { Devtools } from './devtools.js'; -import type { LogEntry, MissReport, RefetchReport } from './types.js'; - /** - * A panel, in the DOM, over the inspection API. + * The devtools overlay: the full panel. * - * **Deliberately not a component.** A React devtools panel forces React on a - * Vue application; a Vue one forces Vue on an Angular application. This is - * `document.createElement` and a shadow root, so it costs whichever framework - * is present exactly nothing and works in an application that has none. + * `mountOverlay` is the import people reach for, so it is the one that has to + * be the whole thing. It was the lean six-table view until 1.11, which meant + * that following your instincts got you the least capable UI in the package + * and no indication that a better one existed one subpath away. * - * The shadow root is not decoration either: an overlay whose styles leak into - * the application it is inspecting, or whose styles are overridden by it, is a - * debugging tool that introduces its own bugs. Everything inside is scoped, and - * nothing outside is touched. + * The lean view has not gone anywhere. It is `mountMini` from `./mini`, and it + * is still six read-only tables in 3.5 kB. * - * It is also, on purpose, thinner than the API beneath it. A superb inspection - * API with a plain panel is more useful than a beautiful panel over a thin one: - * the API is what a developer calls from the console at three in the morning, - * what a test asserts on, and what somebody else's panel is built from. + * This module is an alias and nothing else: `/overlay` and `/panel` are the + * same implementation, so an application already importing `/panel` sees no + * change at all. */ -export interface OverlayOptions { - /** Where to attach. Defaults to `document.body`. */ - readonly parent?: Element; - /** Start with the panel open. Defaults to false -- a button in the corner. */ - readonly open?: boolean; -} - -type Tab = 'queries' | 'entities' | 'tags' | 'sockets' | 'log' | 'explain'; - -const TABS: readonly Tab[] = ['queries', 'entities', 'tags', 'sockets', 'log', 'explain']; - -/** - * The forge mark, as markup. - * - * Inlined rather than linked, for the same reason everything else in this file - * is: an inspector that needs a network request to draw its own button is an - * inspector that does not draw when you are debugging the network. `fill` is - * `currentColor` so one copy serves every state the launcher has. - * - * A constant string through `innerHTML` rather than five `createElementNS` - * calls. There is no interpolation here and never will be -- the whole value is - * a literal in this file -- and the calls cost more bytes than the budget for - * this module has to spare. - */ -const MARK = - ''; - -const CSS = ` -:host { all: initial; } -.root { - position: fixed; right: 12px; bottom: 12px; z-index: 2147483000; - font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: #e6e6e6; -} -.launcher { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; - position: relative; border-radius: 8px; background: #14181f; border: 1px solid #2e3542; - box-shadow: 0 6px 22px rgba(0,0,0,.34); color: #e3e7ee; } -.launcher:hover { background: #1a1f28; } -.launcher svg { width: 15px; height: 15px; display: block; } -.launcher::after { content: ""; position: absolute; inset: -2px; border-radius: 10px; - border: 1.5px solid #3fd39c; opacity: .55; pointer-events: none; } -.launcher[data-pulse="fetching"]::after { border-color: #62a8ff; } -.launcher[data-pulse="error"]::after { border-color: #ff6b6b; opacity: .9; } -.launcher[data-pulse="offline"]::after { border-color: #ff6a2b; opacity: .95; } -.launcher[data-pulse="slow"]::after { border-color: #ff6a2b; opacity: .5; } -.launcher .badge { position: absolute; top: -5px; right: -5px; min-width: 16px; height: 16px; - border-radius: 8px; background: #ff6b6b; color: #12151b; font-size: 10px; font-weight: 600; - display: grid; place-items: center; padding: 0 4px; border: 2px solid #14181f; } -button { font: inherit; color: inherit; background: #2c2c34; border: 1px solid #45454f; - border-radius: 4px; padding: 3px 8px; cursor: pointer; } -button:hover { background: #3a3a44; } -button[aria-selected="true"] { background: #4b5bd6; border-color: #4b5bd6; } -.panel { width: min(720px, 92vw); height: min(460px, 70vh); background: #1c1c22; - border: 1px solid #45454f; border-radius: 6px; display: flex; flex-direction: column; - box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: hidden; } -.bar { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid #35353d; - align-items: center; flex-wrap: wrap; } -.bar .spacer { flex: 1; } -.body { overflow: auto; padding: 8px; flex: 1; } -table { border-collapse: collapse; width: 100%; } -th, td { text-align: left; padding: 3px 6px; border-bottom: 1px solid #2b2b33; - vertical-align: top; word-break: break-word; } -th { color: #9a9aa8; font-weight: normal; position: sticky; top: -8px; background: #1c1c22; } -tr.hot td { background: #2a2233; } -code { color: #9fd0ff; } -.dim { color: #8a8a98; } -.warn { color: #ffb86b; } -.good { color: #8ce99a; } -.bad { color: #ff8f8f; } -h4 { margin: 10px 0 4px; font-size: 12px; color: #9a9aa8; font-weight: normal; } -ul { margin: 4px 0; padding-left: 18px; } -li { margin: 3px 0; } -input { font: inherit; color: inherit; background: #14141a; border: 1px solid #45454f; - border-radius: 4px; padding: 3px 6px; min-width: 240px; } -.pill { display: inline-block; padding: 0 5px; border-radius: 3px; background: #2c2c34; - margin: 0 3px 3px 0; } -`; - -/** - * Mount the panel. Returns the unmount. - * - * Refreshes on log activity, coalesced to one repaint per animation frame: a - * channel at 200 messages a second must not repaint a table 200 times, and an - * inspector that makes the application it is inspecting janky is measuring - * itself. - */ -export function mountOverlay(devtools: Devtools, options: OverlayOptions = {}): () => void { - const doc = globalThis.document as Document | undefined; - - if (doc === undefined) { - throw new Error('[forge] mountOverlay needs a DOM; there is no document here'); - } - - const parent = options.parent ?? doc.body; - const host = doc.createElement('div'); - const shadow = host.attachShadow({ mode: 'open' }); - const style = doc.createElement('style'); - - style.textContent = CSS; - shadow.append(style); - - const root = doc.createElement('div'); - root.className = 'root'; - shadow.append(root); - parent.append(host); - - let open = options.open ?? false; - let tab: Tab = 'queries'; - let filter = ''; - let scheduled = false; - - const el = (tag: string, className?: string, text?: string): HTMLElement => { - const node = doc.createElement(tag); - - if (className !== undefined) node.className = className; - if (text !== undefined) node.textContent = text; - - return node; - }; - - const table = (headers: readonly string[], rows: readonly (readonly string[])[]): HTMLElement => { - const node = doc.createElement('table'); - const head = doc.createElement('tr'); - - for (const header of headers) head.append(el('th', undefined, header)); - node.append(head); - - for (const row of rows) { - const tr = doc.createElement('tr'); - - for (const cell of row) tr.append(el('td', undefined, cell)); - node.append(tr); - } - - if (rows.length === 0) { - const tr = doc.createElement('tr'); - const td = el('td', 'dim', 'nothing here'); - - td.setAttribute('colspan', String(headers.length)); - tr.append(td); - node.append(tr); - } - - return node; - }; - - const matches = (text: string): boolean => - filter === '' || text.toLowerCase().includes(filter.toLowerCase()); - - const renderExplain = (body: HTMLElement): void => { - if (filter === '') { - body.append( - el( - 'p', - 'dim', - 'Type a query key above and press Enter. The key is what queries() lists: ' + - 'operation plus arguments.', - ), - ); - - return; - } - - const report = devtools.explain(filter); - - if ('outcome' in report) renderMiss(body, report); - else renderRefetch(body, report); - }; - - const renderMiss = (body: HTMLElement, report: MissReport): void => { - const tone = - report.outcome === 'missed' ? 'bad' : report.outcome === 'refetched' ? 'good' : 'warn'; - - body.append(el('h4', undefined, `outcome: ${report.outcome}`)); - body.append(el('p', tone, report.reason)); - body.append(el('h4', undefined, `cause: ${report.cause.label}`)); - body.append(pills(report.invalidated, 'invalidated')); - body.append(pills(report.carried, 'carried')); - body.append(pills(report.matched, 'matched')); - - if (report.cause.unresolved.length > 0) { - body.append(pills(report.cause.unresolved, 'unresolved templates')); - } - - if (report.nearest.length > 0) { - body.append(el('h4', undefined, 'where they nearly meet')); - const list = doc.createElement('ul'); - - for (const miss of report.nearest) { - list.append( - el('li', undefined, `${miss.invalidated} vs ${miss.carried} (${miss.relation})`), - ); - } - - body.append(list); - } - - if (report.suggestions.length > 0) { - body.append(el('h4', undefined, 'what to change')); - const list = doc.createElement('ul'); - - for (const suggestion of report.suggestions) list.append(el('li', undefined, suggestion)); - - body.append(list); - } - }; - - const renderRefetch = (body: HTMLElement, report: RefetchReport): void => { - body.append(el('h4', undefined, `refetched (${report.reason})`)); - body.append(el('p', 'good', report.summary)); - - if (report.cause !== undefined) { - body.append(pills(report.cause.tags, `cause: ${report.cause.label} raised`)); - } - - body.append(pills(report.matched, 'matched')); - }; - - const pills = (values: readonly string[], label: string): HTMLElement => { - const wrap = el('div'); - - wrap.append(el('span', 'dim', `${label}: `)); - - if (values.length === 0) wrap.append(el('span', 'dim', 'none')); - else for (const value of values) wrap.append(el('span', 'pill', value)); - - return wrap; - }; - - const describe = (entry: LogEntry): string => { - switch (entry.kind) { - case 'mutation': - return `${entry.operation} -> ${entry.tags.join(', ') || 'no tags'}${ - entry.unresolved.length > 0 ? ` (skipped ${entry.unresolved.join(', ')})` : '' - }`; - case 'frames': - return `${String(entry.frames)} frame(s) -> ${entry.tags.join(', ') || 'no tags'}`; - case 'invalidated': - return `${entry.query} hit by ${entry.matched.join(', ')}`; - case 'placed': - return `${entry.query} answered by placement`; - case 'fetch': - return `${entry.query} (${entry.reason})`; - case 'settle': - return `${entry.query} at store v${String(entry.version)}`; - case 'error': - return `${entry.query}: ${entry.message}`; - case 'principal': - return 'identity changed; the cache was dropped'; - case 'action': - return `${entry.action} ${entry.target}`; - } - }; - - const renderBody = (body: HTMLElement): void => { - switch (tab) { - case 'queries': { - const rows = devtools - .queries() - .filter((entry) => matches(entry.key)) - .map((entry) => [ - entry.key, - String(entry.mounts), - entry.stale ? 'stale' : entry.settled ? 'fresh' : 'empty', - entry.tags.join(' '), - ]); - - body.append(table(['key', 'mounts', 'state', 'tags'], rows)); - break; - } - - case 'entities': { - const rows = devtools - .entities({ limit: 300 }) - .filter((record) => matches(record.key)) - .map((record) => [ - record.key, - `v${String(record.version)}`, - record.frameAt > 0 ? `frame ${String(record.frameAt)}` : '', - Object.keys(record.fields).join(' '), - ]); - - body.append(table(['entity', 'version', 'frame', 'fields'], rows)); - break; - } - - case 'tags': { - const rows = devtools - .tags() - .filter((row) => matches(row.tag)) - .map((row) => [ - row.tag, - String(row.mounted.length), - String(row.carriers.length), - row.carriers.join(' '), - ]); - - body.append(table(['tag', 'mounted', 'carriers', 'queries'], rows)); - break; - } - - case 'sockets': { - const rows = devtools - .sockets() - .filter((socket) => matches(socket.endpoint)) - .map((socket) => [ - socket.endpoint, - socket.connected ? 'open' : socket.reconnecting ? 'reconnecting' : 'closed', - String(socket.refs), - String(socket.opens), - socket.channels.map((c) => `${c.channel}(${String(c.handlers)})`).join(' '), - ]); - - body.append(table(['endpoint', 'state', 'refs', 'opens', 'channels'], rows)); - break; - } - - case 'log': { - const entries = devtools.log().filter((entry) => matches(describe(entry))); - const rows = entries - .slice(-300) - .reverse() - .map((entry) => [String(entry.seq), entry.kind, describe(entry)]); - - if (devtools.dropped > 0) { - body.append( - el( - 'p', - 'dim', - `${String(devtools.dropped)} earlier event(s) have been overwritten; the log holds ` + - `the most recent ${String(devtools.capacity)}.`, - ), - ); - } - - body.append(table(['#', 'kind', 'what'], rows)); - break; - } - - case 'explain': - renderExplain(body); - break; - } - }; - - /** - * The closed state: the mark, a status ring and an error count. - * - * This button is the only part of the inspector most people see most of the - * time, and a launcher that cannot say whether anything is in flight or - * anything has failed is one you have to open in order to learn nothing. Both - * readings come from `records()`, which carries the scalar fields for every - * tracked query and no response bodies, so drawing the button stays O(tracked - * queries) and never O(bytes in the cache). - */ - const launcher = (): HTMLElement => { - const button = el('button', 'launcher'); - let fetching = false; - let errors = 0; - - for (const record of devtools.records()) { - if (record.fetching) fetching = true; - if (record.status === 'error') errors += 1; - } - - // Offline outranks the errors it causes: every request fails while the - // rail is offline, and a red ring over failures you switched on yourself - // sends you debugging a request that was never sent. Slow ranks below a - // real error, because unlike offline it stops nothing from succeeding. - const mode = devtools.controls?.mode; - - button.innerHTML = MARK; - button.setAttribute('aria-label', 'Open Forge devtools'); - button.setAttribute( - 'data-pulse', - mode === 'offline' - ? 'offline' - : errors > 0 - ? 'error' - : fetching - ? 'fetching' - : mode === 'slow' - ? 'slow' - : 'idle', - ); - - if (errors > 0) button.append(el('span', 'badge', String(errors))); - - button.addEventListener('click', () => { - open = true; - render(); - }); - - return button; - }; - - const render = (): void => { - root.replaceChildren(); - - if (!open) { - root.append(launcher()); - - return; - } - - const panel = el('div', 'panel'); - const bar = el('div', 'bar'); - - for (const name of TABS) { - const button = el('button', undefined, name); - - button.setAttribute('aria-selected', String(name === tab)); - button.addEventListener('click', () => { - tab = name; - render(); - }); - bar.append(button); - } - - const search = doc.createElement('input'); - - search.value = filter; - search.placeholder = tab === 'explain' ? 'query key, then Enter' : 'filter'; - search.addEventListener('change', () => { - filter = search.value; - render(); - }); - bar.append(search); - - const spacer = el('div', 'spacer'); - bar.append(spacer); - - const counts = devtools.store(); - bar.append( - el( - 'span', - 'dim', - `${String(counts.records)} entities / ${String(counts.mounted)} mounted / v${String( - counts.version, - )}`, - ), - ); - - const close = el('button', undefined, 'x'); - close.addEventListener('click', () => { - open = false; - render(); - }); - bar.append(close); - - const body = el('div', 'body'); - - renderBody(body); - panel.append(bar, body); - root.append(panel); - }; - - const schedule = (): void => { - // Not gated on `open`: the launcher carries a status ring, and one drawn - // only when the panel was mounted is decoration rather than status. - if (scheduled) return; - - scheduled = true; - - const raf = (globalThis as { requestAnimationFrame?: (cb: () => void) => unknown }) - .requestAnimationFrame; - const run = (): void => { - scheduled = false; - render(); - }; - - if (typeof raf === 'function') raf(run); - else void Promise.resolve().then(run); - }; - - const unsubscribe = devtools.subscribe(schedule); - - render(); - - return () => { - unsubscribe(); - host.remove(); - }; -} +export { mountPanel, mountPanel as mountOverlay } from './panel.js'; +export type { PanelOptions, PanelOptions as OverlayOptions } from './panel.js'; diff --git a/packages/client-react-devtools/__tests__/mount.test.tsx b/packages/client-react-devtools/__tests__/mount.test.tsx index c69d5aa14..556d733b6 100644 --- a/packages/client-react-devtools/__tests__/mount.test.tsx +++ b/packages/client-react-devtools/__tests__/mount.test.tsx @@ -42,6 +42,24 @@ function mount(node: ReactNode): { unmount: () => void } { const panels = (): number => [...document.body.children].filter((node) => node.shadowRoot !== null).length; +/** + * Wait for the panel to actually be in the DOM. + * + * A fixed number of ticks is the wrong tool here: how long the effect's + * dynamic import takes depends on whether that module is already in the + * graph, so the same wait is generous for a warm module and short for a cold + * one. Polling for the thing we are waiting on is stable either way. + */ +async function waitForPanel(): Promise { + for (let i = 0; i < 50 && panels() === 0; i++) { + await act(async () => { + await new Promise((resolve) => { + setTimeout(resolve, 1); + }); + }); + } +} + /** The dynamic imports inside the effect settle on the microtask queue. */ async function settle(): Promise { await act(async () => { @@ -183,3 +201,54 @@ describe('ForgeDevtools', () => { probe.unmount(); }); }); + +describe('choosing the UI', () => { + /** + * `panel={false}` is the escape hatch for the lean view. It used to mount + * `/overlay`, which is the full panel now, so the prop would have quietly + * stopped meaning anything. + */ + it('mounts the lean view when the panel is declined', async () => { + const app = mount( + createElement( + ClientProvider, + { client: cache() }, + createElement(ForgeDevtools, { panel: false, open: true }), + ), + ); + + await waitForPanel(); + + const host = [...document.body.children].find((node) => node.shadowRoot !== null); + + const labels = [...(host?.shadowRoot?.querySelectorAll('.bar button') ?? [])].map( + (node) => node.textContent ?? '', + ); + + expect(labels).toContain('queries'); + expect(labels).not.toContain('trace'); + + app.unmount(); + }); + + it('mounts the full panel by default', async () => { + const app = mount( + createElement( + ClientProvider, + { client: cache() }, + createElement(ForgeDevtools, { open: true }), + ), + ); + + await waitForPanel(); + + const host = [...document.body.children].find((node) => node.shadowRoot !== null); + const labels = [...(host?.shadowRoot?.querySelectorAll('.bar button') ?? [])].map( + (node) => node.textContent ?? '', + ); + + expect(labels).toContain('trace'); + + app.unmount(); + }); +}); diff --git a/packages/client-react-devtools/src/dev.ts b/packages/client-react-devtools/src/dev.ts index 3dcf8238f..311fc1c75 100644 --- a/packages/client-react-devtools/src/dev.ts +++ b/packages/client-react-devtools/src/dev.ts @@ -6,7 +6,14 @@ import { useClient } from '@forge-go/client-react'; export interface ForgeDevtoolsProps { /** Beats the provider and the module default, as everywhere else. */ readonly client?: QueryCache; - /** The full panel. `false` mounts the lean overlay instead. Defaults to true. */ + /** + * The full panel. Defaults to true. + * + * `false` mounts the lean view instead: six read-only tables and a filter + * box, in a fraction of the bytes. It used to reach for `/overlay`, which is + * the full panel now, so this branch would have quietly stopped meaning + * anything. + */ readonly panel?: boolean; /** Start open rather than as a button in the corner. */ readonly open?: boolean; @@ -181,7 +188,7 @@ export function ForgeDevtools(props: ForgeDevtoolsProps = {}): null { unmount = mountPanel(entry.devtools, { open }); } else { - const { mountOverlay } = await import('@forge-go/client-devtools/overlay'); + const { mountMini } = await import('@forge-go/client-devtools/mini'); if (!live) { releaseOnce(); @@ -189,7 +196,7 @@ export function ForgeDevtools(props: ForgeDevtoolsProps = {}): null { return; } - unmount = mountOverlay(entry.devtools, { open }); + unmount = mountMini(entry.devtools, { open }); } })(); } From 750c2d911ce1b3d84189e71b9d1fec96375cf131 Mon Sep 17 00:00:00 2001 From: Rex Raphael Date: Tue, 8 Sep 2026 12:22:20 -0500 Subject: [PATCH 2/2] fix(client-react-devtools): type the props in the mount tests `props: ForgeDevtoolsProps = {}` makes the parameter optional, so a bare `createElement` resolves to the no-props overload and rejects every prop the component actually takes. The existing tests only ever passed `null` or a key, which is why nobody had hit it. Caught by CI and not by me: I ran the package build and not its test typecheck, and those are two different tsconfigs. --- packages/client-react-devtools/__tests__/mount.test.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/client-react-devtools/__tests__/mount.test.tsx b/packages/client-react-devtools/__tests__/mount.test.tsx index 556d733b6..7708e1d7e 100644 --- a/packages/client-react-devtools/__tests__/mount.test.tsx +++ b/packages/client-react-devtools/__tests__/mount.test.tsx @@ -6,6 +6,7 @@ import { createRoot } from 'react-dom/client'; import { describe, expect, it } from 'vitest'; import type { Devtools } from '@forge-go/client-devtools'; import { ForgeDevtools, useForgeDevtools } from '../src/dev'; +import type { ForgeDevtoolsProps } from '../src/dev'; function cache(): QueryCache { const scheduler = manualScheduler(); @@ -213,7 +214,7 @@ describe('choosing the UI', () => { createElement( ClientProvider, { client: cache() }, - createElement(ForgeDevtools, { panel: false, open: true }), + createElement(ForgeDevtools, { panel: false, open: true }), ), ); @@ -236,7 +237,7 @@ describe('choosing the UI', () => { createElement( ClientProvider, { client: cache() }, - createElement(ForgeDevtools, { open: true }), + createElement(ForgeDevtools, { open: true }), ), );