Skip to content

Commit 09de814

Browse files
committed
wip: update
1 parent e5399c3 commit 09de814

File tree

5 files changed

+91
-27
lines changed

5 files changed

+91
-27
lines changed

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

+65-4
Original file line numberDiff line numberDiff line change
@@ -1963,8 +1963,56 @@ describe('Vapor Mode hydration', () => {
19631963
data,
19641964
)
19651965

1966-
expect(container.innerHTML).toMatchInlineSnapshot(
1967-
`"<div><!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->hi</div>"`,
1966+
expect(container.innerHTML).toBe(
1967+
`<div>` +
1968+
`<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
1969+
`hi` +
1970+
`</div>`,
1971+
)
1972+
1973+
data.msg = 'bar'
1974+
await nextTick()
1975+
expect(container.innerHTML).toBe(
1976+
`<div>` +
1977+
`<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
1978+
`bar` +
1979+
`</div>`,
1980+
)
1981+
})
1982+
1983+
test('mixed root slot and text node', async () => {
1984+
const data = reactive({
1985+
text: 'foo',
1986+
msg: 'hi',
1987+
})
1988+
const { container } = await testHydration(
1989+
`<template>
1990+
<components.Child>
1991+
<span>{{data.text}}</span>
1992+
</components.Child>
1993+
</template>`,
1994+
{
1995+
Child: `<template>{{data.text}}<slot/>{{data.msg}}</template>`,
1996+
},
1997+
data,
1998+
)
1999+
2000+
expect(container.innerHTML).toBe(
2001+
`<!--[-->` +
2002+
`foo` +
2003+
`<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
2004+
`hi` +
2005+
`<!--]-->`,
2006+
)
2007+
2008+
data.msg = 'bar'
2009+
await nextTick()
2010+
expect(container.innerHTML).toBe(
2011+
`<!--[-->` +
2012+
`foo` +
2013+
`<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
2014+
`bar` +
2015+
`<!--]-->`,
19682016
)
19692017
})
19702018

@@ -1985,8 +2033,20 @@ describe('Vapor Mode hydration', () => {
19852033
data,
19862034
)
19872035

1988-
expect(container.innerHTML).toMatchInlineSnapshot(
1989-
`"<div><!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}--><div>hi</div></div>"`,
2036+
expect(container.innerHTML).toBe(
2037+
`<div>` +
2038+
`<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
2039+
`<div>hi</div>` +
2040+
`</div>`,
2041+
)
2042+
2043+
data.msg = 'bar'
2044+
await nextTick()
2045+
expect(container.innerHTML).toBe(
2046+
`<div>` +
2047+
`<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
2048+
`<div>bar</div>` +
2049+
`</div>`,
19902050
)
19912051
})
19922052

@@ -2024,6 +2084,7 @@ describe('Vapor Mode hydration', () => {
20242084
`<div>bar</div>` +
20252085
`</div>`,
20262086
)
2087+
20272088
data.msg2 = 'hello'
20282089
await nextTick()
20292090
expect(container.innerHTML).toBe(

packages/runtime-vapor/src/apiCreateDynamicComponent.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export function createDynamicComponent(
2222
const _insertionAnchor = insertionAnchor
2323
if (!isHydrating) resetInsertionState()
2424

25-
const frag = new DynamicFragment(DYNAMIC_COMPONENT_ANCHOR_LABEL)
25+
const frag =
26+
isHydrating || __DEV__
27+
? new DynamicFragment(DYNAMIC_COMPONENT_ANCHOR_LABEL)
28+
: new DynamicFragment()
2629
renderEffect(() => {
2730
const value = getter()
2831
frag.update(

packages/runtime-vapor/src/apiCreateIf.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export function createIf(
2222
if (once) {
2323
frag = condition() ? b1() : b2 ? b2() : []
2424
} else {
25-
frag = new DynamicFragment(IF_ANCHOR_LABEL)
25+
frag =
26+
isHydrating || __DEV__
27+
? new DynamicFragment(IF_ANCHOR_LABEL)
28+
: new DynamicFragment()
2629
renderEffect(() => (frag as DynamicFragment).update(condition() ? b1 : b2))
2730
}
2831

packages/runtime-vapor/src/componentSlots.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ export function createSlot(
124124
fallback,
125125
)
126126
} else {
127-
fragment = new DynamicFragment(SLOT_ANCHOR_LABEL)
127+
fragment =
128+
isHydrating || __DEV__
129+
? new DynamicFragment(SLOT_ANCHOR_LABEL)
130+
: new DynamicFragment()
128131
const isDynamicName = isFunction(name)
129132
const renderSlot = () => {
130133
const slot = getSlot(rawSlots, isFunction(name) ? name() : name)

packages/runtime-vapor/src/dom/node.ts

+14-20
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,19 @@ function _next(node: Node): Node {
7979

8080
/*! #__NO_SIDE_EFFECTS__ */
8181
export function __next(node: Node): Node {
82-
node = handleWrappedNode(node)
82+
// process dynamic node (<!--[[-->...<!--]]-->) as a single node
83+
if (isComment(node, DYNAMIC_START_ANCHOR_LABEL)) {
84+
node = locateEndAnchor(
85+
node,
86+
DYNAMIC_START_ANCHOR_LABEL,
87+
DYNAMIC_END_ANCHOR_LABEL,
88+
)!
89+
}
90+
91+
// process fragment (<!--[-->...<!--]-->) as a single node
92+
else if (isComment(node, '[')) {
93+
node = locateEndAnchor(node)!
94+
}
8395

8496
let n = node.nextSibling!
8597
while (n && isNonHydrationNode(n)) {
@@ -145,7 +157,7 @@ export function disableHydrationNodeLookup(): void {
145157

146158
function isNonHydrationNode(node: Node) {
147159
return (
148-
// empty text nodes, no need to hydrate
160+
// empty text nodes
149161
isEmptyText(node) ||
150162
// dynamic node anchors (<!--[[-->, <!--]]-->)
151163
isDynamicAnchor(node) ||
@@ -168,21 +180,3 @@ export function findVaporFragmentAnchor(
168180

169181
return null
170182
}
171-
172-
function handleWrappedNode(node: Node): Node {
173-
// process dynamic node (<!--[[-->...<!--]]-->) as a single one
174-
if (isComment(node, DYNAMIC_START_ANCHOR_LABEL)) {
175-
return locateEndAnchor(
176-
node,
177-
DYNAMIC_START_ANCHOR_LABEL,
178-
DYNAMIC_END_ANCHOR_LABEL,
179-
)!
180-
}
181-
182-
// process fragment (<!--[-->...<!--]-->) as a single one
183-
else if (isComment(node, '[')) {
184-
return locateEndAnchor(node)!
185-
}
186-
187-
return node
188-
}

0 commit comments

Comments
 (0)