Skip to main content

Views

A React surface the host mounts.

import { function defineMod(definition: ModDefinition): Mod
The entry point of the SDK. A mod's module default-exports one `defineMod` call and nothing else. The returned value is data. It registers nothing, starts nothing, and touches no host state. The host folds it twice. At build time it runs the module in a throwaway sandbox and reads the value to derive the serializable manifest. At runtime it folds the same value again to wire your handlers into their lanes: ext-host for commands, tools, effects, and hooks; the sandboxed renderer for views. That double fold is why the module must be pure. It is re-executed to produce the manifest, so anything at the top level, a file read, a network call, a timer, a `console` line, runs during a build with no host attached. Put behavior inside handlers: `run`, `activate`, `handle`.
@example```ts export default defineMod({ metadata: { displayName: 'Review', description: 'Review helpers for the current change.', }, commands: [ command({ id: 'review.open', title: 'Review: Open', run: openPanel }), slashCommand({ id: 'review', description: 'Review this change', run: review }), ], ai: { tools: [reviewTool], }, }); ```@categoryAuthoring
defineMod
, function view(input: ComponentViewInput): ComponentView
Declare a panel the host docks, floats, or opens in its own window. You hand the host a module reference, not a mount callback. The host owns the React root, mounts your component in a sandboxed renderer webview, and re-renders it on live edits. That webview has no Node access, so it reaches the ext-host half of the same mod through `ctx.action(...)` and shared state, never a shared object. `editorExtension` and `canvasElement` are the renderer-native alternative: they run in the host's own renderer and share its `lexical` and `react` instances. Use `view` when you are drawing the panel yourself. Use treeView when the content is a hierarchy of rows and you want the host's native tree with selection and inline actions.
@categoryAuthoring
view
} from '@modular/sdk';
export default function defineMod(definition: ModDefinition): Mod
The entry point of the SDK. A mod's module default-exports one `defineMod` call and nothing else. The returned value is data. It registers nothing, starts nothing, and touches no host state. The host folds it twice. At build time it runs the module in a throwaway sandbox and reads the value to derive the serializable manifest. At runtime it folds the same value again to wire your handlers into their lanes: ext-host for commands, tools, effects, and hooks; the sandboxed renderer for views. That double fold is why the module must be pure. It is re-executed to produce the manifest, so anything at the top level, a file read, a network call, a timer, a `console` line, runs during a build with no host attached. Put behavior inside handlers: `run`, `activate`, `handle`.
@example```ts export default defineMod({ metadata: { displayName: 'Review', description: 'Review helpers for the current change.', }, commands: [ command({ id: 'review.open', title: 'Review: Open', run: openPanel }), slashCommand({ id: 'review', description: 'Review this change', run: review }), ], ai: { tools: [reviewTool], }, }); ```@categoryAuthoring
defineMod
({
metadata: ModMetadatametadata: { ModMetadata.displayName: stringdisplayName: 'Panels', ModMetadata.description: stringdescription: 'Contributed surfaces' }, views?: readonly View[] | undefinedviews: [ function view(input: ComponentViewInput): ComponentView
Declare a panel the host docks, floats, or opens in its own window. You hand the host a module reference, not a mount callback. The host owns the React root, mounts your component in a sandboxed renderer webview, and re-renders it on live edits. That webview has no Node access, so it reaches the ext-host half of the same mod through `ctx.action(...)` and shared state, never a shared object. `editorExtension` and `canvasElement` are the renderer-native alternative: they run in the host's own renderer and share its `lexical` and `react` instances. Use `view` when you are drawing the panel yourself. Use treeView when the content is a hierarchy of rows and you want the host's native tree with selection and inline actions.
@categoryAuthoring
view
({
id: stringid: 'panels.outline', title: stringtitle: 'Outline', presentation: DeskPresentationpresentation: { kind: "docked"kind: 'docked', region: DeskRegionregion: 'right' }, icon?: string | undefinedicon: 'CodiconListTree', persistent: booleanpersistent: true, component: ViewComponentReferencecomponent: { ViewComponentReference.module: stringmodule: './views/outline', ViewComponentReference.exportName: stringexportName: 'Outline' }, }), ], });

component is a module reference, not a mount callback. The host owns the React root, so it can re-render your component when you edit it.

view produces a View — a type alias, because a view's props depend on what it declares.

Import from the view entry point​

A view's React code imports from @modular/sdk/view, not from the root entry point:

import type { ViewContext } from '@modular/sdk/view';

export function 
function Outline({ ctx }: {
    readonly ctx: ViewContext;
}): string & $brand<"ModId">
Outline
({ ctx: ViewContextctx }: { readonly ctx: ViewContextctx: ViewContext }) {
return ctx: ViewContextctx.ContextBase.modId: string & $brand<"ModId">
The id of the mod this handler belongs to.
modId
;
}

That subpath is a shared live instance. The host injects React and the @modular/sdk/ui component library into it. If your mod bundles its own copy of either, hooks and context break because two Reacts in one tree do not share state.

This is the single most common way a working view stops working.

Use Components for the shared controls, UI hooks, icons, and material surfaces available inside that module.

The context​

Views receive a ViewContext, wider than the base context.

Styling​

Mod webviews see Modular's own design tokens. They do not get the --vscode-* variable set, so a var(--vscode-foreground) in your CSS silently resolves to its fallback rather than to a real colour.