@@ -35,9 +35,29 @@ export const enum StringifyThresholds {
35
35
36
36
type StringiableNode = PlainElementNode | TextCallNode
37
37
38
- // Turn eligible hoisted static trees into stringied static nodes, e.g.
39
- // const _hoisted_1 = createStaticVNode(`<div class="foo">bar</div>`)
40
- // This is only performed in non-in-browser compilations.
38
+ /**
39
+ * Turn eligible hoisted static trees into stringied static nodes, e.g.
40
+ *
41
+ * ```js
42
+ * const _hoisted_1 = createStaticVNode(`<div class="foo">bar</div>`)
43
+ * ```
44
+ *
45
+ * A single static vnode can contain stringified content for **multiple**
46
+ * consecutive nodes (element and plain text), called a "chunk".
47
+ * `@vue/runtime-dom` will create the content via innerHTML in a hidden
48
+ * container element and insert all the nodes in place. The call must also
49
+ * provide the number of nodes contained in the chunk so that during hydration
50
+ * we can know how many nodes the static vnode should adopt.
51
+ *
52
+ * The optimization scans a children list that contains hoisted nodes, and
53
+ * tries to find the largest chunk of consecutive hoisted nodes before running
54
+ * into a non-hoisted node or the end of the list. A chunk is then converted
55
+ * into a single static vnode and replaces the hoisted expression of the first
56
+ * node in the chunk. Other nodes in the chunk are considered "merged" and
57
+ * therefore removed from both the hoist list and the children array.
58
+ *
59
+ * This optimization is only performed in Node.js.
60
+ */
41
61
export const stringifyStatic : HoistTransform = ( children , context ) => {
42
62
let nc = 0 // current node count
43
63
let ec = 0 // current element with binding count
0 commit comments