Skip to content

Commit b0852aa

Browse files
committed
chore: dont process text/comment node as dynamic
1 parent 25b8fbe commit b0852aa

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

packages/compiler-ssr/src/ssrCodegenTransform.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ export function processChildren(
169169
const { children } = parent
170170
for (let i = 0; i < children.length; i++) {
171171
const child = children[i]
172-
if (shouldProcessAsDynamic(parent, child)) {
172+
if (
173+
child.type !== NodeTypes.TEXT &&
174+
child.type !== NodeTypes.COMMENT &&
175+
shouldProcessAsDynamic(parent, child)
176+
) {
173177
processChildren(
174178
{ children: [child] },
175179
context,
@@ -269,7 +273,7 @@ export function processChildrenAsStatement(
269273
return createBlockStatement(childContext.body)
270274
}
271275

272-
const isStaticElement = (c: TemplateChildNode): boolean =>
276+
const isStaticChildNode = (c: TemplateChildNode): boolean =>
273277
c.type === NodeTypes.ELEMENT && c.tagType !== ElementTypes.COMPONENT
274278

275279
/**
@@ -289,7 +293,7 @@ function shouldProcessAsDynamic(
289293
node: TemplateChildNode,
290294
): boolean {
291295
// 1. Must be a dynamic node type
292-
if (isStaticElement(node)) return false
296+
if (isStaticChildNode(node)) return false
293297
// 2. Must be inside a parent element
294298
if (!parent.tag) return false
295299

@@ -301,7 +305,7 @@ function shouldProcessAsDynamic(
301305
let hasStaticPreviousSibling = false
302306
if (index > 0) {
303307
for (let i = index - 1; i >= 0; i--) {
304-
if (isStaticElement(children[i])) {
308+
if (isStaticChildNode(children[i])) {
305309
hasStaticPreviousSibling = true
306310
break
307311
}
@@ -313,7 +317,7 @@ function shouldProcessAsDynamic(
313317
let hasStaticNextSibling = false
314318
if (index > -1 && index < len - 1) {
315319
for (let i = index + 1; i < len; i++) {
316-
if (isStaticElement(children[i])) {
320+
if (isStaticChildNode(children[i])) {
317321
hasStaticNextSibling = true
318322
break
319323
}
@@ -323,13 +327,13 @@ function shouldProcessAsDynamic(
323327

324328
// 5. Check for a consecutive dynamic sibling (immediately before or after)
325329
let hasConsecutiveDynamicNodes = false
326-
if (index > 0 && !isStaticElement(children[index - 1])) {
330+
if (index > 0 && !isStaticChildNode(children[index - 1])) {
327331
hasConsecutiveDynamicNodes = true
328332
}
329333
if (
330334
!hasConsecutiveDynamicNodes &&
331335
index < len - 1 &&
332-
!isStaticElement(children[index + 1])
336+
!isStaticChildNode(children[index + 1])
333337
) {
334338
hasConsecutiveDynamicNodes = true
335339
}

packages/runtime-core/src/hydration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function createHydrationFunctions(
125125

126126
function nextSibling(node: Node) {
127127
let n = next(node)
128-
// skip dynamic child anchor
128+
// skip dynamic anchors
129129
if (n && isDynamicAnchor(n)) {
130130
n = next(n)
131131
}

packages/runtime-vapor/__tests__/hydration.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ describe('Vapor Mode hydration', () => {
334334
},
335335
)
336336
expect(container.innerHTML).toMatchInlineSnapshot(
337-
`"<div><span></span><!--[[-->foo<!--]]--><!--[[--> <!--]]--><!--[[--> foo <!--]]--><!--[[--> <!--]]--><!--[[-->foo<!--]]--><span></span></div>"`,
337+
`"<div><span></span><!--[[-->foo<!--]]--> <!--[[--> foo <!--]]--> <!--[[-->foo<!--]]--><span></span></div>"`,
338338
)
339339

340340
data.value = 'bar'
341341
await nextTick()
342342
expect(container.innerHTML).toMatchInlineSnapshot(
343-
`"<div><span></span><!--[[-->bar<!--]]--><!--[[--> <!--]]--><!--[[--> bar <!--]]--><!--[[--> <!--]]--><!--[[-->bar<!--]]--><span></span></div>"`,
343+
`"<div><span></span><!--[[-->bar<!--]]--> <!--[[--> bar <!--]]--> <!--[[-->bar<!--]]--><span></span></div>"`,
344344
)
345345
})
346346

@@ -439,13 +439,13 @@ describe('Vapor Mode hydration', () => {
439439
},
440440
)
441441
expect(container.innerHTML).toMatchInlineSnapshot(
442-
`"<div><span></span><!--[[--><!--[--><div>foo</div>-foo<!--]--><!--]]--><!--[[--> <!--]]--><!--[[--> foo <!--]]--><!--[[--> <!--]]--><!--[[--><!--[--><div>foo</div>-foo<!--]--><!--]]--><span></span></div>"`,
442+
`"<div><span></span><!--[[--><!--[--><div>foo</div>-foo<!--]--><!--]]--> <!--[[--> foo <!--]]--> <!--[[--><!--[--><div>foo</div>-foo<!--]--><!--]]--><span></span></div>"`,
443443
)
444444

445445
data.value = 'bar'
446446
await nextTick()
447447
expect(container.innerHTML).toMatchInlineSnapshot(
448-
`"<div><span></span><!--[[--><!--[--><div>bar</div>-bar<!--]--><!--]]--><!--[[--> <!--]]--><!--[[--> bar <!--]]--><!--[[--> <!--]]--><!--[[--><!--[--><div>bar</div>-bar<!--]--><!--]]--><span></span></div>"`,
448+
`"<div><span></span><!--[[--><!--[--><div>bar</div>-bar<!--]--><!--]]--> <!--[[--> bar <!--]]--> <!--[[--><!--[--><div>bar</div>-bar<!--]--><!--]]--><span></span></div>"`,
449449
)
450450
})
451451

0 commit comments

Comments
 (0)