liveBook · Manning

DOM patching

As explained in Build a Frontend Web Framework (From Scratch)

The recursive process of applying differences between interface representations to the browser's DOM.

DOM patching updates the browser’s view after an interaction by changing only the HTML parts affected by application-state changes. A single DOM change is a patch. Minimizing patches matters because browser updates can trigger repaint and reflow. section 1.3.2

The process connects four practical responsibilities:

  • Handle the browser event with application-defined event-handling code. section 1.3.2
  • Update the application state and determine the resulting view. section 1.3.2
  • Compare the current representation with the desired one when using a virtual DOM. section 1.3.2
  • Apply only the necessary changes to the browser’s DOM. section 1.3.2

A small DOM update

JavaScript can create a paragraph, assign its text, and append it to the document. After an interaction changes the desired view, patching applies the corresponding update instead of rebuilding unrelated HTML. section 1.3.2

Figure 1.8 SPA handling user interactions
figure

Trace the SPA flow from a browser interaction through event handling and view updates. section 1.3.2

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Defines patches and explains selective updates, but stops short of a framework-specific patching algorithm.
Examples
Uses a programmatically created paragraph and an interaction-driven SPA view update.
What it assumes
Assumes basic browser DOM, JavaScript event handling, and application-state concepts.
What you can do after
Evaluate why frameworks minimize DOM changes and distinguish virtual-DOM and compilation-time update strategies.
How it connects
Connects DOM patching with single-page applications, virtual DOMs, browser events, application state, repaint, and reflow.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.