Skip to content

ADR-004 — Per-extension bar presentation ​

Context ​

Every first-party extension hand-wrote its bar control, and how that control was presented was baked into the extension. A consumer could not say "icons only", "icon plus value", or "render my memory chip my way", so the bar could not be made to look like the host app it is injected into, and a third-party author's only route to a native-looking control was copying JSX out of the docs.

This is hard to reverse. Presentation is configured through the factory options of nine published subpath entry points, and those option bags are published API just as much as DevToolbarExtension is. A shape chosen wrong here is nine simultaneous deprecations later.

Two constraints bounded the answer:

  • Zero runtime dependencies is a rule (AGENTS.md). Whatever ships must not bundle, vendor or peer-depend on an icon library. Icons are the consumer's assets, passed in.
  • src/core/ was not touched. A global presentation default on <DevToolbar> would need a new field on CompactSlotProps, a contract change that reopens the CONTRACT_VERSION question ADR-003 leaves open. ADR-006 later lifted this for one knob: the Viewer's preset travels through core as CompactSlotProps.preset. Everything else below still stays out of core.

Decision ​

Each extension factory gains one option, presentation, holding four knobs: a preset, a consumer-supplied ReactNode icon (or a function returning one), an optional render callback over that extension's own view data, and an optional accessible-name override. Presentation becomes the consumer's decision, per extension, while the extension keeps the trigger element, its data-dtb-* state attributes and its accessible name — a preset changes text, not state.

The vocabulary and resolvers live in src/kit/, which is where shared extension glue belongs and which is already a published subpath. No icon asset enters the package.

The option is named presentation, not compact: compact already names the slot on DevToolbarExtension, and two things called compact is a vocabulary collision.

"default" is a member of the preset enum and resolves to null, so each extension reads parts === null ? <today's tree> : <driven tree>. That makes "today's output is byte-identical" a structural property of the resolver rather than a truth-table coincidence, which is what makes the compatibility claim provable.

Group C takes two knobs, not four ​

/ext/agent and /ext/command-menu publish Pick<CompactPresentation<TView>, "icon" | "name"> instead of the whole interface. Neither control has a value or a short bar word distinct from its full label, so every preset but "default" would resolve to a no-op or a lie, and a render callback over a view that never changes is a ReactNode with extra steps. The narrowing is visible rather than silent — presentation: "icon" is a compile error on those two — and it stays a Pick of the shared interface so icon and name mean the same thing everywhere and a widening later is additive.

Hard rule: a ReactNode never enters a store snapshot ​

The extension stores are signature-based: they build a string signature and republish only when it changes. A ReactNode cannot be signed — left out of the signature it never publishes, JSON.stringify'd into it it republishes on every tick, and anything that serialises a snapshot (diagnostics()) is one refactor away from a circular-structure throw.

Therefore PromotedFlag.icon is not widened to ReactNode: it is copied into the snapshot as FlagView.promotedIcon. Rich icons arrive via PromotedFlag.presentation.icon, which is config held in the factory closure, never a snapshot member. The existing icon?: string stays for back-compat glyphs.

Deliberate deviation: the ⋮ menu always paints text — except under render ​

The overflow menu paints full text under every preset, enforced in the resolver so it holds by construction. It is not enforced for render: a callback is honoured in the bar and in the menu alike, with ctx.isOverflowed as the hook.

A preset is the library's opinion and should be safe by construction; a callback is the consumer taking the wheel, and silently discarding their output in one of two locations is a worse surprise than a documented sharp edge. The cost: a menu row that is named by its content (/ext/metrics' per-metric rows) and paints no text is left named by its title alone. Naming those rows with an aria-label by default is left open — it would change the default DOM and the announced name for every user to cure an edge a consumer has to opt into.

Reversing the deviation — ignoring render when overflowed — is a two-line change if the guarantee is later preferred over the consistency.

Chip's icon / iconProps slots stay, with zero first-party importers ​

First-party chips pass their icon and text as Chip's children, because ctx.fallback has to be one children tree — the same construction handed to render and painted when there is none — and a render that replaced a whole slotted Chip would take the severity dot and data-dtb-status with it. The slots remain as third-party surface, for an author whose control genuinely is a plain slotted chip with no render to honour. They were kept because the approved plan specified them; kit's admission bar is "three users, or a third party asking", so if no third party asks, removal stays a live option.

Alternatives considered ​

OptionWhy not
Bundle an icon setA runtime dependency, or thousands of inlined glyphs in a package whose whole pitch is that it ships none.
Vendor icon path data into the packageThe dependency without the upstream: our bytes, our licence audit, our staleness, and still the wrong icons for somebody's design system.
An optional icon peer dependencyBuys an import the consumer can already write, and adds a third optional peer next to axe-core and @testing-library/react, which earn their place. Consumers pass ReactNode; they need nothing from us.
Four sibling options — preset + icon + render + nameFour names × nine extensions is 36 new option-bag entries, and MetricsOptions already has 15 fields. The four are meaningless apart: icon without a preset that paints it does nothing. Grouping also buys the shorthand — presentation: "icon" is the 90% case in one word.
presentation: CompactPreset | ((data, ctx) => ReactNode)The union cannot express both, and both is a real case: "custom when severity is bad, the preset otherwise" needs preset and render together. It also leaves nowhere to put icon.
A composable { icon, label, value } record instead of a preset enumReads as more flexible and is worse: three independent axes (icon on/off × label none/short/full × value on/off) is 12 combinations, most meaningless, all of which the resolver and its tests would owe an answer. A closed enum of six is the six that make sense, named.
A global presentation default on <DevToolbar>Needs a new CompactSlotProps field, so a contract change and the ADR-003 question. Nine per-extension options are more typing and no new versioning debt.
Expose runtime on the returned extension objectWould make the callback tier redundant — a consumer with the runtime can render whatever they like. Rejected because it promotes MetricsRuntime from "exported type" to "the thing consumers render against", which is a far larger and more permanent published surface than a typed render parameter.

Risk accepted ​

RiskLikelihoodImpactMitigation
Contravariance. A view type that is only read may gain and lose optional fields freely; as a render/icon/name parameter it becomes contravariant, so renaming a field breaks consumer callbacks, not just consumer readersHigh — these types change oftenA field rename becomes a breaking change for seven extensions at oncePass an existing view type only where it genuinely is a display type (MetricView, FlagView); purpose-build a narrow one otherwise, as DiagnosticsBarView does rather than welding DiagnosticsSnapshotState into the API
A future refactor widens something into a snapshot that carries a ReactNodeLow, but silent until it throwsA circular-structure throw inside a click handler, or a store that republishes every 250 msThe hard rule above, plus a serialisation test that promotes a flag with a JSX icon and asserts JSON.stringify(runtime.diagnostics()) succeeds and contains no React element
Collapse settling. "icon" can be ~4× narrower than "default", so nine extensions can each swing tens of pixels between bar and overflowMedium at one specific window widthChips appear to flicker, or more items stay in ⋮ than need toThe collapse machine terminates the 2-cycle by design and reports latched; a collapse.test.ts case drives a 4× swing on one id and asserts it settles

Consequences ​

  • Presentation is configured per extension, next to the control it presents — including PromotedFlag.presentation, because a promoted flag is its own bar control. There is no one Consumer Option that restyles the whole bar.
  • The nine factory option bags are a published API surface that changes more often than the contract does. A PR touching them says so in its description even though CONTRACT_VERSION has not moved.
  • data-dtb-part, data-dtb-severity, data-dtb-status and the rest never depend on the preset. Severity children render outside both the preset and render, under every preset including "icon". Consumer CSS and the Playwright specs select on those hooks.
  • --dtb-glyph-size defaults to 1.15em inside the kit sheet rather than becoming a token in src/styles.css, so glyphs inherit the density font-size switch for free.

Released under the MIT License.