Engineering Notes · Architecture
Reading time · 9 min
Building a Visual Editor Around Portable Code
How isolated rendering, stable identity, and validated editing operations keep StackLiberate’s editor machinery separate from portable website files.

Visual editors have a natural tendency to become entangled with the pages they modify.
The editor inserts selection markers. It registers event listeners. It wraps elements in containers that make positioning easier to compute. It adds attributes, data annotations, and style overrides that support the editing experience.
None of that belongs in the finished website.
When editing instrumentation becomes mixed into the website's authored state, separating it from the delivered artifact becomes harder as the editor gains capabilities.
StackLiberate separates the starting document, accepted changes, and required resources from the machinery used to edit them. The canvas is a projection of that state. A communication layer connects the editing application to the rendered page without making the page itself the authority for saved changes.
The editor exists around the code. It does not live inside it.
The iframe boundary is architectural, not cosmetic
The StackLiberate editor renders the website inside an isolated, cross-origin iframe. This separates the editing application from the page's document and JavaScript environment, rather than merely avoiding CSS collisions.
The parent application communicates with the frame through a structured message bridge. Requests describe actions such as locating a target, measuring its bounds, or applying a visual projection. Responses report observations or completion.
Messages must come from the expected frame and origin. Responses must also correspond to the request being completed. A message arriving is not, by itself, evidence that the current edit has been applied correctly.
The boundary makes cross-frame work explicit and testable. It does not automatically prevent side effects or make every message trustworthy; validation and lifecycle handling remain necessary on both sides.
The bridge connects editing intent to the page
The bridge is editor-specific code installed in the canvas document. It connects editing requests and page observations; it is not the website's public runtime.
It is not the only JavaScript allowed inside the frame. Validated templates can include admitted scripts for navigation, animation, and other supported behavior. Those public interactions must be distinguished from selection tools and editing commands.
It serves several roles:
- Listens for pointer events and reports element identity to the parent.
- Supports selection and hover feedback without turning those effects into authored website changes.
- Executes DOM queries on behalf of the parent (reading text content, computing bounding boxes, enumerating elements).
- Applies patch projections so the user sees the effect of their edits in real time.
- Reports scroll position and viewport dimensions for overlay alignment.
Applying a projection necessarily changes the live DOM. That is different from accepting a persistent edit. The bridge handles browser-level work, while the editing state and persistence boundaries determine which changes belong to the website and its history.
A successful visual update is therefore only part of the operation. Target validation, accepted state, and the corresponding projection must agree before the editor can treat the result as complete.
Stable identity makes structured editing possible
A visual editor that records changes as "replace the innerHTML of the node at this DOM path" is fragile.
Paths break when sections are reordered. Indexes shift when repeater items are added. Query selectors match different elements when the page structure changes for responsive layouts.
StackLiberate retains stable identities for editable surfaces. Attributes such as data-sl-id connect physical elements to their logical targets. Identity is not defined by the element's current position, and an identifier alone does not grant permission to edit it.
An accepted change must address the appropriate target and its supported capabilities. If a target is missing or incompatible, selecting a different node by a convenient fallback is not a substitute for validating the operation.
This means:
- Reconstruction retains the identities used by accepted changes.
- Moving an unrelated section does not redefine an element's identity.
- Duplicated items receive distinct identities rather than sharing their source's targets.
- Restore checks changes against the source and resources associated with the saved version.
- Output generation uses validated targets rather than inferring intent from visible text.
Stable identity supports structured editing; it is not a security boundary by itself. What a target allows is determined separately from whether an element carries an editing attribute.
Accepted operations and projected patches have different roles
A user action is accepted as a structured operation with a defined target, supported payload, and expected prior state. One operation can affect several parts of a document: duplicating a card may create text, images, links, and icon targets together.
Patches remain useful as derived instructions for updating a document. They are not, by themselves, the complete authoritative record. A single accepted action can produce several projection steps while remaining one unit of Undo.
The distinction is:
- Intent: the supported change the user is requesting.
- Accepted operation: the validated change retained as part of the website's ordered state.
- Projection: the document updates needed to present that state in a particular context.
The starting document remains separate from later edits. Reconstructing the authored website requires its accepted changes and the resources needed to interpret them:
validated starting document + ordered, accepted changes + required resources → authored state → context-specific document projectionThis has several consequences that matter for portability:
Chronological reconstruction. Each operation is evaluated against the state produced by earlier accepted operations, rather than against an unrelated final layout.
Non-destructive editing. Undo, Redo, and version restore operate on retained state. They do not require guessing what a previously rendered page meant, and they do not expose arbitrary rearrangement of the operation history as a user feature.
Bounded changes. Runtime validation checks what a target allows and what the requested operation can express. Static types help developers, but they do not replace validation of incoming requests or content.
Export independence. Server-side materialization reconstructs confirmed state and packages its resources. It does not need to inspect a running editor canvas.
Validation protects state and delivery boundaries
A well-formed message is not necessarily a valid edit. User input may contain unsupported content, address an unavailable target, or describe a change based on a state that is no longer current.
Validation needs to answer several separate questions:
- Request validity: is the requested operation supported, and is its payload well formed?
- Editing authority: does the current user have access, and does this target permit the change?
- State validity: do the expected prior state and the complete resulting candidate satisfy the operation's rules?
- Delivery readiness: can the confirmed website and its required resources be materialized safely for the requested output?
These are responsibilities across different boundaries, not one universal sanitization pass. Rejecting an invalid state transition is different from cleaning a fragment or removing editing instrumentation from an output file.
The goal is to accept only supported changes and report failures rather than silently constructing a different website. Tests of invalid input, stale state, reconstruction, and delivery are needed alongside those checks.
The editor sees a projection, not the truth
What the user sees in the editing canvas is not identical to what will be exported.
The editor view includes:
- Selection highlights on the currently targeted element.
- Hover indicators showing available edit targets.
- The bridge script itself.
- Projections of local changes that may not yet be confirmed on the server.
- Resource delivery addresses appropriate to the editing session.
The exported website includes none of those things.
This difference is intentional. Editing feedback belongs to the canvas, not to the authored website. An editor displaying newer local changes must also be distinguished from an export of the last confirmed revision; comparing those two states is not an output-parity test.
The parity contract is:
For the same confirmed revision, projections should preserve authored content, structure, design, resource identity, navigation, section order, and visibility.
Editing instrumentation and transient selection state are excluded. Intentional delivery differences, such as an accordion starting closed for visitors, should preserve the underlying content. Structural and browser tests verify the relevant results; a shared model alone does not prove equivalence.
Why this matters for portability
The exported website does not require the editor's bridge, selection tools, or application runtime. Those are removed from the delivered artifact.
That does not mean removing the website's own behavior. Public scripts for supported menus and interactions remain. A map can still use an iframe, and a form can still use an external destination. Portability means independence from the editor, not the absence of JavaScript or external services.
The export pipeline materializes confirmed authored state on the server, verifies required packaged resources, rewrites portable references, and writes static files. Standard HTML, CSS, JavaScript, and media can then be delivered by a compatible host without the visual editor running.
This makes portability a requirement of capability design rather than a cleanup task left until download time. A complete feature needs valid editing operations, durable reconstruction, and the relevant preview and output behavior.
The architecture supplies common boundaries; regression tests check that they continue to agree as capabilities evolve.
That discipline is the cost of building a visual editor that does not become part of the website it edits.