Ui eng vision widget promoter

From ChromeDevTools/devtools-frontend · View interactive version

Ui eng vision widget promoter is an AI agent skill from the GitHub repository ChromeDevTools/devtools-frontend. Promotes legacy views to modern UI.Widget classes, hooks up performUpdate() rendering, and exports default views.

How to use this skill

Skill file

Subskill: Widget Promoter (Pass 3)

This subskill completes the architectural transition, upgrading the component

from legacy base classes (like SimpleView or custom wrapper layouts) into

clean UI.Widget classes that use native update rendering delegates.


1. Widget Promotion Guidelines

  1. Change Class Inheritance:

sub-layouts like UI.Widget.VBox).

initializations or access .element directly for manual append

operations.

  1. Upgrade View Delegates & Inject View:

view layout (using named imports import {html, render} from '../../ui/lit/lit.js';):

```typescript

export const DEFAULT_VIEW: View = (input, output, target) => {

render(html..., target);

};

```

```typescript

class MyWidget extends UI.Widget.VBox {

static override readonly INJECT = [SDK.TargetManager.TargetManager] as const;

#targetManager: SDK.TargetManager.TargetManager;

#view: View;

constructor(

element?: HTMLElement,

[targetManager]: UI.Widget.WidgetDependencies<typeof MyWidget> = [],

view: View = DEFAULT_VIEW,

) {

super(element);

this.#targetManager = targetManager;

this.#view = view;

}

```

that uses useShadowDom: 'pure' (Widget<ShadowRoot>) while temporarily

retaining a legacy positional constructor overload:

1. Place constructor(element?: HTMLElement, view?: View); last

before the implementation signature so

ConstructorParameters<typeof MyWidget> resolves the declarative

overload for widget() and createViewFunctionStub().

2. Type View's target parameter as HTMLElement|ShadowRoot so it

satisfies ViewFunctionHelpers.ts's ViewFunctionLike

(target: HTMLElement) under strictFunctionTypes:

```typescript

export type View = (input: ViewInput, output: undefined, target: HTMLElement|ShadowRoot) => void;

export class MyWidget extends UI.Widget.Widget<ShadowRoot> {

readonly #view: View;

#text = '';

#needsUpdate = true;

constructor(legacyText: string, view?: View);

constructor(element?: HTMLElement, view?: View);

constructor(textOrElement?: string|HTMLElement, view: View = DEFAULT_VIEW) {

super(textOrElement instanceof HTMLElement ? textOrElement : undefined, {useShadowDom: 'pure'});

this.#view = view;

if (typeof textOrElement === 'string') {

this.#text = textOrElement;

this.performUpdate();

}

}

override wasShown(): void {

super.wasShown();

if (this.#needsUpdate) {

this.requestUpdate();

}

}

override performUpdate(): void {

this.#needsUpdate = false;

this.#view({text: this.#text}, undefined, this.contentElement);

}

}

```

```typescript

override performUpdate(): void {

this.#view(this.viewInput, this.viewOutput, this.contentElement);

}

```

  1. Clean Up Legacy Wrappers:

```typescript

html${widget(MyWidgetClass, {params})}

```

decouple any direct accesses to .element.

  1. Verify Full MVP Architecture Completeness:

2. Safety & Verification Rules


🔍 Mental Audit (Internal Self-Correction)

Before reporting back or committing, re-read the instructions and verify:

  1. ❓ Decoupling: Did I remove all direct .element or .contentElement couplings from instantiator files?
  2. ❓ Inheritance: Does the class now cleanly inherit from UI.Widget or its variants?
  3. ❓ Injectability & Dependencies: Is the constructor signature (element?: HTMLElement, [...]: WidgetDependencies, view: View = DEFAULT_VIEW) (omitting WidgetDependencies when INJECT is empty)?
  4. ❓ Lifecycle & Reactivity: Does presenter code call this.requestUpdate() asynchronously (no synchronous performUpdate()), with non-destructive wasShown()/willHide() subscriptions?
  5. ❓ No Legacy Controls: Are all TreeOutline/TreeElement subclasses, ListControl, and InplaceEditor instances eliminated before using Fixed: <id>?
  6. ❓ Build: Does the code compile and do tests pass?
  7. ❓ CSS @scope Completeness: Does the Light DOM widget satisfy @devtools/no-unscoped-light-dom-styles (removed from the eslint.config.mjs burndown list) and plugin/check_scope_selectors (:scope instead of :host, theme-aware tokens) before marking Fixed: <id>?
  8. ❓ ES Private Fields Cleanup: Are internal private members migrated to #private and is the file removed from the @devtools/prefer-private-class-members ignore list in eslint.config.mjs before marking Fixed: <id>?
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.