Skip to content

Renderer: Pages and Slots

Your renderer is an ESM module that the host dynamically imports into its renderer process. It must default-export a definePluginRenderer() result.

The renderer lifecycle mirrors the backend: register(), then activate(), then deactivate(), with the same semantics. See Backend for the details. This page covers what the renderer adds: contributions and the data plane.

Your UI runs under the host page's Content Security Policy. Scripts load only from the app and from your plugin's own files. Inline scripts, inline event handler attributes (onclick="...") and javascript: URLs are blocked, and frames are blocked.

definePluginRenderer

import { definePluginRenderer } from "@lore-vcs/desktop-plugins-sdk/renderer";
import type { MyContract } from "./contract";

export default definePluginRenderer<MyContract>(() => ({
  register(reg) {
    // reg.provide() calls go here
  },
  activate(ctx) {},
  deactivate(ctx) {},
}));

The factory is called once at import time. The returned object is branded so the host can distinguish a renderer entry from a main entry.

register() must be synchronous. activate() and deactivate() are optional and may be async.

Choosing between React and JsComponent

Before you register anything, decide which kind of component to use. The next two pages, React Components and Hooks and Non-React Components, cover each in detail. The decision is simple:

Consideration React component defineJsComponent
Pages Yes Yes
Slots Yes Yes
SDK hooks (usePluginData, useEvents, ...) Yes No (use ctx.data, ctx.events)
Framework freedom React only Any (vanilla JS, Svelte, Lit, ...)
Prop updates React re-render instance.update(nextProps)

Most plugins should use React. It is simpler and gives you the SDK hooks. Use defineJsComponent when you need a non-React framework or want direct DOM control.

Contributions

A contribution is something your plugin provides to the host UI. There are two kinds:

  • Slot contributions are injected into a host-owned mount point (toolbar, sidebar, row actions).
  • Page contributions are full-tab views mounted inside the repository view.

Both are registered with reg.provide() during register().

What you can provide

Each reg.provide() call accepts a component body that is one of:

Body type Import Surfaces
React component ComponentType<P> from React Slots and pages
lazySlot() wrapper lazySlot from @lore-vcs/desktop-plugins-sdk Slots and pages
defineJsComponent() wrapper defineJsComponent from @lore-vcs/desktop-plugins-sdk Slots and pages

defineJsComponent is a framework-agnostic alternative that receives a raw DOM node. See Non-React Components for the full API. A lazySlot() loader may resolve to either a React component or a JsComponent.

Slot contributions: reg.provide(tag, component, opts?)

The host has a fixed set of slot tags, which are mount points in the UI where plugins can inject components:

Tag Where it renders Props
toolbar.main Main toolbar area EmptySlotProps
toolbar.right Right side of toolbar EmptySlotProps
content.header Content area header EmptySlotProps
sidebar.header Sidebar header EmptySlotProps
sidebar.footer Sidebar footer EmptySlotProps
file-row.actions Action area on each file row FileRowSlotProps
branch-row.actions Action area on each branch row BranchRowSlotProps
revision-row.actions Action area on each revision row RevisionRowSlotProps

Row-level tags pass per-item props:

interface FileRowSlotProps {
  readonly filePath: string;   // relative from repo root
  readonly nodeType: string;   // "file", "directory", etc.
}

interface BranchRowSlotProps {
  readonly branchName: string;
}

interface RevisionRowSlotProps {
  readonly revisionHash: string;
  readonly revisionNumber: number;
}

Slot props must be serializable (strings, numbers, booleans, null, arrays and plain objects of those). The SDK enforces this at compile time for every host slot tag.

Register a component into a slot:

import { definePluginRenderer } from "@lore-vcs/desktop-plugins-sdk/renderer";
import { Badge } from "./Badge";
import { CountChip } from "./CountChip";
import type { MyContract } from "./contract";

export default definePluginRenderer<MyContract>(() => ({
  register(reg) {
    reg.provide("toolbar.right", CountChip, { mode: "prepend" });
    reg.provide("branch-row.actions", Badge, { mode: "append" });
  },
  activate(ctx) {},
  deactivate(ctx) {},
}));

provide() returns a Disposable that removes the contribution when disposed.

Slot modes

  • "append": after existing contributions (default)
  • "prepend": before existing contributions

A third mode, "replace", exists in the SlotMode type, but no host tag currently allows it. Per-tag allowedModes enforces this at compile time.

Page contributions: reg.provide("page:<id>", body, opts)

Pages are full-tab views mounted inside the repository view. Register them with a page: prefixed tag. <id> is a name you choose.

The page body can be a direct React component reference, a lazySlot() wrapper, or a defineJsComponent() wrapper. Page bodies take no props (EmptySlotProps). opts.nav is required.

Direct component reference

The component is bundled eagerly: its code ships in the main renderer bundle.

import { definePluginRenderer } from "@lore-vcs/desktop-plugins-sdk/renderer";
import { ProblemsPage } from "./pages/ProblemsPage";
import type { MyContract } from "./contract";

export default definePluginRenderer<MyContract>(() => ({
  register(reg) {
    reg.provide("page:problems", ProblemsPage, {
      nav: {
        scope: "repository-tabs",
        label: "Problems",
        icon: "ExclamationTriangleIcon",
        priority: 90,
      },
    });
  },
}));

lazySlot() wrapper

Wraps a dynamic import so the host can identify it as a lazy loader. The tab chrome (label, icon) paints immediately from opts.nav, and the page body loads on first navigation:

import { lazySlot } from "@lore-vcs/desktop-plugins-sdk";
import { definePluginRenderer } from "@lore-vcs/desktop-plugins-sdk/renderer";
import type { MyContract } from "./contract";

export default definePluginRenderer<MyContract>(() => ({
  register(reg) {
    reg.provide(
      "page:problems",
      lazySlot(() => import("./pages/ProblemsPage")),
      {
        nav: {
          scope: "repository-tabs",
          label: "Problems",
          icon: "ExclamationTriangleIcon",
          priority: 90,
        },
      }
    );
  },
}));

Note

The bundler may inline the dynamic import, in which case the page code ships in the main bundle as well. The API is correct either way, but do not rely on lazySlot() for code-splitting.

Page options (PageProvideOptions)

  • nav.scope: currently only "repository-tabs" (a tab next to Files / Revisions / Branches).
  • nav.label: tab label text.
  • nav.icon: icon name. See Nav icons below.
  • nav.priority: tab ordering (lower is further left). Pages without a priority sort last. Ties are broken by plugin ID, alphabetically.
  • nav.description: optional text shown as the view's subtitle when the page uses contributesTo.
  • nav.contributesTo: when present, the page renders as an alternate view inside the named host tab's switcher rather than as its own tab. Currently only "branches" is accepted.
  • nav.defaultView: become the target tab's default view instead of the built-in one.
  • keepAlive: whether the page stays mounted when the user navigates away.

nav.icon takes the component name of an EDS icon, without angle brackets. For example, an icon that you would render as <BranchIcon /> is passed as "BranchIcon".

An unrecognized name does not error. The tab renders a question-mark icon instead, and development builds log a warning once per plugin and name.

How a contribution's UI stays up to date

Contributions are static from register() until disposal. There is no dynamic contribution API: you cannot push new props into a contribution or swap it out. The host controls which props a contribution receives (for example the branchName on a branch-row.actions slot), and the plugin cannot change those props.

So how does plugin state reach the UI? Through the data plane:

  1. The backend activate() exposes a data key with an initial value.
  2. The backend updates that key over time, typically from an event subscription.
  3. The component subscribes to the key and re-renders when it changes.
  4. The component combines host props (which row am I?) with plugin data (what should I show for it?).

Walkthrough: data plane pattern

A plugin that shows computed data on branch rows demonstrates the full chain end to end.

Step 1: expose the key (main.ts):

activate(ctx) {
  dataHandle = ctx.data.expose("itemsByBranch", emptySnapshot());

emptySnapshot() returns an initial value (for example { index: {}, summary: { total: 0, lastFetchedAt: null } }). The key exists immediately, so components that subscribe before the first fetch see the empty snapshot rather than undefined.

Step 2: update the key (main.ts):

ctx.events.on("branches.updated", () => {
  fetchAndUpdate(ctx.log);
});

ctx.data.on("repository.current", (repo) => {
  currentRepoPath = repo?.path;
  fetchAndUpdate(ctx.log);
});

Both triggers call fetchAndUpdate, which fetches data and publishes:

const index = buildIndex(items);
dataHandle.set({
  index,
  summary: { total: items.length, lastFetchedAt: new Date().toISOString() },
});

Step 3: subscribe in the component (CountChip.tsx):

const usePluginData = createPluginDataHook<MyContract>();

export const CountChip = memo(function CountChip() {
  const [snapshot] = usePluginData("itemsByBranch");
  const itemCount = snapshot ? Object.keys(snapshot.index).length : 0;

  return (
    <span data-testid="count-chip">
      Items {itemCount}
    </span>
  );
});

The component re-renders whenever dataHandle.set(...) publishes a new snapshot.

Step 4: combine host props with plugin data (Badge.tsx):

export const Badge = memo(function Badge({ branchName }: BranchRowSlotProps) {
  const [snapshot] = usePluginData("itemsByBranch");

  const items = snapshot ? snapshot.index[branchName] : undefined;
  if (!items || items.length === 0) {
    return null;
  }

  return (
    <>
      {items.map((item) => (
        <span key={item.id}>{item.label}</span>
      ))}
    </>
  );
});

branchName comes from the host (it is a prop on every branch-row.actions slot). snapshot comes from the plugin's data plane. The component looks up the items for this branch and renders them, or renders nothing.

Props vs. data

Host props Plugin data
Source Host passes them to the slot Plugin exposes via ctx.data.expose()
Content Describes the surface (branch name, file path, revision hash) Plugin-specific state (analysis results, indexes)
Mutability Read-only; changes when the host re-renders the row Updated by dataHandle.set() on the backend
Access Function parameter (React props / JsComponent props) usePluginData(key) in React, ctx.data.on(key, cb) in JsComponent

A contribution whose visibility depends on runtime state should always be registered and render null when it has nothing to show. Do not try to conditionally register contributions. Register them unconditionally and let the component decide what to render.

Next

With the data-plane pattern in hand, the next two pages cover the two component types you can use to consume it. If you chose React, continue to hooks and EDS primitives. If you chose JsComponent, skip ahead to the imperative API.