Developer guide

Build self-contained React widget bundles from one component library

Use normal npm development, then build versioned widget artifacts with explicit dependencies, host profiles, and reproducible provenance.

Draft preview — this article has not been published.

By ELFUpdated Evidence reviewed

Maintain one source library and produce a separate artifact for each supported host. A small widget can carry the code it needs without becoming a hand-maintained fork of your React components.

Documentation reviewed November 7, 2026. This guide proposes a build discipline. Host limits and real-client compatibility still need verification for the selected delivery profile.

“No runtime npm import” does not mean “no npm”

An authoring-time statement such as import { Card } from "@example/bricks" is useful to a bundler. A browser needs a resolvable URL or a configured import-map entry for a module specifier. It does not discover installed packages the way a Node project does. MDN's browser module guide documents that resolution model.

Three different delivery strategies follow:

StrategyRuntime requirementGood reason to choose it
Bundled artifactExecute the delivered JavaScript and styles.The host needs a compact, independently renderable widget.
External URL modulesPermit the relevant resource origins and module loading.The host explicitly supports those assets and the reliability tradeoff is acceptable.
Host-provided dependenciesSupply a documented, compatible runtime.The host publishes and maintains that contract.

Our portable default is the first. It removes a class of runtime dependency discovery problems. It does not establish that every host bans URL imports.

The phrase “byte-identical vendored copy” needs an object: identical to which bytes? Bundlers transform source. If identical distributed artifacts matter, compare the final artifact hashes. If source provenance matters, record the source revision and dependency lockfile. Avoid promising that minified JavaScript is byte-identical to an npm package's source files.

Separate package publication from widget production

A React package should be easy for an application to consume. A widget artifact should be ready for a host to execute. Give them separate entry points and build settings.

Our recommended package layout is:

AreaContents
domain/Schemas, validators, migrations, and commands with no browser dependency.
react/Controlled views, optional local wrappers, and accessible styles.
runtime/Cached store and controller contracts.
adapters/Individual host implementations behind explicit capability descriptions.
entries/Small applications that select a controller and mount a view.
build/Profiles, artifact assembly, validation, and provenance.

For a published library, declare the React version range it supports and avoid shipping an accidental second React runtime into the consumer's application. React identifies duplicate copies and mismatched renderer versions as causes of hook failures. React's invalid-hook-call guidance explains that risk.

For a self-contained iframe entry point, bundle the React runtime and renderer needed by that entry point unless the host explicitly provides them. Separate iframes do not need to share a single global React instance. What matters is that each mounted React tree uses compatible runtime and renderer modules.

Build a concrete entry point

An entry point should select a host adapter, construct the controller, and mount one root. It should import only the components needed by that widget. Avoid a registry that eagerly imports an entire component catalog, chart stack, and editor framework for a two-control calculator.

A minimal JavaScript build can begin with:

esbuild src/entries/checklist.tsx \
  --bundle \
  --platform=browser \
  --format=iife \
  --minify \
  --outfile=dist/checklist.js \
  --metafile=dist/checklist.meta.json

esbuild's external setting preserves imports for runtime resolution, while code splitting creates additional chunks. Neither belongs in a strict single-artifact profile unless the artifact assembler also satisfies the resulting runtime requirements. Inspect the build output rather than assuming one entry point always produces one file. esbuild API

This command compiles JavaScript; it is not a complete host artifact. Your assembler must handle emitted CSS, fonts and images, a mount node, initial data, and the host's accepted HTML shape. OpenAI's MCP UI guidance demonstrates building React code and embedding it in a UI resource. OpenAI MCP UI build guide

Make delivery profiles explicit

A profile should describe both policy and evidence:

type DeliveryProfile = {
  id: string;
  documentShape: "fragment" | "document";
  bundleDependencies: boolean;
  allowExternalAssets: boolean;
  maxHtmlBytes?: number;
  evidence: "official" | "observed" | "local-design";
  reviewedAt: string;
};

Do not assign the same byte limit or document shape to all hosts because their previews look similar. For an experimentally observed host limit, keep the evidence label next to the limit. For a native authoring profile, validate against the current environment before submission. For a hosted Site, use its deployment build instead of wrapping the application in an inline-widget fragment.

Keep theme mapping in the profile or adapter too. The reusable component should consume your semantic tokens; the entry point maps those tokens to the host's documented or observed values and provides readable fallbacks.

Verify the assembled artifact

Validate final UTF-8 bytes after HTML assembly, including styles and initial data. Confirm there are no unresolved package imports, unexpected dynamic chunks, undeclared external resources, or environment-specific filesystem paths. Scan for client secrets and preserve dependency license notices as required by the actual licenses.

Use a host-equivalent sandbox for layout and interaction checks. Test keyboard controls, narrow widths, light and dark themes, initialization failures, and missing capabilities. Then run a small real-host smoke check for each adapter you claim is supported. A screenshot proves appearance; a persistence claim needs a persistence test.

When embedding initial data, serialize it safely for its HTML context. Do not concatenate arbitrary user strings into executable JavaScript or markup. Keep code artifacts immutable and load business records through their separate authority when the host supports that design.

Preserve enough provenance to rebuild and retire artifacts

Record the source revision, package versions, lockfile hash, build tool version, delivery profile, output byte count, artifact hash, license inventory, and state-schema range. Store any real-host test result with the artifact it tested.

An artifact version and a data-schema version solve different problems. You may rebuild identical data handling with new styles, or deploy a migration without replacing the component's public props. Do not use a bundle hash as a user's document ID.

The practical result is one maintained library with reproducible host artifacts. Start with the portable React contract, then choose the OpenAI surface or experimental Hatch adapter that matches the experience.