diff --git a/packages/client-devtools/README.md b/packages/client-devtools/README.md index 25838bba1..bb260e036 100644 --- a/packages/client-devtools/README.md +++ b/packages/client-devtools/README.md @@ -273,7 +273,8 @@ 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: +The lean view is still here, deprecated, and going away in the next major. It +is `/mini`: ```ts import { mountMini } from '@forge-go/client-devtools/mini'; @@ -281,9 +282,11 @@ 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. +Six read-only tables and a filter box in 3.5 kB gzipped. Prefer `/overlay`. +The bytes were the whole case for a second UI and they do not survive contact +with the fact that this package is dev-only: none of it reaches a production +bundle, so what you save comes off a development build. Meanwhile the lean view +drifted, and still has a `log` tab where the panel has a causal trace. A DOM panel in a shadow root: `document.createElement` and nothing else. Deliberately **not a component** — a React panel forces React on a Vue diff --git a/packages/client-devtools/__tests__/entrypoints.test.ts b/packages/client-devtools/__tests__/entrypoints.test.ts index cee499f85..df17181c5 100644 --- a/packages/client-devtools/__tests__/entrypoints.test.ts +++ b/packages/client-devtools/__tests__/entrypoints.test.ts @@ -27,7 +27,8 @@ afterEach(() => { function tabs(): string[] { return [...shadow().querySelectorAll('.bar button')] - .map((node) => node.textContent ?? '') + // The name is the first span; the second is the row count. + .map((node) => node.querySelector('span')?.textContent ?? node.textContent ?? '') .filter((text) => text !== ''); } diff --git a/packages/client-devtools/__tests__/mini.test.ts b/packages/client-devtools/__tests__/mini.test.ts index e877210cc..d73401633 100644 --- a/packages/client-devtools/__tests__/mini.test.ts +++ b/packages/client-devtools/__tests__/mini.test.ts @@ -171,3 +171,32 @@ describe('the launcher ring', () => { devtools.dispose(); }); }); + +describe('table layout', () => { + /** + * A regression, and one jsdom cannot catch by measuring: it has no layout + * engine, so the assertion is on the declaration rather than on the width. + * + * `word-break: break-word` is a deprecated alias that computes to + * `word-break: normal; overflow-wrap: anywhere`, and `anywhere` -- unlike + * `break-word` -- shrinks an element's min-content size. In a table that + * makes every column's minimum one character wide, so a long query key gets + * a 1ch column and the header reads downwards, one letter per line. + * + * `overflow-wrap: break-word` still wraps a long key and leaves min-content + * at the longest word, which is what keeps the columns usable. + */ + it('does not shrink table columns to a single character', () => { + const h = harness(); + const devtools = attach(h.cache, { now: counter() }); + const unmount = mountMini(devtools, { parent: document.body, open: true }); + + const css = shadow().querySelector('style')?.textContent ?? ''; + + expect(css).not.toContain('word-break: break-word'); + expect(css).toContain('overflow-wrap: break-word'); + + unmount(); + devtools.dispose(); + }); +}); diff --git a/packages/client-devtools/__tests__/panel.test.ts b/packages/client-devtools/__tests__/panel.test.ts index ee9209cbd..7e93a6962 100644 --- a/packages/client-devtools/__tests__/panel.test.ts +++ b/packages/client-devtools/__tests__/panel.test.ts @@ -189,7 +189,7 @@ describe('the trace', () => { await h.settle(); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'trace') + .find((node) => node.textContent?.startsWith('trace') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); const causes = [...shadow().querySelectorAll('.cause')]; @@ -223,7 +223,7 @@ describe('the trace', () => { await h.settle(); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'trace') + .find((node) => node.textContent?.startsWith('trace') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); const yours = [...shadow().querySelectorAll('.cause[data-kind="action"]')]; @@ -395,7 +395,7 @@ describe('the network tab', () => { const unmount = mountPanel(devtools, { parent: document.body, open: true }); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'network') + .find((node) => node.textContent?.startsWith('network') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); const text = shadow().querySelector('.list')?.textContent ?? ''; @@ -435,7 +435,7 @@ describe('the network tab', () => { }); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'network') + .find((node) => node.textContent?.startsWith('network') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); const row = shadow().querySelector('tr.row'); @@ -476,7 +476,7 @@ describe('the network tab', () => { ).rejects.toThrow(); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'network') + .find((node) => node.textContent?.startsWith('network') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); [...shadow().querySelectorAll('tr.row')][0]?.dispatchEvent( @@ -503,7 +503,7 @@ describe('the overlay tab', () => { ); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'overlay') + .find((node) => node.textContent?.startsWith('overlay') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); const layers = [...shadow().querySelectorAll('.layer')]; @@ -523,7 +523,7 @@ describe('the overlay tab', () => { const unmount = mountPanel(devtools, { parent: document.body, open: true }); [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'overlay') + .find((node) => node.textContent?.startsWith('overlay') === true) ?.dispatchEvent(new Event('click', { bubbles: true })); expect(shadow().querySelector('.list')?.textContent).toContain('No optimistic write'); @@ -563,7 +563,9 @@ describe('the panel shell', () => { const devtools = attach(h.cache, { now: counter() }); const unmount = mountPanel(devtools, { parent: document.body, open: true }); - const labels = [...shadow().querySelectorAll('button')].map((node) => node.textContent); + const labels = [...shadow().querySelectorAll('button')].map( + (node) => node.querySelector('span')?.textContent ?? node.textContent, + ); for (const tab of [ 'trace', @@ -609,7 +611,8 @@ describe('the header buckets', () => { * counts, so `explainfresh 1` is what a greedy word match actually sees. */ const bucket = (name: string): number => { - const text = shadow().querySelector('.bar')?.textContent ?? ''; + // Only the buckets, not every number that shares the status bar with them. + const text = shadow().querySelector('.statusbar .buckets')?.textContent ?? ''; const found = new RegExp(`${name} (\\d+)`).exec(text); return found?.[1] === undefined ? -1 : Number(found[1]); @@ -618,7 +621,7 @@ describe('the header buckets', () => { /** Repaint now, rather than waiting on the coalesced animation frame. */ const repaint = (): void => { [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === 'queries') + .find((node) => node.textContent?.startsWith('queries') === true) ?.dispatchEvent(new Event('click')); }; @@ -762,7 +765,9 @@ describe('the detail pane', () => { await h.cache.fetch(ops.orderList); - [...shadow().querySelectorAll('.bar button')] + // Session-wide actions live in the status bar, beside the session-wide + // numbers, rather than in the row of tabs. + [...shadow().querySelectorAll('.statusbar button')] .find((node) => node.textContent === 'clear cache') ?.dispatchEvent(new Event('click')); @@ -776,7 +781,7 @@ describe('the detail pane', () => { describe('sort and selection are per tab', () => { const clickTab = (name: string): void => { [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === name) + .find((node) => node.textContent?.startsWith(name) === true) ?.dispatchEvent(new Event('click')); }; @@ -921,7 +926,7 @@ describe('the streams and frames tabs', () => { const unmount = mountPanel(devtools, { parent: document.body, open: true }); [...shadow().querySelectorAll('button')] - .find((node) => node.textContent === 'streams') + .find((node) => node.textContent?.startsWith('streams') === true) ?.dispatchEvent(new Event('click')); expect(shadow().textContent).toContain('no stream runtime'); @@ -936,7 +941,7 @@ describe('the streams and frames tabs', () => { const unmount = mountPanel(devtools, { parent: document.body, open: true }); [...shadow().querySelectorAll('button')] - .find((node) => node.textContent === 'frames') + .find((node) => node.textContent?.startsWith('frames') === true) ?.dispatchEvent(new Event('click')); const text = shadow().textContent ?? ''; @@ -1187,8 +1192,9 @@ function typeFilter(text: string): void { } function goTo(name: string): void { + // A tab button holds its name and its row count, so the name is a prefix. [...shadow().querySelectorAll('.bar button')] - .find((node) => node.textContent === name) + .find((node) => node.textContent?.startsWith(name) === true) ?.dispatchEvent(new Event('click', { bubbles: true })); } @@ -1509,8 +1515,12 @@ describe('the launcher, fully dressed', () => { }); describe('the launcher, out of the way', () => { - /** The collision in the corner that started all of this. */ - it('lifts itself above a framework dev badge already in the corner', () => { + /** + * It sits where you put it. Guessing from an element name got this wrong: + * a framework whose badge exists but is not in this corner still matched, + * and the launcher lifted itself away from the edge for no reason. + */ + it('stays in the corner even with a framework dev badge on the page', () => { const badge = document.createElement('nextjs-portal'); document.body.append(badge); @@ -1519,7 +1529,7 @@ describe('the launcher, out of the way', () => { const devtools = attach(h.cache, { now: counter() }); const unmount = mountPanel(devtools, { parent: document.body }); - expect(shadow().querySelector('.root')?.getAttribute('data-offset')).toBe('badge'); + expect(shadow().querySelector('.root')?.getAttribute('data-offset')).toBe('none'); unmount(); badge.remove(); @@ -1748,7 +1758,7 @@ describe('the keyboard', () => { const current = (): string | null | undefined => [...shadow().querySelectorAll('.bar button')] .find((node) => node.getAttribute('aria-selected') === 'true') - ?.textContent; + ?.querySelector('span')?.textContent; expect(current()).toBe('trace'); @@ -1816,9 +1826,9 @@ describe('the keyboard', () => { input?.dispatchEvent(new KeyboardEvent('keydown', { key: '3', bubbles: true })); expect( - [...shadow().querySelectorAll('.bar button')].find( - (node) => node.getAttribute('aria-selected') === 'true', - )?.textContent, + [...shadow().querySelectorAll('.bar button')] + .find((node) => node.getAttribute('aria-selected') === 'true') + ?.querySelector('span')?.textContent, ).toBe('trace'); unmount(); diff --git a/packages/client-devtools/__tests__/zero-cost.test.ts b/packages/client-devtools/__tests__/zero-cost.test.ts index 0dbfab823..a06740b33 100644 --- a/packages/client-devtools/__tests__/zero-cost.test.ts +++ b/packages/client-devtools/__tests__/zero-cost.test.ts @@ -215,9 +215,10 @@ describe('the panel entry point', () => { // The parts that *could* be declined were split out already, and they are // `./requests` and `./control`. // - // 20 kB leaves room to finish the remaining views without moving it again. - // If it needs a fifth increase, that is the signal to split for real. - expect(panel.gzipped - production.gzipped).toBeLessThan(20_000); + // 22 kB after the title bar, the status bar, the sparkline and the tab + // counts. Those are chrome rather than views, and chrome is where the + // design was thinnest, so this is the last of it. + expect(panel.gzipped - production.gzipped).toBeLessThan(22_000); }); }); diff --git a/packages/client-devtools/src/mini.ts b/packages/client-devtools/src/mini.ts index 8804f1fe4..09babc66e 100644 --- a/packages/client-devtools/src/mini.ts +++ b/packages/client-devtools/src/mini.ts @@ -4,6 +4,21 @@ import type { LogEntry, MissReport, RefetchReport } from './types.js'; /** * The lean view: six read-only tables and a filter box. * + * @deprecated Use `mountOverlay` from `./overlay`. Removed in the next major. + * + * The case for a second, smaller UI was bytes, and it does not hold. This + * package is dev-only by construction: the React adapter sits behind a + * `development` export condition and a `NODE_ENV` guard, and the documented + * way to reach the inspector directly is a dynamic import behind a development + * check. None of it is in a production bundle, so the ten kilobytes this saves + * come off a development build, which is not a trade worth maintaining a + * second UI for. + * + * The cost of keeping it was never bytes anyway, it was drift. This view still + * has a `log` tab where the panel has a causal trace, and none of the network, + * overlay-stack or explain-from-a-row work reached it. A second UI nobody + * updates is a second UI that lies about what the cache can tell you. + * * 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 @@ -29,6 +44,7 @@ import type { LogEntry, MissReport, RefetchReport } from './types.js'; * 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. */ +/** @deprecated See `mountMini`. */ export interface MiniOptions { /** Where to attach. Defaults to `document.body`. */ readonly parent?: Element; @@ -94,7 +110,7 @@ button[aria-selected="true"] { background: #4b5bd6; border-color: #4b5bd6; } .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; } + vertical-align: top; overflow-wrap: break-word; } th { color: #9a9aa8; font-weight: normal; position: sticky; top: -8px; background: #1c1c22; } tr.hot td { background: #2a2233; } code { color: #9fd0ff; } @@ -119,6 +135,7 @@ input { font: inherit; color: inherit; background: #14141a; border: 1px solid #4 * inspector that makes the application it is inspecting janky is measuring * itself. */ +/** @deprecated Use `mountOverlay` from `@forge-go/client-devtools/overlay`. */ export function mountMini(devtools: Devtools, options: MiniOptions = {}): () => void { const doc = globalThis.document as Document | undefined; diff --git a/packages/client-devtools/src/panel.ts b/packages/client-devtools/src/panel.ts index 4d44d2b69..4dff8007f 100644 --- a/packages/client-devtools/src/panel.ts +++ b/packages/client-devtools/src/panel.ts @@ -42,15 +42,6 @@ export interface PanelOptions { readonly offset?: number; } -/** - * Dev badges that already own the bottom-right corner. - * - * Matched by element name rather than by position: reading layout would mean - * measuring, and measuring on mount is how a devtools panel starts causing the - * reflows it exists to help you find. - */ -const BADGES = 'nextjs-portal, #__next-build-watcher, [data-nextjs-toast], vite-error-overlay'; - type Tab = | 'trace' | 'network' @@ -185,156 +176,266 @@ 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; + --ground: #0e1116; --panel: #14181f; --raised: #1a1f28; --hover: #1f2531; + --line: #242a35; --line2: #2e3542; --text: #e3e7ee; --dim: #8992a2; + --faint: #5e6675; --ember: #ff6a2b; --mint: #3fd39c; --amber: #ffb648; + --coral: #ff6b6b; --violet: #ae8cff; --sky: #62a8ff; + --ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif; + --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; + font: 12px/1.5 var(--ui); color: var(--text); } + +/* chrome speaks sans, data speaks mono. The old sheet was mono throughout, + which flattened labels and values into one texture. */ +button { font: 500 12px/1.4 var(--ui); color: var(--dim); background: transparent; + border: 1px solid transparent; border-radius: 6px; padding: 4px 10px; cursor: pointer; } +button:hover { background: var(--hover); color: var(--text); } +button[aria-selected="true"] { background: var(--raised); border-color: var(--line2); + color: var(--text); box-shadow: inset 0 -2px 0 var(--ember); } +button:focus-visible { outline: 2px solid var(--ember); outline-offset: 1px; } + +.panel { width: min(1100px, 96vw); height: min(660px, 84vh); background: var(--ground); + border: 1px solid var(--line2); border-radius: 10px; display: flex; flex-direction: column; + box-shadow: 0 24px 70px rgba(0,0,0,.5); overflow: hidden; } +.panel[data-mode="full"] { width: 96vw; height: 92vh; } +.panel[data-mode="right"] { width: min(560px, 96vw); height: 92vh; } + +.titlebar { display: flex; align-items: center; gap: 8px; padding: 0 8px; height: 38px; + background: var(--panel); border-bottom: 1px solid var(--line); flex: none; } +.titlebar .mark { color: var(--ember); display: grid; place-items: center; } +.titlebar .mark svg { width: 15px; height: 15px; display: block; } +.titlebar .name { font: 500 12px var(--mono); color: var(--text); } +.titlebar .crumb { display: flex; align-items: center; gap: 6px; font: 11px var(--mono); + color: var(--faint); } +.titlebar .crumb b { color: var(--dim); font-weight: 400; } +.titlebar .spacer { flex: 1; } + +.statusbar { display: flex; align-items: center; gap: 14px; height: 26px; padding: 0 10px; + background: var(--panel); border-top: 1px solid var(--line); flex: none; + font: 10.5px var(--mono); color: var(--faint); overflow-x: auto; white-space: nowrap; } +.statusbar .spacer { flex: 1; } +.statusbar span { display: flex; align-items: center; gap: 5px; } +.statusbar button { font: 10.5px var(--mono); padding: 2px 8px; border: 1px solid var(--line2); + border-radius: 5px; color: var(--dim); } +.statusbar button:hover { color: var(--text); background: var(--hover); } +.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; background: var(--faint); } +.dot.ok { background: var(--mint); } +.dot.warn { background: var(--amber); } +.dot.hot { background: var(--ember); } + +.bar { display: flex; gap: 3px; padding: 7px 8px; border-bottom: 1px solid var(--line); + align-items: center; flex-wrap: wrap; background: var(--ground); } +.bar .tab { padding: 5px 11px; font: 500 13px/1.3 var(--ui); display: flex; align-items: baseline; + gap: 7px; } +.bar .tab .n { font: 10.5px var(--mono); color: var(--faint); font-variant-numeric: tabular-nums; } +.bar .tab[aria-selected="true"] .n { color: var(--ember); } +.bar .spacer { flex: 1; } +.bar > span.dim { font: 11px var(--mono); color: var(--faint); padding: 0 6px; } + +input { font: 11px var(--mono); color: var(--text); background: var(--ground); + border: 1px solid var(--line2); border-radius: 6px; padding: 4px 8px; min-width: 200px; } +input::placeholder { color: var(--faint); } +input:focus-visible { outline: none; border-color: var(--ember); } + +.split { display: flex; flex: 1; min-height: 0; } +.list { flex: 1 1 55%; overflow: auto; padding: 0; border-right: 1px solid var(--line); } +.list:only-child { flex: 1 1 100%; border-right: 0; } +.detail { flex: 1 1 45%; overflow: auto; padding: 10px 12px; background: var(--panel); } + +/* tables. min-content must not collapse to one character: word-break:break-word + computes to overflow-wrap:anywhere, which does exactly that in a table. */ +table { border-collapse: collapse; width: 100%; } +th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); + vertical-align: top; overflow-wrap: break-word; } +th { position: sticky; top: 0; z-index: 2; background: var(--ground); + font: 500 9.5px/1.4 var(--ui); letter-spacing: .12em; text-transform: uppercase; + color: var(--faint); white-space: nowrap; cursor: pointer; } +th:hover { color: var(--dim); } +td { font: 11.5px/1.5 var(--mono); color: var(--dim); font-variant-numeric: tabular-nums; } +td:first-child { color: var(--text); } +tr.row { cursor: pointer; } +tr.row:hover td { background: var(--hover); } +tr.row[aria-selected="true"] td { background: var(--raised); } +tr.row[aria-selected="true"] td:first-child { box-shadow: inset 2px 0 0 var(--ember); } + +code { color: var(--sky); font: 11.5px var(--mono); } +.dim { color: var(--faint); } +.warn { color: var(--amber); } +.good { color: var(--mint); } +.bad { color: var(--coral); } +h4 { margin: 14px 0 6px; font: 500 9.5px/1.4 var(--ui); letter-spacing: .13em; + text-transform: uppercase; color: var(--faint); } +summary { cursor: pointer; color: var(--dim); font: 11px var(--mono); } +ul { margin: 6px 0; padding-left: 18px; } +li { margin: 4px 0; font: 11.5px/1.6 var(--mono); color: var(--dim); } +pre { font: 10.5px/1.6 var(--mono); background: var(--ground); border: 1px solid var(--line); + border-radius: 5px; padding: 8px 10px; overflow-x: auto; color: var(--dim); margin: 0; } +.pillrow { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 7px; } +.pilllabel { font: 500 9.5px/1.4 var(--ui); letter-spacing: .13em; text-transform: uppercase; + color: var(--faint); margin-right: 6px; } +.pill { display: inline-block; padding: 1px 6px; border-radius: 3px; margin: 0 3px 3px 0; + font: 10px var(--mono); border: 1px solid var(--line2); color: var(--violet); + background: rgba(174,140,255,.08); } + +/* launcher */ +.launcher-dock { display: flex; align-items: center; padding: 5px; + border: 1px solid transparent; border-radius: 9px; } +.launcher-dock:hover, .launcher-dock:focus-within { background: var(--panel); + border-color: var(--line2); box-shadow: 0 6px 22px rgba(0,0,0,.34); } +.launcher-dock:hover .launcher, .launcher-dock:focus-within .launcher { + background: transparent; border-color: transparent; box-shadow: none; } .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; } -.root[data-offset="badge"] { bottom: 62px; } -.launcher-dock { display: flex; align-items: center; background: #14181f; - border: 1px solid #2e3542; border-radius: 9px; padding: 5px; - box-shadow: 0 6px 22px rgba(0,0,0,.34); } -.launcher-dock .launcher { box-shadow: none; border: 0; background: transparent; } -.launcher-vitals { display: none; align-items: center; gap: 4px; padding: 0 8px 0 8px; - margin-left: 3px; border-left: 1px solid #242a35; color: #8992a2; font-size: 10.5px; - white-space: nowrap; } -.launcher-vitals b { color: #e3e7ee; font-weight: 500; } -.launcher-dock:hover .launcher-vitals, .launcher-dock:focus-within .launcher-vitals { - display: flex; } -.launcher[data-pulse="pending"]::after { border-color: #ffb648; } -.launcher:hover { background: #1a1f28; } + position: relative; border-radius: 8px; background: var(--panel); border: 1px solid var(--line2); + box-shadow: 0 6px 22px rgba(0,0,0,.34); color: var(--text); } +.launcher:hover { background: var(--raised); } .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; } + border: 1.5px solid var(--mint); opacity: .55; pointer-events: none; } +.launcher[data-pulse="fetching"]::after { border-color: var(--sky); } +.launcher[data-pulse="pending"]::after { border-color: var(--amber); } +.launcher[data-pulse="error"]::after { border-color: var(--coral); opacity: .9; } +.launcher[data-pulse="offline"]::after { border-color: var(--ember); opacity: .95; } +.launcher[data-pulse="slow"]::after { border-color: var(--ember); opacity: .5; } +.launcher .badge { position: absolute; top: -5px; right: -5px; min-width: 15px; height: 15px; + border-radius: 8px; background: var(--coral); color: #12151b; font: 600 9.5px var(--ui); + display: grid; place-items: center; padding: 0 4px; border: 2px solid var(--ground); } +.launcher-vitals { display: none; align-items: center; gap: 4px; padding: 0 8px; + margin-left: 3px; border-left: 1px solid var(--line); color: var(--dim); + font: 10.5px var(--mono); white-space: nowrap; } +.launcher-vitals b { color: var(--text); font-weight: 500; } +.launcher-dock:hover .launcher-vitals, .launcher-dock:focus-within .launcher-vitals { + display: flex; } + +/* icon chrome */ .ico { width: 26px; height: 22px; padding: 0; display: grid; place-items: center; - background: transparent; border: 1px solid transparent; border-radius: 5px; color: #8992a2; } -.ico:hover { background: #1f2531; color: #e3e7ee; } -.ico[aria-pressed="true"] { background: #1a1f28; color: #ff6a2b; border-color: #2e3542; } + border-radius: 5px; color: var(--dim); } +.ico:hover { background: var(--hover); color: var(--text); } +.ico[aria-pressed="true"] { background: var(--raised); color: var(--ember); border-color: var(--line2); } .ico svg { width: 13px; height: 13px; display: block; } -.docks { display: flex; border: 1px solid #2e3542; border-radius: 6px; overflow: hidden; } -.docks .ico { border-radius: 0; border: 0; border-right: 1px solid #2e3542; width: 28px; } +.docks { display: flex; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; } +.docks .ico { border-radius: 0; border: 0; border-right: 1px solid var(--line2); width: 28px; } .docks .ico:last-child { border-right: 0; } .tip { position: relative; } .tip::after { content: attr(data-tip); position: absolute; top: calc(100% + 7px); left: 50%; - transform: translateX(-50%); background: #1a1f28; color: #e3e7ee; border: 1px solid #2e3542; - border-radius: 5px; padding: 3px 7px; font-size: 10px; white-space: nowrap; - pointer-events: none; opacity: 0; transition: opacity .12s ease .3s; z-index: 20; } + transform: translateX(-50%); background: var(--raised); color: var(--text); + border: 1px solid var(--line2); border-radius: 5px; padding: 3px 7px; + font: 10px var(--mono); white-space: nowrap; pointer-events: none; opacity: 0; + transition: opacity .12s ease .3s; z-index: 20; } .tip:hover::after, .tip:focus-visible::after { opacity: 1; } .tip-r::after { left: auto; right: 0; transform: none; } -.panel[data-mode="full"] { width: 96vw; height: 92vh; } -.panel[data-mode="right"] { width: min(560px, 96vw); height: 92vh; } -.detail-head { display: flex; align-items: center; gap: 8px; position: sticky; top: -8px; - margin: -8px -8px 8px; padding: 6px 6px 6px 8px; background: #1c1c22; - border-bottom: 1px solid #35353d; z-index: 3; } -.detail-head .what { color: #8a8a98; font-size: 10px; letter-spacing: .13em; + +/* vitals */ +.vitals { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); + background: var(--ground); } +.vital { padding: 6px 14px; border-right: 1px solid var(--line); white-space: nowrap; } +.vital .k { display: block; color: var(--faint); font: 500 9.5px/1.4 var(--ui); + letter-spacing: .12em; text-transform: uppercase; } +.vital .v { color: var(--text); font: 14px var(--mono); font-variant-numeric: tabular-nums; } +.vital .n { color: var(--faint); font: 10px var(--mono); margin-left: 5px; } +.vital.spark { flex: 1; min-width: 120px; border-right: 0; display: flex; align-items: center; + color: var(--ember); padding: 6px 14px; } +.vital.spark svg { width: 100%; height: 30px; display: block; } +.vital[data-vital="pending"] .v { color: var(--amber); } + +/* rail */ +.rail { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; padding: 5px 8px; + border-bottom: 1px solid var(--line); background: var(--panel); } +.rail .spacer { flex: 1; } +.rail-label { color: var(--faint); font: 500 9.5px/1.4 var(--ui); letter-spacing: .12em; text-transform: uppercase; } -.detail-head .spacer { flex: 1; } -.wf { display: flex; height: 8px; min-width: 90px; border-radius: 2px; background: #2b2b33; +.latency { width: 84px; accent-color: var(--ember); } + +/* facets */ +.facets { display: flex; gap: 5px; flex-wrap: wrap; padding: 8px 12px 8px; align-items: center; + border-bottom: 1px solid var(--line); } +.facets .spacer { flex: 1; } +.facets .only { font: 500 9.5px/1.4 var(--ui); letter-spacing: .13em; text-transform: uppercase; + color: var(--faint); margin-right: 4px; } +.facets .shown { font: 10.5px var(--mono); color: var(--faint); } +.facet { font: 10px var(--mono); padding: 2px 9px; border-radius: 10px; + border: 1px solid var(--line2); color: var(--dim); } +.facet:hover { color: var(--text); background: var(--hover); } +.facet[aria-pressed="true"] { background: rgba(255,106,43,.12); + border-color: rgba(255,106,43,.5); color: var(--ember); } +.facet .count { color: var(--faint); margin-left: 5px; } +.facet[aria-pressed="true"] .count { color: var(--ember); } +.facet.clear { border-color: transparent; text-decoration: underline; } + +/* trace */ +.cause { position: relative; padding: 11px 14px 11px 34px; border-bottom: 1px solid var(--line); } +.cause::before { content: ""; position: absolute; left: 15px; top: 30px; bottom: 11px; + width: 1px; background: var(--line2); } +.cause-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; + font: 11.5px var(--mono); } +.cause-head .seq { color: var(--faint); font-variant-numeric: tabular-nums; } +.cause-head .kind { color: var(--faint); font: 500 9.5px/1.4 var(--ui); letter-spacing: .1em; + text-transform: uppercase; } +.cause-head .op { color: var(--text); } +.cause-head .when { margin-left: auto; color: var(--faint); font-variant-numeric: tabular-nums; } +.cause > .mark { position: absolute; left: 8px; top: 10px; width: 14px; height: 14px; + border-radius: 3px; display: grid; place-items: center; color: #0e1116; + font: 600 9px var(--ui); background: var(--faint); } +.cause[data-kind="mutation"] > .mark { background: var(--violet); } +.cause[data-kind="frames"] > .mark { background: var(--sky); } +.cause[data-kind="action"] > .mark { background: var(--ember); } +.cause[data-kind="error"] > .mark { background: var(--coral); } +.effect .verb { color: var(--dim); margin-right: 6px; } +.effect .verb.good { color: var(--mint); } +.effect .verb.bad { color: var(--coral); } +.effect .verb.miss { color: var(--faint); } +.effect .said { color: var(--dim); } +.effect { position: relative; margin-top: 7px; padding-left: 14px; font: 11px var(--mono); + color: var(--dim); } +.effect::before { content: ""; position: absolute; left: -12px; top: 8px; width: 20px; + height: 1px; background: var(--line2); } +.nearmiss { margin-top: 8px; padding: 6px 9px; border: 1px solid rgba(255,182,72,.28); + background: rgba(255,182,72,.06); border-radius: 5px; color: var(--amber); + font: 10.5px/1.5 var(--mono); } +.nearmiss .warn { font: 500 9.5px/1.4 var(--ui); letter-spacing: .1em; text-transform: uppercase; + margin-right: 6px; } + +/* network */ +.wf { display: flex; height: 8px; min-width: 90px; border-radius: 2px; background: var(--line); overflow: hidden; } .wf i { display: block; height: 100%; } -.wf .wire { background: #62a8ff; } -.wf .auth { background: #ae8cff; } -.wf .backoff { background: repeating-linear-gradient(90deg, #45454f 0 3px, transparent 3px 6px); } -.wf .pending { width: 100%; background: repeating-linear-gradient(90deg, #35353d 0 4px, +.wf .wire { background: var(--sky); } +.wf .auth { background: var(--violet); } +.wf .backoff { background: repeating-linear-gradient(90deg, var(--line2) 0 3px, + transparent 3px 6px); } +.wf .pending { width: 100%; background: repeating-linear-gradient(90deg, var(--line) 0 4px, transparent 4px 8px); } -.diff { line-height: 1.6; } -.diff .was { color: #ff8f8f; } -.diff .now { color: #8ce99a; } -.diff .same { color: #6b6b78; } -.held { color: #ff6a2b; } +.curl { white-space: pre-wrap; } + +/* overlay stack */ +.layer { border: 1px solid var(--line2); border-radius: 7px; padding: 10px 12px; + margin: 0 12px 8px; background: var(--panel); } +.patch { display: flex; gap: 8px; margin-top: 5px; font: 10.5px var(--mono); } +.patch .kind { min-width: 46px; text-align: right; color: var(--faint); } +.patch .kind.merge { color: var(--sky); } +.patch .kind.create { color: var(--mint); } +.patch .kind.delete { color: var(--coral); } +.patch .key { color: var(--text); word-break: break-all; } +.diff { font: 10.5px/1.6 var(--mono); margin-top: 8px; } +.diff .was { color: var(--coral); } +.diff .now { color: var(--mint); } +.diff .same { color: var(--faint); } +.buttons { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; } +.buttons button { font: 10.5px var(--mono); background: var(--raised); + border: 1px solid var(--line2); padding: 4px 9px; } +.buttons button:hover { color: var(--text); border-color: var(--faint); } +.buttons input { min-width: 0; width: 92px; } + +.held { color: var(--ember); } .held-banner { border: 1px solid rgba(255,106,43,.45); background: rgba(255,106,43,.08); - border-radius: 5px; padding: 7px 9px; color: #ff6a2b; margin-bottom: 8px; } -.vitals { display: flex; overflow-x: auto; border-bottom: 1px solid #35353d; } -.vital { padding: 5px 12px; border-right: 1px solid #2b2b33; white-space: nowrap; } -.vital .k { display: block; color: #6b6b78; font-size: 9.5px; letter-spacing: .12em; - text-transform: uppercase; } -.vital .v { color: #e6e6e6; font-size: 13px; } -.vital .n { color: #6b6b78; font-size: 10px; margin-left: 5px; } -.vital[data-vital="pending"] .v { color: #ffb648; } -.panel[data-density="compact"] td, .panel[data-density="compact"] th { padding: 1px 6px; } -.panel[data-density="compact"] .vital { padding: 3px 10px; } -.panel[data-density="compact"] .cause { padding: 5px 4px 5px 24px; } -.rail { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; padding: 5px 6px; - border-bottom: 1px solid #35353d; } -.rail .spacer { flex: 1; } -.rail-label { color: #8a8a98; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; } -.facets { display: flex; gap: 5px; flex-wrap: wrap; padding: 0 0 8px; } -.facet { font-size: 10px; padding: 2px 9px; border-radius: 10px; background: transparent; - border: 1px solid #45454f; color: #9a9aa8; } -.facet:hover { color: #e6e6e6; background: #2c2c34; } -.facet[aria-pressed="true"] { background: rgba(255,106,43,.12); border-color: rgba(255,106,43,.5); - color: #ff6a2b; } -.facet .count { color: #6b6b78; margin-left: 5px; } -.facet[aria-pressed="true"] .count { color: #ff6a2b; } -.facet.clear { border-color: transparent; text-decoration: underline; } -.latency { width: 84px; accent-color: #ff6a2b; } -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(1080px, 96vw); height: min(620px, 84vh); 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; } -.split { display: flex; flex: 1; min-height: 0; } -.list { flex: 1 1 55%; overflow: auto; padding: 8px; border-right: 1px solid #35353d; } -.list:only-child { flex: 1 1 100%; border-right: 0; } -.detail { flex: 1 1 45%; overflow: auto; padding: 8px; } -.cause { position: relative; padding: 8px 4px 8px 24px; border-bottom: 1px solid #2b2b33; } -.cause::before { content: ""; position: absolute; left: 8px; top: 22px; bottom: 8px; width: 1px; - background: #35353d; } -.cause::after { content: ""; position: absolute; left: 4px; top: 10px; width: 9px; height: 9px; - border-radius: 2px; background: #8a8a98; } -.cause[data-kind="mutation"]::after { background: #ae8cff; } -.cause[data-kind="frames"]::after { background: #62a8ff; } -.cause[data-kind="action"]::after { background: #ff6a2b; } -.cause[data-kind="error"]::after { background: #ff6b6b; } -.cause-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; } -.cause-head .seq { color: #8a8a98; } -.cause-head .kind { color: #8a8a98; font-size: 10px; letter-spacing: .1em; + border-radius: 5px; padding: 8px 10px; color: var(--ember); margin-bottom: 10px; + font: 10.5px/1.55 var(--mono); } +.detail-head { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; + margin: -10px -12px 10px; padding: 7px 8px 7px 12px; background: var(--panel); + border-bottom: 1px solid var(--line); z-index: 3; } +.detail-head .what { color: var(--faint); font: 500 9.5px/1.4 var(--ui); letter-spacing: .13em; text-transform: uppercase; } -.cause-head .op { color: #e6e6e6; } -.effect { position: relative; margin-top: 6px; padding-left: 14px; color: #9a9aa8; } -.effect::before { content: ""; position: absolute; left: -12px; top: 8px; width: 20px; height: 1px; - background: #35353d; } -.nearmiss { margin-top: 8px; padding: 6px 9px; border: 1px solid rgba(255,182,72,.28); - background: rgba(255,182,72,.06); border-radius: 5px; color: #ffb86b; } -.nearmiss .warn { text-transform: uppercase; letter-spacing: .1em; font-size: 10px; } -.layer { border: 1px solid #45454f; border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; } -.patch { display: flex; gap: 8px; margin-top: 4px; } -.patch .kind { min-width: 46px; text-align: right; color: #8a8a98; } -.patch .kind.merge { color: #62a8ff; } -.patch .kind.create { color: #3fd39c; } -.patch .kind.delete { color: #ff6b6b; } -.patch .key { color: #e6e6e6; word-break: break-all; } -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.row { cursor: pointer; } -tr.row[aria-selected="true"] 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; } -summary { cursor: pointer; color: #9a9aa8; } -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; } +.detail-head .spacer { flex: 1; } +.no-rows { padding: 20px 14px; font: 11px var(--mono); color: var(--faint); } `; /** @@ -364,14 +465,15 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = root.className = 'root'; - // Explicit beats guessed. Guessed beats colliding with the framework's badge. + // Only ever what you asked for. Guessing from an element name got this + // wrong: a framework whose badge is present but not in this corner, or not + // rendered at all, still matched, and the launcher lifted itself off the + // corner for no reason. Sitting where you put it beats a clever guess. if (options.offset !== undefined) { root.style.bottom = `${String(options.offset)}px`; root.setAttribute('data-offset', 'set'); } else { - const crowded = doc.querySelector(BADGES) !== null; - - root.setAttribute('data-offset', crowded ? 'badge' : 'none'); + root.setAttribute('data-offset', 'none'); } shadow.append(root); @@ -847,6 +949,57 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = const blockText = (one: Block): string => [describe(one.entry), ...one.effects.map(describe)].join(' '); + /** The letter in the square beside a cause. */ + const markOf = (entry: LogEntry): string => + entry.kind === 'mutation' + ? 'M' + : entry.kind === 'frames' + ? 'F' + : entry.kind === 'action' + ? 'Y' + : entry.kind === 'error' + ? 'E' + : '·'; + + /** Wall clock, to the millisecond. Two causes 4ms apart are a different story. */ + const clockOf = (at: number): string => { + const when = new Date(at); + const pad = (value: number, size = 2): string => String(value).padStart(size, '0'); + + return `${pad(when.getHours())}:${pad(when.getMinutes())}:${pad(when.getSeconds())}.${pad( + when.getMilliseconds(), + 3, + )}`; + }; + + /** What the effect did, as one word, so the sentence after it can be data. */ + const verbOf = (entry: LogEntry): string => { + switch (entry.kind) { + case 'invalidated': + return 'reached'; + case 'placed': + return 'placed'; + case 'fetch': + return 'fetch'; + case 'settle': + return 'settled'; + case 'error': + return 'failed'; + default: + return entry.kind; + } + }; + + /** Green for something that worked, coral for a failure, faint for a no-op. */ + const toneOf = (entry: LogEntry): string => + entry.kind === 'error' + ? 'bad' + : entry.kind === 'placed' + ? 'miss' + : entry.kind === 'settle' || entry.kind === 'invalidated' + ? 'good' + : ''; + /** The word in the eyebrow. `action` is rendered as what it is: you. */ const kindOf = (entry: LogEntry): string => entry.kind === 'action' ? 'you' : entry.kind === 'frames' ? 'frames' : entry.kind; @@ -860,9 +1013,11 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = const head = el('div', 'cause-head'); node.setAttribute('data-kind', one.entry.kind); + node.append(el('span', 'mark', markOf(one.entry))); head.append(el('span', 'seq', `#${String(one.entry.seq)}`)); head.append(el('span', 'kind', kindOf(one.entry))); head.append(el('span', 'op', describe(one.entry))); + head.append(el('span', 'when', clockOf(one.entry.at))); node.append(head); const raised = raisedBy(one.entry); @@ -872,10 +1027,16 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = // The single most common cause of an invalidation that silently did not // happen, and invisible without this. if (one.entry.kind === 'mutation' && one.entry.unresolved.length > 0) { - node.append(pills(one.entry.unresolved, 'skipped, resolved to nothing')); + node.append(pills(one.entry.unresolved, 'skipped')); } - for (const effect of one.effects) node.append(el('div', 'effect', describe(effect))); + for (const effect of one.effects) { + const row = el('div', 'effect'); + + row.append(el('span', `verb ${toneOf(effect)}`, verbOf(effect))); + row.append(el('span', 'said', describe(effect))); + node.append(row); + } for (const miss of missedBy(one)) node.append(missBanner(miss)); @@ -915,7 +1076,10 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = // it is just as much a near miss. const carried = devtools.tags().map((row) => row.tag); - return nearMisses(missed, carried, 3); + // The closest one only. `nearMisses` sorts most-suspicious first, and + // three banners for one cause is a wall you skim rather than a warning you + // read. The rest are a click away on the explain tab. + return nearMisses(missed, carried, 1); }; const missBanner = (miss: NearMiss): HTMLElement => { @@ -935,9 +1099,9 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = }; const pills = (values: readonly string[], label: string): HTMLElement => { - const wrap = el('div'); + const wrap = el('div', 'pillrow'); - wrap.append(el('span', 'dim', `${label}: `)); + wrap.append(el('span', 'pilllabel', label)); if (values.length === 0) wrap.append(el('span', 'dim', 'none')); else for (const value of values) wrap.append(el('span', 'pill', value)); @@ -1299,12 +1463,13 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = ); } - const blocks = trace() - .filter((one) => matches(blockText(one))) - .slice(-200) - .reverse(); + const traceSource = trace().filter((one) => passes({ text: blockText(one) })); + + body.append(chipBar(traceSource, TRACE_FACETS)); + + const blocks = narrow(traceSource, TRACE_FACETS).slice(-200).reverse(); - if (blocks.length === 0) body.append(el('p', 'dim', 'nothing here')); + if (blocks.length === 0) body.append(el('p', 'no-rows', 'Nothing matches.')); else for (const one of blocks) body.append(causeBlock(one)); break; @@ -1861,6 +2026,14 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = test(row: T): boolean; } + const TRACE_FACETS: readonly Facet[] = [ + { id: 'mutations', label: 'mutations', test: (one) => one.entry.kind === 'mutation' }, + { id: 'frames', label: 'frames', test: (one) => one.entry.kind === 'frames' }, + { id: 'yours', label: 'yours', test: (one) => one.entry.kind === 'action' }, + { id: 'errors', label: 'errors', test: (one) => one.entry.kind === 'error' }, + { id: 'misses', label: 'near misses', test: (one) => missedBy(one).length > 0 }, + ]; + const QUERY_FACETS: readonly Facet[] = [ { id: 'mounted', label: 'mounted', test: (row) => row.mounts > 0 }, { id: 'unmounted', label: 'unmounted', test: (row) => row.mounts === 0 }, @@ -1922,6 +2095,8 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = const bar = el('div', 'facets'); const on = chosen(); + bar.append(el('span', 'only', 'only')); + for (const one of all) { const button = el('button', 'facet'); @@ -1938,6 +2113,11 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = bar.append(button); } + bar.append(el('div', 'spacer')); + bar.append( + el('span', 'shown', `${String(narrow(source, all).length)} of ${String(source.length)}`), + ); + if (on.size > 0 || filter !== '') { const clear = el('button', 'facet clear', 'clear'); @@ -1990,6 +2170,7 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = cell('tags', 'tags', String(counts.indexedTags), `${String(counts.stampedTags)} stamped`); cell('tombstones', 'tombstones', String(counts.tombstones)); cell('tracked', 'tracked', String(counts.tracked)); + strip.append(spark()); return strip; }; @@ -2043,6 +2224,44 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = return bar; }; + /** + * Causes per slice of the log, drawn small. + * + * Not a chart, a shape: what it answers is "is the cache busy right now, and + * was it busy a moment ago", which is the question the numbers to its left + * cannot answer because they are all instantaneous. + */ + const spark = (): HTMLElement => { + const wrap = el('div', 'vital spark'); + const entries = devtools.log(); + const buckets = 24; + const counts = new Array(buckets).fill(0); + + for (const [index, entry] of entries.entries()) { + if (entry.kind !== 'mutation' && entry.kind !== 'frames' && entry.kind !== 'fetch') continue; + + counts[Math.min(buckets - 1, Math.floor((index / Math.max(1, entries.length)) * buckets))] += + 1; + } + + const peak = Math.max(1, ...counts); + const points = counts + .map((value, index) => { + const x = (index / (buckets - 1)) * 100; + const y = 26 - (value / peak) * 22; + + return `${String(Math.round(x * 10) / 10)},${String(Math.round(y * 10) / 10)}`; + }) + .join(' '); + + wrap.innerHTML = + ''; + + return wrap; + }; + /** One icon button on the rail. Icon only, so the tooltip carries the name. */ const railButton = ( paths: string, @@ -2189,6 +2408,121 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = return 'idle'; }; + /** + * The row that names what you are looking at. + * + * The panel had no title bar at all: it opened straight onto tabs, so + * nothing said which cache this was, which session, or which version of the + * runtime you were debugging. Those three are the first questions when two + * tabs of the same app are open. + */ + const titleBar = (): HTMLElement => { + const bar = el('div', 'titlebar'); + const mark = el('span', 'mark'); + + mark.innerHTML = MARK; + bar.append(mark); + bar.append(el('span', 'name', 'devtools')); + + const crumb = el('span', 'crumb'); + + // Session, not identity: the cache is emptied on an identity change, so a + // rising session number is the thing that tells you the log above spans + // two principals and the earlier half explains nothing about this one. + crumb.append(el('span', 'sep', '/')); + crumb.append(el('span', undefined, 'session')); + crumb.append(el('b', undefined, String(devtools.session))); + crumb.append(el('span', 'sep', '/')); + crumb.append(el('b', undefined, `${String(devtools.log().length)} events`)); + bar.append(crumb); + bar.append(el('div', 'spacer')); + bar.append(dockBar()); + + const density = el('button', 'ico tip'); + + density.innerHTML = icon(''); + density.setAttribute('data-act', 'density'); + density.setAttribute('data-tip', 'Compact rows'); + density.setAttribute('aria-label', 'Compact rows'); + density.setAttribute('aria-pressed', String(compact)); + density.addEventListener('click', () => { + compact = !compact; + render(); + }); + bar.append(density); + + const close = el('button', 'ico tip tip-r'); + + close.innerHTML = icon(''); + close.setAttribute('data-tip', 'Close the panel'); + close.setAttribute('aria-label', 'Close the panel'); + close.addEventListener('click', () => { + open = false; + render(); + }); + bar.append(close); + + return bar; + }; + + /** How many rows each tab would show, so you can see before you click. */ + const countFor = (name: Tab): number | undefined => { + switch (name) { + case 'trace': + return devtools.log().length; + case 'network': + return devtools.watchingRequests ? devtools.requests().length : undefined; + case 'queries': + return devtools.queries().length; + case 'entities': + return devtools.store().records; + case 'overlay': + return devtools.overlays().length; + case 'tags': + return devtools.tags().length; + case 'sockets': + return devtools.sockets().length; + default: + return undefined; + } + }; + + /** + * The line along the bottom, which is where the numbers that are true of the + * whole session belong rather than in a tab that happens to be open. + */ + const statusBar = (): HTMLElement => { + const bar = el('div', 'statusbar'); + const counts = devtools.store(); + const pending = devtools.overlays().length; + const orphans = devtools.tags().filter((row) => row.carriers.length === 0).length; + + const cell = (text: string, dot?: string, cls?: string): void => { + const node = el('span', cls); + + if (dot !== undefined) node.append(el('i', `dot ${dot}`)); + + node.append(el('span', undefined, text)); + bar.append(node); + }; + + cell('cache live', 'ok'); + cell(buckets(), undefined, 'buckets'); + cell(`${String(devtools.log().length)} events`); + + if (devtools.dropped > 0) cell(`${String(devtools.dropped)} dropped`); + if (devtools.watchingRequests) cell(`${String(devtools.requests().length)} requests`); + if (pending > 0) cell(`${String(pending)} pending writes`, 'hot'); + + bar.append(el('div', 'spacer')); + + if (orphans > 0) cell(`${String(orphans)} orphan tag${orphans === 1 ? '' : 's'}`, 'warn'); + + cell(`v${String(counts.version)} · ${String(counts.tracked)} tracked`); + + return bar; + }; + /** The four dock modes, as one segmented control. */ const dockBar = (): HTMLElement => { const group = el('div', 'docks'); @@ -2228,7 +2562,12 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = const bar = el('div', 'bar'); for (const name of TABS) { - const button = el('button', undefined, name); + const button = el('button', 'tab'); + const count = countFor(name); + + button.append(el('span', undefined, name)); + + if (count !== undefined) button.append(el('span', 'n', String(count))); button.setAttribute('aria-selected', String(name === tab)); button.addEventListener('click', () => { @@ -2251,10 +2590,7 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = }); bar.append(search); - const spacer = el('div', 'spacer'); - bar.append(spacer); - - bar.append(el('span', 'dim', buckets())); + const status = statusBar(); const clearCache = el('button', undefined, 'clear cache'); @@ -2266,7 +2602,7 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = selected.clear(); render(); }); - bar.append(clearCache); + status.append(clearCache); // Named for both halves when there is a second half. `devtools.clear()` // empties the frame ring along with the event log, and losing a capture to @@ -2282,32 +2618,7 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = devtools.clear(); render(); }); - bar.append(clearLog); - bar.append(dockBar()); - - const density = el('button', 'ico tip'); - - density.innerHTML = icon(''); - density.setAttribute('data-act', 'density'); - density.setAttribute('data-tip', 'Compact rows'); - density.setAttribute('aria-label', 'Compact rows'); - density.setAttribute('aria-pressed', String(compact)); - density.addEventListener('click', () => { - compact = !compact; - render(); - }); - bar.append(density); - - const close = el('button', 'ico tip tip-r'); - - close.innerHTML = icon(''); - close.setAttribute('data-tip', 'Close the panel'); - close.setAttribute('aria-label', 'Close the panel'); - close.addEventListener('click', () => { - open = false; - render(); - }); - bar.append(close); + status.append(clearLog); const rail = controlRail(); const vitals = vitalsStrip(); @@ -2325,11 +2636,11 @@ export function mountPanel(devtools: Devtools, options: PanelOptions = {}): () = split.append(detail); } - panel.append(bar, vitals); + panel.append(titleBar(), vitals); if (rail !== undefined) panel.append(rail); - panel.append(split); + panel.append(bar, split, status); root.append(panel); }; diff --git a/packages/client-react-devtools/__tests__/mount.test.tsx b/packages/client-react-devtools/__tests__/mount.test.tsx index 7708e1d7e..f3536386f 100644 --- a/packages/client-react-devtools/__tests__/mount.test.tsx +++ b/packages/client-react-devtools/__tests__/mount.test.tsx @@ -3,7 +3,7 @@ import { ClientProvider } from '@forge-go/client-react'; import { act, createElement, StrictMode, useEffect } from 'react'; import type { ReactNode } from 'react'; import { createRoot } from 'react-dom/client'; -import { describe, expect, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import type { Devtools } from '@forge-go/client-devtools'; import { ForgeDevtools, useForgeDevtools } from '../src/dev'; import type { ForgeDevtoolsProps } from '../src/dev'; @@ -204,52 +204,79 @@ describe('ForgeDevtools', () => { }); 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 warnings: string[] = []; + + beforeEach(() => { + warnings.length = 0; + vi.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => { + warnings.push(args.map((arg) => String(arg)).join(' ')); + }); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + const labels = (): string[] => { + const host = [...document.body.children].find((node) => node.shadowRoot !== null); + + // A tab button holds its name and its row count; the name is the first span. + return [...(host?.shadowRoot?.querySelectorAll('.bar button') ?? [])].map( + (node) => node.querySelector('span')?.textContent ?? node.textContent ?? '', + ); + }; + + it('mounts the full panel by default', async () => { const app = mount( createElement( ClientProvider, { client: cache() }, - createElement(ForgeDevtools, { panel: false, open: true }), + 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('queries'); - expect(labels).not.toContain('trace'); + expect(labels()).toContain('trace'); app.unmount(); }); - it('mounts the full panel by default', async () => { + /** + * `panel={false}` used to reach for the lean view. That view is deprecated, + * so honouring it would hand you a worse UI than passing nothing at all. + * Mounting the panel and saying so is the one behaviour that never surprises + * anyone; silently ignoring the prop would be worse than either. + * + * Two components, one warning. A deprecation that fires per render of per + * component is noise you learn to scroll past, which is the opposite of what + * a deprecation is for, so the flag behind it is deliberately per page. + */ + it('mounts the panel even when declined, warning once', async () => { const app = mount( createElement( ClientProvider, { client: cache() }, - createElement(ForgeDevtools, { open: true }), + 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 ?? '', + const app2 = mount( + createElement( + ClientProvider, + { client: cache() }, + createElement(ForgeDevtools, { panel: false }), + ), ); - expect(labels).toContain('trace'); + await waitForPanel(); + + expect(labels()).toContain('trace'); + expect(warnings.filter((line) => line.includes('panel={false}'))).toHaveLength(1); + app2.unmount(); app.unmount(); }); }); diff --git a/packages/client-react-devtools/src/dev.ts b/packages/client-react-devtools/src/dev.ts index 311fc1c75..3443dab92 100644 --- a/packages/client-react-devtools/src/dev.ts +++ b/packages/client-react-devtools/src/dev.ts @@ -7,12 +7,17 @@ export interface ForgeDevtoolsProps { /** Beats the provider and the module default, as everywhere else. */ readonly client?: QueryCache; /** - * The full panel. Defaults to true. + * @deprecated Ignored, and removed in the next major. * - * `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. + * This used to choose between the full panel and the lean six-table view. + * The lean view is deprecated, so `false` now warns once and mounts the + * panel anyway: honouring it would hand you a worse UI than passing nothing + * at all, and silently ignoring a prop is worse than either. + * + * The case for the lean view was bytes, and it does not hold here. The + * effect below is behind a `development` export condition and a `NODE_ENV` + * guard, so none of this reaches your production bundle. What `false` bought + * was a smaller development build and a UI that had not kept up. */ readonly panel?: boolean; /** Start open rather than as a button in the corner. */ @@ -126,10 +131,32 @@ function release(cache: QueryCache): void { * cannot reach it. That is the argument the panel itself makes about * frameworks, drawn one level out. */ +/** + * Said once per page, not once per render. + * + * A deprecation that fires on every render of every component is noise you + * learn to scroll past, which is the opposite of what a deprecation is for. + */ +let warnedAboutPanel = false; + +function warnAboutPanelProp(): void { + if (warnedAboutPanel) return; + + warnedAboutPanel = true; + // eslint-disable-next-line no-console + console.warn( + '[forge] ForgeDevtools: panel={false} is deprecated and ignored; the full ' + + 'panel is mounted instead. The lean view it used to select is deprecated ' + + 'too. Drop the prop.', + ); +} + export function ForgeDevtools(props: ForgeDevtoolsProps = {}): null { const client = useClient(props.client); const { panel = true, open, frames, limit, manager, binder } = props; + if (!panel) warnAboutPanelProp(); + useEffect(() => { let live = true; let unmount: (() => void) | undefined; @@ -177,27 +204,15 @@ export function ForgeDevtools(props: ForgeDevtoolsProps = {}): null { if (entry === undefined) return; - if (panel) { - const { mountPanel } = await import('@forge-go/client-devtools/panel'); - - if (!live) { - releaseOnce(); + const { mountPanel } = await import('@forge-go/client-devtools/panel'); - return; - } - - unmount = mountPanel(entry.devtools, { open }); - } else { - const { mountMini } = await import('@forge-go/client-devtools/mini'); - - if (!live) { - releaseOnce(); - - return; - } + if (!live) { + releaseOnce(); - unmount = mountMini(entry.devtools, { open }); + return; } + + unmount = mountPanel(entry.devtools, { open }); })(); }