v0.6.22

Rendering Pipeline

Last updated


This page walks through the steps a render takes from template to real DOM, and the order in which patches are applied.

Initialization


StepBehavior
1Resolve the element by id; with no id but a render function, create a detached <section class="QUIFragment">
2Clone the element as the original template and build the first vDOM from the unprocessed template as the diff baseline
3When render is given, replace the template content with its output
4Load i18n (string values are fetched); only then are app.data, app.event and app.body assigned
5Enable the SVG and lazyload listeners according to option, create the Lifecycle and run the initial render

If the element is missing, or neither id nor render is given, an error is logged to the console and the instance renders nothing.

Each Render


StageBehavior
Rebuild vDOMBuild a new vDOM from a copy of the original template, using a JSON.parse(JSON.stringify(app.data)) snapshot as data
Expand directivesProcess :for → :if → <temp :path>, then run :for and :if again on content inserted by :path
Replace textReplace {{ i18n.* }} first, then every other {{ }}
DiffCompare the old and new vDOM child by child using indexes, producing patches
ApplyApply the patches inside requestAnimationFrame, then strip leftover :if attributes and handle Render Effects

Patch Types


TypeTriggerAction
REMOVEThe new tree has no node at that positionRemoved from the deepest, last position first so indexes do not shift
CREATEThe old tree has no nodeCreate the element and append it to the parent
APPENDThe number of children growsInsert at the matching index
REPLACEThe tag name differs at the same positionReplace with the new element
PROPEvery attribute of every new nodeDispatched by prefix to attribute, event or form handling
TEXTThe text differs at the same positionOverwrite the text content

REMOVE patches always run before every other patch.

Edge Cases


SituationResult
Inserting at the front of a listDiffing has no keys and aligns by index, so every item after the insertion point receives patches
<script> inside a templateMoved to <head> while the vDOM is built; skipped when an existing <script> has the same src or content
Values the snapshot cannot serializeFunctions, Date, Map and similar values are not available in templates; convert them to strings or numbers first
中文