liveBook · Manning

Rendering

As explained in Vanilla Web

Rendering is the process of producing visible interface content from application data, state, or route information.

Rendering turns application state or a matched route into visible DOM content. Keep the contract explicit: inputs and events update state; a render function reads that state and updates the interface. Nothing observes ordinary state changes automatically, so the application must call—or schedule—the render. section 13.2.2 section 13.2.3

Render a filtered product list

An input handler reads a search form into state, then schedules a render. The render computes matching products from the current query and availability flag, writes the match count, and replaces the list with DOM nodes for those products. Keep the full product collection as source state; compute the visible list when rendering rather than storing a second list that can drift out of sync. section 13.2.3 section 13.5

If one event changes several state properties, schedule one render instead of rendering after every assignment. A queueMicrotask() callback can batch those synchronous changes; a flag prevents duplicate scheduled passes. For small views, this explicit pattern may be enough. Shared state or finer-grained updates can justify a store, Proxy, or signals, but each adds machinery. section 13.2.3 section 13.2.10

Listing 13.1 Batching renders so several state writes collapse into one pass
let renderQueued = false;

function scheduleRender() {
  if (renderQueued) return;
  renderQueued = true;

  queueMicrotask(() => {
    renderQueued = false;
    render();
  });
}

A guarded scheduler collapses several state writes into one render pass. section 13.2.3

Route rendering has a separate boundary: match the URL, obtain the route’s view, and place it in an outlet. A small route handler can return a title and DOM node. The router then owns document metadata and browser cues such as active links, focus, and optional scroll handling. A first-pass router that only replaces the outlet and title does not yet provide all those behaviors. section 11.1 section 11.4.1

Keep input validation and parsing outside the render function: validate forms at the browser boundary, and normalize network or restored data before a view uses it. In a custom element, call a shared render method when it connects and when an observed attribute changes. Where presentation alone changes, reflecting state into an attribute can let CSS handle the visual update. section 13.4 section 7.9.3 section 13.2.10

How Vanilla Web covers it

How deep it goes
Works through explicit render functions, derived values, batching, and route outlets; treats stores, proxies, and signals as optional alternatives.
Examples
Uses a quantity subtotal, a filtered product list, and a function-based router with a DOM outlet.
What it assumes
Assumes basic JavaScript, DOM, and event handling while developing state-to-DOM binding without a framework runtime.
What you can do after
Build it from scratch with DOM APIs and queueMicrotask() to keep small interactive views synchronized with state.
How it connects
Connects rendering to data binding, derived state, routing, form validation, custom elements, and CSS selectors.

Also explained in

Compare how 6 books explain rendering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.