@page-engine/page-runtime-browser
v0.5.1
Published
Browser runtime host and trusted renderer ABI for PageEngine execution plans.
Readme
@page-engine/page-runtime-browser
Browser runtime and trusted renderer ABI for the PageEngine declarative front-end engine.
Consumes page.execution-plan/v1 (never Page Source or Runtime Manifests),
mounts trusted web-component renderers, and runs the engine's closed
interaction loop: event routing, the read-only Query Gateway, the Command
Gateway write path, context state, and the standard collection query
semantics. Renderer assets integrate through the TrustedRendererHandle ABI
(light-DOM, framework-agnostic from the engine's perspective) — the
renderer-adapter-react and renderer-adapter-vue3 packages implement it
for their frameworks.
- Depends only on
@page-engine/page-contractsand@page-engine/page-runtime-core. - Browser-safe synchronous SHA-256 verification; no network or clock access inside the runtime.
Install
npm install @page-engine/page-runtime-browserRequires Node >= 22.12 (for tooling); the runtime itself targets browsers. ESM only.
Minimal example
import { mountPageRuntime } from "@page-engine/page-runtime-browser";
const controller = new AbortController();
const mounted = await mountPageRuntime({
plan, root,
dependencies: { rendererRegistry, queryGateway, correlationIdFactory },
signal: controller.signal, // optional; also destroys a ready runtime
rendererConcurrency: 4, // optional; integer 1–16, default 4
});
if (!mounted.ok) console.warn(mounted.diagnostics);
// On host invalidation/unload, even while mountPageRuntime is still pending:
controller.abort();
// The existing mounted.handle.destroy() path remains available and idempotent.Renderer preparation and cancellation
Independent rendererRegistry.resolve(binding) calls run with bounded
concurrency. A session deduplicates the complete module identity
(rendererRef, rendererDigest, entryAsset, entryAssetDigest,
elementName, protocol), then checks every module before creating page
DOM. Widget DOM order and the plan's mountOrder stay deterministic. The
old call without new options still works; set rendererConcurrency: 1 if
an existing loader needs serial resolution.
Resolve describes a module, not widget state. Its createHandle() must
return a fresh handle for each widget, including multiple widgets sharing
the same module. Modules/promises shared across sessions remain host-owned.
The optional preload hint still only warms bytes: it must not execute
modules or register elements. Concurrent imports happen through resolve.
An aborted mount returns ok: false with runtime.mount-aborted, stops
starting new resolves and releases the root without waiting for pending
imports. Late results cannot create handles, mount or release a replacement
runtime's root. Aborting a ready runtime is equivalent to destroy() and
cancels its queries, commands, listeners and refresh subscriptions.
Synchronous renderer/host callbacks finish before their returned resources
are cleaned up. Native module evaluation itself cannot be undone.
Failure/destroy releases all returned handles, including handles never
mounted and handles whose mount threw. Unattempted handles are released in
reverse creation order, then attempted mounts in reverse attempt order.
unmount() must tolerate an unmounted or partially mounted handle. Factories
that throw before returning a handle own cleanup of their unreturned resources.
The React and Vue adapters already support this cleanup contract.
Mount diagnostics
Existing runtime.renderer-mount-failed and /runtime/mount are preserved.
RuntimeMountDiagnostic and telemetry add optional stage, widgetId,
rendererRef and causeCode fields. Stages are renderer-resolve,
renderer-identity, renderer-create-handle, renderer-mount and
runtime-initialize; cause codes distinguish loader, identity, factory,
mount and initialization failures. Raw exceptions, stacks, asset URLs and
business data are not copied to diagnostics/telemetry. A throwing telemetry
sink does not affect cleanup or the result.
runtime.renderer-concurrency-invalid rejects invalid concurrency options
before the root is claimed. See docs/page-engine-eng01-eng02.md in the
repository for tests, measurements and isolated integration instructions.
Applications should usually install @page-engine/page-standalone-host
(which builds on this runtime) and framework adapters, not this package
alone. See the monorepo README for the runtime contract details and docs/
for the phase design documents.
