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





