Skip to content
Anjunar/ DOCS

Rendering and hydration

Ember has no renderer of its own. DocumentView projects the document onto the scalajs-ui component tree, on the server into HTML and in the browser onto the delivered page.

View

A keyed projection

Every container gets keyed children by NodeId. An unchanged node is not touched, and typing writes exactly one characterData mutation.

scala
val view = DocumentView.mount(session, cursor, TableSupport.views, parent = Some(host)) view.projectedRevision // what is shown right now view.onProjected(revision => ...) // after each projection view.dispose()
Server

The same call, another cursor

Inside a server-rendered page, mount the view under the page's cursor as usual. For output without a page, renderToHtml takes a Document, not a session: no selection, history or focus.

scala
DocumentView.mount(session, Runtime.contentCursor(host), TableSupport.views, parent = Some(host)) if cursor.isBrowser then val element = DomNodes.raw(host.host).asInstanceOf[dom.HTMLElement] val selection = SelectionPort.detached(session, view, element) val input = BrowserInputController.detached(session, view, selection, EditorBindings.everything, EditorBindings.everythingKeyboard, TabPolicy.LeavesEditor, EditorMode.Editable, None, BusyPolicy.Defer) cursor.afterHydration { () => selection.attach() input.attach() }

The live editors on these pages are built exactly this way: rendered with the page, then attached after hydration has claimed the markup.

Activation

Editable only when it is safe

Before the first claim, hydration captures what the user may already have typed. Editing begins only when the page is hydrated and no input session could be running.

Active
Editable.
Deferred(PageHydrating)
The page around the editor is still hydrating.
Deferred(InputSession)
An input session is open, or might be.
Deferred(UnimportedSource)
The source text changed since it was rendered.
Failed
The local claim failed; nothing is coming.