React Renderer
@surfaceweave/react is an optional Runtime Binding. It consumes Core contracts but does not redefine them.
Install
# Existing React application
npm install @surfaceweave/react@next
# Generic DOM Driver host
npm install @surfaceweave/react@next react-domReact is a peer dependency expected from the application. React DOM is needed only when the application renders React or imports the isolated ./dom entry.
Register components and render
import {
SurfaceRenderer,
createStandardReactComponentRegistry,
} from "@surfaceweave/react";
const reactComponents = createStandardReactComponentRegistry(components);
function DynamicSurface() {
return (
<SurfaceRenderer
surfaceId="order-form"
store={surfaces}
componentRegistry={components}
reactComponents={reactComponents}
mode="workspace"
onActionIntent={(intent) => runtime.handleActionIntent(intent)}
/>
);
}The semantic ComponentRegistry comes from Core. The React registry maps those semantic names to trusted React implementations. Unknown components are rejected or resolved through declared semantic fallback.
Share chat and workspace state
Render the same surfaceId and SurfaceStore twice:
<SurfaceRenderer {...shared} mode="compact" />
<SurfaceRenderer {...shared} mode="workspace" />Both views subscribe to the same Store. A field update from either view writes through its DataBinding and is visible in the other view immediately.
With InMemorySurfaceStore, the renderer uses the optional immutable observation capability and subscribes each rendered node to its binding path. A data-only change rerenders the bound node and any prefix-dependent nodes, not unrelated siblings. Structural operations and Surface replacement rebuild the per-view tree. Custom Stores that implement only the stable SurfaceStore interface use the same node-level read model through the existing subscribe() fallback; they do not need a new required method.
Semantic direction, columns, gap, align, justify, and span values are resolved before conversion to local styles. Compact mode safely reduces multi-column declarations to one column. The same rules are used by the default, React Aria, and Ant Design Packs; see the Semantic Layout guide.
Mount from a non-React DOM host
Import the optional DOM entry when Vue, Svelte, Agentdown, or plain host code owns the mount point:
import { createReactDOMRendererDriver } from "@surfaceweave/react/dom";
const driver = createReactDOMRendererDriver({
store: surfaces,
componentRegistry: components,
reactComponents,
onActionIntent: (intent) => runtime.handleActionIntent(intent),
enabledPackIds: ["default"],
capabilities: ["web"],
});
const view = driver.mount(targetElement, {
surfaceId: "order-form",
mode: "compact",
});
view.update({ surfaceId: "order-result", mode: "workspace" });
view.unmount();react-dom is an optional peer used only by @surfaceweave/react/dom; importing the React package root does not load it. See the Generic Renderer Driver guide for host boundaries and an Agentdown/Vue example.
Security boundary
- Register only trusted component implementations.
- Treat every
ActionIntentas untrusted input at the host boundary. - Do not use
eval, inject raw HTML, or execute values from Surface props. - Keep API clients and credentials in the Host Executor, not components.