Skip to content

Commit 76a1196

Browse files
committed
feat(runtime): support rendering comment nodes
1 parent f5b3f58 commit 76a1196

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

packages/runtime-core/src/componentRenderUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
FunctionalComponent,
44
Data
55
} from './component'
6-
import { VNode, normalizeVNode, createVNode, Empty } from './vnode'
6+
import { VNode, normalizeVNode, createVNode, Comment } from './vnode'
77
import { ShapeFlags } from './shapeFlags'
88
import { handleError, ErrorCodes } from './errorHandling'
99
import { PatchFlags } from './patchFlags'
@@ -45,7 +45,7 @@ export function renderComponentRoot(
4545
}
4646
} catch (err) {
4747
handleError(err, instance, ErrorCodes.RENDER_FUNCTION)
48-
result = createVNode(Empty)
48+
result = createVNode(Comment)
4949
}
5050
currentRenderingInstance = null
5151
return result

packages/runtime-core/src/createRenderer.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Text,
33
Fragment,
4-
Empty,
4+
Comment,
55
Portal,
66
normalizeVNode,
77
VNode,
@@ -191,8 +191,8 @@ export function createRenderer<
191191
case Text:
192192
processText(n1, n2, container, anchor)
193193
break
194-
case Empty:
195-
processEmptyNode(n1, n2, container, anchor)
194+
case Comment:
195+
processCommentNode(n1, n2, container, anchor)
196196
break
197197
case Fragment:
198198
processFragment(
@@ -283,15 +283,20 @@ export function createRenderer<
283283
}
284284
}
285285

286-
function processEmptyNode(
286+
function processCommentNode(
287287
n1: HostVNode | null,
288288
n2: HostVNode,
289289
container: HostElement,
290290
anchor: HostNode | null
291291
) {
292292
if (n1 == null) {
293-
hostInsert((n2.el = hostCreateComment('')), container, anchor)
293+
hostInsert(
294+
(n2.el = hostCreateComment((n2.children as string) || '')),
295+
container,
296+
anchor
297+
)
294298
} else {
299+
// there's no support for dynamic comments
295300
n2.el = n1.el
296301
}
297302
}
@@ -677,7 +682,7 @@ export function createRenderer<
677682
}
678683
}
679684
// insert an empty node as the placeholder for the portal
680-
processEmptyNode(n1, n2, container, anchor)
685+
processCommentNode(n1, n2, container, anchor)
681686
}
682687

683688
function processSuspense(
@@ -1057,8 +1062,8 @@ export function createRenderer<
10571062
})
10581063

10591064
// give it a placeholder
1060-
const placeholder = (instance.subTree = createVNode(Empty))
1061-
processEmptyNode(null, placeholder, container, anchor)
1065+
const placeholder = (instance.subTree = createVNode(Comment))
1066+
processCommentNode(null, placeholder, container, anchor)
10621067
initialVNode.el = placeholder.el
10631068
return
10641069
}

packages/runtime-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export {
1919
createBlock
2020
} from './vnode'
2121
// VNode type symbols
22-
export { Text, Empty, Fragment, Portal, Suspense } from './vnode'
22+
export { Text, Comment, Fragment, Portal, Suspense } from './vnode'
2323
// VNode flags
2424
export { PublicPatchFlags as PatchFlags } from './patchFlags'
2525
export { PublicShapeFlags as ShapeFlags } from './shapeFlags'

packages/runtime-core/src/vnode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { SuspenseBoundary } from './suspense'
1616

1717
export const Fragment = __DEV__ ? Symbol('Fragment') : Symbol()
1818
export const Text = __DEV__ ? Symbol('Text') : Symbol()
19-
export const Empty = __DEV__ ? Symbol('Empty') : Symbol()
19+
export const Comment = __DEV__ ? Symbol('Empty') : Symbol()
2020
export const Portal = __DEV__ ? Symbol('Portal') : Symbol()
2121
export const Suspense = __DEV__ ? Symbol('Suspense') : Symbol()
2222

@@ -27,7 +27,7 @@ export type VNodeTypes =
2727
| typeof Fragment
2828
| typeof Portal
2929
| typeof Text
30-
| typeof Empty
30+
| typeof Comment
3131
| typeof Suspense
3232

3333
type VNodeChildAtom<HostNode, HostElement> =
@@ -245,7 +245,7 @@ export function cloneVNode(vnode: VNode): VNode {
245245
export function normalizeVNode(child: VNodeChild): VNode {
246246
if (child == null) {
247247
// empty placeholder
248-
return createVNode(Empty)
248+
return createVNode(Comment)
249249
} else if (isArray(child)) {
250250
// fragment
251251
return createVNode(Fragment, null, child)

0 commit comments

Comments
 (0)