Skip to content

Commit 15c7e5a

Browse files
committed
chore: fix test
1 parent a0ae1fa commit 15c7e5a

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

packages/runtime-core/__tests__/components/Teleport.spec.ts

+17-24
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import {
77
Text,
88
ref,
99
nextTick,
10-
openBlock,
11-
createBlock
10+
markRaw
1211
} from '@vue/runtime-test'
1312
import { createVNode, Fragment } from '../../src/vnode'
14-
import { PatchFlags } from '@vue/shared'
13+
import { compile } from 'vue'
1514

1615
describe('renderer: teleport', () => {
1716
test('should work', () => {
@@ -309,37 +308,31 @@ describe('renderer: teleport', () => {
309308
const disabled = ref(false)
310309

311310
const App = {
312-
render() {
313-
return (
314-
openBlock(),
315-
createBlock(
316-
Fragment,
317-
null,
318-
[
319-
h(
320-
Teleport,
321-
{ to: target, disabled: disabled.value },
322-
h('div', 'teleported')
323-
),
324-
h('div', 'root')
325-
],
326-
PatchFlags.STABLE_FRAGMENT
327-
)
328-
)
329-
}
311+
setup() {
312+
return {
313+
target: markRaw(target),
314+
disabled
315+
}
316+
},
317+
render: compile(`
318+
<teleport :to="target" :disabled="disabled">
319+
<div>teleported</div><span>{{ disabled }}</span>
320+
</teleport>
321+
<div>root</div>
322+
`)
330323
}
331324
render(h(App), root)
332325
expect(serializeInner(root)).toMatchInlineSnapshot(
333326
`"<!--teleport start--><!--teleport end--><div>root</div>"`
334327
)
335328
expect(serializeInner(target)).toMatchInlineSnapshot(
336-
`"<div>teleported</div>"`
329+
`"<div>teleported</div><span>false</span>"`
337330
)
338331

339332
disabled.value = true
340333
await nextTick()
341334
expect(serializeInner(root)).toMatchInlineSnapshot(
342-
`"<!--teleport start--><div>teleported</div><!--teleport end--><div>root</div>"`
335+
`"<!--teleport start--><div>teleported</div><span>true</span><!--teleport end--><div>root</div>"`
343336
)
344337
expect(serializeInner(target)).toBe(``)
345338

@@ -350,7 +343,7 @@ describe('renderer: teleport', () => {
350343
`"<!--teleport start--><!--teleport end--><div>root</div>"`
351344
)
352345
expect(serializeInner(target)).toMatchInlineSnapshot(
353-
`"<div>teleported</div>"`
346+
`"<div>teleported</div><span>false</span>"`
354347
)
355348
})
356349
})

packages/runtime-core/src/components/Teleport.ts

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ export const TeleportImpl = {
139139
parentSuspense,
140140
isSVG
141141
)
142+
if (n2.patchFlag > 0 && n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
143+
const oldChildren = n1.children as VNode[]
144+
const children = n2.children as VNode[]
145+
for (let i = 0; i < children.length; i++) {
146+
children[i].el = oldChildren[i].el
147+
}
148+
}
142149
} else if (!optimized) {
143150
patchChildren(
144151
n1,

0 commit comments

Comments
 (0)