← All @molecule/* packages · App templates
@molecule/app-live-preview-iframeProvider bond · live-preview · App (browser) · v1.0.1 · Apache-2.0
Iframe-based live preview provider
npm install @molecule/app-live-preview-iframenpm · Source on GitHub · Implements @molecule/app-live-preview
@molecule/app-live-preview-iframe is a provider bond on the app (browser) side: it implements the live-preview core interface (@molecule/app-live-preview) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { setProvider } from '@molecule/app-live-preview'
import { provider } from '@molecule/app-live-preview-iframe'
setProvider(provider) // once, at app startup (bonds.ts)Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Iframe-based live preview provider for molecule.dev — manages preview STATE
(load-target url, URL-bar currentUrl, Back/Forward history, device
frame, loading/error, loadNonce). A companion renderer (e.g.
@molecule/app-ide-react's preview panel) renders the actual <iframe>
and feeds notifyLoaded / notifyError / recordNavigation back in.
import { setProvider } from '@molecule/app-live-preview'
import { provider } from '@molecule/app-live-preview-iframe'
setProvider(provider) // once, at app startup (bonds.ts)
provider
npm install @molecule/app-live-preview-iframe @molecule/app-live-preview
IframePreviewConfigConfiguration for iframe preview.
interface IframePreviewConfig {
/** Initial preview URL. */
defaultUrl?: string
/** Default device frame. */
defaultDevice?: DeviceFrame
}
IframePreviewProviderIframe-based implementation of PreviewProvider. Manages preview URL, device frame selection,
loading state, and connection status. The actual iframe rendering is handled by a companion React component.
createProvider(config)Creates an IframePreviewProvider with optional default URL and device frame.
function createProvider(config?: IframePreviewConfig): IframePreviewProvider
config — Iframe preview configuration (default URL, default device frame).Returns: An IframePreviewProvider that manages live preview state.
providerPre-instantiated provider singleton.
const provider: IframePreviewProvider
Implements @molecule/app-live-preview interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/app-live-preview'
import { provider } from '@molecule/app-live-preview-iframe'
export function setupLivePreviewIframe(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/app-live-preview ^1.0.1@molecule/app-live-preview
setUrl(sameUrl) is a deliberate no-op — renderers key reloads off
loadNonce. See @molecule/app-live-preview's remarks for the full
renderer contract (molecule:navigate reporting, nav-command Back/Forward,
?_r cache-buster stripping) — this bond implements all of it.
Integration checklist — drive the real preview panel this app renders (use navigate_preview, read_preview_ui, and interact_preview; no mocks), adapt each item to this app's actual preview UI + routes, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
currentUrl, not the raw load target) and
read_preview_ui returns the previewed screen's visible elements + pageText, not
a blank frame.mobile frame narrows the viewport, tablet is mid-width, desktop is wide,
and none shows it unframed/full-width. Switch between two presets and confirm
the framed width ACTUALLY changes — not merely that a button looks selected.loadNonce bump (a repeated setUrl with the same url
is a no-op), so verify the CONTENT updated, not just that a reload fired.currentUrl follows the
client-side route change the app reports via the molecule:navigate message —
the frame does not stay stuck on the old route.canGoBack/canGoForward say there is
nowhere to go (Back disabled at the first entry).error set; an alert/status message in read_preview_ui),
not a frozen blank iframe.